Skip to content

Commit

Permalink
Merge pull request #75 from thankthemaker/rel/2.5.0
Browse files Browse the repository at this point in the history
Prepare release 2.5.0
  • Loading branch information
thankthemaker authored Oct 29, 2023
2 parents 80a36ba + 86156e1 commit 738092a
Show file tree
Hide file tree
Showing 30 changed files with 134 additions and 175 deletions.
8 changes: 4 additions & 4 deletions lib/ble_ota_dfu/src/ble_ota_dfu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void BLEOverTheAirDeviceFirmwareUpdate::onNotify(
uint8_t *pData = (uint8_t *)value.data();

if (pData != NULL) {
ESP_LOGD(TAG, "Notify callback for characteristic %s of data length %d",
ESP_LOGD(LOG_TAG_BLE_OTA, "Notify callback for characteristic %s of data length %d",
pCharacteristic->getUUID().toString().c_str(), len);

// Print transferred packets
Expand All @@ -189,7 +189,7 @@ void BLEOverTheAirDeviceFirmwareUpdate::onWrite(
if (pData != NULL) {
// #define DEBUG_BLE_OTA_DFU_RX
#ifdef DEBUG_BLE_OTA_DFU_RX
ESP_LOGD(TAG, "Write callback for characteristic %s of data length %d",
ESP_LOGD(LOG_TAG_BLE_OTA, "Write callback for characteristic %s of data length %d",
pCharacteristic->getUUID().toString().c_str(), len);
Serial.print("RX ");
for (uint16_t index = 0; index < len; index++) {
Expand Down Expand Up @@ -261,7 +261,7 @@ void BLEOverTheAirDeviceFirmwareUpdate::onWrite(
write_len[selected_updater]);

if (received_file_size > expected_file_size) {
ESP_LOGW(TAG, "Unexpected size:\n Expected: %d\nReceived: %d",
ESP_LOGW(LOG_TAG_BLE_OTA, "Unexpected size:\n Expected: %d\nReceived: %d",
expected_file_size, received_file_size);
}

Expand Down Expand Up @@ -308,7 +308,7 @@ void BLEOverTheAirDeviceFirmwareUpdate::onWrite(
break;

default:
ESP_LOGW(TAG, "Unknown command: %02X", pData[0]);
ESP_LOGW(LOG_TAG_BLE_OTA, "Unknown command: %02X", pData[0]);
break;
}
// Serial.printf("Not stuck in loop");
Expand Down
2 changes: 2 additions & 0 deletions lib/ble_ota_dfu/src/ble_ota_dfu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const bool FASTMODE = true;
#endif
// #endif

static const char* LOG_TAG_BLE_OTA = "BleOtaDfu";

const char SERVICE_OTA_BLE_UUID[] = "fe590001-54ae-4a28-9f74-dfccb248601d";
const char CHARACTERISTIC_OTA_BL_UUID_RX[] =
"fe590002-54ae-4a28-9f74-dfccb248601d";
Expand Down
14 changes: 11 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,20 @@ default_envs = wemos_d1_mini32
[common_env_data]
lib_deps_external =
adafruit/Adafruit NeoPixel @ ^1.11.0
bakercp/Logger @ 1.0.3
h2zero/[email protected]
fabianoriccardi/Melody Player @ ^2.2.2
bblanchon/ArduinoJson @ ^6.21.2
fabianoriccardi/Melody Player @ ^2.4.0
bblanchon/ArduinoJson @ ^6.21.3
paulo-raca/Buffered Streams @ ^1.0.8
build_flags =
-D CONFIG_BT_NIMBLE_PINNED_TO_CORE=0
-D CONFIG_NIMBLE_STACK_USE_MEM_POOLS=1
-D CONFIG_BT_NIMBLE_ROLE_CENTRAL_DISABLED ; Disable NimBLE Client code, will save ~7kB
-D CONFIG_BT_NIMBLE_ROLE_OBSERVER_DISABLED ; Disable NimBLE Client code, will save ~26kB
-D CORE_DEBUG_LEVEL=0

[ESP32]
build_flags=
${common_env_data.build_flags}
-D PIN_NEOPIXEL=4 ; DIN of WS28xx stripe for front- / backlight, only needed if WS28xx is used
-D MOSFET_PIN_1=22 ; PWM signal for MOSFET 1 (front white, back red), only needed if COB is used
-D MOSFET_PIN_2=23 ; PWM signal for MOSFET 2 (front red, back white), only needed if COB is used
Expand All @@ -41,6 +47,7 @@ build_flags=

[ESP32-S3]
build_flags=
${common_env_data.build_flags}
-D PIN_NEOPIXEL=3 ; DIN of WS28xx stripe for front- / backlight, only needed if WS28xx is used
; -D MOSFET_PIN_1= ; PWM signal for MOSFET 1 (front white, back red), only needed if COB is used
; -D MOSFET_PIN_2= ; PWM signal for MOSFET 2 (front red, back white), only needed if COB is used
Expand All @@ -58,6 +65,7 @@ build_flags=

[AVASPARK-RGB]
build_flags=
${common_env_data.build_flags}
-D PIN_NEOPIXEL_FRONT=18 ; DIN of WS28xx stripe for front light, only needed if WS28xx is used
-D PIN_NEOPIXEL_BACK=17 ; DIN of WS28xx stripe for back light, only needed if WS28xx is used
;-D MOSFET_PIN_1=22 ; PWM signal for MOSFET 1 (front white, back red), only needed if COB is used
Expand Down
12 changes: 6 additions & 6 deletions src/AppConfiguration.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "AppConfiguration.h"
#include "config.h"

static const char* TAG = "AppConfiguration";

AppConfiguration* AppConfiguration::instance = nullptr;

AppConfiguration* AppConfiguration::getInstance() {
Expand All @@ -13,15 +15,15 @@ AppConfiguration* AppConfiguration::getInstance() {
boolean AppConfiguration::readPreferences() {
String json = "";
if(!preferences.begin("rESCue", true)) {
log_e("no config file found");
ESP_LOGE(TAG, "no config file found");
} else {
log_n("found config file");
ESP_LOGI(TAG, "found config file");
json = preferences.getString("config", "");
}
StaticJsonDocument<1024> doc;
deserializeJson(doc, json);
preferences.end();
log_n("readPreferences: %s", json.c_str());
ESP_LOGI(TAG, "readPreferences: %s", json.c_str());
config.deviceName = doc["deviceName"] | "rESCue";
config.otaUpdateActive = false;
config.isNotificationEnabled = doc["isNotificationEnabled"] | false;
Expand Down Expand Up @@ -65,7 +67,6 @@ boolean AppConfiguration::readPreferences() {
config.isLightBarLedTypeDifferent = doc["isLightBarLedTypeDifferent"] | false;
config.idleLightTimeout = doc["idleLightTimeout"] | 60000;
config.mallGrab = doc["mallGrab"] | false;
config.logLevel = doc["logLevel"] | Logger::SILENT;
config.mtuSize = doc["mtuSize"] | 512;
config.oddevenActive = doc["oddevenActive"] | true;
config.lightsSwitch = true;
Expand Down Expand Up @@ -110,11 +111,10 @@ boolean AppConfiguration::savePreferences() {
doc["isLightBarLedTypeDifferent"] = config.isLightBarLedTypeDifferent;
doc["idleLightTimeout"] = config.idleLightTimeout;
doc["mallGrab"] = config.mallGrab;
doc["logLevel"] = config.logLevel;
doc["mtuSize"] = config.mtuSize;
String json = "";
serializeJson(doc, json);
log_n("savePreferences: %s", json.c_str());
ESP_LOGI(TAG, "savePreferences: %s", json.c_str());

if(doc.overflowed()) {
return false;
Expand Down
5 changes: 2 additions & 3 deletions src/AppConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <config.h>
#include <Preferences.h>
#include <ArduinoJson.h>
#include "Logger.h"
#include "visit_struct.hh"
#include "visit_struct_intrusive.hh"

Expand Down Expand Up @@ -45,9 +44,8 @@ struct Config {
VISITABLE(int, numberPixelLight);
VISITABLE(int, numberPixelBatMon);
VISITABLE(int, vescId);
VISITABLE(Logger::Level, logLevel);
VISITABLE(boolean, sendConfig);
VISITABLE(boolean, saveConfig);
VISITABLE(boolean, sendConfig);
VISITABLE(String , ledType);
VISITABLE(String , lightBarLedType);
VISITABLE(String , ledFrequency);
Expand All @@ -59,6 +57,7 @@ struct Config {
VISITABLE(int , mtuSize);
VISITABLE(boolean , oddevenActive);
VISITABLE(boolean, lightsSwitch);
VISITABLE(boolean, sendConfigFinished);
END_VISITABLES;
};

Expand Down
1 change: 0 additions & 1 deletion src/BMSController.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <Arduino.h>
#include <Logger.h>

#include "bms_relay.h"
#include "packet.h"
Expand Down
16 changes: 6 additions & 10 deletions src/BatteryMonitor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "BatteryMonitor.h"

#define LOG_TAG_BATMON "BatteryMonitor"

const int numCurReadings = 50;

unsigned long lastCheck = 0;
Expand All @@ -15,7 +13,7 @@ BatteryMonitor::BatteryMonitor(VescData *vescData) {
}

void BatteryMonitor::init() {
Logger::notice(LOG_TAG_BATMON, "initializing...");
ESP_LOGI(LOG_TAG_BATMON, "initializing...");
this->min_voltage = (int) AppConfiguration::getInstance()->config.minBatteryVoltage * 100;
this->max_voltage = (int) AppConfiguration::getInstance()->config.maxBatteryVoltage * 100;
this->warn_voltage = (int) AppConfiguration::getInstance()->config.lowBatteryVoltage * 100;
Expand All @@ -28,9 +26,7 @@ double BatteryMonitor::readValues() {
auto current = (double) abs(vescData->current);
updateCurrentArray(current);

if (Logger::getLogLevel() == Logger::VERBOSE) {
Logger::verbose(LOG_TAG_BATMON, String("Voltage: " + String(voltage) + "V").c_str());
}
ESP_LOGV(LOG_TAG_BATMON, "Voltage: %fV", voltage);
return voltage;
}

Expand All @@ -52,16 +48,16 @@ void BatteryMonitor::checkValues() {

// check if voltage is below absolute minimum or above absolute maximum (regen)
if (voltage < min_voltage || voltage > max_voltage) {
Serial.printf("Voltages: %d %d, %d", min_voltage, voltage, max_voltage);
Logger::warning(LOG_TAG_BATMON, "ALARM: Battery voltage out of range");
// Serial.printf("Voltages: %d %d, %d", min_voltage, voltage, max_voltage);
ESP_LOGW(LOG_TAG_BATMON, "ALARM: Battery voltage out of range");
Buzzer::alarm(); // play an anoying alarm tone
return;
}

// check if the voltage is close to the minimum
if (voltage < warn_voltage) {
if (millis() - lastBatWarn > 5000) {
Logger::warning(LOG_TAG_BATMON, "WARN: Battery voltage out of range");
ESP_LOGW(LOG_TAG_BATMON, "WARN: Battery voltage out of range");
Buzzer::warning(); // play a warn tonen every 5 seconds
lastBatWarn = millis();
}
Expand All @@ -70,7 +66,7 @@ void BatteryMonitor::checkValues() {
// check if the average current is higher max
if (getAverageCurrent() > max_current) {
if (millis() - lastCurWarn > 5000) {
Logger::warning(LOG_TAG_BATMON, "WARN: Average current too high");
ESP_LOGW(LOG_TAG_BATMON, "WARN: Average current too high");
Buzzer::warning(); // play a warn tonen every 5 seconds
lastCurWarn = millis();
}
Expand Down
3 changes: 2 additions & 1 deletion src/BatteryMonitor.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#ifndef __BATTERY_CONTROLLER_H__
#define __BATTERY_CONTROLLER_H__

#include <Logger.h>
#include "config.h"
#include "Buzzer.h"
#include "CanBus.h"

static const char* LOG_TAG_BATMON = "BatteryMonitor";

class BatteryMonitor {
public:
explicit BatteryMonitor(VescData *vescData);
Expand Down
12 changes: 3 additions & 9 deletions src/BleCanProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ void BleCanProxy::proxyIn(std::string in) {
default:
return;
}
if (Logger::getLogLevel() == Logger::VERBOSE) {
snprintf(buf, bufSize, "Proxy in, command %d, length %d\n", command, length);
Logger::verbose(LOG_TAG_BLE_CAN_PROXY, buf);
}
ESP_LOGD(LOG_TAG_BLE_CAN_PROXY, "Proxy in, command %d, length %d\n", command, length);
}

if (length <= 6) {
Expand Down Expand Up @@ -126,13 +123,10 @@ void BleCanProxy::proxyIn(std::string in) {

void BleCanProxy::proxyOut(uint8_t *data, unsigned int size, uint8_t crc1, uint8_t crc2) {
if (size > BUFFER_SIZE) {
Logger::error(LOG_TAG_BLE_CAN_PROXY, "proxyOut - Buffer size exceeded, abort (message not sent via proxy)");
ESP_LOGE(LOG_TAG_BLE_CAN_PROXY, "proxyOut - Buffer size exceeded, abort (message not sent via proxy)");
return;
}
if (Logger::getLogLevel() == Logger::VERBOSE) {
snprintf(buf, bufSize, "Proxy out, sending %d bytes\n", size);
Logger::verbose(LOG_TAG_BLE_CAN_PROXY, buf);
}
ESP_LOGD(LOG_TAG_BLE_CAN_PROXY, "Proxy out, sending %d bytes\n", size);
//Start bit, package size
if (size <= 255) {
//Serial.print(0x02);
Expand Down
3 changes: 1 addition & 2 deletions src/BleCanProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@

#include "Arduino.h"
#include "config.h"
#include <Logger.h>
#include "VescCanConstants.h"
#include "LoopbackStream.h"
#include "CanDevice.h"

#define LOG_TAG_BLE_CAN_PROXY "BleCanProxy"
static const char* LOG_TAG_BLE_CAN_PROXY = "BleCanProxy";

class BleCanProxy {
public:
Expand Down
Loading

0 comments on commit 738092a

Please sign in to comment.