diff --git a/Arduino/BTCDieselHeater/CustomFont.cpp b/Arduino/BTCDieselHeater/128x64OLED.cpp similarity index 80% rename from Arduino/BTCDieselHeater/CustomFont.cpp rename to Arduino/BTCDieselHeater/128x64OLED.cpp index c644ff6..fc9f6ce 100644 --- a/Arduino/BTCDieselHeater/CustomFont.cpp +++ b/Arduino/BTCDieselHeater/128x64OLED.cpp @@ -5,7 +5,7 @@ * Author: ray */ -#include "CustomFont.h" +#include "128x64OLED.h" #include "DebugPort.h" #define DBG DebugPort.print @@ -13,12 +13,12 @@ //#define DEBUG_FONT -CCustomFont::CCustomFont(int8_t DC, int8_t CS, int8_t RST) : Adafruit_SH1106(DC, CS, RST) +C128x64_OLED::C128x64_OLED(int8_t DC, int8_t CS, int8_t RST) : Adafruit_SH1106(DC, CS, RST) { m_pFontInfo = NULL; } -size_t CCustomFont::write(uint8_t c) +size_t C128x64_OLED::write(uint8_t c) { if(m_pFontInfo) { if (c == '\n') { @@ -47,7 +47,7 @@ size_t CCustomFont::write(uint8_t c) void -CCustomFont::drawDotFactoryChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, const FONT_INFO* pFontDescriptor, int& xsize, int& ysize) +C128x64_OLED::drawDotFactoryChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, const FONT_INFO* pFontDescriptor, int& xsize, int& ysize) { #ifdef DEBUG_FONT char pr = c; @@ -97,3 +97,12 @@ CCustomFont::drawDotFactoryChar(int16_t x, int16_t y, unsigned char c, uint16_t } } } + +void +C128x64_OLED::printRightJustify(const char* str, int yPos, int RHS) +{ + int xPos = RHS - strlen(str) * 6; // standard font width + setCursor(xPos, yPos); + print(str); +} + diff --git a/Arduino/BTCDieselHeater/CustomFont.h b/Arduino/BTCDieselHeater/128x64OLED.h similarity index 73% rename from Arduino/BTCDieselHeater/CustomFont.h rename to Arduino/BTCDieselHeater/128x64OLED.h index 3849817..1048dc3 100644 --- a/Arduino/BTCDieselHeater/CustomFont.h +++ b/Arduino/BTCDieselHeater/128x64OLED.h @@ -2,10 +2,10 @@ #include "FontTypes.h" -class CCustomFont : public Adafruit_SH1106 { +class C128x64_OLED : public Adafruit_SH1106 { const FONT_INFO* m_pFontInfo; public: - CCustomFont(int8_t DC, int8_t CS, int8_t RST); + C128x64_OLED(int8_t DC, int8_t CS, int8_t RST); void drawDotFactoryChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, const FONT_INFO* pFontDescriptor, int& xsize, int& ysize); void setFontInfo(const FONT_INFO* pFontInfo) { m_pFontInfo = pFontInfo; }; @@ -13,6 +13,7 @@ public: cursor_x += x; cursor_y += y; }; + void printRightJustify(const char* str, int yPos, int RHS=127); size_t write(uint8_t c); }; diff --git a/Arduino/BTCDieselHeater/BTCDieselHeater.ino b/Arduino/BTCDieselHeater/BTCDieselHeater.ino index 2bc66fa..61e25d7 100644 --- a/Arduino/BTCDieselHeater/BTCDieselHeater.ino +++ b/Arduino/BTCDieselHeater/BTCDieselHeater.ino @@ -112,7 +112,6 @@ static HardwareSerial& BlueWireSerial(Serial1); void initBlueWireSerial(); bool validateFrame(const CProtocol& frame, const char* name); -void keyCallback(uint8_t event); // DS18B20 temperature sensor support OneWire ds(DS18B20_Pin); // on pin 5 (a 4.7K resistor is necessary) @@ -201,7 +200,6 @@ void setup() { DebugPort.begin(115200); KeyPad.init(keyLeft_pin, keyRight_pin, keyCentre_pin, keyUp_pin, keyDown_pin); - KeyPad.setCallback(keyCallback); // initialise DS18B20 temperature sensor(s) TempSensor.begin(); @@ -779,9 +777,36 @@ bool validateFrame(const CProtocol& frame, const char* name) return true; } -void keyCallback(uint8_t event) + +int getRunState() { - DebugPort.print("\007Callback key event=0x"); - DebugPort.println(event, HEX); + return pRxFrame->getRunState(); } +void requestOn() +{ + TxManage.queueOnRequest(); + SmartError.reset(); + Bluetooth.setRefTime(); +} + +void requestOff() +{ + TxManage.queueOffRequest(); + SmartError.inhibit(); + Bluetooth.setRefTime(); +} + +void ToggleOnOff() +{ + if(getRunState()) { + DebugPort.println("ToggleOnOff: Heater OFF"); + requestOff(); + } + else { + DebugPort.println("ToggleOnOff: Heater ON"); + requestOn(); + } +} + + diff --git a/Arduino/BTCDieselHeater/BluetoothAbstract.h b/Arduino/BTCDieselHeater/BluetoothAbstract.h index 836d76e..d657a68 100644 --- a/Arduino/BTCDieselHeater/BluetoothAbstract.h +++ b/Arduino/BTCDieselHeater/BluetoothAbstract.h @@ -37,4 +37,6 @@ public: virtual bool isConnected() { return false; }; }; +extern CBluetoothAbstract& getBluetoothClient(); + #endif // __BLUETOOTHABSTRACT_H__ diff --git a/Arduino/BTCDieselHeater/OLEDconsts.cpp b/Arduino/BTCDieselHeater/OLEDconsts.cpp new file mode 100644 index 0000000..e2d707f --- /dev/null +++ b/Arduino/BTCDieselHeater/OLEDconsts.cpp @@ -0,0 +1,213 @@ +#include "OLEDconsts.h" + +// 'Thermometer', 8x50px +const unsigned char thermometerBitmap [] PROGMEM = { + 0x00, 0x18, 0x24, 0x24, 0x24, 0x24, 0x24, 0x26, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, + 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x26, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, + 0x24, 0x24, 0x24, 0x24, 0x24, 0x26, 0x24, 0x24, 0x24, 0x24, 0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, + 0x7e, 0x3c +}; + +// 'ThermoPtr', 3x5px +const unsigned char thermoPtr [] PROGMEM = { + 0x80, 0xc0, 0xe0, 0xc0, 0x80 +}; + +// 'Bluetooth icon', 6x11px +#define W_BTICON 6 +#define H_BTICON 11 +const unsigned char BTicon [] PROGMEM = { + 0x20, 0x30, 0x28, 0xa4, 0x68, 0x30, 0x68, 0xa4, 0x28, 0x30, 0x20, +}; + +// 'wifiIcon', 13x10px +#define W_WIFIICON 13 +#define H_WIFIICON 10 +const unsigned char wifiIcon [] PROGMEM = { + 0x1f, 0xc0, 0x20, 0x20, 0x40, 0x10, 0x8f, 0x88, 0x10, 0x40, 0x20, 0x20, + 0x07, 0x00, 0x08, 0x80, 0x00, 0x00, 0x02, 0x00 +}; + + +// 'BatteryIcon', 15x10px +const unsigned char BatteryIcon [] PROGMEM = { + 0x30, 0x18, 0xff, 0xfe, 0x80, 0x02, 0xb6, 0xda, 0xb6, 0xda, 0xb6, 0xda, 0xb6, 0xda, 0xb6, 0xda, + 0x80, 0x02, 0xff, 0xfe +}; + +// 'GlowPlugIcon', 16x9px +const unsigned char GlowPlugIcon [] PROGMEM = { + 0x71, 0xc7, 0x0e, 0x38, 0x14, 0x14, 0x12, 0x24, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x0a, 0x28, + 0x0e, 0x38 +}; + +// 'HeatRise', 17x2px +const unsigned char GlowHeatIcon [] PROGMEM = { + 0x80, 0x00, 0x80, 0x40, 0x01, 0x00 +}; + +// 'Fan3_1a', 16x16px +const unsigned char FanIcon1 [] PROGMEM = { + 0x03, 0xc0, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x03, 0xc0, 0x07, 0xe0, 0x06, 0x60, + 0x7e, 0x7e, 0x87, 0xe1, 0x87, 0xe1, 0x84, 0x21, 0x84, 0x21, 0x78, 0x1e, 0x00, 0x00, 0x00, 0x00 +}; +// 'Fan3_2a', 16x16px +const unsigned char FanIcon2 [] PROGMEM = { + 0x00, 0x78, 0x00, 0x84, 0x00, 0x84, 0x00, 0x84, 0x00, 0x84, 0x7b, 0xf8, 0x87, 0xe0, 0x86, 0x60, + 0x86, 0x60, 0x87, 0xe0, 0x7b, 0xf8, 0x00, 0x84, 0x00, 0x84, 0x00, 0x84, 0x00, 0x84, 0x00, 0x78 +}; +// 'Fan3_3a', 16x16px +const unsigned char FanIcon3 [] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, 0x78, 0x1e, 0x84, 0x21, 0x84, 0x21, 0x87, 0xe1, 0x87, 0xe1, 0x7e, 0x7e, + 0x06, 0x60, 0x07, 0xe0, 0x03, 0xc0, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x03, 0xc0 +}; +// 'Fan3_4a', 16x16px +const unsigned char FanIcon4 [] PROGMEM = { + 0x1e, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x1f, 0xde, 0x07, 0xe1, 0x06, 0x61, + 0x06, 0x61, 0x07, 0xe1, 0x1f, 0xde, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x1e, 0x00 +}; + + +// 'FuelIcon', 7x12px +const unsigned char FuelIcon [] PROGMEM = { + 0x10, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe, 0xfe, 0xfe, 0x7c, 0x38 +}; + +// 'Target', 13x13px +const unsigned char TargetIcon [] PROGMEM = { + 0x0f, 0x80, 0x10, 0x40, 0x20, 0x20, 0x47, 0x10, 0x88, 0x88, 0x92, 0x48, 0x97, 0x48, 0x92, 0x48, + 0x88, 0x88, 0x47, 0x10, 0x20, 0x20, 0x10, 0x40, 0x0f, 0x80 +}; + + + +// # # ## ### # # ### ## ### ### ### +// # # ## # # # # # # # # # # # +// # # # # ## ### ## ### # ### ### +// # # # # # # # # # # # # # +// # ### ### ### # ## ### # ### ## +// '0', 3x5px +const unsigned char Mini0 [] PROGMEM = { + 0x40, 0xb0, 0xb0, 0xb0, 0x40 +}; + +// '1', 3x5px +const unsigned char Mini1 [] PROGMEM = { + 0x40, 0xc0, 0x40, 0x40, 0xe0 +}; + +// '2', 3x5px +const unsigned char Mini2 [] PROGMEM = { + 0xc0, 0x20, 0x40, 0x80, 0xe0 +}; + +// '3', 3x5px +const unsigned char Mini3 [] PROGMEM = { + 0xe0, 0x20, 0x60, 0x20, 0xe0 +}; + +// '4', 3x5px +const unsigned char Mini4 [] PROGMEM = { + 0xb0, 0xb0, 0xe0, 0x20, 0x20 +}; + +// '5', 3x5px +const unsigned char Mini5 [] PROGMEM = { + 0xe0, 0x80, 0xc0, 0x20, 0xc0 +}; + +// '6', 3x5px +const unsigned char Mini6 [] PROGMEM = { + 0x60, 0x80, 0xe0, 0xb0, 0xe0 +}; + +// '7', 3x5px +const unsigned char Mini7 [] PROGMEM = { + 0xe0, 0x20, 0x20, 0x20, 0x20 +}; + +// '8', 3x5px +const unsigned char Mini8 [] PROGMEM = { + 0xe0, 0xb0, 0xe0, 0xb0, 0xe0 +}; + +// '9', 3x5px +const unsigned char Mini9 [] PROGMEM = { + 0xe0, 0xb0, 0xe0, 0x20, 0xc0 +}; + +// 'DP', 3x5px +const unsigned char MiniDP [] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, 0x40 +}; + +// 'Deg', 3x5px +const unsigned char MiniDeg [] PROGMEM = { + 0xc0, 0xc0, 0x00, 0x00, 0x00 +}; + +// 'C', 3x5px +const unsigned char MiniC [] PROGMEM = { + 0xe0, 0x80, 0x80, 0x80, 0xe0 +}; + +// 'H', 3x5px +const unsigned char MiniH [] PROGMEM = { + 0xb0, 0xb0, 0xe0, 0xb0, 0xb0 +}; + +// 'z', 3x5px +const unsigned char Miniz [] PROGMEM = { + 0x00, 0x00, 0xe0, 0x40, 0xe0 +}; + +// ' ', 3x5px +const unsigned char MiniSpc [] PROGMEM = { + 0x00, 0x00, 0x00, 0x00, 0x00 +}; + +// 'A', 3x5px +const unsigned char MiniA [] PROGMEM = { + 0xe0, 0xb0, 0xe0, 0xb0, 0xb0 +}; + +// 'P', 3x5px +const unsigned char MiniP [] PROGMEM = { + 0xe0, 0xb0, 0xe0, 0x80, 0x80 +}; + +// 'V', 3x5px +const unsigned char MiniV [] PROGMEM = { + 0xb0, 0xb0, 0xb0, 0xb0, 0x40 +}; + +// 'W', 3x5px +const unsigned char MiniW [] PROGMEM = { + 0xb0, 0xb0, 0xb0, 0xe0, 0xb0 +}; + +const char* Runstates [] PROGMEM = { + " Stopped/Ready ", + "Starting...", + "Igniting...", + " Ignition retry ", + "Ignited", + "Running", + "Stopping", + "Shutdown", + "Cooling" +}; + +const char* Errstates [] PROGMEM = { + "Low voltage", // E-01 + "High voltage", // E-02 + "Glow plug fault", // E-03 + "Pump fault", // E-04 + "Overheat", // E-05 + "Motor fault", // E-06 + "Comms fault", // E-07 + "Flame out", // E-08 + "Temp sense", // E-09 + "Ignition fail", // E-10 + "Unknown error?" // mystery code! +}; diff --git a/Arduino/BTCDieselHeater/OLEDconsts.h b/Arduino/BTCDieselHeater/OLEDconsts.h index e07b7c5..7dc258a 100644 --- a/Arduino/BTCDieselHeater/OLEDconsts.h +++ b/Arduino/BTCDieselHeater/OLEDconsts.h @@ -1,212 +1,63 @@ +#include // 'Thermometer', 8x50px -const unsigned char thermometerBitmap [] PROGMEM = { - 0x00, 0x18, 0x24, 0x24, 0x24, 0x24, 0x24, 0x26, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, - 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x26, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, 0x24, - 0x24, 0x24, 0x24, 0x24, 0x24, 0x26, 0x24, 0x24, 0x24, 0x24, 0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, - 0x7e, 0x3c -}; +#define W_BULB_ICON 8 +#define H_BULB_ICON 50 +extern const unsigned char thermometerBitmap []; // 'ThermoPtr', 3x5px -const unsigned char thermoPtr [] PROGMEM = { - 0x80, 0xc0, 0xe0, 0xc0, 0x80 -}; +#define W_PTR_ICON 3 +#define H_PTR_ICON 5 +extern const unsigned char thermoPtr []; // 'Bluetooth icon', 6x11px -#define W_BTICON 6 -#define H_BTICON 11 -const unsigned char BTicon [] PROGMEM = { - 0x20, 0x30, 0x28, 0xa4, 0x68, 0x30, 0x68, 0xa4, 0x28, 0x30, 0x20, -}; +#define W_BT_ICON 6 +#define H_BT_ICON 11 +extern const unsigned char BTicon []; // 'wifiIcon', 13x10px -#define W_WIFIICON 13 -#define H_WIFIICON 10 -const unsigned char wifiIcon [] PROGMEM = { - 0x1f, 0xc0, 0x20, 0x20, 0x40, 0x10, 0x8f, 0x88, 0x10, 0x40, 0x20, 0x20, - 0x07, 0x00, 0x08, 0x80, 0x00, 0x00, 0x02, 0x00 -}; - +#define W_WIFI_ICON 13 +#define H_WIFI_ICON 10 +extern const unsigned char wifiIcon []; // 'BatteryIcon', 15x10px -const unsigned char BatteryIcon [] PROGMEM = { - 0x30, 0x18, 0xff, 0xfe, 0x80, 0x02, 0xb6, 0xda, 0xb6, 0xda, 0xb6, 0xda, 0xb6, 0xda, 0xb6, 0xda, - 0x80, 0x02, 0xff, 0xfe -}; +#define W_BATT_ICON 15 +#define H_BATT_ICON 10 +extern const unsigned char BatteryIcon []; // 'GlowPlugIcon', 16x9px -const unsigned char GlowPlugIcon [] PROGMEM = { - 0x71, 0xc7, 0x0e, 0x38, 0x14, 0x14, 0x12, 0x24, 0x11, 0x44, 0x11, 0x44, 0x11, 0x44, 0x0a, 0x28, - 0x0e, 0x38 -}; +#define W_GLOW_ICON 16 +#define H_GLOW_ICON 9 +extern const unsigned char GlowPlugIcon []; // 'HeatRise', 17x2px -const unsigned char GlowHeatIcon [] PROGMEM = { - 0x80, 0x00, 0x80, 0x40, 0x01, 0x00 -}; +#define W_HEAT_ICON 17 +#define H_HEAT_ICON 2 +extern const unsigned char GlowHeatIcon []; +#define W_FAN_ICON 16 +#define H_FAN_ICON 16 // 'Fan3_1a', 16x16px -const unsigned char FanIcon1 [] PROGMEM = { - 0x03, 0xc0, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x03, 0xc0, 0x07, 0xe0, 0x06, 0x60, - 0x7e, 0x7e, 0x87, 0xe1, 0x87, 0xe1, 0x84, 0x21, 0x84, 0x21, 0x78, 0x1e, 0x00, 0x00, 0x00, 0x00 -}; +extern const unsigned char FanIcon1 []; // 'Fan3_2a', 16x16px -const unsigned char FanIcon2 [] PROGMEM = { - 0x00, 0x78, 0x00, 0x84, 0x00, 0x84, 0x00, 0x84, 0x00, 0x84, 0x7b, 0xf8, 0x87, 0xe0, 0x86, 0x60, - 0x86, 0x60, 0x87, 0xe0, 0x7b, 0xf8, 0x00, 0x84, 0x00, 0x84, 0x00, 0x84, 0x00, 0x84, 0x00, 0x78 -}; +extern const unsigned char FanIcon2 []; // 'Fan3_3a', 16x16px -const unsigned char FanIcon3 [] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, 0x78, 0x1e, 0x84, 0x21, 0x84, 0x21, 0x87, 0xe1, 0x87, 0xe1, 0x7e, 0x7e, - 0x06, 0x60, 0x07, 0xe0, 0x03, 0xc0, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x04, 0x20, 0x03, 0xc0 -}; +extern const unsigned char FanIcon3 []; // 'Fan3_4a', 16x16px -const unsigned char FanIcon4 [] PROGMEM = { - 0x1e, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x1f, 0xde, 0x07, 0xe1, 0x06, 0x61, - 0x06, 0x61, 0x07, 0xe1, 0x1f, 0xde, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x21, 0x00, 0x1e, 0x00 -}; +extern const unsigned char FanIcon4 []; // 'FuelIcon', 7x12px -const unsigned char FuelIcon [] PROGMEM = { - 0x10, 0x10, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe, 0xfe, 0xfe, 0x7c, 0x38 -}; +#define W_FUEL_ICON 7 +#define H_FUEL_ICON 12 +extern const unsigned char FuelIcon []; // 'Target', 13x13px -const unsigned char TargetIcon [] PROGMEM = { - 0x0f, 0x80, 0x10, 0x40, 0x20, 0x20, 0x47, 0x10, 0x88, 0x88, 0x92, 0x48, 0x97, 0x48, 0x92, 0x48, - 0x88, 0x88, 0x47, 0x10, 0x20, 0x20, 0x10, 0x40, 0x0f, 0x80 -}; +#define W_TARGET_ICON 13 +#define H_TARGET_ICON 13 +extern const unsigned char TargetIcon []; +extern const char* Runstates []; -// # # ## ### # # ### ## ### ### ### -// # # ## # # # # # # # # # # # -// # # # # ## ### ## ### # ### ### -// # # # # # # # # # # # # # -// # ### ### ### # ## ### # ### ## -// '0', 3x5px -const unsigned char Mini0 [] PROGMEM = { - 0x40, 0xb0, 0xb0, 0xb0, 0x40 -}; - -// '1', 3x5px -const unsigned char Mini1 [] PROGMEM = { - 0x40, 0xc0, 0x40, 0x40, 0xe0 -}; - -// '2', 3x5px -const unsigned char Mini2 [] PROGMEM = { - 0xc0, 0x20, 0x40, 0x80, 0xe0 -}; - -// '3', 3x5px -const unsigned char Mini3 [] PROGMEM = { - 0xe0, 0x20, 0x60, 0x20, 0xe0 -}; - -// '4', 3x5px -const unsigned char Mini4 [] PROGMEM = { - 0xb0, 0xb0, 0xe0, 0x20, 0x20 -}; - -// '5', 3x5px -const unsigned char Mini5 [] PROGMEM = { - 0xe0, 0x80, 0xc0, 0x20, 0xc0 -}; - -// '6', 3x5px -const unsigned char Mini6 [] PROGMEM = { - 0x60, 0x80, 0xe0, 0xb0, 0xe0 -}; - -// '7', 3x5px -const unsigned char Mini7 [] PROGMEM = { - 0xe0, 0x20, 0x20, 0x20, 0x20 -}; - -// '8', 3x5px -const unsigned char Mini8 [] PROGMEM = { - 0xe0, 0xb0, 0xe0, 0xb0, 0xe0 -}; - -// '9', 3x5px -const unsigned char Mini9 [] PROGMEM = { - 0xe0, 0xb0, 0xe0, 0x20, 0xc0 -}; - -// 'DP', 3x5px -const unsigned char MiniDP [] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, 0x40 -}; - -// 'Deg', 3x5px -const unsigned char MiniDeg [] PROGMEM = { - 0xc0, 0xc0, 0x00, 0x00, 0x00 -}; - -// 'C', 3x5px -const unsigned char MiniC [] PROGMEM = { - 0xe0, 0x80, 0x80, 0x80, 0xe0 -}; - -// 'H', 3x5px -const unsigned char MiniH [] PROGMEM = { - 0xb0, 0xb0, 0xe0, 0xb0, 0xb0 -}; - -// 'z', 3x5px -const unsigned char Miniz [] PROGMEM = { - 0x00, 0x00, 0xe0, 0x40, 0xe0 -}; - -// ' ', 3x5px -const unsigned char MiniSpc [] PROGMEM = { - 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -// 'A', 3x5px -const unsigned char MiniA [] PROGMEM = { - 0xe0, 0xb0, 0xe0, 0xb0, 0xb0 -}; - -// 'P', 3x5px -const unsigned char MiniP [] PROGMEM = { - 0xe0, 0xb0, 0xe0, 0x80, 0x80 -}; - -// 'V', 3x5px -const unsigned char MiniV [] PROGMEM = { - 0xb0, 0xb0, 0xb0, 0xb0, 0x40 -}; - -// 'W', 3x5px -const unsigned char MiniW [] PROGMEM = { - 0xb0, 0xb0, 0xb0, 0xe0, 0xb0 -}; - -const char* Runstates [] PROGMEM = { - " Stopped/Ready ", - "Starting...", - "Igniting...", - " Ignition retry ", - "Ignited", - "Running", - "Stopping", - "Shutdown", - "Cooling" -}; - -const char* Errstates [] PROGMEM = { - "Low voltage", // E-01 - "High voltage", // E-02 - "Glow plug fault", // E-03 - "Pump fault", // E-04 - "Overheat", // E-05 - "Motor fault", // E-06 - "Comms fault", // E-07 - "Flame out", // E-08 - "Temp sense", // E-09 - "Ignition fail", // E-10 - "Unknown error?" // mystery code! -}; +extern const char* Errstates []; \ No newline at end of file diff --git a/Arduino/BTCDieselHeater/Screen1.cpp b/Arduino/BTCDieselHeater/Screen1.cpp new file mode 100644 index 0000000..60096e0 --- /dev/null +++ b/Arduino/BTCDieselHeater/Screen1.cpp @@ -0,0 +1,361 @@ +#include "128x64OLED.h" +#include "MiniFont.h" +#include "tahoma16.h" +#include "OLEDconsts.h" +#include "BluetoothAbstract.h" +#include "Screen1.h" +#include "BTCWifi.h" +#include "KeyPad.h" + +#include "Protocol.h" + +bool animatePump = false; +bool animateRPM = false; +bool animateGlow = false; + +extern float fFilteredTemperature; + +void showThermometer(C128x64_OLED& display, float desired, float actual); +void showBodyThermometer(C128x64_OLED& display, int actual); +void showGlowPlug(C128x64_OLED& display, int power); +void showFan(C128x64_OLED& display, int RPM); +void showFuel(C128x64_OLED& display, float rate); +void showRunState(C128x64_OLED& display, int state, int errstate); + +extern void ToggleOnOff(); +extern void requestOn(); +extern void requestOff(); +extern int getRunState(); + +#define MAXIFONT tahoma_16ptFontInfo +#define MINIFONT miniFontInfo + +#define X_FAN_ICON 55 +#define Y_FAN_ICON 39 +#define X_FUEL_ICON 81 +#define Y_FUEL_ICON 39 +#define X_TARGET_ICON 31 +#define Y_TARGET_ICON 39 +#define Y_BASELINE 58 +#define X_GLOW_ICON 97 +#define Y_GLOW_ICON 38 +#define X_BODY_BULB 119 +#define X_BULB 1 // >= 1 +#define Y_BULB 4 + + +#define MINI_BATTLABEL +#define MINI_TEMPLABEL +#define MINI_TARGETLABEL +#define MINI_FANLABEL +#define MINI_GLOWLABEL +#define MINI_FUELLABEL +#define MINI_BODYLABEL + + +void showScreen1(C128x64_OLED& display, const CProtocol& CtlFrame, const CProtocol& HtrFrame) +{ + int runstate = HtrFrame.getRunState(); + int errstate = HtrFrame.getErrState(); + if(errstate) errstate--; // correct for +1 biased return value + + float desiredT = 0; + if(runstate && (runstate <= 5)) { + if(CtlFrame.isThermostat()) + desiredT = CtlFrame.getTemperature_Desired(); + else + desiredT = -HtrFrame.getPump_Fixed() * 0.1f; + } + + showThermometer(display, + desiredT, // read values from most recently sent [BTC] frame + fFilteredTemperature); + + animateRPM = false; + animatePump = false; + animateGlow = false; + + if(runstate) { + float power = HtrFrame.getGlowPlug_Current() * 0.01 * HtrFrame.getGlowPlug_Voltage() * 0.1; + if(power > 1) { + showGlowPlug(display, int(power)); + } + + showFan(display, HtrFrame.getFan_Actual()); + + showFuel(display, HtrFrame.getPump_Actual() * 0.1f); + + showBodyThermometer(display, HtrFrame.getTemperature_HeatExchg()); + } + else { + if(isWifiConnected()) { + display.printRightJustify(getWifiAddrStr(), 57); + } + } + + showRunState(display, runstate, errstate); + +#ifdef DEMO_LARGEFONT + display.fillRect(20,20, 80,16, BLACK); + display.setCursor(20,20); + display.setFontInfo(&MAXIFONT); // Dot Factory Font + display.print("25.6`"); + display.setFontInfo(NULL); // standard 5x7 font +#endif + +} + + +void animateScreen1(C128x64_OLED& display) +{ + static int fan = 0; + static int drip = 0; + static int heat = 0; + + if(animatePump || animateRPM || animateGlow) { + + if(animatePump) { + // erase region of fuel icon + display.fillRect(X_FUEL_ICON, Y_FUEL_ICON, W_FUEL_ICON, H_FUEL_ICON + 4, BLACK); + display.drawBitmap(X_FUEL_ICON, Y_FUEL_ICON+(drip/2), FuelIcon, W_FUEL_ICON, H_FUEL_ICON, WHITE); + drip++; + drip &= 0x07; + } + + if(animateRPM) { + // erase region of fuel icon + display.fillRect(X_FAN_ICON, Y_FAN_ICON, W_FAN_ICON, H_FAN_ICON, BLACK); + switch(fan) { + case 0: display.drawBitmap(X_FAN_ICON, Y_FAN_ICON, FanIcon1, W_FAN_ICON, H_FAN_ICON, WHITE); break; + case 1: display.drawBitmap(X_FAN_ICON, Y_FAN_ICON, FanIcon2, W_FAN_ICON, H_FAN_ICON, WHITE); break; + case 2: display.drawBitmap(X_FAN_ICON, Y_FAN_ICON, FanIcon3, W_FAN_ICON, H_FAN_ICON, WHITE); break; + case 3: display.drawBitmap(X_FAN_ICON, Y_FAN_ICON, FanIcon4, W_FAN_ICON, H_FAN_ICON, WHITE); break; + } + fan++; + fan &= 0x03; + } + + if(animateGlow) { + display.fillRect(X_GLOW_ICON, Y_GLOW_ICON, 17, 10, BLACK); + display.drawBitmap(X_GLOW_ICON, Y_GLOW_ICON, GlowPlugIcon, 16, 9, WHITE); + display.drawBitmap(X_GLOW_ICON, Y_GLOW_ICON + 2 + heat, GlowHeatIcon, 17, 2, WHITE); + heat -= 2; + heat &= 0x07; + } + } + display.display(); +} + + +#define TEMP_YPOS(A) ((((20 - A) * 3) / 2) + 22) +void showThermometer(C128x64_OLED& display, float desired, float actual) +{ + char msg[16]; + // draw bulb design + display.drawBitmap(X_BULB, Y_BULB, thermometerBitmap, W_BULB_ICON, H_BULB_ICON, WHITE); + // draw mercury + int yPos = Y_BULB + TEMP_YPOS(actual); + display.drawLine(X_BULB + 3, yPos, X_BULB + 3, Y_BULB + 42, WHITE); + display.drawLine(X_BULB + 4, yPos, X_BULB + 4, Y_BULB + 42, WHITE); + // print actual temperature +#ifdef MINI_TEMPLABEL + sprintf(msg, "%.1f`C", actual); + display.setCursor(0, Y_BASELINE); + display.setFontInfo(&MINIFONT); // select Mini Font + display.print(msg); + display.setFontInfo(NULL); +#else + display.setTextColor(WHITE); + display.setCursor(0, Y_BASELINE); + display.print(actual, 1); +#endif + + // draw set point + if(desired) { + display.drawBitmap(X_TARGET_ICON, Y_TARGET_ICON, TargetIcon, W_TARGET_ICON, H_TARGET_ICON, WHITE); // set indicator against bulb + char msg[16]; + if(desired > 0) { + int yPos = Y_BULB + TEMP_YPOS(desired) - 2; + display.drawBitmap(X_BULB-1, yPos, thermoPtr, 3, 5, WHITE); // set indicator against bulb + sprintf(msg, "%.0f`C", desired); + } + else { + sprintf(msg, "%.1fHz", -desired); + } +#ifdef MINI_TARGETLABEL + int xPos = X_TARGET_ICON + 7 - strlen(msg) * 2; // 2 = 1/2 width mini font + display.setCursor(xPos, Y_BASELINE); + display.setFontInfo(&MINIFONT); // select Mini Font + display.print(msg); + display.setFontInfo(NULL); +#else + int xPos = X_TARGET_ICON + 6 - strlen(msg) * 3; // 3 = 1/2 width normal font + display.setCursor(xPos, Y_BASELINE); + display.print(msg); +#endif + } +} + +#define BODY_YPOS(A) ((((100 - A) * 3) / 16) + 22) // 100degC centre - ticks +- 80C +void showBodyThermometer(C128x64_OLED& display, int actual) +{ + // draw bulb design + display.drawBitmap(X_BODY_BULB, Y_BULB, thermometerBitmap, 8, 50, WHITE); + // draw mercury + int yPos = Y_BULB + BODY_YPOS(actual); + display.drawLine(X_BODY_BULB + 3, yPos, X_BODY_BULB + 3, Y_BULB + 42, WHITE); + display.drawLine(X_BODY_BULB + 4, yPos, X_BODY_BULB + 4, Y_BULB + 42, WHITE); + // print actual temperature + display.setTextColor(WHITE); + char label[16]; + // determine width and position right justified +#ifdef MINI_BODYLABEL + sprintf(label, "%d`C", actual); + int width = strlen(label) * 4; + display.setCursor(125-width, Y_BASELINE); + display.setFontInfo(&MINIFONT); // select Mini Font + display.print(label); + display.setFontInfo(NULL); +#else + sprintf(label, "%d", actual); + int width = strlen(label) * 6; + display.setCursor(127-width, Y_BASELINE); + display.print(label); +#endif +} + + +void showGlowPlug(C128x64_OLED& display, int power) +{ + display.drawBitmap(X_GLOW_ICON, Y_GLOW_ICON, GlowPlugIcon, W_GLOW_ICON, H_GLOW_ICON, WHITE); +// animateGlow = true; +#ifdef MINI_GLOWLABEL + char msg[16]; + sprintf(msg, "%dW", power); + int xPos = X_GLOW_ICON + (W_GLOW_ICON/2) - strlen(msg) * 2; + display.setCursor(xPos, Y_GLOW_ICON+H_GLOW_ICON+3); + display.setFontInfo(&MINIFONT); // select Mini Font + display.print(msg); + display.setFontInfo(NULL); +#else + display.setCursor(X_GLOW_ICON, Y_GLOW_ICON+H_GLOW_ICON+3); + display.print(power); + display.print("W"); +#endif +} + +void showFan(C128x64_OLED& display, int RPM) +{ + // NOTE: fan rotation animation performed in animateOLED + animateRPM = RPM != 0; // used by animation routine + + display.setTextColor(WHITE); + char msg[16]; + sprintf(msg, "%d", RPM); +#ifdef MINI_FANLABEL + int xPos = X_FAN_ICON + (W_FAN_ICON/2) - strlen(msg) * 2; // 3 = 1/2 width font + display.setCursor(xPos, Y_BASELINE); + display.setFontInfo(&MINIFONT); // select Mini Font + display.print(msg); + display.setFontInfo(NULL); +#else + int xPos = X_FAN_ICON + (W_FAN_ICON/2) - ( strlen(msg) * 3); // 3 = 1/2 width font + display.setCursor(xPos, Y_BASELINE); + display.print(msg); +#endif +} + +void showFuel(C128x64_OLED& display, float rate) +{ + // NOTE: fuel drop animation performed in animateOLED + animatePump = rate != 0; // used by animation routine + if(rate) { + char msg[16]; + sprintf(msg, "%.1f", rate); +#ifdef MINI_FUELLABEL + int xPos = X_FUEL_ICON + (W_FUEL_ICON/2) - strlen(msg) * 2; // 3 = 1/2 width font + display.setCursor(xPos, Y_BASELINE); + display.setFontInfo(&MINIFONT); // select Mini Font + display.print(msg); + display.setFontInfo(NULL); +#else + int xPos = X_FUEL_ICON + (W_FUEL_ICON/2) - ( strlen(msg) * 3); // 3 = 1/2 width font + display.setCursor(xPos, Y_BASELINE); + display.setTextColor(WHITE); + display.print(msg); +#endif + } +} + +void showRunState(C128x64_OLED& display, int runstate, int errstate) +{ + static bool toggle = false; + const char* toPrint = NULL; + int yPos = 25; + display.setTextColor(WHITE, BLACK); + if(runstate >= 0 && runstate <= 8) { + if(((runstate == 0) || (runstate > 5)) && errstate) { + // create an "E-XX" message to display + char msg[16]; + sprintf(msg, "E-%02d", errstate); + int xPos = 64 - ((strlen(msg)/2) * 6); + if(runstate > 5) + yPos -= 8; + display.setCursor(xPos, yPos); + yPos += 8; + // flash error code + toggle = !toggle; + if(toggle) + display.print(msg); + else { + display.print(" "); + } + // bounds limit error and gather message + if(errstate > 10) errstate = 11; + toPrint = Errstates[errstate-1]; + } + else { + toPrint = Runstates[runstate]; + } + } + if(toPrint) { + int width = strlen(toPrint); + int xPos = 64 - ((width/2) * 6); + display.setCursor(xPos, yPos); + display.print(toPrint); + } +} + + +void keyhandlerScreen1(uint8_t event) +{ + static int repeatCount = -1; + if(event & keyPressed) { + repeatCount = 0; // unlock tracking of repeat events + } + // require hold to turn ON or OFF + if(event & keyRepeat) { + if(repeatCount >= 0) { + repeatCount++; + if(event & key_Centre) { + if(getRunState()) { + if(repeatCount > 5) { + repeatCount = -1; // prevent double handling + requestOff(); + } + } + else { + if(repeatCount > 3) { + repeatCount = -1; + requestOn(); + } + } + } + } + } + if(event & keyReleased) { + repeatCount = -1; + } +} + + diff --git a/Arduino/BTCDieselHeater/Screen1.h b/Arduino/BTCDieselHeater/Screen1.h new file mode 100644 index 0000000..ce55309 --- /dev/null +++ b/Arduino/BTCDieselHeater/Screen1.h @@ -0,0 +1,9 @@ +#include "stdint.h" + +class C128x64_OLED; +class CProtocol; + +void showScreen1(C128x64_OLED& display, const CProtocol& CtlFrame, const CProtocol& HtrFrame); +void animateScreen1(C128x64_OLED& display); + +void keyhandlerScreen1(uint8_t event); diff --git a/Arduino/BTCDieselHeater/SmartError.cpp b/Arduino/BTCDieselHeater/SmartError.cpp index 7a477ab..021683a 100644 --- a/Arduino/BTCDieselHeater/SmartError.cpp +++ b/Arduino/BTCDieselHeater/SmartError.cpp @@ -84,12 +84,12 @@ CSmartError::monitor(unsigned char newRunState) if(m_prevRunState != newRunState) { // check for transition to startup // - force cancellation of an on request if we generated it - if(newRunState == 2) { + if(newRunState >= 2) { TxManage.queueOnRequest(false); // ensure ON request is cancelled } // check for transition to shutdown // - force cancellation of an off request if we generated it - if(newRunState == 7) { + if(newRunState >= 7) { TxManage.queueOffRequest(false); // ensure OFF request is cancelled } } diff --git a/Arduino/BTCDieselHeater/display.cpp b/Arduino/BTCDieselHeater/display.cpp index fb89f94..d9bb8d8 100644 --- a/Arduino/BTCDieselHeater/display.cpp +++ b/Arduino/BTCDieselHeater/display.cpp @@ -1,5 +1,5 @@ #include -#include "CustomFont.h" +#include "128x64OLED.h" #include "MiniFont.h" #include "tahoma16.h" #include "protocol.h" @@ -8,37 +8,25 @@ #include "BluetoothAbstract.h" #include "OLEDconsts.h" #include "BTCWifi.h" +#include "BluetoothAbstract.h" +#include "Screen1.h" +#include "KeyPad.h" #define MAXIFONT tahoma_16ptFontInfo #define MINIFONT miniFontInfo -#define X_FANICON 55 -#define Y_FANICON 39 -#define X_FUELICON 81 -#define Y_FUELICON 39 -#define X_TARGETICON 31 -#define Y_TARGETICON 39 -#define Y_BASELINE 58 -#define X_BATTICON 95 -#define Y_BATTICON 0 -#define X_GLOWICON 97 -#define Y_GLOWICON 38 -#define X_BODYBULB 119 -#define X_BULB 1 // >= 1 -#define Y_BULB 4 -#define X_WIFIICON 22 -#define Y_WIFIICON 0 -#define X_BTICON 12 -#define Y_BTICON 0 - +#define X_BATT_ICON 95 +#define Y_BATT_ICON 0 +#define X_WIFI_ICON 22 +#define Y_WIFI_ICON 0 +#define X_BT_ICON 12 +#define Y_BT_ICON 0 #define MINI_BATTLABEL -#define MINI_TEMPLABEL -#define MINI_TARGETLABEL -#define MINI_FANLABEL -#define MINI_GLOWLABEL -#define MINI_FUELLABEL -#define MINI_BODYLABEL + +void showBTicon(C128x64_OLED& display); +void showWifiIcon(C128x64_OLED& display); +void showBatteryIcon(C128x64_OLED& display, float voltage); // // **** NOTE: There are two very lame libaries conspiring to make life difficult **** @@ -53,14 +41,13 @@ // 128 x 64 OLED support SPIClass SPI; // default constructor opens HSPI on standard pins : MOSI=13,CLK=14,MISO=12(unused) //Adafruit_SH1106 display(OLED_DC_pin, -1, OLED_CS_pin); -CCustomFont display(OLED_DC_pin, -1, OLED_CS_pin); +C128x64_OLED display(OLED_DC_pin, -1, OLED_CS_pin); -bool animatePump = false; +/*bool animatePump = false; bool animateRPM = false; bool animateGlow = false; - -extern int TestKeys; -extern float fFilteredTemperature; +*/ +/*extern float fFilteredTemperature; extern CBluetoothAbstract& getBluetoothClient(); void showThermometer(float desired, float actual); @@ -73,7 +60,7 @@ void showFan(int RPM); void showFuel(float rate); void showRunState(int state, int errstate); void printRightJustify(const char* str, int yPos, int RHS=128); - +*/ void initOLED() { SPI.setFrequency(8000000); @@ -83,214 +70,59 @@ void initOLED() // Show initial display buffer contents on the screen -- // the library initializes this with an Adafruit splash screen. display.display(); -} -void updateOLED(const CProtocol& CtlFrame, const CProtocol& HtrFrame) -{ - int runstate = HtrFrame.getRunState(); - int errstate = HtrFrame.getErrState(); - if(errstate) errstate--; // correct for +1 biased return value - - display.clearDisplay(); - - float desiredT = 0; - if(runstate && (runstate <= 5)) { - if(CtlFrame.isThermostat()) - desiredT = CtlFrame.getTemperature_Desired(); - else - desiredT = -HtrFrame.getPump_Fixed() * 0.1f; - } - - showThermometer(desiredT, // read values from most recently sent [BTC] frame - fFilteredTemperature); - - if(getBluetoothClient().isConnected()) - showBTicon(); - - if(isWifiConnected()) { - showWifiIcon(); - display.fillRect(X_WIFIICON + 8, Y_WIFIICON + 5, 10, 7, BLACK); - display.setFontInfo(&MINIFONT); // select Mini Font - display.setCursor(X_WIFIICON+9, Y_WIFIICON+6); - display.print("AP"); - display.setFontInfo(NULL); - } - - float voltage = HtrFrame.getVoltage_Supply() * 0.1f; - showBatteryIcon(voltage); - - animateRPM = false; - animatePump = false; - animateGlow = false; - - if(runstate) { - float power = HtrFrame.getGlowPlug_Current() * 0.01 * HtrFrame.getGlowPlug_Voltage() * 0.1; - if(power > 1) { - showGlowPlug(int(power)); - } - - showFan(HtrFrame.getFan_Actual()); - - showFuel(HtrFrame.getPump_Actual() * 0.1f); - - showBodyThermometer(HtrFrame.getTemperature_HeatExchg()); - } - else { - if(isWifiConnected()) { - printRightJustify(getWifiAddrStr(), 57); - } - } - - showRunState(runstate, errstate); - -#ifdef DEMO_LARGEFONT - display.fillRect(20,20, 80,16, BLACK); - display.setCursor(20,20); - display.setFontInfo(&MAXIFONT); // Dot Factory Font - display.print("25.6`"); - display.setFontInfo(NULL); // standard 5x7 font -#endif + KeyPad.setCallback(keyhandlerScreen1); } - void animateOLED() { - static int fan = 0; - static int drip = 0; - static int heat = 0; - - if(animatePump || animateRPM || animateGlow) { - - if(animatePump) { - // erase region of fuel icon - display.fillRect(X_FUELICON, Y_FUELICON, 7, 16, BLACK); - display.drawBitmap(X_FUELICON, Y_FUELICON+(drip/2), FuelIcon, 7, 12, WHITE); - drip++; - drip &= 0x07; - } - - if(animateRPM) { - // erase region of fuel icon - display.fillRect(X_FANICON, Y_FANICON, 16, 16, BLACK); - switch(fan) { - case 0: display.drawBitmap(X_FANICON, Y_FANICON, FanIcon1, 16, 16, WHITE); break; - case 1: display.drawBitmap(X_FANICON, Y_FANICON, FanIcon2, 16, 16, WHITE); break; - case 2: display.drawBitmap(X_FANICON, Y_FANICON, FanIcon3, 16, 16, WHITE); break; - case 3: display.drawBitmap(X_FANICON, Y_FANICON, FanIcon4, 16, 16, WHITE); break; - } - fan++; - fan &= 0x03; - } - - if(animateGlow) { - display.fillRect(X_GLOWICON, Y_GLOWICON, 17, 10, BLACK); - display.drawBitmap(X_GLOWICON, Y_GLOWICON, GlowPlugIcon, 16, 9, WHITE); - display.drawBitmap(X_GLOWICON, Y_GLOWICON + 2 + heat, GlowHeatIcon, 17, 2, WHITE); - heat -= 2; - heat &= 0x07; - } - } - display.display(); + animateScreen1(display); } -#define TEMP_YPOS(A) ((((20 - A) * 3) / 2) + 22) -void showThermometer(float desired, float actual) +void updateOLED(const CProtocol& CtlFrame, const CProtocol& HtrFrame) { - char msg[16]; display.clearDisplay(); - // draw bulb design - display.drawBitmap(X_BULB, Y_BULB, thermometerBitmap, 8, 50, WHITE); - // draw mercury - int yPos = Y_BULB + TEMP_YPOS(actual); - display.drawLine(X_BULB + 3, yPos, X_BULB + 3, Y_BULB + 42, WHITE); - display.drawLine(X_BULB + 4, yPos, X_BULB + 4, Y_BULB + 42, WHITE); - // print actual temperature -#ifdef MINI_TEMPLABEL - sprintf(msg, "%.1f`C", actual); - display.setCursor(0, Y_BASELINE); - display.setFontInfo(&MINIFONT); // select Mini Font - display.print(msg); - display.setFontInfo(NULL); -#else - display.setTextColor(WHITE); - display.setCursor(0, Y_BASELINE); - display.print(actual, 1); -#endif - // draw set point - if(desired) { - display.drawBitmap(X_TARGETICON, Y_TARGETICON, TargetIcon, 13, 13, WHITE); // set indicator against bulb - char msg[16]; - if(desired > 0) { - int yPos = Y_BULB + TEMP_YPOS(desired) - 2; - display.drawBitmap(X_BULB-1, yPos, thermoPtr, 3, 5, WHITE); // set indicator against bulb - sprintf(msg, "%.0f`C", desired); - } - else { - sprintf(msg, "%.1fHz", -desired); - } -#ifdef MINI_TARGETLABEL - int xPos = X_TARGETICON + 7 - strlen(msg) * 2; // 2 = 1/2 width mini font - display.setCursor(xPos, Y_BASELINE); + // standard header items + //Bluetooth + if(getBluetoothClient().isConnected()) + showBTicon(display); + // WiFi + if(isWifiConnected()) { + showWifiIcon(display); + display.fillRect(X_WIFI_ICON + 8, Y_WIFI_ICON + 5, 10, 7, BLACK); display.setFontInfo(&MINIFONT); // select Mini Font - display.print(msg); + display.setCursor(X_WIFI_ICON+9, Y_WIFI_ICON+6); + display.print("AP"); display.setFontInfo(NULL); -#else - int xPos = X_TARGETICON + 6 - strlen(msg) * 3; // 3 = 1/2 width normal font - display.setCursor(xPos, Y_BASELINE); - display.print(msg); -#endif } + // battery + float voltage = HtrFrame.getVoltage_Supply() * 0.1f; + showBatteryIcon(display, voltage); + + showScreen1(display, CtlFrame, HtrFrame); } -#define BODY_YPOS(A) ((((100 - A) * 3) / 16) + 22) // 100degC centre - ticks +- 80C -void showBodyThermometer(int actual) +void showBTicon(C128x64_OLED& display) { - // draw bulb design - display.drawBitmap(X_BODYBULB, Y_BULB, thermometerBitmap, 8, 50, WHITE); - // draw mercury - int yPos = Y_BULB + BODY_YPOS(actual); - display.drawLine(X_BODYBULB + 3, yPos, X_BODYBULB + 3, Y_BULB + 42, WHITE); - display.drawLine(X_BODYBULB + 4, yPos, X_BODYBULB + 4, Y_BULB + 42, WHITE); - // print actual temperature - display.setTextColor(WHITE); - char label[16]; - // determine width and position right justified -#ifdef MINI_BODYLABEL - sprintf(label, "%d`C", actual); - int width = strlen(label) * 4; - display.setCursor(125-width, Y_BASELINE); - display.setFontInfo(&MINIFONT); // select Mini Font - display.print(label); - display.setFontInfo(NULL); -#else - sprintf(label, "%d", actual); - int width = strlen(label) * 6; - display.setCursor(127-width, Y_BASELINE); - display.print(label); -#endif + display.drawBitmap(X_BT_ICON, Y_BT_ICON, BTicon, W_BT_ICON, H_BT_ICON, WHITE); } -void showBTicon() +void showWifiIcon(C128x64_OLED& display) { - display.drawBitmap(X_BTICON, Y_BTICON, BTicon, W_BTICON, H_BTICON, WHITE); + display.drawBitmap(X_WIFI_ICON, Y_WIFI_ICON, wifiIcon, W_WIFI_ICON, H_WIFI_ICON, WHITE); } -void showWifiIcon() +void showBatteryIcon(C128x64_OLED& display, float voltage) { - display.drawBitmap(X_WIFIICON, Y_WIFIICON, wifiIcon, W_WIFIICON, H_WIFIICON, WHITE); -} - -void showBatteryIcon(float voltage) -{ - display.drawBitmap(X_BATTICON, Y_BATTICON, BatteryIcon, 15, 10, WHITE); + display.drawBitmap(X_BATT_ICON, Y_BATT_ICON, BatteryIcon, W_BATT_ICON, H_BATT_ICON, WHITE); #ifdef MINI_BATTLABEL char msg[16]; sprintf(msg, "%.1fV", voltage); - int xPos = X_BATTICON + 7 - strlen(msg) * 2; - display.setCursor(xPos, Y_BATTICON+12); + int xPos = X_BATT_ICON + 7 - strlen(msg) * 2; + display.setCursor(xPos, Y_BATT_ICON+H_BATT_ICON+2); display.setFontInfo(&MINIFONT); // select Mini Font display.print(msg); display.setFontInfo(NULL); @@ -302,121 +134,8 @@ void showBatteryIcon(float voltage) #endif // nominal 10.5 -> 13.5V bargraph -// int Capacity = int((voltage - 11.0) * 4.5); -// int Capacity = (voltage - 11.4) * 7; int Capacity = (voltage - 10.7) * 4; if(Capacity < 0) Capacity = 0; if(Capacity > 11) Capacity = 11; - display.fillRect(X_BATTICON+2 + Capacity, Y_BATTICON+2, 11-Capacity, 6, BLACK); + display.fillRect(X_BATT_ICON+2 + Capacity, Y_BATT_ICON+2, W_BATT_ICON-4-Capacity, 6, BLACK); } - -void showGlowPlug(int power) -{ - display.drawBitmap(X_GLOWICON, Y_GLOWICON, GlowPlugIcon, 16, 9, WHITE); -// animateGlow = true; -#ifdef MINI_GLOWLABEL - char msg[16]; - sprintf(msg, "%dW", power); - int xPos = X_GLOWICON + 9 - strlen(msg) * 2; - display.setCursor(xPos, Y_GLOWICON+12); - display.setFontInfo(&MINIFONT); // select Mini Font - display.print(msg); - display.setFontInfo(NULL); -#else - display.setCursor(X_GLOWICON, Y_GLOWICON+12); - display.print(power); - display.print("W"); -#endif -} - -void showFan(int RPM) -{ - // NOTE: fan rotation animation performed in animateOLED - animateRPM = RPM != 0; // used by animation routine - - display.setTextColor(WHITE); - char msg[16]; - sprintf(msg, "%d", RPM); -#ifdef MINI_FANLABEL - int xPos = X_FANICON + 8 - strlen(msg) * 2; // 3 = 1/2 width font - display.setCursor(xPos, Y_BASELINE); - display.setFontInfo(&MINIFONT); // select Mini Font - display.print(msg); - display.setFontInfo(NULL); -#else - int xPos = X_FANICON + 8 - ( strlen(msg) * 3); // 3 = 1/2 width font - display.setCursor(xPos, Y_BASELINE); - display.print(msg); -#endif -} - -void showFuel(float rate) -{ - // NOTE: fuel drop animation performed in animateOLED - animatePump = rate != 0; // used by animation routine - if(rate) { - char msg[16]; - sprintf(msg, "%.1f", rate); -#ifdef MINI_FUELLABEL - int xPos = X_FUELICON + 3 - strlen(msg) * 2; // 3 = 1/2 width font - display.setCursor(xPos, Y_BASELINE); - display.setFontInfo(&MINIFONT); // select Mini Font - display.print(msg); - display.setFontInfo(NULL); -#else - int xPos = X_FUELICON + 3 - ( strlen(msg) * 3); // 3 = 1/2 width font - display.setCursor(xPos, Y_BASELINE); - display.setTextColor(WHITE); - display.print(msg); -#endif - } -} - -void showRunState(int runstate, int errstate) -{ - static bool toggle = false; - const char* toPrint = NULL; - int yPos = 25; - display.setTextColor(WHITE, BLACK); - if(runstate >= 0 && runstate <= 8) { - if(((runstate == 0) || (runstate > 5)) && errstate) { - // create an "E-XX" message to display - char msg[16]; - sprintf(msg, "E-%02d", errstate); - int xPos = 64 - ((strlen(msg)/2) * 6); - if(runstate > 5) - yPos -= 8; - display.setCursor(xPos, yPos); - yPos += 8; - // flash error code - toggle = !toggle; - if(toggle) - display.print(msg); - else { - display.print(" "); - } - // bounds limit error and gather message - if(errstate > 10) errstate = 11; - toPrint = Errstates[errstate-1]; - } - else { - toPrint = Runstates[runstate]; - } - } - if(toPrint) { - int width = strlen(toPrint); - int xPos = 64 - ((width/2) * 6); - display.setCursor(xPos, yPos); - display.print(toPrint); - } -} - - - -void printRightJustify(const char* str, int yPos, int RHS) -{ - int xPos = RHS - strlen(str) * 6; - display.setCursor(xPos, yPos); - display.print(str); -} - diff --git a/Arduino/BTCDieselHeater/keypad.cpp b/Arduino/BTCDieselHeater/keypad.cpp index 5755bc2..1cc915c 100644 --- a/Arduino/BTCDieselHeater/keypad.cpp +++ b/Arduino/BTCDieselHeater/keypad.cpp @@ -41,7 +41,6 @@ uint8_t readKeys() if (newKey != debouncedKey) { debouncedKey = newKey; } - } return debouncedKey; } @@ -77,11 +76,11 @@ CKeyPad::scanPins() { uint8_t newPins = 0; - if(digitalRead(_pins[0]) == LOW) newPins |= keyPress_Left; - if(digitalRead(_pins[1]) == LOW) newPins |= keyPress_Right; - if(digitalRead(_pins[2]) == LOW) newPins |= keyPress_Centre; - if(digitalRead(_pins[3]) == LOW) newPins |= keyPress_Up; - if(digitalRead(_pins[4]) == LOW) newPins |= keyPress_Down; + if(digitalRead(_pins[0]) == LOW) newPins |= key_Left; + if(digitalRead(_pins[1]) == LOW) newPins |= key_Right; + if(digitalRead(_pins[2]) == LOW) newPins |= key_Centre; + if(digitalRead(_pins[3]) == LOW) newPins |= key_Up; + if(digitalRead(_pins[4]) == LOW) newPins |= key_Down; if(newPins != _prevPins) { _lastDebounceTime = millis(); diff --git a/Arduino/BTCDieselHeater/keypad.h b/Arduino/BTCDieselHeater/keypad.h index 87f1dfa..c7e2467 100644 --- a/Arduino/BTCDieselHeater/keypad.h +++ b/Arduino/BTCDieselHeater/keypad.h @@ -6,14 +6,14 @@ //void initKeyPad(); //uint8_t readKeys(); -const uint8_t keyPress_Left = 0x01; -const uint8_t keyPress_Right = 0x02; -const uint8_t keyPress_Centre = 0x04; -const uint8_t keyPress_Up = 0x08; -const uint8_t keyPress_Down = 0x10; -const uint8_t keyPressed = 0x20; // action flag -const uint8_t keyReleased = 0x40; // action flag -const uint8_t keyRepeat = 0x80; // action flag +const uint8_t key_Left = 0x01; +const uint8_t key_Right = 0x02; +const uint8_t key_Centre = 0x04; +const uint8_t key_Up = 0x08; +const uint8_t key_Down = 0x10; +const uint8_t keyPressed = 0x20; // action flag +const uint8_t keyReleased = 0x40; // action flag +const uint8_t keyRepeat = 0x80; // action flag class CKeyPad { private: @@ -36,4 +36,6 @@ public: void setCallback(void (*Callback)(uint8_t event)); }; +extern CKeyPad KeyPad; + #endif \ No newline at end of file