One value page working
This commit is contained in:
parent
10d6b3fa50
commit
9f6aebe978
|
@ -2,6 +2,13 @@
|
|||
#include "OBP60Hardware.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);
|
||||
|
||||
// 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
|
||||
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){
|
||||
|
||||
if(pin <=7){
|
||||
|
@ -58,12 +86,14 @@ void setBlinkingLED(bool 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
|
||||
frequency = 8000;
|
||||
}
|
||||
if(power > 100){ // Max 100%
|
||||
power = 100;
|
||||
if(buzzerpower > 100){ // Max 100%
|
||||
buzzerpower = 100;
|
||||
}
|
||||
if(duration > 1000){ // Max 1000ms
|
||||
duration = 1000;
|
||||
|
@ -72,11 +102,15 @@ void buzzer(uint frequency, uint power, uint duration){
|
|||
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%
|
||||
ledcWrite(0, uint(buzzerpower * 1.28)); // 50% duty cycle are 100%
|
||||
delay(duration);
|
||||
ledcWrite(0, 0); // 0% duty cycle are 0%
|
||||
}
|
||||
|
||||
void setBuzzerPower(uint power){
|
||||
buzzerpower = power;
|
||||
}
|
||||
|
||||
void underVoltageDetection(){
|
||||
noInterrupts();
|
||||
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){
|
||||
setPortPin(OBP_BACKLIGHT_LED, false); // Backlight 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_33, false); // Power rail 3.3V Off
|
||||
// Shutdown EInk display
|
||||
|
|
|
@ -8,20 +8,25 @@
|
|||
#include <GxIO/GxIO_SPI/GxIO_SPI.h> // GxEPD lip for SPI display communikation
|
||||
#include <GxIO/GxIO.h> // GxEPD lip for SPI
|
||||
|
||||
extern MCP23017 mcp;
|
||||
|
||||
#define buzPower 50 // Buzzer loudness in [%]
|
||||
void MCP23017Init();
|
||||
|
||||
// SPI pin definitions for E-Ink display
|
||||
extern GxIO_Class io;
|
||||
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 togglePortPin(uint pin);
|
||||
|
||||
void blinkingFlashLED();
|
||||
|
||||
void buzzer(uint frequency, uint power, uint duration);
|
||||
void buzzer(uint frequency, uint duration);
|
||||
void setBuzzerPower(uint power);
|
||||
|
||||
void underVoltageDetection();
|
||||
|
||||
|
|
|
@ -34,8 +34,8 @@
|
|||
// Buzzer
|
||||
#define OBP_BUZZER 19
|
||||
#define TONE1 1500 // 1500Hz
|
||||
#define TONE2 2000 // 2000Hz
|
||||
#define TONE3 3000 // 3000Hz
|
||||
#define TONE2 2500 // 2500Hz
|
||||
#define TONE3 3500 // 3500Hz
|
||||
#define TONE4 4000 // 4000Hz
|
||||
// Analog Input
|
||||
#define OBP_ANALOG0 34 // Voltage power supplay
|
||||
|
|
|
@ -86,7 +86,7 @@ int readKeypad() {
|
|||
keycodeold = 0;
|
||||
keycode2 = 0;
|
||||
keycodeold2 = 0;
|
||||
buzzer(TONE4, buzPower, 100);
|
||||
buzzer(TONE4, 100);
|
||||
keylock = false;
|
||||
delay(keydelay);
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ int readKeypad() {
|
|||
keycodeold = 0;
|
||||
keycode2 = 0;
|
||||
keycodeold2 = 0;
|
||||
buzzer(TONE4, buzPower, 1000);
|
||||
buzzer(TONE4, 1000);
|
||||
keylock = false;
|
||||
delay(keydelay);
|
||||
|
||||
|
@ -119,8 +119,8 @@ int readKeypad() {
|
|||
keycode2 = 0;
|
||||
keycodeold2 = 0;
|
||||
keystatus = 9;
|
||||
buzzer(TONE3, buzPower, 150);
|
||||
buzzer(TONE4, buzPower, 150);
|
||||
buzzer(TONE3, 150);
|
||||
buzzer(TONE4, 150);
|
||||
}
|
||||
|
||||
// Detect swipe left
|
||||
|
@ -131,8 +131,8 @@ int readKeypad() {
|
|||
keycode2 = 0;
|
||||
keycodeold2 = 0;
|
||||
keystatus = 10;
|
||||
buzzer(TONE4, buzPower, 150);
|
||||
buzzer(TONE3, buzPower, 150);
|
||||
buzzer(TONE4, 150);
|
||||
buzzer(TONE3, 150);
|
||||
}
|
||||
|
||||
// Reset keylock after release
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
|
||||
class PageApparentWind : public Page
|
||||
{
|
||||
|
@ -17,13 +18,14 @@ public:
|
|||
return key;
|
||||
}
|
||||
|
||||
virtual void display(CommonData &commonData, PageData &pageData)
|
||||
virtual void displayPage(CommonData &commonData, PageData &pageData)
|
||||
{
|
||||
GwLog *logger = commonData.logger;
|
||||
|
||||
GwConfigHandler *config = commonData.config;
|
||||
String test = config->getString(config->lengthFormat);
|
||||
|
||||
display.setFont(&Ubuntu_Bold8pt7b);
|
||||
|
||||
dummy++;
|
||||
for (int i = 0; i < 2; i++)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class PageForValues : public Page
|
||||
{
|
||||
public:
|
||||
virtual void display(CommonData &commonData, PageData &pageData)
|
||||
virtual void displayPage(CommonData &commonData, PageData &pageData)
|
||||
{
|
||||
GwLog *logger = commonData.logger;
|
||||
for (int i = 0; i < 4; i++)
|
||||
|
|
|
@ -1,15 +1,93 @@
|
|||
#include "Pagedata.h"
|
||||
#include "OBP60ExtensionPort.h"
|
||||
|
||||
class PageOneValue : public Page{
|
||||
public:
|
||||
virtual void display(CommonData &commonData, PageData &pageData){
|
||||
virtual void displayPage(CommonData &commonData, PageData &pageData){
|
||||
GwConfigHandler *config = commonData.config;
|
||||
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];
|
||||
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;
|
||||
LOG_DEBUG(GwLog::LOG,"drawing at PageOneValue, p=%s,v=%f",
|
||||
value->getName().c_str(),
|
||||
value->valid?value->value:-1.0
|
||||
);
|
||||
LOG_DEBUG(GwLog::LOG,"drawing at PageOneValue, p=%s, v=%f", name1, value1);
|
||||
|
||||
// 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)
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
class PageThreeValues : public Page
|
||||
{
|
||||
public:
|
||||
virtual void display(CommonData &commonData, PageData &pageData)
|
||||
virtual void displayPage(CommonData &commonData, PageData &pageData)
|
||||
{
|
||||
GwLog *logger = commonData.logger;
|
||||
for (int i = 0; i < 3; i++)
|
||||
|
|
|
@ -7,7 +7,7 @@ public:
|
|||
comon.logger->logDebug(GwLog::LOG,"created PageTwoValue");
|
||||
//add some initialization code here
|
||||
}
|
||||
virtual void display(CommonData &commonData, PageData &pageData)
|
||||
virtual void displayPage(CommonData &commonData, PageData &pageData)
|
||||
{
|
||||
GwLog *logger = commonData.logger;
|
||||
for (int i = 0; i < 2; i++)
|
||||
|
|
|
@ -13,14 +13,6 @@ typedef struct{
|
|||
} PageData;
|
||||
|
||||
typedef struct{
|
||||
|
||||
}OutputData;
|
||||
|
||||
typedef struct{
|
||||
String distanceformat="m";
|
||||
String lengthformat="m";
|
||||
//...
|
||||
OutputData output;
|
||||
GwApi::Status status;
|
||||
GwLog *logger=NULL;
|
||||
GwConfigHandler *config=NULL;
|
||||
|
@ -29,7 +21,7 @@ typedef struct{
|
|||
//a base class that all pages must inherit from
|
||||
class Page{
|
||||
public:
|
||||
virtual void display(CommonData &commonData, PageData &pageData)=0;
|
||||
virtual void displayPage(CommonData &commonData, PageData &pageData)=0;
|
||||
virtual void displayNew(CommonData &commonData, PageData &pageData){}
|
||||
//return -1 if handled by the page
|
||||
virtual int handleKey(int key){return key;}
|
||||
|
|
|
@ -14,12 +14,7 @@
|
|||
#include "OBP60Keypad.h" // Functions for keypad
|
||||
|
||||
// True type character sets
|
||||
#include "Ubuntu_Bold8pt7b.h"
|
||||
#include "Ubuntu_Bold20pt7b.h"
|
||||
#include "Ubuntu_Bold32pt7b.h"
|
||||
#include "DSEG7Classic-BoldItalic16pt7b.h"
|
||||
#include "DSEG7Classic-BoldItalic42pt7b.h"
|
||||
#include "DSEG7Classic-BoldItalic60pt7b.h"
|
||||
// See OBP60ExtensionPort.h
|
||||
|
||||
// Pictures
|
||||
//#include GxEPD_BitmapExamples // Example picture
|
||||
|
@ -62,23 +57,7 @@ void OBP60Init(GwApi *api){
|
|||
}
|
||||
else{
|
||||
// Start communication
|
||||
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
|
||||
MCP23017Init();
|
||||
|
||||
// Settings for 1Wire
|
||||
bool enable1Wire = api->getConfig()->getConfigItem(api->getConfig()->use1Wire,true)->asBoolean();
|
||||
|
@ -144,8 +123,8 @@ void OBP60Init(GwApi *api){
|
|||
initComplete = true;
|
||||
|
||||
// Buzzer tone for initialization finish
|
||||
//Todo buzPower = uint(api->getConfig()->getConfigItem(api->getConfig()->buzzerPower,true)->asInt());
|
||||
buzzer(TONE4, buzPower, 500);
|
||||
setBuzzerPower(uint(api->getConfig()->getConfigItem(api->getConfig()->buzzerPower,true)->asInt()));
|
||||
buzzer(TONE4, 500);
|
||||
|
||||
}
|
||||
|
||||
|
@ -402,12 +381,15 @@ void OBP60Task(GwApi *api){
|
|||
if (pages[pageNumber].description && pages[pageNumber].description->header){
|
||||
|
||||
//build some header and footer using commonData
|
||||
|
||||
|
||||
}
|
||||
//....
|
||||
//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
|
||||
}
|
||||
else{
|
||||
if (lastPage != pageNumber){
|
||||
|
@ -416,7 +398,7 @@ void OBP60Task(GwApi *api){
|
|||
}
|
||||
//call the page code
|
||||
LOG_DEBUG(GwLog::DEBUG,"calling page %d",pageNumber);
|
||||
currentPage->display(commonData,pages[pageNumber].parameters);
|
||||
currentPage->displayPage(commonData,pages[pageNumber].parameters);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue