Modified web server javascript to use bluetooth commands.
I2C OLED changes added
This commit is contained in:
parent
269da353de
commit
b5e57de2f2
9 changed files with 68 additions and 18 deletions
|
@ -37,12 +37,19 @@
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
// Hardware SPI constructor
|
||||||
C128x64_OLED::C128x64_OLED(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;
|
m_pFontInfo = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// I2C constructor
|
||||||
|
C128x64_OLED::C128x64_OLED(int8_t SDA, int8_t SCL) : Adafruit_SH1106(SDA, SCL)
|
||||||
|
{
|
||||||
|
m_pFontInfo = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t C128x64_OLED::write(uint8_t c)
|
size_t C128x64_OLED::write(uint8_t c)
|
||||||
{
|
{
|
||||||
if(m_pFontInfo) {
|
if(m_pFontInfo) {
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
class C128x64_OLED : public Adafruit_SH1106 {
|
class C128x64_OLED : public Adafruit_SH1106 {
|
||||||
const FONT_INFO* m_pFontInfo;
|
const FONT_INFO* m_pFontInfo;
|
||||||
public:
|
public:
|
||||||
C128x64_OLED(int8_t DC, int8_t CS, int8_t RST);
|
C128x64_OLED(int8_t DC, int8_t CS, int8_t RST); // Hardware SPI constructor
|
||||||
|
C128x64_OLED(int8_t SDA, int8_t SCL); // I2C constructor
|
||||||
|
|
||||||
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 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; };
|
void setFontInfo(const FONT_INFO* pFontInfo) { m_pFontInfo = pFontInfo; };
|
||||||
|
|
|
@ -350,7 +350,8 @@ void Adafruit_SH1106::begin(uint8_t vccstate, uint8_t i2caddr, bool reset) {
|
||||||
TWI1->TWI_CWGR = ((VARIANT_MCK / (2 * 400000)) - 4) * 0x101;
|
TWI1->TWI_CWGR = ((VARIANT_MCK / (2 * 400000)) - 4) * 0x101;
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
Wire.begin(sda, scl);
|
Serial.println("Opening I2C port");
|
||||||
|
Wire.begin(sda, scl, 800000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,3 +56,11 @@
|
||||||
|
|
||||||
|
|
||||||
#define SUPPORT_OEM_CONTROLLER 1
|
#define SUPPORT_OEM_CONTROLLER 1
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
// SH1106 128x64 OLED support
|
||||||
|
//
|
||||||
|
// 0: I2C,
|
||||||
|
// 1: HW SPI
|
||||||
|
//
|
||||||
|
#define OLED_HW_SPI 1
|
||||||
|
|
|
@ -86,6 +86,8 @@
|
||||||
#define FAILEDSSID "BTCESP32"
|
#define FAILEDSSID "BTCESP32"
|
||||||
#define FAILEDPASSWORD "thereisnospoon"
|
#define FAILEDPASSWORD "thereisnospoon"
|
||||||
|
|
||||||
|
#define RX_DATA_TIMOUT 500
|
||||||
|
|
||||||
//comment this out to remove TELNET
|
//comment this out to remove TELNET
|
||||||
|
|
||||||
//#define TELNET
|
//#define TELNET
|
||||||
|
@ -203,6 +205,9 @@ void setup() {
|
||||||
|
|
||||||
KeyPad.init(keyLeft_pin, keyRight_pin, keyCentre_pin, keyUp_pin, keyDown_pin);
|
KeyPad.init(keyLeft_pin, keyRight_pin, keyCentre_pin, keyUp_pin, keyDown_pin);
|
||||||
|
|
||||||
|
// pinMode(OLED_SDA, OUTPUT); // debug only
|
||||||
|
// digitalWrite(OLED_SDA, LOW);
|
||||||
|
|
||||||
// initialise DS18B20 temperature sensor(s)
|
// initialise DS18B20 temperature sensor(s)
|
||||||
TempSensor.begin();
|
TempSensor.begin();
|
||||||
TempSensor.setWaitForConversion(false);
|
TempSensor.setWaitForConversion(false);
|
||||||
|
@ -388,7 +393,7 @@ void loop()
|
||||||
|
|
||||||
// precautionary state machine action if all 24 bytes were not received
|
// precautionary state machine action if all 24 bytes were not received
|
||||||
// whilst expecting a frame from the blue wire
|
// whilst expecting a frame from the blue wire
|
||||||
if(RxTimeElapsed > 50) {
|
if(RxTimeElapsed > RX_DATA_TIMOUT) {
|
||||||
if( CommState.is(CommStates::OEMCtrlRx) ||
|
if( CommState.is(CommStates::OEMCtrlRx) ||
|
||||||
CommState.is(CommStates::HeaterRx1) ||
|
CommState.is(CommStates::HeaterRx1) ||
|
||||||
CommState.is(CommStates::HeaterRx2) ) {
|
CommState.is(CommStates::HeaterRx2) ) {
|
||||||
|
@ -443,7 +448,7 @@ void loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
#if SUPPORT_OEM_CONTROLLER == 1
|
#if SUPPORT_OEM_CONTROLLER == 1
|
||||||
if(BlueWireData.available() && (RxTimeElapsed > 100)) {
|
if(BlueWireData.available() && (RxTimeElapsed > RX_DATA_TIMOUT+10)) {
|
||||||
#ifdef REPORT_OEM_RESYNC
|
#ifdef REPORT_OEM_RESYNC
|
||||||
DebugPort.print("Re-sync'd with OEM Controller. ");
|
DebugPort.print("Re-sync'd with OEM Controller. ");
|
||||||
DebugPort.print(RxTimeElapsed);
|
DebugPort.print(RxTimeElapsed);
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
#include "BTCWebServer.h"
|
#include "BTCWebServer.h"
|
||||||
#include "DebugPort.h"
|
#include "DebugPort.h"
|
||||||
#include "TxManage.h"
|
#include "TxManage.h"
|
||||||
|
#include "helpers.h"
|
||||||
|
#include "pins.h"
|
||||||
|
|
||||||
|
extern void Command_Interpret(const char* pLine); // decodes received command lines, implemented in main .ino file!
|
||||||
|
|
||||||
WebServer server(80);
|
WebServer server(80);
|
||||||
WebSocketsServer webSocket = WebSocketsServer(81);
|
WebSocketsServer webSocket = WebSocketsServer(81);
|
||||||
|
@ -50,17 +54,30 @@ void initWebServer(void) {
|
||||||
unsigned char cVal;
|
unsigned char cVal;
|
||||||
|
|
||||||
void doWebServer(void) {
|
void doWebServer(void) {
|
||||||
|
static unsigned long lastTx = 0;
|
||||||
webSocket.loop();
|
webSocket.loop();
|
||||||
server.handleClient();
|
server.handleClient();
|
||||||
char c[] = { "23" };
|
if(millis() > lastTx) { // moderate the delivery of new messages - we simply cannot send every pass of the main loop!
|
||||||
webSocket.broadcastTXT(c, sizeof(c));
|
lastTx = millis() + 1000;
|
||||||
|
char msg[16];
|
||||||
|
sprintf(msg, "%.1f", fFilteredTemperature);
|
||||||
|
webSocket.broadcastTXT(msg);
|
||||||
|
// char c[] = { "23" };
|
||||||
|
// webSocket.broadcastTXT(c, sizeof(c));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
|
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
|
||||||
if (type == WStype_TEXT) {
|
if (type == WStype_TEXT) {
|
||||||
for (int i = 0; i < length; i++)
|
char cmd[16];
|
||||||
Serial.print((char)payload[i]);
|
memset(cmd, 0, 16);
|
||||||
Serial.println();
|
for (int i = 0; i < length && i < 15; i++) {
|
||||||
|
cmd[i] = payload[i];
|
||||||
|
// Serial.print((char)payload[i]);
|
||||||
|
}
|
||||||
|
// Serial.println();
|
||||||
|
Serial.println(cmd);
|
||||||
|
Command_Interpret(cmd); // send to the main heater controller decode routine
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -118,13 +118,15 @@ const char MAIN_PAGE[] PROGMEM = R"=====(
|
||||||
|
|
||||||
if (checkBox.checked == true){
|
if (checkBox.checked == true){
|
||||||
//Insert Code Here To Turn On The Heater
|
//Insert Code Here To Turn On The Heater
|
||||||
Socket.send("P1");
|
// Socket.send("P1");
|
||||||
|
Socket.send("[CMD]ON");
|
||||||
text.style.display = "block";
|
text.style.display = "block";
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
//Insert Code Here To Turn Off The Heater
|
//Insert Code Here To Turn Off The Heater
|
||||||
text.style.display = "none";
|
text.style.display = "none";
|
||||||
Socket.send("P0");
|
// Socket.send("P0");
|
||||||
|
Socket.send("[CMD]OFF");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "KeyPad.h"
|
#include "KeyPad.h"
|
||||||
#include "helpers.h"
|
#include "helpers.h"
|
||||||
#include "clock.h"
|
#include "clock.h"
|
||||||
|
#include "BTCConfig.h"
|
||||||
|
|
||||||
#define MAXIFONT tahoma_16ptFontInfo
|
#define MAXIFONT tahoma_16ptFontInfo
|
||||||
#define MINIFONT miniFontInfo
|
#define MINIFONT miniFontInfo
|
||||||
|
@ -49,15 +50,23 @@ const int maxScreens = 4;
|
||||||
|
|
||||||
// 128 x 64 OLED support
|
// 128 x 64 OLED support
|
||||||
SPIClass SPI; // default constructor opens HSPI on standard pins : MOSI=13,CLK=14,MISO=12(unused)
|
SPIClass SPI; // default constructor opens HSPI on standard pins : MOSI=13,CLK=14,MISO=12(unused)
|
||||||
|
#if OLED_HW_SPI == 1
|
||||||
C128x64_OLED display(OLED_DC_pin, -1, OLED_CS_pin);
|
C128x64_OLED display(OLED_DC_pin, -1, OLED_CS_pin);
|
||||||
|
#else
|
||||||
|
C128x64_OLED display(OLED_SDA_pin, OLED_SCL_pin);
|
||||||
|
#endif
|
||||||
|
|
||||||
void initOLED()
|
void initOLED()
|
||||||
{
|
{
|
||||||
currentScreen = 1;
|
currentScreen = 1;
|
||||||
|
|
||||||
SPI.setFrequency(8000000);
|
|
||||||
// SH1106_SWITCHCAPVCC = generate display voltage from 3.3V internally
|
// SH1106_SWITCHCAPVCC = generate display voltage from 3.3V internally
|
||||||
|
#if OLED_HW_SPI == 1
|
||||||
|
SPI.setFrequency(8000000);
|
||||||
display.begin(SH1106_SWITCHCAPVCC, 0, false);
|
display.begin(SH1106_SWITCHCAPVCC, 0, false);
|
||||||
|
#else
|
||||||
|
display.begin(SH1106_SWITCHCAPVCC);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Show initial display buffer contents on the screen --
|
// Show initial display buffer contents on the screen --
|
||||||
display.display();
|
display.display();
|
||||||
|
|
|
@ -11,8 +11,8 @@ const uint8_t Rx1Pin = 16;
|
||||||
const uint8_t Tx1Pin = 17;
|
const uint8_t Tx1Pin = 17;
|
||||||
const uint8_t Rx2Pin = 18;
|
const uint8_t Rx2Pin = 18;
|
||||||
const uint8_t Tx2Pin = 19;
|
const uint8_t Tx2Pin = 19;
|
||||||
const uint8_t OLED_SDA = 21; // I2C std pins
|
const uint8_t OLED_SDA_pin = 21; // I2C std pins
|
||||||
const uint8_t OLED_SCK = 22; // "
|
const uint8_t OLED_SCL_pin = 22; // "
|
||||||
const uint8_t HC05_SensePin = 23;
|
const uint8_t HC05_SensePin = 23;
|
||||||
const uint8_t OLED_DC_pin = 26;
|
const uint8_t OLED_DC_pin = 26;
|
||||||
const uint8_t OLED_CS_pin = 27;
|
const uint8_t OLED_CS_pin = 27;
|
||||||
|
|
Loading…
Reference in a new issue