diff --git a/Arduino/BTCDieselHeater/BTCDieselHeater.ino b/Arduino/BTCDieselHeater/BTCDieselHeater.ino index 36299b0..ce26a54 100644 --- a/Arduino/BTCDieselHeater/BTCDieselHeater.ino +++ b/Arduino/BTCDieselHeater/BTCDieselHeater.ino @@ -953,3 +953,24 @@ float getActualTemperature() { return fFilteredTemperature; } + +float getPumpMin() +{ + return DefaultBTCParams.getPump_Min(); +} + +float getPumpMax() +{ + return DefaultBTCParams.getPump_Max(); +} + +short getFanMin() +{ + return DefaultBTCParams.getFan_Min(); +} + +short getFanMax() +{ + return DefaultBTCParams.getFan_Max(); +} + diff --git a/Arduino/BTCDieselHeater/Screen5.cpp b/Arduino/BTCDieselHeater/Screen5.cpp index ab701fd..d0b11eb 100644 --- a/Arduino/BTCDieselHeater/Screen5.cpp +++ b/Arduino/BTCDieselHeater/Screen5.cpp @@ -26,6 +26,9 @@ #include "Screen5.h" #include "BTCWifi.h" +const int border = 4; +const int radius = 4; +const char* baseLabel = "<- ->"; CScreen5::CScreen5(C128x64_OLED& display, CScreenManager& mgr) : CScreen(display, mgr) { @@ -43,68 +46,91 @@ CScreen5::show(const CProtocol& CtlFrame, const CProtocol& HtrFrame) CScreen::show(CtlFrame, HtrFrame); CRect extents; + char str[16]; + int yPos; + const int col2 = 90; + const int col3 = _display.width() - border; _display.setCursor(0, 16); _display.print("Fuel Settings:"); - if(_rowSel == 1) { - _display.setCursor(0, 30); - _display.print("Enter password..."); - _showPassword(); - } - else { - char str[16]; - int yPos = 28; - const int border = 4; - const int radius = 4; - const int col2 = 90; - const int col3 = _display.width() - border; - CRect extents; - _display.setCursor(0, yPos); - _display.print("Pump (Hz)"); - _display.setCursor(col2, yPos); - sprintf(str, "%.1f", CtlFrame.getPump_Min()); - _display.printRightJustified(str); - if(_rowSel == 3 && _colSel == 0) { - _display.getTextExtents(str, extents); - extents.xPos = col2 - extents.width; - extents.yPos = yPos; - extents.Expand(border); - _display.drawRoundRect(extents.xPos, extents.yPos, extents.width, extents.height, radius, WHITE); - } - _display.setCursor(col3, yPos); - sprintf(str, "%.1f", CtlFrame.getPump_Max()); - _display.printRightJustified(str); - if(_rowSel == 3 && _colSel == 1) { - _display.getTextExtents(str, extents); - extents.xPos = col3 - extents.width; - extents.yPos = yPos; - extents.Expand(border); - _display.drawRoundRect(extents.xPos, extents.yPos, extents.width, extents.height, radius, WHITE); - } - yPos = 40; - _display.setCursor(0, yPos); - _display.print("Fan (RPM)"); - _display.setCursor(col2, yPos); - sprintf(str, "%d", CtlFrame.getFan_Min()); - _display.printRightJustified(str); - if(_rowSel == 2 && _colSel == 0) { - _display.getTextExtents(str, extents); - extents.xPos = col2 - extents.width; - extents.yPos = yPos; - extents.Expand(border); - _display.drawRoundRect(extents.xPos, extents.yPos, extents.width, extents.height, radius, WHITE); - } - _display.setCursor(col3, yPos); - sprintf(str, "%d", CtlFrame.getFan_Max()); - _display.printRightJustified(str); - if(_rowSel == 2 && _colSel == 1) { - _display.getTextExtents(str, extents); - extents.xPos = col3 - extents.width; - extents.yPos = yPos; - extents.Expand(border); - _display.drawRoundRect(extents.xPos, extents.yPos, extents.width, extents.height, radius, WHITE); - } + switch(_rowSel) { + case 0: + yPos = 28; + _display.setCursor(0, yPos); + _display.print("Pump (Hz)"); + _display.setCursor(col2, yPos); + sprintf(str, "%.1f", CtlFrame.getPump_Min()); + _display.printRightJustified(str); + _display.setCursor(col3, yPos); + sprintf(str, "%.1f", CtlFrame.getPump_Max()); + _display.printRightJustified(str); + yPos = 40; + _display.setCursor(0, yPos); + _display.print("Fan (RPM)"); + _display.setCursor(col2, yPos); + sprintf(str, "%d", CtlFrame.getFan_Min()); + _display.printRightJustified(str); + _display.setCursor(col3, yPos); + sprintf(str, "%d", CtlFrame.getFan_Max()); + _display.printRightJustified(str); + break; + case 1: + _display.setCursor(_display.xCentre(), 30); + _display.printCentreJustified("Enter password..."); + _showPassword(); + break; + case 2: + case 3: + case 4: + case 5: + _display.clearDisplay(); + //50, 38, 26, 14 + yPos = border + 36; + // Pump Minimum adjustment + _display.setCursor(0, yPos); + _display.print("Pump Min"); + _display.setCursor(col3, yPos); + sprintf(str, "%.1f", adjPump[0]); + _display.printRightJustified(str); + if(_rowSel == 2) { + _drawSelectionBox(col3, yPos, str); + } + // Pump Maximum adjustment + yPos = border + 24; + _display.setCursor(0, yPos); + _display.print("Pump Hz Max"); + _display.setCursor(col3, yPos); + sprintf(str, "%.1f", adjPump[1]); + _display.printRightJustified(str); + if(_rowSel == 3) { + _drawSelectionBox(col3, yPos, str); + } + // Fan Minimum adjustment + yPos = border + 12; + _display.setCursor(0, yPos); + _display.print("Fan Min"); + _display.setCursor(col3, yPos); + sprintf(str, "%d", adjFan[0]); + _display.printRightJustified(str); + if(_rowSel == 4) { + _drawSelectionBox(col3, yPos, str); + } + // Fan Maximum adjustment + yPos = border; + _display.setCursor(0, yPos); + _display.print("Fan RPM Max"); + _display.setCursor(col3, yPos); + sprintf(str, "%d", adjFan[1]); + _display.printRightJustified(str); + if(_rowSel == 5) { + _drawSelectionBox(col3, yPos, str); + } + + yPos = 53; + _display.setCursor(_display.xCentre(), yPos); + _display.printCentreJustified(baseLabel); + break; } _display.display(); @@ -133,6 +159,10 @@ CScreen5::keyHandler(uint8_t event) _bPWOK = true; _rowSel = 2; _colSel = 0; + adjPump[0] = getPumpMin(); + adjPump[1] = getPumpMax(); + adjFan[0] = getFanMin(); + adjFan[1] = getFanMax(); } else { for(int i= 0; i < 4; i++) @@ -157,7 +187,9 @@ CScreen5::keyHandler(uint8_t event) break; case 2: case 3: - _colSel = 0; + case 4: + case 5: + _adjustSetting(-1); break; } } @@ -169,11 +201,13 @@ CScreen5::keyHandler(uint8_t event) break; case 1: _colSel++; - UPPERLIMIT(_colSel, 3); + UPPERLIMIT(_colSel, 5); break; case 2: case 3: - _colSel = 1; + case 4: + case 5: + _adjustSetting(+1); break; } } @@ -181,16 +215,17 @@ CScreen5::keyHandler(uint8_t event) if(event & key_Up) { switch(_rowSel) { case 0: - _rowSel = 1; + case 2: + case 3: + case 4: + _rowSel++; _colSel = 0; + UPPERLIMIT(_rowSel, 5); break; case 1: _PWdig[_colSel]++; ROLLUPPERLIMIT(_PWdig[_colSel], 9, 0); break; - case 2: - _rowSel = 3; - break; } } // press DOWN @@ -201,10 +236,13 @@ CScreen5::keyHandler(uint8_t event) ROLLLOWERLIMIT(_PWdig[_colSel], 0, 9); break; case 2: - _rowSel--; // force skip over line 1 (password) - // deliberately not breaking + _rowSel = 0; + break; case 3: + case 4: + case 5: _rowSel--; + _colSel = 0; break; } } @@ -235,7 +273,6 @@ CScreen5::_showPassword() for(int i =0 ; i < 4; i++) { int xPos = _display.xCentre() - (2 - i) * (charWidth + spaceWidth); -// Serial.print(" xPos="); Serial.print(xPos); char str[8]; if(_PWdig[i] < 0) { @@ -251,13 +288,47 @@ CScreen5::_showPassword() // draw selection box extents.Expand(border); _display.drawRoundRect(extents.xPos, extents.yPos, extents.width, extents.height, radius, WHITE); - // // draw white background - // extents.Expand(1); - // _display.fillRect(extents.xPos, extents.yPos, extents.width, extents.height, WHITE); extents.Expand(-border); } _display.setCursor(extents.xPos, extents.yPos); _display.print(str); } -// Serial.println(""); } + +void +CScreen5::_drawSelectionBox(int x, int y, const char* str, int border, int radius) +{ + CRect extents; + _display.getTextExtents(str, extents); + extents.xPos = x - extents.width; + extents.yPos = y; + extents.Expand(border); + _display.drawRoundRect(extents.xPos, extents.yPos, extents.width, extents.height, radius, WHITE); +} + +void +CScreen5::_adjustSetting(int dir) +{ + switch(_rowSel) { + case 2: + adjPump[0] += (float(dir) * 0.1f); + LOWERLIMIT(adjPump[0], 0.5f); + UPPERLIMIT(adjPump[0], 10.f); + break; + case 3: + adjPump[1] += (float(dir) * 0.1f); + LOWERLIMIT(adjPump[1], 0.5f); + UPPERLIMIT(adjPump[1], 10.f); + break; + case 4: + adjFan[0] += dir * 10; + LOWERLIMIT(adjFan[0], 1000); + UPPERLIMIT(adjFan[0], 5000); + break; + case 5: + adjFan[1] += dir * 10; + LOWERLIMIT(adjFan[1], 1000); + UPPERLIMIT(adjFan[1], 5000); + break; + } +} \ No newline at end of file diff --git a/Arduino/BTCDieselHeater/Screen5.h b/Arduino/BTCDieselHeater/Screen5.h index bca270f..28d9b87 100644 --- a/Arduino/BTCDieselHeater/Screen5.h +++ b/Arduino/BTCDieselHeater/Screen5.h @@ -28,9 +28,14 @@ class CProtocol; class CScreen5 : public CScreen { bool _bPWOK; int _PWdig[4]; + float adjPump[2]; + short adjFan[2]; int _rowSel; int _colSel; void _showPassword(); + void _drawSelectionBox(int x, int y, const char* str, int border = 3, int radius = 4); + void _adjustSetting(int dir); + public: CScreen5(C128x64_OLED& display, CScreenManager& mgr); void show(const CProtocol& CtlFrame, const CProtocol& HtrFrame); diff --git a/Arduino/BTCDieselHeater/helpers.h b/Arduino/BTCDieselHeater/helpers.h index f0a3283..28e7ea0 100644 --- a/Arduino/BTCDieselHeater/helpers.h +++ b/Arduino/BTCDieselHeater/helpers.h @@ -35,6 +35,10 @@ extern float getFixedHz(); extern float getPumpHz(); extern void reqPumpPrime(bool on); extern float getActualTemperature(); +extern float getPumpMin(); +extern float getPumpMax(); +extern short getFanMin(); +extern short getFanMax(); #define LOWERLIMIT(A, B) if(A < B) A = B #define UPPERLIMIT(A, B) if(A > B) A = B