Intermediate restructure

This commit is contained in:
norbert-walter 2022-02-13 16:37:12 +01:00
parent 33f2aac271
commit 10d6b3fa50
6 changed files with 143 additions and 102 deletions

View File

@ -0,0 +1,105 @@
#include <Arduino.h>
#include "OBP60Hardware.h"
#include "OBP60ExtensionPort.h"
MCP23017 mcp = MCP23017(MCP23017_I2C_ADDR);
// SPI pin definitions for E-Ink display
GxIO_Class io(SPI, OBP_SPI_CS, OBP_SPI_DC, OBP_SPI_RST); // SPI, CS, DC, RST
GxEPD_Class display(io, OBP_SPI_RST, OBP_SPI_BUSY); // io, RST, BUSY
// Global vars
int outA = 0; // Outport Byte A
int outB = 0; // Outport Byte B
bool blinkingLED = false; // Enable / disable blinking flash LED
int uvDuration = 0; // Under voltage duration in n x 100ms
void setPortPin(uint pin, bool value){
if(pin <=7){
outA &= ~(1 << pin); // Clear bit
outA |= (value << pin); // Set bit
mcp.writeRegister(MCP23017Register::GPIO_A, outA);
}
else{
pin = pin - 8;
outB &= ~(1 << pin); // Clear bit
outB |= (value << pin); // Set bit
mcp.writeRegister(MCP23017Register::GPIO_B, outB);
}
}
void togglePortPin(uint pin){
if(pin <=7){
outA ^= (1 << pin); // Set bit
mcp.writeRegister(MCP23017Register::GPIO_A, outA);
}
else{
pin = pin - 8;
outB ^= (1 << pin); // Set bit
mcp.writeRegister(MCP23017Register::GPIO_B, outB);
}
}
void blinkingFlashLED(){
noInterrupts();
if(blinkingLED == true){
togglePortPin(OBP_FLASH_LED);
}
else{
setPortPin(OBP_FLASH_LED, false);
}
interrupts();
}
void setBlinkingLED(bool on){
blinkingLED = on;
}
void buzzer(uint frequency, uint power, uint duration){
if(frequency > 8000){ // Max 8000Hz
frequency = 8000;
}
if(power > 100){ // Max 100%
power = 100;
}
if(duration > 1000){ // Max 1000ms
duration = 1000;
}
pinMode(OBP_BUZZER, OUTPUT);
ledcSetup(0, frequency, 8); // Ch 0, ferquency in Hz, 8 Bit resolution of PWM
ledcAttachPin(OBP_BUZZER, 0);
ledcWrite(0, int(power * 1.28)); // 50% duty cycle are 100%
delay(duration);
ledcWrite(0, 0); // 0% duty cycle are 0%
}
void underVoltageDetection(){
noInterrupts();
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20
if(actVoltage < MIN_VOLTAGE){
uvDuration ++;
}
else{
uvDuration = 0;
}
if(uvDuration > POWER_FAIL_TIME){
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
setPortPin(OBP_FLASH_LED, false); // Flash LED Off
buzzer(TONE4, buzPower, 20); // Buzzer tone 4kHz 20% 20ms
setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off
setPortPin(OBP_POWER_33, false); // Power rail 3.3V Off
// Shutdown EInk display
display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw white sreen
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, false); // Partial update
// display._sleep(); // Display shut dow
// Stop system
while(true){
esp_deep_sleep_start(); // Deep Sleep without weakup. Weakup only after power cycle (restart).
}
}
interrupts();
}

View File

@ -3,104 +3,28 @@
#include <Arduino.h>
#include "OBP60Hardware.h"
#include <MCP23017.h>
#include <GxGDEW042T2/GxGDEW042T2.h> // 4.2" Waveshare S/W 300 x 400 pixel
#include <GxIO/GxIO_SPI/GxIO_SPI.h> // GxEPD lip for SPI display communikation
#include <GxIO/GxIO.h> // GxEPD lip for SPI
MCP23017 mcp = MCP23017(MCP23017_I2C_ADDR);
extern MCP23017 mcp;
#define buzPower 50 // Buzzer loudness in [%]
// SPI pin definitions for E-Ink display
GxIO_Class io(SPI, OBP_SPI_CS, OBP_SPI_DC, OBP_SPI_RST); // SPI, CS, DC, RST
GxEPD_Class display(io, OBP_SPI_RST, OBP_SPI_BUSY); // io, RST, BUSY
extern GxIO_Class io;
extern GxEPD_Class display;
// Global vars
int outA = 0; // Outport Byte A
int outB = 0; // Outport Byte B
bool blinkingLED = false; // Enable / disable blinking flash LED
int uvDuration = 0; // Under voltage duration in n x 100ms
uint buzPower = 50; // Buzzer loudness in [%]
void setPortPin(uint pin, bool value);
void setPortPin(uint pin, bool value){
void togglePortPin(uint pin);
void blinkingFlashLED();
if(pin <=7){
void buzzer(uint frequency, uint power, uint duration);
outA &= ~(1 << pin); // Clear bit
void underVoltageDetection();
outA |= (value << pin); // Set bit
mcp.writeRegister(MCP23017Register::GPIO_A, outA);
}
else{
pin = pin - 8;
outB &= ~(1 << pin); // Clear bit
outB |= (value << pin); // Set bit
mcp.writeRegister(MCP23017Register::GPIO_B, outB);
}
}
void togglePortPin(uint pin){
if(pin <=7){
outA ^= (1 << pin); // Set bit
mcp.writeRegister(MCP23017Register::GPIO_A, outA);
}
else{
pin = pin - 8;
outB ^= (1 << pin); // Set bit
mcp.writeRegister(MCP23017Register::GPIO_B, outB);
}
}
void blinkingFlashLED(){
noInterrupts();
if(blinkingLED == true){
togglePortPin(OBP_FLASH_LED);
}
else{
setPortPin(OBP_FLASH_LED, false);
}
interrupts();
}
void buzzer(uint frequency, uint power, uint duration){
if(frequency > 8000){ // Max 8000Hz
frequency = 8000;
}
if(power > 100){ // Max 100%
power = 100;
}
if(duration > 1000){ // Max 1000ms
duration = 1000;
}
pinMode(OBP_BUZZER, OUTPUT);
ledcSetup(0, frequency, 8); // Ch 0, ferquency in Hz, 8 Bit resolution of PWM
ledcAttachPin(OBP_BUZZER, 0);
ledcWrite(0, int(power * 1.28)); // 50% duty cycle are 100%
delay(duration);
ledcWrite(0, 0); // 0% duty cycle are 0%
}
void underVoltageDetection(){
noInterrupts();
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20
if(actVoltage < MIN_VOLTAGE){
uvDuration ++;
}
else{
uvDuration = 0;
}
if(uvDuration > POWER_FAIL_TIME){
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
setPortPin(OBP_FLASH_LED, false); // Flash LED Off
buzzer(TONE4, buzPower, 20); // Buzzer tone 4kHz 20% 20ms
setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off
setPortPin(OBP_POWER_33, false); // Power rail 3.3V Off
// Shutdown EInk display
display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw white sreen
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, false); // Partial update
// display._sleep(); // Display shut dow
// Stop system
while(true){
esp_deep_sleep_start(); // Deep Sleep without weakup. Weakup only after power cycle (restart).
}
}
interrupts();
}
void setBlinkingLED(bool on);
#endif

View File

@ -28,14 +28,14 @@ long starttime = 0; // Start time point for pressed key
int readKeypad() {
int keystatus = 0; // Status of key [0...11], 0 = processed, 1...8 = key 1..8, 9 = right swipe , 10 = left swipe, 11 keys disabled
noInterrupts();
pinMode(TTP_SDO, INPUT);
pinMode(TTP_SCL, OUTPUT);
keycode = 0;
// Read key code from raw data
for (int i = 0; i < 9; i++) {
digitalWrite(TTP_SCL, LOW);
delay(0); // 0ms clock
// delay(1); // 0ms clock
delayMicroseconds(100);
keypad[i] = digitalRead(TTP_SDO);
if(i > 0){
// Invert keypad
@ -48,9 +48,9 @@ int readKeypad() {
keycode += key * i;
}
digitalWrite(TTP_SCL, HIGH);
delay(0); // 0ms clock
// delay(1); // 0ms clock
delayMicroseconds(100);
}
interrupts();
// Remapping keycode
keycode = keyposition[keycode];

View File

@ -9,9 +9,22 @@ public:
common.logger->logDebug(GwLog::LOG,"created PageApparentWind");
dummy=1;
}
virtual int handleKey(int key){
if(key == 3){
dummy++;
return 0; // Commit the key
}
return key;
}
virtual void display(CommonData &commonData, PageData &pageData)
{
GwLog *logger = commonData.logger;
GwConfigHandler *config = commonData.config;
String test = config->getString(config->lengthFormat);
dummy++;
for (int i = 0; i < 2; i++)
{

View File

@ -23,6 +23,7 @@ typedef struct{
OutputData output;
GwApi::Status status;
GwLog *logger=NULL;
GwConfigHandler *config=NULL;
} CommonData;
//a base class that all pages must inherit from

View File

@ -10,9 +10,6 @@
#include <NMEA0183Msg.h>
#include <NMEA0183Messages.h>
#include <GxEPD.h> // GxEPD lib for E-Ink displays
#include <GxGDEW042T2/GxGDEW042T2.h> // 4.2" Waveshare S/W 300 x 400 pixel
#include <GxIO/GxIO_SPI/GxIO_SPI.h> // GxEPD lip for SPI display communikation
#include <GxIO/GxIO.h> // GxEPD lip for SPI
#include "OBP60ExtensionPort.h" // Functions lib for extension board
#include "OBP60Keypad.h" // Functions for keypad
@ -120,10 +117,10 @@ void OBP60Init(GwApi *api){
String ledMode = api->getConfig()->getConfigItem(api->getConfig()->flashLED,true)->asString();
api->getLogger()->logDebug(GwLog::DEBUG,"Backlight Mode is: %s", ledMode);
if(String(ledMode) == "Off"){
blinkingLED = false;
setBlinkingLED(false);
}
if(String(ledMode) == "Limits Overrun"){
blinkingLED = true;
setBlinkingLED(true);
}
// Start serial stream and take over GPS data stream form internal GPS
@ -147,7 +144,7 @@ void OBP60Init(GwApi *api){
initComplete = true;
// Buzzer tone for initialization finish
buzPower = uint(api->getConfig()->getConfigItem(api->getConfig()->buzzerPower,true)->asInt());
//Todo buzPower = uint(api->getConfig()->getConfigItem(api->getConfig()->buzzerPower,true)->asInt());
buzzer(TONE4, buzPower, 500);
}
@ -311,6 +308,7 @@ void OBP60Task(GwApi *api){
PageStruct pages[MAX_PAGE_NUMBER];
CommonData commonData;
commonData.logger=logger;
commonData.config=config;
BoatValueList boatValues; //all the boat values for the api query
//commonData.distanceformat=config->getString(xxx);
//add all necessary data to common data
@ -359,7 +357,7 @@ void OBP60Task(GwApi *api){
allParameters.logger=api->getLogger();
allParameters.page0=3;
allParameters.queue=xQueueCreate(10,sizeof(int));
xTaskCreate(keyboardTask,"keyboard",2000,&allParameters,0,NULL);
xTaskCreate(keyboardTask,"keyboard",2000,&allParameters,configMAX_PRIORITIES-1,NULL);
// Task Loop