diff --git a/lib/obp60task/AS5600.cpp b/lib/obp60task/AS5600.cpp index bc206dd..3bb54bc 100644 --- a/lib/obp60task/AS5600.cpp +++ b/lib/obp60task/AS5600.cpp @@ -1,3 +1,4 @@ +#ifdef BOARD_NODEMCU32S_OBP60 /**************************************************** AMS 5600 class for Arduino platform @@ -458,3 +459,5 @@ void AMS_5600::writeOneByte(int adr_in, int dat_in) } /********** END OF AMS 5600 CALSS *****************/ + +#endif \ No newline at end of file diff --git a/lib/obp60task/OBP60ExtensionPort.cpp b/lib/obp60task/OBP60ExtensionPort.cpp index 4a9bcfa..bd1007b 100644 --- a/lib/obp60task/OBP60ExtensionPort.cpp +++ b/lib/obp60task/OBP60ExtensionPort.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include #include "Pagedata.h" #include "OBP60Hardware.h" @@ -200,4 +202,6 @@ void displayHeader(CommonData &commonData, GwApi::BoatValue *hdop, GwApi::BoatVa else{ display.print("No GPS data"); } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/lib/obp60task/OBP60Formater.cpp b/lib/obp60task/OBP60Formater.cpp index 8ebddb5..1f3006b 100644 --- a/lib/obp60task/OBP60Formater.cpp +++ b/lib/obp60task/OBP60Formater.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include #include "GwApi.h" #include "Pagedata.h" @@ -431,3 +433,5 @@ FormatedData formatValue(GwApi::BoatValue *value, CommonData &commondata){ result.svalue = String(buffer); return result; } + +#endif diff --git a/lib/obp60task/OBP60Hardware.h b/lib/obp60task/OBP60Hardware.h index a4d9064..b3409d4 100644 --- a/lib/obp60task/OBP60Hardware.h +++ b/lib/obp60task/OBP60Hardware.h @@ -14,11 +14,13 @@ // BME280 #define BME280_I2C_ADDR 0x76 // Addr. 0x76 (0x77) // BMP280 - #define BMP280_I2C_ADDR 0x77 // Addr. 0x77 + #define BMP280_I2C_ADDR 0x76 // Addr. 0x76 (0x77) // BMP085 / BMP180 - #define BMP280_I2C_ADDR 0x77 // Addr. 0x77 (fix) + #define BMP180_I2C_ADDR 0x77 // Addr. 0x77 (fix) // SHT21 / HUT21 #define SHT21_I2C_ADDR 0x40 // Addr. 0x40 (fix) + // AS5600 + #define AS5600_I2C_ADDR 0x36 // Addr. 0x36 (fix) // SPI (E-Ink display, Extern Bus) #define OBP_SPI_CS 5 #define OBP_SPI_DC 17 diff --git a/lib/obp60task/PageApparentWind.cpp b/lib/obp60task/PageApparentWind.cpp index 6bdc45e..f1bbf29 100644 --- a/lib/obp60task/PageApparentWind.cpp +++ b/lib/obp60task/PageApparentWind.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -199,4 +201,6 @@ PageDescription registerPageApparentWind( 0, // Number of bus values depends on selection in Web configuration {"AWS","AWA"}, // Bus values we need in the page true // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageBME280.cpp b/lib/obp60task/PageBME280.cpp index 40b8b64..2a51b7a 100644 --- a/lib/obp60task/PageBME280.cpp +++ b/lib/obp60task/PageBME280.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -227,4 +229,6 @@ PageDescription registerPageBME280( 0, // Number of bus values depends on selection in Web configuration {}, // Names of bus values undepends on selection in Web configuration (refer GwBoatData.h) true // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageClock.cpp b/lib/obp60task/PageClock.cpp index b842b9c..3e37953 100644 --- a/lib/obp60task/PageClock.cpp +++ b/lib/obp60task/PageClock.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -187,17 +189,17 @@ public: //******************************************************************************************* // Draw clock - int rWindGraphic = 110; // Radius of clock + int rInstrument = 110; // Radius of clock float pi = 3.141592; - display.fillCircle(200, 150, rWindGraphic + 10, pixelcolor); // Outer circle - display.fillCircle(200, 150, rWindGraphic + 7, bgcolor); // Outer circle + display.fillCircle(200, 150, rInstrument + 10, pixelcolor); // Outer circle + display.fillCircle(200, 150, rInstrument + 7, bgcolor); // Outer circle for(int i=0; i<360; i=i+10) { // Scaling values - float x = 200 + (rWindGraphic-30)*sin(i/180.0*pi); // x-coordinate dots - float y = 150 - (rWindGraphic-30)*cos(i/180.0*pi); // y-coordinate cots + float x = 200 + (rInstrument-30)*sin(i/180.0*pi); // x-coordinate dots + float y = 150 - (rInstrument-30)*cos(i/180.0*pi); // y-coordinate cots const char *ii = ""; switch (i) { @@ -227,8 +229,8 @@ public: } // Draw sub scale with dots - float x1c = 200 + rWindGraphic*sin(i/180.0*pi); - float y1c = 150 - rWindGraphic*cos(i/180.0*pi); + float x1c = 200 + rInstrument*sin(i/180.0*pi); + float y1c = 150 - rInstrument*cos(i/180.0*pi); display.fillCircle((int)x1c, (int)y1c, 2, pixelcolor); float sinx=sin(i/180.0*pi); float cosx=cos(i/180.0*pi); @@ -238,8 +240,8 @@ public: float dx=2; // Line thickness = 2*dx+1 float xx1 = -dx; float xx2 = +dx; - float yy1 = -(rWindGraphic-10); - float yy2 = -(rWindGraphic+10); + float yy1 = -(rInstrument-10); + float yy2 = -(rInstrument+10); display.fillTriangle(200+(int)(cosx*xx1-sinx*yy1),150+(int)(sinx*xx1+cosx*yy1), 200+(int)(cosx*xx2-sinx*yy1),150+(int)(sinx*xx2+cosx*yy1), 200+(int)(cosx*xx1-sinx*yy2),150+(int)(sinx*xx1+cosx*yy2),pixelcolor); @@ -280,7 +282,7 @@ public: float xx1 = -startwidth; float xx2 = startwidth; float yy1 = -startwidth; - float yy2 = -(rWindGraphic * 0.5); + float yy2 = -(rInstrument * 0.5); display.fillTriangle(200+(int)(cosx*xx1-sinx*yy1),150+(int)(sinx*xx1+cosx*yy1), 200+(int)(cosx*xx2-sinx*yy1),150+(int)(sinx*xx2+cosx*yy1), 200+(int)(cosx*0-sinx*yy2),150+(int)(sinx*0+cosx*yy2),pixelcolor); @@ -289,7 +291,7 @@ public: float endwidth = 2; // End width of pointer float ix1 = endwidth; float ix2 = -endwidth; - float iy1 = -(rWindGraphic * 0.5); + float iy1 = -(rInstrument * 0.5); float iy2 = -endwidth; display.fillTriangle(200+(int)(cosx*ix1-sinx*iy1),150+(int)(sinx*ix1+cosx*iy1), 200+(int)(cosx*ix2-sinx*iy1),150+(int)(sinx*ix2+cosx*iy1), @@ -306,7 +308,7 @@ public: float xx1 = -startwidth; float xx2 = startwidth; float yy1 = -startwidth; - float yy2 = -(rWindGraphic - 15); + float yy2 = -(rInstrument - 15); display.fillTriangle(200+(int)(cosx*xx1-sinx*yy1),150+(int)(sinx*xx1+cosx*yy1), 200+(int)(cosx*xx2-sinx*yy1),150+(int)(sinx*xx2+cosx*yy1), 200+(int)(cosx*0-sinx*yy2),150+(int)(sinx*0+cosx*yy2),pixelcolor); @@ -315,7 +317,7 @@ public: float endwidth = 2; // End width of pointer float ix1 = endwidth; float ix2 = -endwidth; - float iy1 = -(rWindGraphic - 15); + float iy1 = -(rInstrument - 15); float iy2 = -endwidth; display.fillTriangle(200+(int)(cosx*ix1-sinx*iy1),150+(int)(sinx*ix1+cosx*iy1), 200+(int)(cosx*ix2-sinx*iy1),150+(int)(sinx*ix2+cosx*iy1), @@ -364,4 +366,6 @@ PageDescription registerPageClock( 0, // Number of bus values depends on selection in Web configuration {"GPST", "GPSD"}, // Bus values we need in the page true // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageDST810.cpp b/lib/obp60task/PageDST810.cpp index dea856f..a61335a 100644 --- a/lib/obp60task/PageDST810.cpp +++ b/lib/obp60task/PageDST810.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -299,4 +301,6 @@ PageDescription registerPageDST810( 0, // Number of bus values depends on selection in Web configuration {"DBT","STW","Log","WTemp"}, // Bus values we need in the page true // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageForValues.cpp b/lib/obp60task/PageForValues.cpp index 3a4910a..999e791 100644 --- a/lib/obp60task/PageForValues.cpp +++ b/lib/obp60task/PageForValues.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -338,4 +340,6 @@ PageDescription registerPageForValues( createPage, // Action 4, // Number of bus values depends on selection in Web configuration true // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageForValues2.cpp b/lib/obp60task/PageForValues2.cpp index c8b8338..a4518ce 100644 --- a/lib/obp60task/PageForValues2.cpp +++ b/lib/obp60task/PageForValues2.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -338,4 +340,6 @@ PageDescription registerPageForValues2( createPage, // Action 4, // Number of bus values depends on selection in Web configuration true // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageKeelPosition.cpp b/lib/obp60task/PageKeelPosition.cpp new file mode 100644 index 0000000..5a69657 --- /dev/null +++ b/lib/obp60task/PageKeelPosition.cpp @@ -0,0 +1,245 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + +#include "Pagedata.h" +#include "OBP60ExtensionPort.h" + +class PageKeelPosition : public Page +{ +bool keylock = false; // Keylock + +public: + PageKeelPosition(CommonData &common){ + common.logger->logDebug(GwLog::LOG,"Show PageKeelPosition"); + } + + // Key functions + virtual int handleKey(int key){ + // Keylock function + if(key == 11){ // Code for keylock + keylock = !keylock; // Toggle keylock + return 0; // Commit the key + } + return key; + } + + virtual void displayPage(CommonData &commonData, PageData &pageData) + { + GwConfigHandler *config = commonData.config; + GwLog *logger=commonData.logger; + + double value1 = 0; + double value1old = 0; + + // Get config data + String lengthformat = config->getString(config->lengthFormat); + bool simulation = config->getBool(config->useSimuData); + String displaycolor = config->getString(config->displaycolor); + bool holdvalues = config->getBool(config->holdvalues); + String flashLED = config->getString(config->flashLED); + String backlightMode = config->getString(config->backlight); + + // Get boat values for Keel position + GwApi::BoatValue *bvalue1 = pageData.values[0]; // First element in list + value1 = commonData.data.rotationAngle; // Raw value without unit convertion + bool valid1 = commonData.data.validRotAngle; // Valid information + String unit1 = "Deg"; // Unit of value + if(valid1 == true){ + value1old = value1; // Save old value + } + + // Optical warning by limit violation (unused) + if(String(flashLED) == "Limit Violation"){ + setBlinkingLED(false); + setPortPin(OBP_FLASH_LED, false); + } + + // Logging boat values + if (bvalue1 == NULL) return; + LOG_DEBUG(GwLog::LOG,"Drawing at PageKeelPosition, Keel:%f", value1); + + // Draw page + //*********************************************************** + + // Set background color and text color + int textcolor = GxEPD_BLACK; + int pixelcolor = GxEPD_BLACK; + int bgcolor = GxEPD_WHITE; + if(displaycolor == "Normal"){ + textcolor = GxEPD_BLACK; + pixelcolor = GxEPD_BLACK; + bgcolor = GxEPD_WHITE; + } + else{ + textcolor = GxEPD_WHITE; + pixelcolor = GxEPD_WHITE; + bgcolor = GxEPD_BLACK; + } + // Clear display by call in obp60task.cpp in main loop + + +//******************************************************************************************* + + // Draw KeelPosition + int rInstrument = 110; // Radius of KeelPosition + float pi = 3.141592; + + display.fillCircle(200, 150, rInstrument + 10, pixelcolor); // Outer circle + display.fillCircle(200, 150, rInstrument + 7, bgcolor); // Outer circle + display.fillRect(0, 30, 400, 122, bgcolor); // Delete half top circle + + for(int i=90; i<=270; i=i+10) + { + // Scaling values + float x = 200 + (rInstrument-30)*sin(i/180.0*pi); // x-coordinate dots + float y = 150 - (rInstrument-30)*cos(i/180.0*pi); // y-coordinate cots + const char *ii = " "; + switch (i) + { + case 0: ii=" "; break; // Use a blank for a empty scale value + case 30 : ii=" "; break; + case 60 : ii=" "; break; + case 90 : ii="45"; break; + case 120 : ii="30"; break; + case 150 : ii="15"; break; + case 180 : ii="0"; break; + case 210 : ii="15"; break; + case 240 : ii="30"; break; + case 270 : ii="45"; break; + case 300 : ii=" "; break; + case 330 : ii=" "; break; + default: break; + } + + // Print text centered on position x, y + int16_t x1, y1; // Return values of getTextBounds + uint16_t w, h; // Return values of getTextBounds + display.getTextBounds(ii, int(x), int(y), &x1, &y1, &w, &h); // Calc width of new string + display.setCursor(x-w/2, y+h/2); + if(i % 30 == 0){ + display.setFont(&Ubuntu_Bold8pt7b); + display.print(ii); + } + + // Draw sub scale with dots + float x1c = 200 + rInstrument*sin(i/180.0*pi); + float y1c = 150 - rInstrument*cos(i/180.0*pi); + display.fillCircle((int)x1c, (int)y1c, 2, pixelcolor); + float sinx=sin(i/180.0*pi); + float cosx=cos(i/180.0*pi); + + // Draw sub scale with lines (two triangles) + if(i % 30 == 0){ + float dx=2; // Line thickness = 2*dx+1 + float xx1 = -dx; + float xx2 = +dx; + float yy1 = -(rInstrument-10); + float yy2 = -(rInstrument+10); + display.fillTriangle(200+(int)(cosx*xx1-sinx*yy1),150+(int)(sinx*xx1+cosx*yy1), + 200+(int)(cosx*xx2-sinx*yy1),150+(int)(sinx*xx2+cosx*yy1), + 200+(int)(cosx*xx1-sinx*yy2),150+(int)(sinx*xx1+cosx*yy2),pixelcolor); + display.fillTriangle(200+(int)(cosx*xx2-sinx*yy1),150+(int)(sinx*xx2+cosx*yy1), + 200+(int)(cosx*xx1-sinx*yy2),150+(int)(sinx*xx1+cosx*yy2), + 200+(int)(cosx*xx2-sinx*yy2),150+(int)(sinx*xx2+cosx*yy2),pixelcolor); + } + + } + + // Print label + display.setTextColor(textcolor); + display.setFont(&Ubuntu_Bold16pt7b); + display.setCursor(100, 70); + display.print("Keel Position"); // Label + + // Print Unit of keel position + display.setFont(&Ubuntu_Bold12pt7b); + display.setCursor(175, 110); + display.print(unit1); // Unit + + // Angle limits to +/-45° + if(value1 < (-PI / 4)){ + value1 = -PI / 4; + } + if(value1 > (PI / 4)){ + value1 = PI / 4; + } + + // Calculate keel position + value1 = (value1 * 2) + PI; + + // Draw keel position pointer + float startwidth = 8; // Start width of pointer + + if(valid1 == true || holdvalues == true || simulation == true){ + float sinx=sin(value1); + float cosx=cos(value1); + // Normal pointer + // Pointer as triangle with center base 2*width + float xx1 = -startwidth; + float xx2 = startwidth; + float yy1 = -startwidth; + float yy2 = -(rInstrument * 0.6); + display.fillTriangle(200+(int)(cosx*xx1-sinx*yy1),150+(int)(sinx*xx1+cosx*yy1), + 200+(int)(cosx*xx2-sinx*yy1),150+(int)(sinx*xx2+cosx*yy1), + 200+(int)(cosx*0-sinx*yy2),150+(int)(sinx*0+cosx*yy2),pixelcolor); + // Inverted pointer + // Pointer as triangle with center base 2*width + float endwidth = 2; // End width of pointer + float ix1 = endwidth; + float ix2 = -endwidth; + float iy1 = -(rInstrument * 0.6); + float iy2 = -endwidth; + display.fillTriangle(200+(int)(cosx*ix1-sinx*iy1),150+(int)(sinx*ix1+cosx*iy1), + 200+(int)(cosx*ix2-sinx*iy1),150+(int)(sinx*ix2+cosx*iy1), + 200+(int)(cosx*0-sinx*iy2),150+(int)(sinx*0+cosx*iy2),pixelcolor); + + // Draw counterweight + display.fillCircle(200+(int)(cosx*0-sinx*yy2),150+(int)(sinx*0+cosx*yy2), 5, pixelcolor); + } + + // Center circle + display.fillCircle(200, 150, startwidth + 22, bgcolor); + display.fillCircle(200, 150, startwidth + 20, pixelcolor); + display.fillRect(200 - 30, 150 - 30, 2 * 30, 30, bgcolor); // Delete half top circle + + +//******************************************************************************************* + // Key Layout + display.setTextColor(textcolor); + display.setFont(&Ubuntu_Bold8pt7b); + display.setCursor(130, 290); + if(keylock == false){ + display.print("[ <<<< " + String(commonData.data.actpage) + "/" + String(commonData.data.maxpage) + " >>>> ]"); + if(String(backlightMode) == "Control by Key"){ // Key for illumination + display.setCursor(343, 290); + display.print("[ILUM]"); + } + } + else{ + display.print(" [ Keylock active ]"); + } + + // Update display + display.updateWindow(0, 0, GxEPD_WIDTH, GxEPD_HEIGHT, true); // Partial update (fast) + + }; +}; + +static Page *createPage(CommonData &common){ + return new PageKeelPosition(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 (0 here) + * and will will provide the names of the fixed values we need + */ +PageDescription registerPageKeelPosition( + "KeelPosition", // Page name + createPage, // Action + 0, // Number of bus values depends on selection in Web configuration + {"RPOS"}, // Bus values we need in the page + true // Show display header on/off +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageOneValue.cpp b/lib/obp60task/PageOneValue.cpp index 2d808c6..065bb80 100644 --- a/lib/obp60task/PageOneValue.cpp +++ b/lib/obp60task/PageOneValue.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -151,4 +153,6 @@ PageDescription registerPageOneValue( createPage, // Action 1, // Number of bus values depends on selection in Web configuration true // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageRudderPosition.cpp b/lib/obp60task/PageRudderPosition.cpp index 0fa38ba..28cc75d 100644 --- a/lib/obp60task/PageRudderPosition.cpp +++ b/lib/obp60task/PageRudderPosition.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -83,18 +85,18 @@ public: //******************************************************************************************* // Draw RudderPosition - int rWindGraphic = 110; // Radius of RudderPosition + int rInstrument = 110; // Radius of RudderPosition float pi = 3.141592; - display.fillCircle(200, 150, rWindGraphic + 10, pixelcolor); // Outer circle - display.fillCircle(200, 150, rWindGraphic + 7, bgcolor); // Outer circle + display.fillCircle(200, 150, rInstrument + 10, pixelcolor); // Outer circle + display.fillCircle(200, 150, rInstrument + 7, bgcolor); // Outer circle display.fillRect(0, 30, 400, 122, bgcolor); // Delete half top circle for(int i=90; i<=270; i=i+10) { // Scaling values - float x = 200 + (rWindGraphic-30)*sin(i/180.0*pi); // x-coordinate dots - float y = 150 - (rWindGraphic-30)*cos(i/180.0*pi); // y-coordinate cots + float x = 200 + (rInstrument-30)*sin(i/180.0*pi); // x-coordinate dots + float y = 150 - (rInstrument-30)*cos(i/180.0*pi); // y-coordinate cots const char *ii = " "; switch (i) { @@ -124,8 +126,8 @@ public: } // Draw sub scale with dots - float x1c = 200 + rWindGraphic*sin(i/180.0*pi); - float y1c = 150 - rWindGraphic*cos(i/180.0*pi); + float x1c = 200 + rInstrument*sin(i/180.0*pi); + float y1c = 150 - rInstrument*cos(i/180.0*pi); display.fillCircle((int)x1c, (int)y1c, 2, pixelcolor); float sinx=sin(i/180.0*pi); float cosx=cos(i/180.0*pi); @@ -135,8 +137,8 @@ public: float dx=2; // Line thickness = 2*dx+1 float xx1 = -dx; float xx2 = +dx; - float yy1 = -(rWindGraphic-10); - float yy2 = -(rWindGraphic+10); + float yy1 = -(rInstrument-10); + float yy2 = -(rInstrument+10); display.fillTriangle(200+(int)(cosx*xx1-sinx*yy1),150+(int)(sinx*xx1+cosx*yy1), 200+(int)(cosx*xx2-sinx*yy1),150+(int)(sinx*xx2+cosx*yy1), 200+(int)(cosx*xx1-sinx*yy2),150+(int)(sinx*xx1+cosx*yy2),pixelcolor); @@ -184,7 +186,7 @@ public: float xx1 = -startwidth; float xx2 = startwidth; float yy1 = -startwidth; - float yy2 = -(rWindGraphic * 0.5); + float yy2 = -(rInstrument * 0.5); display.fillTriangle(200+(int)(cosx*xx1-sinx*yy1),150+(int)(sinx*xx1+cosx*yy1), 200+(int)(cosx*xx2-sinx*yy1),150+(int)(sinx*xx2+cosx*yy1), 200+(int)(cosx*0-sinx*yy2),150+(int)(sinx*0+cosx*yy2),pixelcolor); @@ -193,7 +195,7 @@ public: float endwidth = 2; // End width of pointer float ix1 = endwidth; float ix2 = -endwidth; - float iy1 = -(rWindGraphic * 0.5); + float iy1 = -(rInstrument * 0.5); float iy2 = -endwidth; display.fillTriangle(200+(int)(cosx*ix1-sinx*iy1),150+(int)(sinx*ix1+cosx*iy1), 200+(int)(cosx*ix2-sinx*iy1),150+(int)(sinx*ix2+cosx*iy1), @@ -242,4 +244,6 @@ PageDescription registerPageRudderPosition( 0, // Number of bus values depends on selection in Web configuration {"RPOS"}, // Bus values we need in the page true // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageThreeValues.cpp b/lib/obp60task/PageThreeValues.cpp index b45a530..fdb466c 100644 --- a/lib/obp60task/PageThreeValues.cpp +++ b/lib/obp60task/PageThreeValues.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -277,4 +279,6 @@ PageDescription registerPageThreeValues( createPage, // Action 3, // Number of bus values depends on selection in Web configuration true // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageTwoValues.cpp b/lib/obp60task/PageTwoValues.cpp index b8852f7..85252b3 100644 --- a/lib/obp60task/PageTwoValues.cpp +++ b/lib/obp60task/PageTwoValues.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -217,4 +219,6 @@ PageDescription registerPageTwoValues( createPage, // Action 2, // Number of bus values depends on selection in Web configuration true // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageVoltage.cpp b/lib/obp60task/PageVoltage.cpp index 04b655e..8610535 100644 --- a/lib/obp60task/PageVoltage.cpp +++ b/lib/obp60task/PageVoltage.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -182,4 +184,6 @@ PageDescription registerPageVoltage( 0, // Number of bus values depends on selection in Web configuration {}, // Names of bus values undepends on selection in Web configuration (refer GwBoatData.h) true // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageWhite.cpp b/lib/obp60task/PageWhite.cpp index 3654711..3f312f8 100644 --- a/lib/obp60task/PageWhite.cpp +++ b/lib/obp60task/PageWhite.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -56,4 +58,6 @@ PageDescription registerPageWhite( createPage, // Action 0, // Number of bus values depends on selection in Web configuration false // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/PageWindRose.cpp b/lib/obp60task/PageWindRose.cpp index bdd1d80..3c12743 100644 --- a/lib/obp60task/PageWindRose.cpp +++ b/lib/obp60task/PageWindRose.cpp @@ -1,3 +1,5 @@ +#ifdef BOARD_NODEMCU32S_OBP60 + #include "Pagedata.h" #include "OBP60ExtensionPort.h" @@ -241,19 +243,19 @@ public: //******************************************************************************************* // Draw wind rose - int rWindGraphic = 110; // Radius of grafic instrument + int rInstrument = 110; // Radius of grafic instrument float pi = 3.141592; - display.fillCircle(200, 150, rWindGraphic + 10, pixelcolor); // Outer circle - display.fillCircle(200, 150, rWindGraphic + 7, bgcolor); // Outer circle - display.fillCircle(200, 150, rWindGraphic - 10, pixelcolor); // Inner circle - display.fillCircle(200, 150, rWindGraphic - 13, bgcolor); // Inner circle + display.fillCircle(200, 150, rInstrument + 10, pixelcolor); // Outer circle + display.fillCircle(200, 150, rInstrument + 7, bgcolor); // Outer circle + display.fillCircle(200, 150, rInstrument - 10, pixelcolor); // Inner circle + display.fillCircle(200, 150, rInstrument - 13, bgcolor); // Inner circle for(int i=0; i<360; i=i+10) { // Scaling values - float x = 200 + (rWindGraphic-30)*sin(i/180.0*pi); // x-coordinate dots - float y = 150 - (rWindGraphic-30)*cos(i/180.0*pi); // y-coordinate cots + float x = 200 + (rInstrument-30)*sin(i/180.0*pi); // x-coordinate dots + float y = 150 - (rInstrument-30)*cos(i/180.0*pi); // y-coordinate cots const char *ii = ""; switch (i) { @@ -283,8 +285,8 @@ public: } // Draw sub scale with dots - float x1c = 200 + rWindGraphic*sin(i/180.0*pi); - float y1c = 150 - rWindGraphic*cos(i/180.0*pi); + float x1c = 200 + rInstrument*sin(i/180.0*pi); + float y1c = 150 - rInstrument*cos(i/180.0*pi); display.fillCircle((int)x1c, (int)y1c, 2, pixelcolor); float sinx=sin(i/180.0*pi); float cosx=cos(i/180.0*pi); @@ -294,8 +296,8 @@ public: float dx=2; // Line thickness = 2*dx+1 float xx1 = -dx; float xx2 = +dx; - float yy1 = -(rWindGraphic-10); - float yy2 = -(rWindGraphic+10); + float yy1 = -(rInstrument-10); + float yy2 = -(rInstrument+10); display.fillTriangle(200+(int)(cosx*xx1-sinx*yy1),150+(int)(sinx*xx1+cosx*yy1), 200+(int)(cosx*xx2-sinx*yy1),150+(int)(sinx*xx2+cosx*yy1), 200+(int)(cosx*xx1-sinx*yy2),150+(int)(sinx*xx1+cosx*yy2),pixelcolor); @@ -315,7 +317,7 @@ public: float xx1 = -startwidth; float xx2 = startwidth; float yy1 = -startwidth; - float yy2 = -(rWindGraphic-15); + float yy2 = -(rInstrument-15); display.fillTriangle(200+(int)(cosx*xx1-sinx*yy1),150+(int)(sinx*xx1+cosx*yy1), 200+(int)(cosx*xx2-sinx*yy1),150+(int)(sinx*xx2+cosx*yy1), 200+(int)(cosx*0-sinx*yy2),150+(int)(sinx*0+cosx*yy2),pixelcolor); @@ -324,7 +326,7 @@ public: float endwidth = 2; // End width of pointer float ix1 = endwidth; float ix2 = -endwidth; - float iy1 = -(rWindGraphic-15); + float iy1 = -(rInstrument-15); float iy2 = -endwidth; display.fillTriangle(200+(int)(cosx*ix1-sinx*iy1),150+(int)(sinx*ix1+cosx*iy1), 200+(int)(cosx*ix2-sinx*iy1),150+(int)(sinx*ix2+cosx*iy1), @@ -373,4 +375,6 @@ PageDescription registerPageWindRose( 0, // Number of bus values depends on selection in Web configuration {"AWA", "AWS", "TWD", "TWS"}, // Bus values we need in the page true // Show display header on/off -); \ No newline at end of file +); + +#endif \ No newline at end of file diff --git a/lib/obp60task/Pagedata.h b/lib/obp60task/Pagedata.h index 99aa8c0..fc2b1ee 100644 --- a/lib/obp60task/Pagedata.h +++ b/lib/obp60task/Pagedata.h @@ -32,7 +32,8 @@ typedef struct{ double onewireTemp4 = 0; double onewireTemp5 = 0; double onewireTemp6 = 0; - int rotationAngle = 0; + double rotationAngle = 0; // Rotation angle in radiant + bool validRotAngle = false; // Valid flag for magnet present } SensorData; typedef struct{ diff --git a/lib/obp60task/config.json b/lib/obp60task/config.json index 4179eb7..0b8e48c 100644 --- a/lib/obp60task/config.json +++ b/lib/obp60task/config.json @@ -457,7 +457,7 @@ "list": [ "Off", "Bus Data", - "GPS Fix", + "GPS Fix Lost", "Limit Violation" ], "category": "OBP60 Display", @@ -548,7 +548,7 @@ "type": "list", "default": "Voltage", "description": "Type of page for page 1", - "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition"], + "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition"], "category": "OBP60 Page 1", "capabilities": { "obp60":"true" @@ -608,7 +608,7 @@ "type": "list", "default": "apparentWind", "description": "Type of page for page 2", - "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition"], + "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition"], "category": "OBP60 Page 2", "capabilities": { "obp60":"true" @@ -669,7 +669,7 @@ "type": "list", "default": "oneValue", "description": "Type of page for page 3", - "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition"], + "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition"], "category": "OBP60 Page 3", "capabilities": { "obp60":"true" @@ -730,7 +730,7 @@ "type": "list", "default": "oneValue", "description": "Type of page for page 4", - "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition"], + "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition"], "category": "OBP60 Page 4", "capabilities": { "obp60":"true" @@ -791,7 +791,7 @@ "type": "list", "default": "oneValue", "description": "Type of page for page 5", - "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition"], + "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition"], "category": "OBP60 Page 5", "capabilities": { "obp60":"true" @@ -852,7 +852,7 @@ "type": "list", "default": "oneValue", "description": "Type of page for page 6", - "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition"], + "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition"], "category": "OBP60 Page 6", "capabilities": { "obp60":"true" @@ -913,7 +913,7 @@ "type": "list", "default": "oneValue", "description": "Type of page for page 7", - "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition"], + "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition"], "category": "OBP60 Page 7", "capabilities": { "obp60":"true" @@ -974,7 +974,7 @@ "type": "list", "default": "oneValue", "description": "Type of page for page 8", - "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition"], + "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition"], "category": "OBP60 Page 8", "capabilities": { "obp60":"true" @@ -1035,7 +1035,7 @@ "type": "list", "default": "oneValue", "description": "Type of page for page 9", - "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition"], + "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition"], "category": "OBP60 Page 9", "capabilities": { "obp60":"true" @@ -1096,7 +1096,7 @@ "type": "list", "default": "oneValue", "description": "Type of page for page 10", - "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition"], + "list":["oneValue","twoValues","threeValues","forValues","forValues2","apparentWind","WindRose","Voltage","DST810","Clock","WhitePage","BME280","RudderPosition","KeelPosition"], "category": "OBP60 Page 10", "capabilities": { "obp60":"true" diff --git a/lib/obp60task/obp60task.cpp b/lib/obp60task/obp60task.cpp index 8e0ac33..35b6fea 100644 --- a/lib/obp60task/obp60task.cpp +++ b/lib/obp60task/obp60task.cpp @@ -252,7 +252,8 @@ void OBP60Init(GwApi *api){ String rotSensor=api->getConfig()->getConfigItem(api->getConfig()->useRotSensor,true)->asString(); if(String(rotSensor) == "AS5600"){ - if (as5600.detectMagnet() == 0) { + Wire.beginTransmission(AS5600_I2C_ADDR); + if (Wire.endTransmission() != 0) { api->getLogger()->logDebug(GwLog::ERROR,"Modul AS5600 not found, check wiring"); } else{ @@ -394,6 +395,8 @@ void registerAllPages(PageList &list){ list.add(®isterPageBME280); extern PageDescription registerPageRudderPosition; list.add(®isterPageRudderPosition); + extern PageDescription registerPageKeelPosition; + list.add(®isterPageKeelPosition); } // OBP60 Task @@ -525,6 +528,8 @@ void OBP60Task(GwApi *api){ String backlight = api->getConfig()->getConfigItem(api->getConfig()->backlight,true)->asString(); String envsensor = api->getConfig()->getConfigItem(api->getConfig()->useEnvSensor,true)->asString(); String rotsensor = api->getConfig()->getConfigItem(api->getConfig()->useRotSensor,true)->asString(); + String rotfunction = api->getConfig()->getConfigItem(api->getConfig()->rotFunction,true)->asString(); + int rotoffset = api->getConfig()->getConfigItem(api->getConfig()->rotOffset,true)->asInt(); // refreshmode defined in init section // displaycolor defined in init section @@ -576,11 +581,11 @@ void OBP60Task(GwApi *api){ } // If GPS fix then LED off (HDOP) - if(String(gpsFix) == "GPS Fix" && hdop->valid == true && int(hdop->value) <= 50){ + if(String(gpsFix) == "GPS Fix Lost" && hdop->valid == true && int(hdop->value) <= 50){ setPortPin(OBP_FLASH_LED, false); } // Ifmissing GPS fix then LED on - if(String(gpsFix) == "GPS Fix" && ((hdop->valid == true && int(hdop->value) > 50) || hdop->valid == false)){ + if(String(gpsFix) == "GPS Fix Lost" && ((hdop->valid == true && int(hdop->value) > 50) || hdop->valid == false)){ setPortPin(OBP_FLASH_LED, true); } @@ -748,17 +753,50 @@ void OBP60Task(GwApi *api){ } } - // Send rotation angle all 100ms - if(millis() > starttime7 + 100){ + // Send rotation angle all 1000ms + if(millis() > starttime7 + 1000){ starttime7 = millis(); - if(String(rotsensor) == "AS5600" && AS5600_ready == true){ + if(String(rotsensor) == "AS5600" && AS5600_ready == true && as5600.detectMagnet() == 1){ rotationangle = as5600.getRawAngle() * 0.087; // 0...4095 segments = 0.087 degree - commonData.data.rotationAngle = rotationangle; // Data take over to page - // Send to NMEA200 bus - if(!isnan(rotationangle)){ - SetN2kRudder(N2kMsg, rotationangle, 0, N2kRDO_NoDirectionOrder, N2kDoubleNA); + // Offset correction + if(rotoffset >= 0){ + rotationangle = rotationangle + rotoffset; + rotationangle = int(rotationangle) % 360; + } + else{ + rotationangle = rotationangle + 360 + rotoffset; + rotationangle = int(rotationangle) % 360; + } + commonData.data.rotationAngle = DegToRad(rotationangle); // Data take over to page + commonData.data.validRotAngle = true; // Valid true, magnet present + // Send to NMEA200 bus as rudder angle values + if(!isnan(rotationangle) && String(rotfunction) == "Rudder"){ + double rudder = rotationangle - 180; // Center position is 180° + // Rudder limits to +/-45° + if(rudder < -45){ + rudder = -45; + } + if(rudder > 45){ + rudder = 45; + } + SetN2kRudder(N2kMsg, DegToRad(rudder), 0, N2kRDO_NoDirectionOrder, PI); api->sendN2kMessage(N2kMsg); } + // Send to NMEA200 bus as wind angle values + if(!isnan(rotationangle) && String(rotfunction) == "Wind"){ + SetN2kWindSpeed(N2kMsg, 1, 0, DegToRad(rotationangle), N2kWind_Apprent); + api->sendN2kMessage(N2kMsg); + } + // Send to NMEA200 bus as trim angle values in [%] + if(!isnan(rotationangle) && (String(rotfunction) == "Mast" || String(rotfunction) == "Keel" || String(rotfunction) == "Trim" || String(rotfunction) == "Boom")){ + int trim = rotationangle * 100 / 360; // 0...360° -> 0...100% + SetN2kTrimTab(N2kMsg, trim, trim); + api->sendN2kMessage(N2kMsg); + } + } + else{ + commonData.data.rotationAngle = 0; // Center position 0° + commonData.data.validRotAngle = false; // Valid false, magnet missing } } diff --git a/platformio.ini b/platformio.ini index 80594ca..decf238 100644 --- a/platformio.ini +++ b/platformio.ini @@ -76,4 +76,4 @@ build_flags = -D BOARD_HOMBERGER ${env.build_flags} upload_port = /dev/esp32 -upload_protocol = esptool +upload_protocol = esptool \ No newline at end of file