Add new system page

This commit is contained in:
Thomas Hooge 2024-12-07 11:11:07 +01:00
parent 4ad82299fc
commit 57e194e39d
3 changed files with 151 additions and 18 deletions

View File

@ -128,6 +128,15 @@ int readKeypad(uint thSensitivity) {
}
}
// System page with key 5 and 4 in fast series
if (keycode2 == 5 && keycodeold2 == 4) {
keycode = 0;
keycodeold = 0;
keycode2 = 0;
keycodeold2 = 0;
keystatus = 12;
}
// Key lock with key 1 and 6 or 6 and 1 in fast series
if((keycode2 == 1 && keycodeold2 == 6) || (keycode2 == 6 && keycodeold2 == 1)) {
keycode = 0;

View File

@ -0,0 +1,104 @@
#ifdef BOARD_OBP60S3
#include "Pagedata.h"
#include "OBP60Extensions.h"
/*
* Special system page, called directly with fast key sequence 5,4
* Out of normal page order.
*/
class PageSystem : public Page{
bool keylock = false;
public:
PageSystem(CommonData &common){
common.logger->logDebug(GwLog::LOG,"Show PageSystem");
}
virtual int handleKey(int key){
// Code for keylock
if (key == 11) {
keylock = !keylock;
return 0;
}
return key;
}
virtual void displayPage(CommonData &commonData, PageData &pageData){
GwConfigHandler *config = commonData.config;
GwLog *logger=commonData.logger;
// Get config data
String displaycolor = config->getString(config->displaycolor);
String backlightMode = config->getString(config->backlight);
String flashLED = config->getString(config->flashLED);
// Optical warning by limit violation (unused)
if(String(flashLED) == "Limit Violation"){
setBlinkingLED(false);
setFlashLED(false);
}
// Logging boat values
LOG_DEBUG(GwLog::LOG,"Drawing at PageSystem");
// Draw page
//***********************************************************
// Set colors
int fgcolor = GxEPD_BLACK;
int bgcolor = GxEPD_WHITE;
if (displaycolor != "Normal") {
fgcolor = GxEPD_WHITE;
bgcolor = GxEPD_BLACK;
}
// Set display in partial refresh mode
getdisplay().setPartialWindow(0, 0, getdisplay().width(), getdisplay().height()); // Set partial update
getdisplay().setFont(&Ubuntu_Bold12pt7b);
getdisplay().setCursor(20, 60);
getdisplay().print("System Information and Settings");
// Key Layout
getdisplay().setTextColor(fgcolor);
getdisplay().setFont(&Ubuntu_Bold8pt7b);
if (keylock == false) {
getdisplay().setCursor(10, 290);
getdisplay().print("[STBY]");
if (String(backlightMode) == "Control by Key") {
getdisplay().setCursor(343, 290);
getdisplay().print("[ILUM]");
}
}
else {
getdisplay().setCursor(130, 290);
getdisplay().print(" [ Keylock active ]");
}
// Update display
getdisplay().nextPage(); // Partial update (fast)
};
};
static Page* createPage(CommonData &common){
return new PageSystem(common);
}
/**
* with the code below we make this page known to the PageTask
* we give it a type (name) that can be selected in the config
* we define which function is to be called
* and we provide the number of user parameters we expect
* this will be number of BoatValue pointers in pageData.values
*/
PageDescription registerPageSystem(
"System", // Page name
createPage, // Action
0, // No bus values
true // Headers are anabled so far
);
#endif

View File

@ -201,8 +201,10 @@ void registerAllPages(PageList &list){
//this way this separate source file can be compiled by it's own
//and has no access to any of our data except the one that we
//give as a parameter to the page function
extern PageDescription registerPageOneValue;
extern PageDescription registerPageSystem;
//we add the variable to our list
list.add(&registerPageSystem);
extern PageDescription registerPageOneValue;
list.add(&registerPageOneValue);
extern PageDescription registerPageTwoValues;
list.add(&registerPageTwoValues);
@ -470,11 +472,11 @@ void OBP60Task(GwApi *api){
// Main loop runs with 100ms
//####################################################################################
bool systemPage = false;
while (true){
delay(100); // Delay 100ms (loop time)
// Undervoltage detection
if(uvoltage == true){
underVoltageDetection(api);
@ -515,9 +517,19 @@ void OBP60Task(GwApi *api){
int keyboardMessage=0;
while (xQueueReceive(allParameters.queue,&keyboardMessage,0)){
LOG_DEBUG(GwLog::LOG,"new key from keyboard %d",keyboardMessage);
Page *currentPage=pages[pageNumber].page;
if (currentPage ){
Page *currentPage;
if (keyboardMessage == 12) {
LOG_DEBUG(GwLog::LOG, "Calling system page");
systemPage = true; // System page is out of band
currentPage = allPages.pages[0]->creator(commonData);
}
else {
systemPage = false;
currentPage = pages[pageNumber].page;
}
if (currentPage) {
keyboardMessage=currentPage->handleKey(keyboardMessage);
}
if (keyboardMessage > 0)
@ -641,19 +653,27 @@ void OBP60Task(GwApi *api){
}
// Call the particular page
Page *currentPage=pages[pageNumber].page;
if (currentPage == NULL){
LOG_DEBUG(GwLog::ERROR,"page number %d not found",pageNumber);
// Error handling for missing page
Page *currentPage;
if (systemPage) {
currentPage = allPages.pages[0]->creator(commonData);
PageData sysparams;
currentPage->displayPage(commonData, sysparams);
}
else{
if (lastPage != pageNumber){
currentPage->displayNew(commonData,pages[pageNumber].parameters);
lastPage=pageNumber;
else {
currentPage = pages[pageNumber].page;
if (currentPage == NULL){
LOG_DEBUG(GwLog::ERROR,"page number %d not found",pageNumber);
// Error handling for missing page
}
else{
if (lastPage != pageNumber){
currentPage->displayNew(commonData,pages[pageNumber].parameters);
lastPage=pageNumber;
}
//call the page code
LOG_DEBUG(GwLog::DEBUG,"calling page %d",pageNumber);
currentPage->displayPage(commonData,pages[pageNumber].parameters);
}
//call the page code
LOG_DEBUG(GwLog::DEBUG,"calling page %d",pageNumber);
currentPage->displayPage(commonData,pages[pageNumber].parameters);
}
}
}
@ -662,4 +682,4 @@ void OBP60Task(GwApi *api){
}
#endif
#endif