Skip to content

Commit

Permalink
Merge pull request #136 from WLANThermo-nano/develop
Browse files Browse the repository at this point in the history
Version 1.1.1
  • Loading branch information
tuniii authored Jan 17, 2021
2 parents 4f21742 + 72e2fa8 commit 9e4a559
Show file tree
Hide file tree
Showing 55 changed files with 3,739 additions and 784 deletions.
30 changes: 26 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ core_dir = ./.core
miniV1 = HW_MINI_V1
miniV2 = HW_MINI_V2
miniV3 = HW_MINI_V3
connectV1 = HW_CONNECT_V1
nanoV3 = HW_NANO_V3
linkV1 = HW_LINK_V1

Expand All @@ -27,7 +28,7 @@ build_flags =
-DTFT_SCLK=18
-DTFT_CS=16
-DTFT_DC=17
-DTFT_RST=27
-DTFT_RST=-1
-DTOUCH_CS=32
-DLOAD_GLCD=1
-DLOAD_FONT2=1
Expand Down Expand Up @@ -104,7 +105,9 @@ board_build.embed_files =
webui/dist/mini/favicon.ico.gz
lib_deps = ${env.lib_deps}
lv_arduino@3.0.1
TFT_eSPI@2.2.23
TFT_eSPI@2.3.4
https://github.com/tuniii/lv_lib_qrcode
https://github.com/NicoFR75/PCA9533.git
src_filter =
${env.src_filter}
+<system/System.cpp>
Expand All @@ -113,6 +116,25 @@ src_filter =
+<display/DisplayBase.cpp>
+<display/tft/>

[env:connectV1]
; patched core for power management
platform = https://github.com/tuniii/platform-espressif32.git
build_flags = -D${hw.connectV1} ${env.build_flags} ${tft.build_flags}
board_build.embed_files =
webui/dist/mini/index.html.gz
webui/dist/mini/favicon.ico.gz
lib_deps = ${env.lib_deps}
lv_arduino@3.0.1
TFT_eSPI@2.3.4
https://github.com/tuniii/lv_lib_qrcode
src_filter =
${env.src_filter}
+<system/System.cpp>
+<system/SystemBase.cpp>
+<system/SystemConnectV1.cpp>
+<display/DisplayBase.cpp>
+<display/tft/>

[env:nanoV3]
; patched core for power management
platform = https://github.com/tuniii/platform-espressif32.git
Expand All @@ -121,7 +143,7 @@ board_build.embed_files =
webui/dist/nano/index.html.gz
webui/dist/nano/favicon.ico.gz
lib_deps = ${env.lib_deps}
ESP8266_SSD1306@4.0.0
squix78/ESP8266 and ESP32 OLED driver for SSD1306 displays @ 4.0.0
https://github.com/mathertel/OneButton.git#1.3.0
src_filter =
${env.src_filter}
Expand All @@ -139,7 +161,7 @@ board_build.embed_files =
webui/dist/link/index.html.gz
webui/dist/link/favicon.ico.gz
lib_deps = ${env.lib_deps}
ESP8266_SSD1306@4.0.0
squix78/ESP8266 and ESP32 OLED driver for SSD1306 displays @ 4.0.0
https://github.com/mathertel/OneButton.git#1.3.0
src_filter =
${env.src_filter}
Expand Down
11 changes: 11 additions & 0 deletions src/SerialCmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "WebHandler.h"
#include "API.h"
#include "DbgPrint.h"
#include <Preferences.h>

//++++++++++++++++++++++++++++++++++++++++++++++++++++++
// React to Serial Input
Expand Down Expand Up @@ -185,6 +186,16 @@ void read_serial(char *buffer)
gDisplay->calibrate();
return;
}
else if (str == "removecalibrationTFT")
{
Preferences prefs;
prefs.begin("TFT");
prefs.remove("Touch");
Serial.println("Settings::remove: Touch");
prefs.end();
return;
}

#endif

#if defined HW_NANO_V3
Expand Down
2 changes: 1 addition & 1 deletion src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// include html files
#include "webui/restart.html.gz.h"

#if defined(HW_MINI_V1) || defined(HW_MINI_V2) || defined(HW_MINI_V3)
#if defined(HW_MINI_V1) || defined(HW_MINI_V2) || defined(HW_MINI_V3) || defined(HW_CONNECT_V1)
#define WEB_SUBFOLDER "mini"
#elif HW_NANO_V3
#define WEB_SUBFOLDER "nano"
Expand Down
1 change: 1 addition & 0 deletions src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ static const NvsKeyConfig_t NvsKeyConfig[] = {
{STRINGIFY(kOtaUpdate), true, true},
{STRINGIFY(kServer), true, true},
{STRINGIFY(kBluetooth), true, true},
{STRINGIFY(kConnect), true, true},
{STRINGIFY(kPbGuard), true, true}};

const char *Settings::nvsNamespace = "wlanthermo";
Expand Down
1 change: 1 addition & 0 deletions src/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum SettingsNvsKeys
kOtaUpdate,
kServer,
kBluetooth,
kConnect,
kPbGuard
};

Expand Down
1 change: 1 addition & 0 deletions src/Wlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ void Wlan::onWifiConnect(WiFiEvent_t event, WiFiEventInfo_t info)
MDNS.addServiceTxt("wlanthermo", "tcp", "device", gSystem->getDeviceName());
MDNS.addServiceTxt("wlanthermo", "tcp", "hw_version", String("v") + String(gSystem->getHardwareVersion()));
MDNS.addServiceTxt("wlanthermo", "tcp", "sw_version", FIRMWAREVERSION);
MDNS.addServiceTxt("wlanthermo", "tcp", "mac_address", getMacAddress());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Wlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Wlan
WifiStrength getSignalStrength();
int32_t getRssi();
static void clearCredentials();
String getMacAddress();
static String getMacAddress();
WifiState getWifiState();
boolean isConnected();
boolean isAP();
Expand Down
116 changes: 92 additions & 24 deletions src/bluetooth/Bluetooth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
****************************************************/

#include "Bluetooth.h"
#include "bleFirmwareDat.h"
#include "bleFirmwareBin.h"
#include "bleFirmwareBin_nrf52832.h"
#include "bleFirmwareDat_nrf52832.h"
#include "bleFirmwareBin_nrf52840.h"
#include "bleFirmwareDat_nrf52840.h"
#include "temperature/TemperatureBase.h"
#include "system/SystemBase.h"
#include "Settings.h"
Expand All @@ -35,9 +37,11 @@
#define BLE_JSON_ADDRESS "a"
#define BLE_JSON_STATUS "s"
#define BLE_JSON_COUNT "c"
#define BLE_JSON_TEMPERATURES "t"
#define BLE_JSON_LAST_SEEN "ls"
#define BLE_JSON_RSSI "r"
#define BLE_JSON_SENSORS "t"
#define BLE_JSON_SENSORS_VALUE "v"
#define BLE_JSON_SENSORS_UNIT "u"

HardwareSerial *Bluetooth::serialBle = NULL;
std::vector<BleDeviceType *> Bluetooth::bleDevices;
Expand All @@ -50,6 +54,7 @@ Bluetooth::Bluetooth(int8_t rxPin, int8_t txPin, uint8_t resetPin)
this->resetPin = resetPin;
this->builtIn = false;
this->chipEnabled = false;
this->isNrf52840 = false;
pinMode(this->resetPin, OUTPUT);
digitalWrite(this->resetPin, LOW);
}
Expand All @@ -61,6 +66,7 @@ Bluetooth::Bluetooth(HardwareSerial *serial, uint8_t resetPin)
this->resetPin = resetPin;
this->builtIn = false;
this->chipEnabled = false;
this->isNrf52840 = false;
pinMode(this->resetPin, OUTPUT);
digitalWrite(this->resetPin, LOW);
}
Expand Down Expand Up @@ -94,10 +100,10 @@ void Bluetooth::loadConfig(TemperatureGrp *temperatureGrp)
memset(bleDevice, 0, sizeof(BleDeviceType));
bleDevice->remoteIndex = BLE_DEVICE_REMOTE_INDEX_INIT;

// reset temperatures
for (uint8_t i = 0; i < BLE_TEMPERATURE_MAX_COUNT; i++)
// reset sensors
for (uint8_t i = 0; i < BLE_SENSORS_MAX_COUNT; i++)
{
bleDevice->temperatures[i] = INACTIVEVALUE;
bleDevice->sensors[i] = INACTIVEVALUE;
}

strcpy(bleDevice->name, json["tname"][i]);
Expand Down Expand Up @@ -266,15 +272,32 @@ void Bluetooth::getDevices()
bleDevice->count = _device[BLE_JSON_COUNT];
}

// reset temperatures before updating
for (uint8_t i = 0; i < BLE_TEMPERATURE_MAX_COUNT; i++)
// reset sensors before updating
for (uint8_t i = 0; i < BLE_SENSORS_MAX_COUNT; i++)
{
bleDevice->temperatures[i] = INACTIVEVALUE;
bleDevice->sensors[i] = INACTIVEVALUE;
memset(bleDevice->units[i], 0u, BLE_SENSOR_UNIT_MAX_SIZE);
}

if (_device.containsKey(BLE_JSON_TEMPERATURES) == true)
if (_device.containsKey(BLE_JSON_SENSORS) == true)
{
_device[BLE_JSON_TEMPERATURES].asArray().copyTo(bleDevice->temperatures, BLE_TEMPERATURE_MAX_COUNT);
JsonArray &_sensors = _device[BLE_JSON_SENSORS].asArray();
uint8_t sensorIndex = 0u;

for (JsonArray::iterator itSensor = _sensors.begin(); (itSensor != _sensors.end()) && (sensorIndex < BLE_SENSORS_MAX_COUNT); ++itSensor, sensorIndex++)
{
JsonObject &_sensor = itSensor->asObject();

if (_sensor.containsKey(BLE_JSON_SENSORS_VALUE) == true)
{
bleDevice->sensors[sensorIndex] = _sensor[BLE_JSON_SENSORS_VALUE];
}

if (_sensor.containsKey(BLE_JSON_SENSORS_UNIT) == true)
{
memcpy(bleDevice->units[sensorIndex], _sensor[BLE_JSON_SENSORS_UNIT].asString(), BLE_SENSOR_UNIT_MAX_SIZE - 1u);
}
}
}
}
}
Expand Down Expand Up @@ -328,18 +351,18 @@ boolean Bluetooth::isDeviceConnected(String peerAddress)
if (false == enabled)
{
isConnected = false;
// reset temperatures
for (uint8_t i = 0; i < BLE_TEMPERATURE_MAX_COUNT; i++)
// reset sensors
for (uint8_t i = 0; i < BLE_SENSORS_MAX_COUNT; i++)
{
(*it)->temperatures[i] = INACTIVEVALUE;
(*it)->sensors[i] = INACTIVEVALUE;
}
}
}

return isConnected;
}

float Bluetooth::getTemperatureValue(String peerAddress, uint8_t index)
float Bluetooth::getSensorValue(String peerAddress, uint8_t index)
{
float value = INACTIVEVALUE;
const auto isKnownDevice = [peerAddress](BleDevice *d) {
Expand All @@ -348,14 +371,31 @@ float Bluetooth::getTemperatureValue(String peerAddress, uint8_t index)

auto it = std::find_if(bleDevices.begin(), bleDevices.end(), isKnownDevice);

if ((it != bleDevices.end()) && (index < BLE_TEMPERATURE_MAX_COUNT))
if ((it != bleDevices.end()) && (index < BLE_SENSORS_MAX_COUNT))
{
value = (*it)->temperatures[index];
value = (*it)->sensors[index];
}

return value;
}

String Bluetooth::getSensorUnit(String peerAddress, uint8_t index)
{
char unit[BLE_SENSOR_UNIT_MAX_SIZE] = {0u};
const auto isKnownDevice = [peerAddress](BleDevice *d) {
return (peerAddress.equalsIgnoreCase(d->address));
};

auto it = std::find_if(bleDevices.begin(), bleDevices.end(), isKnownDevice);

if ((it != bleDevices.end()) && (index < BLE_SENSORS_MAX_COUNT))
{
memcpy(unit, (*it)->units[index], BLE_SENSOR_UNIT_MAX_SIZE);
}

return unit;
}

void Bluetooth::task(void *parameter)
{
TickType_t xLastWakeTime = xTaskGetTickCount();
Expand All @@ -381,26 +421,39 @@ void Bluetooth::task(void *parameter)
boolean Bluetooth::waitForBootloader(uint32_t timeoutInMs)
{
const char bootloaderString[] = {'@', '@', 'B', 'O', 'O', 'T', 'L', 'O', 'A', 'D', 'E', 'R'};
const uint8_t variantIndex = 8u;
uint32_t currentMillis = millis();
uint32_t serialStringIndex = 0u;
uint32_t bootloaderStringIndex = 0u;
boolean success = false;
boolean nrf52840Check = false;

while ((millis() - currentMillis) < timeoutInMs)
{
if (serialBle->available())
{
if (bootloaderString[bootloaderStringIndex++] == (char)serialBle->read())
char currentChar = (char)serialBle->read();

// check for nrf52840 variant
if ((variantIndex == bootloaderStringIndex) && ('4' == currentChar))
{
nrf52840Check = true;
bootloaderStringIndex++;
continue;
}
else if (bootloaderString[bootloaderStringIndex++] == currentChar)
{
if (sizeof(bootloaderString) == bootloaderStringIndex)
{
success = true;
this->isNrf52840 = nrf52840Check;
break;
}
}
else
{
bootloaderStringIndex = 0u;
nrf52840Check = false;
}
}
}
Expand Down Expand Up @@ -431,19 +484,34 @@ boolean Bluetooth::doDfu()
{
Serial.println("Hello from BLE bootloader");
Serial.println("Start flashing of BLE application");
Log.notice("BLE chip detected" CR);
uint32_t flashStart = millis();

TFwu sFwu;
memset(&sFwu, 0, sizeof(TFwu));
sFwu.commandObject = (uint8_t *)bleFirmwareDat_h;
sFwu.commandObjectLen = sizeof(bleFirmwareDat_h);
sFwu.dataObject = (uint8_t *)bleFirmwareBin_h;
sFwu.dataObjectLen = sizeof(bleFirmwareBin_h);
sFwu.dataObjectVer = bleFirmwareBin_h_version;
sFwu.txFunction = Bluetooth::dfuTxFunction;
sFwu.responseTimeoutMillisec = 5000u;

if (this->isNrf52840)
{
// nrf52840 firmware
sFwu.commandObject = (uint8_t *)bleFirmwareDat_nrf52840_h;
sFwu.commandObjectLen = sizeof(bleFirmwareDat_nrf52840_h);
sFwu.dataObject = (uint8_t *)bleFirmwareBin_nrf52840_h;
sFwu.dataObjectLen = sizeof(bleFirmwareBin_nrf52840_h);
sFwu.dataObjectVer = bleFirmwareBin_nrf52840_h_version;
Log.notice("BLE chip: nrf52840" CR);
}
else
{
// nrf52832 firmware
sFwu.commandObject = (uint8_t *)bleFirmwareDat_nrf52832_h;
sFwu.commandObjectLen = sizeof(bleFirmwareDat_nrf52832_h);
sFwu.dataObject = (uint8_t *)bleFirmwareBin_nrf52832_h;
sFwu.dataObjectLen = sizeof(bleFirmwareBin_nrf52832_h);
sFwu.dataObjectVer = bleFirmwareBin_nrf52832_h_version;
Log.notice("BLE chip: nrf52832" CR);
}

fwuInit(&sFwu);
fwuExec(&sFwu);

Expand Down
Loading

0 comments on commit 9e4a559

Please sign in to comment.