Skip to content

Commit

Permalink
Support for rESCue s3
Browse files Browse the repository at this point in the history
  • Loading branch information
thankthemaker committed Sep 23, 2023
2 parents afd3c71 + c4397b5 commit f192c7a
Show file tree
Hide file tree
Showing 22 changed files with 530 additions and 118 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ jobs:
python -m pip install --upgrade pip
pip install --upgrade platformio
- name: Run PlatformIO
run: pio run -e wemos_d1_mini32 -e nodemcu-32s
run: pio run -e wemos_d1_mini32 -e wemos_d1_mini32_cob -e wemos_d1_mini32_uart -e wemos_d1_mini32_cob_uart -e lolin_wemos_s3_mini -e lolin_wemos_s3_mini_cob -e lolin_wemos_s3_mini_uart -e lolin_wemos_s3_mini_cob_uart
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
generate_release_notes: true
files: |
.pio/build/wemos_d1_mini32/firmware.bin
.pio/build/wemos_d1_mini32/partitions.bin
.pio/build/lolin_wemos_s3_mini/firmware_lolin_wemos_s3_mini.bin
.pio/build/wemos_d1_mini32/firmware_wemos_d1_mini32.bin
.pio/build/wemos_d1_mini32/firmware_nodemcu-32s.bin
.pio/build/wemos_d1_mini32/partitions.bin
.pio/build/wemos_d1_mini32/bootloader.bin
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ extensions.json
/cmake-build-**
/CMakeLists.txt
/CMakeListsPrivate.txt
rESCue.code-workspace
.vscode/settings.json
3 changes: 3 additions & 0 deletions change_firmware_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Import("env")
#print("ENV: ", env.Dump())
env.Replace(PROGNAME="%s" % env.GetProjectOption("custom_firmware_name"))
104 changes: 102 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
[platformio]
default_envs = wemos_d1_mini32
;default_envs = nodemcu-32s
;default_envs = avaspark-rgb
;default_envs = lolin_wemos_s3_mini

[common_env_data]
lib_deps_external =
Expand All @@ -37,6 +39,41 @@ build_flags=
-D CAN_TX_PIN=_26
-D CAN_RX_PIN=_27

[ESP32-S3]
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
-D PIN_FORWARD=11 ; digital signal from Cheap Focer 2 if direction is forward
-D PIN_BACKWARD=12 ; digital signal from Cheap Focer 2 if direction is backward
-D PIN_BRAKE=13 ; digital signal from Cheap Focer 2 if electric motor brakes is on
-D BUZPIN=38 ; PIN for Piezo buzzer for acoustic signals (e.g. battery warning)
-D BATTERY_PIN=33 ; analog input for battery monitor, connected to voltage divider
-D LIGHT_BAR_PIN=2 ; DIN of WS28xx for battery indicator
-D VESC_RX_PIN=9 ; UART RX to Cheap Focer 2, connent to TX on CF2
-D VESC_TX_PIN=10 ; UART TX to Cheap Focer 2, connent to RX on CF2
-D CAN_TX_PIN=16
-D CAN_RX_PIN=17
-D ESP32S3

[AVASPARK-RGB]
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
;-D MOSFET_PIN_2=23 ; PWM signal for MOSFET 2 (front red, back white), only needed if COB is used
;-D PIN_FORWARD=18 ; digital signal from Cheap Focer 2 if direction is forward
;-D PIN_BACKWARD=19 ; digital signal from Cheap Focer 2 if direction is backward
;-D PIN_BRAKE=21 ; digital signal from Cheap Focer 2 if electric motor brakes is on
-D BUZPIN=19 ; PIN for Piezo buzzer for acoustic signals (e.g. battery warning)
-D BATTERY_PIN=34 ; analog input for battery monitor, connected to voltage divider
-D LIGHT_BAR_PIN=4 ; DIN of WS28xx for battery indicator
-D VESC_RX_PIN=27 ; UART RX to Cheap Focer 2, connent to TX on CF2
-D VESC_TX_PIN=25 ; UART TX to Cheap Focer 2, connent to RX on CF2
-D CAN_TX_PIN=_33
-D CAN_RX_PIN=_32
-D PIN_BOARD_LED=16 ; Onboard LED for avaspark-rgb

[env:native]
platform = native

Expand All @@ -49,11 +86,28 @@ upload_Speed = 921600
#upload_Port = /dev/cu.wchusbserial54FC0080641
board_build.partitions = default.csv
lib_deps = ${common_env_data.lib_deps_external}
build_flags = ${ESP32.build_flags}
build_flags = ${ESP32.build_flags} -D LED_WS28xx -D CANBUS_ENABLED -D CANBUS_ONLY
monitor_filters =
time
esp32_exception_decoder
; build_type = debug
extra_scripts = pre:change_firmware_name.py
custom_firmware_name = firmware_wemos_d1_mini32

[env:wemos_d1_mini32_cob]
extends = env:wemos_d1_mini32
build_flags = ${ESP32.build_flags} -D LED_COB -D CANBUS_ENABLED -D CANBUS_ONLY
custom_firmware_name = firmware_wemos_d1_mini32_cob

[env:wemos_d1_mini32_uart]
extends = env:wemos_d1_mini32
build_flags = ${ESP32.build_flags} -D LED_WS28xx
custom_firmware_name = firmware_wemos_d1_mini32_uart

[env:wemos_d1_mini32_cob_uart]
extends = env:wemos_d1_mini32
build_flags = ${ESP32.build_flags} -D LED_COB
custom_firmware_name = firmware_wemos_d1_mini32_cob_uart

[env:nodemcu-32s]
platform = espressif32
Expand All @@ -64,4 +118,50 @@ board_build.partitions = default.csv
lib_deps =
${common_env_data.lib_deps_external}
build_flags =
${ESP32.build_flags}
${ESP32.build_flags} -D LED_WS28xx -D CANBUS_ENABLED -D CANBUS_ONLY
extra_scripts = pre:change_firmware_name.py
custom_firmware_name = firmware_nodemcu-32s

[env:avaspark-rgb]
platform = espressif32
board = nodemcu-32s
framework = arduino
monitor_speed = 115200
board_build.partitions = default.csv
lib_deps =
${common_env_data.lib_deps_external}
build_flags =
${AVASPARK-RGB.build_flags} -D LED_WS28xx -D CANBUS_ENABLED -D CANBUS_ONLY
extra_scripts = pre:change_firmware_name.py
custom_firmware_name = firmware_avaspark-rgb

[env:lolin_wemos_s3_mini]
platform = espressif32
board = lolin_s3_mini
framework = arduino
monitor_speed = 115200
upload_Speed = 921600
board_build.partitions = default.csv
lib_deps = ${common_env_data.lib_deps_external}
build_flags = ${ESP32-S3.build_flags} -D LED_WS28xx -D CANBUS_ENABLED -D CANBUS_ONLY
monitor_filters =
time
esp32_exception_decoder
; build_type = debug
extra_scripts = pre:change_firmware_name.py
custom_firmware_name = firmware_lolin_wemos_s3_mini

[env:lolin_wemos_s3_mini_cob]
extends = env:lolin_wemos_s3_mini
build_flags = ${ESP32-S3.build_flags} -D LED_COB -D CANBUS_ENABLED -D CANBUS_ONLY
custom_firmware_name = firmware_lolin_wemos_s3_mini_cob

[env:lolin_wemos_s3_mini_uart]
extends = env:lolin_wemos_s3_mini
build_flags = ${ESP32-S3.build_flags} -D LED_WS28xx
custom_firmware_name = firmware_lolin_wemos_s3_mini_uart

[env:lolin_wemos_s3_mini_cob_uart]
extends = env:lolin_wemos_s3_mini
build_flags = ${ESP32-S3.build_flags} -D LED_COB
custom_firmware_name = firmware_lolin_wemos_s3_mini_cob_uart
24 changes: 20 additions & 4 deletions src/AppConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ AppConfiguration* AppConfiguration::getInstance() {

return instance;
}
void AppConfiguration::readPreferences() {
boolean AppConfiguration::readPreferences() {
String json = "";
if(!preferences.begin("rESCue", true)) {
log_e("no config file found");
Expand All @@ -20,6 +20,7 @@ void AppConfiguration::readPreferences() {
}
StaticJsonDocument<1024> doc;
deserializeJson(doc, json);
preferences.end();
log_n("readPreferences: %s", json.c_str());
config.deviceName = doc["deviceName"] | "rESCue";
config.otaUpdateActive = false;
Expand Down Expand Up @@ -65,11 +66,13 @@ void AppConfiguration::readPreferences() {
config.lightsSwitch = true;
config.saveConfig = false;
config.sendConfig = false;
preferences.end();
if(doc.overflowed()) {
return false;
}
return true;
}

void AppConfiguration::savePreferences() {
preferences.begin("rESCue", false);
boolean AppConfiguration::savePreferences() {
StaticJsonDocument<1024> doc;
doc["deviceName"] = config.deviceName;
doc["otaUpdateActive"] = config.otaUpdateActive;
Expand Down Expand Up @@ -102,6 +105,19 @@ void AppConfiguration::savePreferences() {
String json = "";
serializeJson(doc, json);
log_n("savePreferences: %s", json.c_str());

if(doc.overflowed()) {
return false;
}

preferences.begin("rESCue", false);
preferences.putString("config", json);
preferences.end();
return true;
}

boolean AppConfiguration::readMelodies() {
}

boolean AppConfiguration::saveMelodies() {
}
6 changes: 4 additions & 2 deletions src/AppConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@ struct Config {
class AppConfiguration {
public:
static AppConfiguration* getInstance();
void readPreferences();
void savePreferences();
boolean readPreferences();
boolean savePreferences();
boolean readMelodies();
boolean saveMelodies();
Config config;

private:
Expand Down
32 changes: 18 additions & 14 deletions src/BleServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ uint32_t value = 0;
Stream *vescSerial;
std::string vescBuffer;
std::string updateBuffer;
int bleLoop = 0;
unsigned long bleLoop = 0;
unsigned long loopTimeSum = 0;
unsigned long loopCount = 0;

BleServer::BleServer() = default;

Expand Down Expand Up @@ -57,7 +59,11 @@ void BleServer::onMTUChange(uint16_t MTU, ble_gap_conn_desc* desc) {
PACKET_SIZE = MTU_SIZE - 3;
}

#if defined(CANBUS_ENABLED)
void BleServer::init(Stream *vesc, CanBus *canbus) {
#else
void BleServer::init(Stream *vesc) {
#endif
vescSerial = vesc;

// Create the BLE Device
Expand All @@ -68,8 +74,9 @@ void BleServer::init(Stream *vesc, CanBus *canbus) {

snprintf(buf, bufSize, "Initial MTU size %d", mtu_size);
Logger::notice(LOG_TAG_BLESERVER, buf);
#if defined(CANBUS_ENABLED)
this->canbus = canbus;

#endif
// Create the BLE Server
pServer = NimBLEDevice::createServer();
pServer->setCallbacks(this);
Expand Down Expand Up @@ -122,14 +129,6 @@ void BleServer::init(Stream *vesc, CanBus *canbus) {
);
pCharacteristicConf->setCallbacks(this);

pCharacteristicLoop = pServiceRescue->createCharacteristic(
RESCUE_CHARACTERISTIC_UUID_FW,
NIMBLE_PROPERTY::NOTIFY |
NIMBLE_PROPERTY::WRITE |
NIMBLE_PROPERTY::WRITE_NR
);
pCharacteristicLoop->setCallbacks(this);

pCharacteristicLoop = pServiceRescue->createCharacteristic(
RESCUE_CHARACTERISTIC_UUID_LOOP,
NIMBLE_PROPERTY::NOTIFY |
Expand Down Expand Up @@ -165,6 +164,9 @@ void BleServer::init(Stream *vesc, CanBus *canbus) {
}

void BleServer::loop(VescData *vescData, unsigned long loopTime, unsigned long maxLoopTime) {
loopCount++;
loopTimeSum += loopTime;

if (vescSerial->available()) {
int oneByte;
while (vescSerial->available()) {
Expand Down Expand Up @@ -203,8 +205,10 @@ void BleServer::loop(VescData *vescData, unsigned long loopTime, unsigned long m
}

if (millis() - bleLoop > 500) {
updateRescueApp(loopTime, maxLoopTime);
updateRescueApp(loopCount, loopTimeSum/loopCount, maxLoopTime);
bleLoop = millis();
loopTimeSum = 0;
loopCount = 0;
}
}

Expand Down Expand Up @@ -363,9 +367,9 @@ void BleServer::onStatus(NimBLECharacteristic *pCharacteristic, Status status, i
}
}

void BleServer::updateRescueApp(long loopTime, long maxLoopTime) {
this->sendValue(pCharacteristicLoop, "loopTime", loopTime);
this->sendValue(pCharacteristicLoop, "maxLoopTime", maxLoopTime);
void BleServer::updateRescueApp(long count, long loopTime, long maxLoopTime) {
snprintf(buf, bufSize, "%d;%d;%d", count, loopTime, maxLoopTime);
this->sendValue(pCharacteristicLoop, "loopTime", buf);
}

template<typename TYPE>
Expand Down
8 changes: 6 additions & 2 deletions src/BleServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ class BleServer :
public BLECharacteristicCallbacks {
public:
BleServer();
#ifdef CANBUS_ENABLED
void init(Stream *vesc, CanBus *canbus);
void loop(VescData *vescData, unsigned long loopTime, unsigned long maxLoopTime);
#else
void init(Stream *vesc);
#endif
void loop(VescData *vescData, unsigned long loopTime, unsigned long maxLoopTime);
void stop();

// NimBLEServerCallbacks
Expand All @@ -43,7 +47,7 @@ class BleServer :
static void sendConfig();
template<typename TYPE>
void sendValue(NimBLECharacteristic *pCharacteristic, std::string key, TYPE value);
void updateRescueApp(long loopTime, long maxLoopTime);
void updateRescueApp(long count, long loopTime, long maxLoopTime);

private:
const static int bufSize = 256;
Expand Down
Loading

0 comments on commit f192c7a

Please sign in to comment.