One value page working

This commit is contained in:
norbert-walter 2022-02-13 22:15:09 +01:00
parent 10d6b3fa50
commit 9f6aebe978
11 changed files with 155 additions and 62 deletions

View File

@ -2,6 +2,13 @@
#include "OBP60Hardware.h" #include "OBP60Hardware.h"
#include "OBP60ExtensionPort.h" #include "OBP60ExtensionPort.h"
#include "Ubuntu_Bold8pt7b.h"
#include "Ubuntu_Bold20pt7b.h"
#include "Ubuntu_Bold32pt7b.h"
#include "DSEG7Classic-BoldItalic16pt7b.h"
#include "DSEG7Classic-BoldItalic42pt7b.h"
#include "DSEG7Classic-BoldItalic60pt7b.h"
MCP23017 mcp = MCP23017(MCP23017_I2C_ADDR); MCP23017 mcp = MCP23017(MCP23017_I2C_ADDR);
// SPI pin definitions for E-Ink display // SPI pin definitions for E-Ink display
@ -14,6 +21,27 @@ int outB = 0; // Outport Byte B
bool blinkingLED = false; // Enable / disable blinking flash LED bool blinkingLED = false; // Enable / disable blinking flash LED
int uvDuration = 0; // Under voltage duration in n x 100ms int uvDuration = 0; // Under voltage duration in n x 100ms
void MCP23017Init()
{
mcp.init();
mcp.portMode(MCP23017Port::A, 0b00110000); // Port A, 0 = out, 1 = in
mcp.portMode(MCP23017Port::B, 0b11110000); // Port B, 0 = out, 1 = in
// Extension Port A set defaults
setPortPin(OBP_DIGITAL_OUT1, false); // PA0
setPortPin(OBP_DIGITAL_OUT2, false); // PA1
setPortPin(OBP_FLASH_LED, false); // PA2
setPortPin(OBP_BACKLIGHT_LED, false); // PA3
setPortPin(OBP_POWER_50, true); // PA6
setPortPin(OBP_POWER_33, true); // PA7
// Extension Port B set defaults
setPortPin(PB0, false); // PB0
setPortPin(PB1, false); // PB1
setPortPin(PB2, false); // PB2
setPortPin(PB3, false); // PB3
}
void setPortPin(uint pin, bool value){ void setPortPin(uint pin, bool value){
if(pin <=7){ if(pin <=7){
@ -58,12 +86,14 @@ void setBlinkingLED(bool on){
blinkingLED = on; blinkingLED = on;
} }
void buzzer(uint frequency, uint power, uint duration){ uint buzzerpower = 50;
void buzzer(uint frequency, uint duration){
if(frequency > 8000){ // Max 8000Hz if(frequency > 8000){ // Max 8000Hz
frequency = 8000; frequency = 8000;
} }
if(power > 100){ // Max 100% if(buzzerpower > 100){ // Max 100%
power = 100; buzzerpower = 100;
} }
if(duration > 1000){ // Max 1000ms if(duration > 1000){ // Max 1000ms
duration = 1000; duration = 1000;
@ -72,11 +102,15 @@ void buzzer(uint frequency, uint power, uint duration){
pinMode(OBP_BUZZER, OUTPUT); pinMode(OBP_BUZZER, OUTPUT);
ledcSetup(0, frequency, 8); // Ch 0, ferquency in Hz, 8 Bit resolution of PWM ledcSetup(0, frequency, 8); // Ch 0, ferquency in Hz, 8 Bit resolution of PWM
ledcAttachPin(OBP_BUZZER, 0); ledcAttachPin(OBP_BUZZER, 0);
ledcWrite(0, int(power * 1.28)); // 50% duty cycle are 100% ledcWrite(0, uint(buzzerpower * 1.28)); // 50% duty cycle are 100%
delay(duration); delay(duration);
ledcWrite(0, 0); // 0% duty cycle are 0% ledcWrite(0, 0); // 0% duty cycle are 0%
} }
void setBuzzerPower(uint power){
buzzerpower = power;
}
void underVoltageDetection(){ void underVoltageDetection(){
noInterrupts(); noInterrupts();
float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20 float actVoltage = (float(analogRead(OBP_ANALOG0)) * 3.3 / 4096 + 0.17) * 20; // Vin = 1/20
@ -89,7 +123,7 @@ void underVoltageDetection(){
if(uvDuration > POWER_FAIL_TIME){ if(uvDuration > POWER_FAIL_TIME){
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off setPortPin(OBP_BACKLIGHT_LED, false); // Backlight Off
setPortPin(OBP_FLASH_LED, false); // Flash LED Off setPortPin(OBP_FLASH_LED, false); // Flash LED Off
buzzer(TONE4, buzPower, 20); // Buzzer tone 4kHz 20% 20ms buzzer(TONE4, 20); // Buzzer tone 4kHz 20% 20ms
setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off setPortPin(OBP_POWER_50, false); // Power rail 5.0V Off
setPortPin(OBP_POWER_33, false); // Power rail 3.3V Off setPortPin(OBP_POWER_33, false); // Power rail 3.3V Off
// Shutdown EInk display // Shutdown EInk display

View File

@ -8,20 +8,25 @@
#include <GxIO/GxIO_SPI/GxIO_SPI.h> // GxEPD lip for SPI display communikation #include <GxIO/GxIO_SPI/GxIO_SPI.h> // GxEPD lip for SPI display communikation
#include <GxIO/GxIO.h> // GxEPD lip for SPI #include <GxIO/GxIO.h> // GxEPD lip for SPI
extern MCP23017 mcp; void MCP23017Init();
#define buzPower 50 // Buzzer loudness in [%]
// SPI pin definitions for E-Ink display // SPI pin definitions for E-Ink display
extern GxIO_Class io;
extern GxEPD_Class display; extern GxEPD_Class display;
extern const GFXfont Ubuntu_Bold8pt7b;
extern const GFXfont Ubuntu_Bold20pt7b;
extern const GFXfont Ubuntu_Bold32pt7b;
extern const GFXfont DSEG7Classic_BoldItalic16pt7b;
extern const GFXfont DSEG7Classic_BoldItalic42pt7b;
extern const GFXfont DSEG7Classic_BoldItalic60pt7b;
void setPortPin(uint pin, bool value); void setPortPin(uint pin, bool value);
void togglePortPin(uint pin); void togglePortPin(uint pin);
void blinkingFlashLED(); void blinkingFlashLED();
void buzzer(uint frequency, uint power, uint duration); void buzzer(uint frequency, uint duration);
void setBuzzerPower(uint power);
void underVoltageDetection(); void underVoltageDetection();

View File

@ -34,8 +34,8 @@
// Buzzer // Buzzer
#define OBP_BUZZER 19 #define OBP_BUZZER 19
#define TONE1 1500 // 1500Hz #define TONE1 1500 // 1500Hz
#define TONE2 2000 // 2000Hz #define TONE2 2500 // 2500Hz
#define TONE3 3000 // 3000Hz #define TONE3 3500 // 3500Hz
#define TONE4 4000 // 4000Hz #define TONE4 4000 // 4000Hz
// Analog Input // Analog Input
#define OBP_ANALOG0 34 // Voltage power supplay #define OBP_ANALOG0 34 // Voltage power supplay

View File

@ -86,7 +86,7 @@ int readKeypad() {
keycodeold = 0; keycodeold = 0;
keycode2 = 0; keycode2 = 0;
keycodeold2 = 0; keycodeold2 = 0;
buzzer(TONE4, buzPower, 100); buzzer(TONE4, 100);
keylock = false; keylock = false;
delay(keydelay); delay(keydelay);
} }
@ -98,7 +98,7 @@ int readKeypad() {
keycodeold = 0; keycodeold = 0;
keycode2 = 0; keycode2 = 0;
keycodeold2 = 0; keycodeold2 = 0;
buzzer(TONE4, buzPower, 1000); buzzer(TONE4, 1000);
keylock = false; keylock = false;
delay(keydelay); delay(keydelay);
@ -119,8 +119,8 @@ int readKeypad() {
keycode2 = 0; keycode2 = 0;
keycodeold2 = 0; keycodeold2 = 0;
keystatus = 9; keystatus = 9;
buzzer(TONE3, buzPower, 150); buzzer(TONE3, 150);
buzzer(TONE4, buzPower, 150); buzzer(TONE4, 150);
} }
// Detect swipe left // Detect swipe left
@ -131,8 +131,8 @@ int readKeypad() {
keycode2 = 0; keycode2 = 0;
keycodeold2 = 0; keycodeold2 = 0;
keystatus = 10; keystatus = 10;
buzzer(TONE4, buzPower, 150); buzzer(TONE4, 150);
buzzer(TONE3, buzPower, 150); buzzer(TONE3, 150);
} }
// Reset keylock after release // Reset keylock after release

View File

@ -1,4 +1,5 @@
#include "Pagedata.h" #include "Pagedata.h"
#include "OBP60ExtensionPort.h"
class PageApparentWind : public Page class PageApparentWind : public Page
{ {
@ -17,13 +18,14 @@ public:
return key; return key;
} }
virtual void display(CommonData &commonData, PageData &pageData) virtual void displayPage(CommonData &commonData, PageData &pageData)
{ {
GwLog *logger = commonData.logger; GwLog *logger = commonData.logger;
GwConfigHandler *config = commonData.config; GwConfigHandler *config = commonData.config;
String test = config->getString(config->lengthFormat); String test = config->getString(config->lengthFormat);
display.setFont(&Ubuntu_Bold8pt7b);
dummy++; dummy++;
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)

View File

@ -3,7 +3,7 @@
class PageForValues : public Page class PageForValues : public Page
{ {
public: public:
virtual void display(CommonData &commonData, PageData &pageData) virtual void displayPage(CommonData &commonData, PageData &pageData)
{ {
GwLog *logger = commonData.logger; GwLog *logger = commonData.logger;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)

View File

@ -1,15 +1,93 @@
#include "Pagedata.h" #include "Pagedata.h"
#include "OBP60ExtensionPort.h"
class PageOneValue : public Page{ class PageOneValue : public Page{
public: public:
virtual void display(CommonData &commonData, PageData &pageData){ virtual void displayPage(CommonData &commonData, PageData &pageData){
GwConfigHandler *config = commonData.config;
GwLog *logger=commonData.logger; GwLog *logger=commonData.logger;
// Get config data
String lengthformat = config->getString(config->lengthFormat);
bool simulation = config->getBool(config->useSimuData);
bool holdvalues = config->getBool(config->holdvalues);
// Get boat values
GwApi::BoatValue *value=pageData.values[0]; GwApi::BoatValue *value=pageData.values[0];
String name1 = value->getName().c_str();
double value1 = value->value;
bool valid1 = value->valid;
String format1 = value->getFormat().c_str();
// Logging boat values
if (value == NULL) return; if (value == NULL) return;
LOG_DEBUG(GwLog::LOG,"drawing at PageOneValue, p=%s,v=%f", LOG_DEBUG(GwLog::LOG,"drawing at PageOneValue, p=%s, v=%f", name1, value1);
value->getName().c_str(),
value->valid?value->value:-1.0 // Draw page
); //***********************************************************
// Clear display
display.fillRect(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, GxEPD_WHITE); // Draw white sreen
// Show name
display.setFont(&Ubuntu_Bold32pt7b);
display.setTextColor(GxEPD_BLACK);
display.setCursor(20, 100);
display.print(name1); // Page name
display.setFont(&Ubuntu_Bold20pt7b);
display.setCursor(270, 100);
// Show unit
if(String(lengthformat) == "m"){
display.print("m");
}
if(String(lengthformat) == "ft"){
display.print("ft");
}
display.setFont(&DSEG7Classic_BoldItalic60pt7b);
display.setCursor(20, 240);
// Reading bus data or using simulation data
if(simulation == true){
value1 = 84;
value1 += float(random(0, 120)) / 10; // Simulation data
display.print(value1,1);
}
else{
// Check vor valid real data, display also if hold values activated
if(valid1 == true || holdvalues == true){
// Unit conversion
if(String(lengthformat) == "m"){
value1 = value1; // Real bus data m
}
if(String(lengthformat) == "ft"){
value1 = value1 * 3.28084; // Bus data in ft
}
// Resolution switching
if(value1 <= 99.9){
display.print(value1,1);
}
else{
display.print(value1,0);
}
}
else{
display.print("---"); // Missing bus data
}
}
// Key Layout
display.setFont(&Ubuntu_Bold8pt7b);
display.setTextColor(GxEPD_BLACK);
display.setCursor(0, 290);
display.print(" [ < ]");
display.setCursor(290, 290);
display.print("[ > ]");
display.setCursor(343, 290);
display.print("[ILUM]");
// Update display
display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast)
}; };
}; };

View File

@ -3,7 +3,7 @@
class PageThreeValues : public Page class PageThreeValues : public Page
{ {
public: public:
virtual void display(CommonData &commonData, PageData &pageData) virtual void displayPage(CommonData &commonData, PageData &pageData)
{ {
GwLog *logger = commonData.logger; GwLog *logger = commonData.logger;
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)

View File

@ -7,7 +7,7 @@ public:
comon.logger->logDebug(GwLog::LOG,"created PageTwoValue"); comon.logger->logDebug(GwLog::LOG,"created PageTwoValue");
//add some initialization code here //add some initialization code here
} }
virtual void display(CommonData &commonData, PageData &pageData) virtual void displayPage(CommonData &commonData, PageData &pageData)
{ {
GwLog *logger = commonData.logger; GwLog *logger = commonData.logger;
for (int i = 0; i < 2; i++) for (int i = 0; i < 2; i++)

View File

@ -13,14 +13,6 @@ typedef struct{
} PageData; } PageData;
typedef struct{ typedef struct{
}OutputData;
typedef struct{
String distanceformat="m";
String lengthformat="m";
//...
OutputData output;
GwApi::Status status; GwApi::Status status;
GwLog *logger=NULL; GwLog *logger=NULL;
GwConfigHandler *config=NULL; GwConfigHandler *config=NULL;
@ -29,7 +21,7 @@ typedef struct{
//a base class that all pages must inherit from //a base class that all pages must inherit from
class Page{ class Page{
public: public:
virtual void display(CommonData &commonData, PageData &pageData)=0; virtual void displayPage(CommonData &commonData, PageData &pageData)=0;
virtual void displayNew(CommonData &commonData, PageData &pageData){} virtual void displayNew(CommonData &commonData, PageData &pageData){}
//return -1 if handled by the page //return -1 if handled by the page
virtual int handleKey(int key){return key;} virtual int handleKey(int key){return key;}

View File

@ -14,12 +14,7 @@
#include "OBP60Keypad.h" // Functions for keypad #include "OBP60Keypad.h" // Functions for keypad
// True type character sets // True type character sets
#include "Ubuntu_Bold8pt7b.h" // See OBP60ExtensionPort.h
#include "Ubuntu_Bold20pt7b.h"
#include "Ubuntu_Bold32pt7b.h"
#include "DSEG7Classic-BoldItalic16pt7b.h"
#include "DSEG7Classic-BoldItalic42pt7b.h"
#include "DSEG7Classic-BoldItalic60pt7b.h"
// Pictures // Pictures
//#include GxEPD_BitmapExamples // Example picture //#include GxEPD_BitmapExamples // Example picture
@ -62,23 +57,7 @@ void OBP60Init(GwApi *api){
} }
else{ else{
// Start communication // Start communication
mcp.init(); MCP23017Init();
mcp.portMode(MCP23017Port::A, 0b00110000); //Port A, 0 = out, 1 = in
mcp.portMode(MCP23017Port::B, 0b11110000); //Port B, 0 = out, 1 = in
// Extension Port A set defaults
setPortPin(OBP_DIGITAL_OUT1, false); // PA0
setPortPin(OBP_DIGITAL_OUT2, false); // PA1
setPortPin(OBP_FLASH_LED, false); // PA2
setPortPin(OBP_BACKLIGHT_LED, false); // PA3
setPortPin(OBP_POWER_50, true); // PA6
setPortPin(OBP_POWER_33, true); // PA7
// Extension Port B set defaults
setPortPin(PB0, false); // PB0
setPortPin(PB1, false); // PB1
setPortPin(PB2, false); // PB2
setPortPin(PB3, false); // PB3
// Settings for 1Wire // Settings for 1Wire
bool enable1Wire = api->getConfig()->getConfigItem(api->getConfig()->use1Wire,true)->asBoolean(); bool enable1Wire = api->getConfig()->getConfigItem(api->getConfig()->use1Wire,true)->asBoolean();
@ -144,8 +123,8 @@ void OBP60Init(GwApi *api){
initComplete = true; initComplete = true;
// Buzzer tone for initialization finish // Buzzer tone for initialization finish
//Todo buzPower = uint(api->getConfig()->getConfigItem(api->getConfig()->buzzerPower,true)->asInt()); setBuzzerPower(uint(api->getConfig()->getConfigItem(api->getConfig()->buzzerPower,true)->asInt()));
buzzer(TONE4, buzPower, 500); buzzer(TONE4, 500);
} }
@ -402,12 +381,15 @@ void OBP60Task(GwApi *api){
if (pages[pageNumber].description && pages[pageNumber].description->header){ if (pages[pageNumber].description && pages[pageNumber].description->header){
//build some header and footer using commonData //build some header and footer using commonData
} }
//.... //....
//call the particular page //call the particular page
Page *currentPage=pages[pageNumber].page; Page *currentPage=pages[pageNumber].page;
if (currentPage == NULL){ if (currentPage == NULL){
LOG_DEBUG(GwLog::ERROR,"page number %d not found",pageNumber); LOG_DEBUG(GwLog::ERROR,"page number %d not found",pageNumber);
// Error handling for missing page
} }
else{ else{
if (lastPage != pageNumber){ if (lastPage != pageNumber){
@ -416,7 +398,7 @@ void OBP60Task(GwApi *api){
} }
//call the page code //call the page code
LOG_DEBUG(GwLog::DEBUG,"calling page %d",pageNumber); LOG_DEBUG(GwLog::DEBUG,"calling page %d",pageNumber);
currentPage->display(commonData,pages[pageNumber].parameters); currentPage->displayPage(commonData,pages[pageNumber].parameters);
} }
} }