Skip to content

Commit

Permalink
Add STARBASE_BOOT_BUTTON_PIN (WIP)
Browse files Browse the repository at this point in the history
pio.ini
- add STARBASE_BOOTPIN WIP

LedModEffects and LedModFixture
- use saveMode check on Fixture and Effect .onChange

SysModPrint
- loop: show 🚑 if in saveMode

SysModules
- add buttonPressedTime (WIP) and saveMode
- setup: set in savemode if boot button pressed
- loop: set savemode off if boot button pressed and check for longpress (not used yet)
  • Loading branch information
ewowi committed Dec 9, 2024
1 parent bbac830 commit b797fea
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 10 deletions.
5 changes: 5 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ build_flags =
-D EXTPRINTF=ppf ;redirect Live Script prints to StarBase print
lib_deps =
https://github.com/ewowi/ESPLiveScript.git#d62bf25 ; v3.1 ;ewowi repo adds some proposed PR's and makes sure we don't have unexpected updates
; https://github.com/ewowi/ESPLiveScript.git#3c6fa7f ; v3.1 ;ewowi repo adds some proposed PR's and makes sure we don't have unexpected updates

[STARLIGHT_CLOCKLESS_LED_DRIVER]
build_flags =
Expand Down Expand Up @@ -127,6 +128,7 @@ build_flags =
-D PIOENV=$PIOENV
-D VERSION=24112412 ; Date and time (GMT!), update at every commit!!
-D LFS_THREADSAFE ; enables use of semaphores in LittleFS driver
-D STARBASE_BOOT_BUTTON_PIN=0 ; boot pin on the esp32 board
-D STARBASE_DEVMODE
-mtext-section-literals ;otherwise [UserModLive::setup()]+0xa17): dangerous relocation: l32r: literal target out of range (try using text-section-literals)
;for StarLight, first only for s2, now for all due to something in UserModLive.Setup...
Expand Down Expand Up @@ -267,6 +269,7 @@ build_flags =
${env.build_flags}
-D CONFIG_IDF_TARGET_ESP32=1
-D ARDUINO_USB_CDC_ON_BOOT=0 ; Make sure that the right HardwareSerial driver is picked in arduino-esp32 (needed on "classic ESP32")
-D STARBASE_BOOT_BUTTON_PIN=0 ;check
lib_deps =
${env.lib_deps}

Expand Down Expand Up @@ -300,6 +303,7 @@ build_flags =
-D ARDUINO_USB_MODE=0 ; Make sure that the right HardwareSerial driver is picked in arduino-esp32 (mandatory on -S2)
; -D DEBUG=1 -D CORE_DEBUG_LEVEL=1 -D ARDUINOJSON_DEBUG=1 ; for more debug output
-D STARBASE_LOLIN_WIFI_FIX ; workaround for LOLIN C3/S2/S3 wifi instability. https://www.wemos.cc/en/latest/c3/c3_mini_1_0_0.html#about-wifi
-D STARBASE_BOOT_BUTTON_PIN=18 ;check
lib_deps =
${env.lib_deps}

Expand Down Expand Up @@ -367,6 +371,7 @@ build_flags =
${env.build_flags}
-D CONFIG_IDF_TARGET_ESP32S3=1
-D STARBASE_LOLIN_WIFI_FIX ; shouldn't be necessary, but otherwise WiFi issues on my board
-D STARBASE_BOOT_BUTTON_PIN=48 ;check
-D STARLIGHT_MAXLEDS=16384 ;LEDs specific
${STARLIGHT_CLOCKLESS_VIRTUAL_LED_DRIVER.build_flags}
lib_deps =
Expand Down
4 changes: 1 addition & 3 deletions src/App/LedModEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ inline uint16_t getRGBWsize(uint16_t nleds){
return true; }
case onChange:

// return true; //do this if the effect crashes at boot, then change effect to working effect, recompile, reboot (WIP)
//to do save mode button...

if (mdls->saveMode) return true; //do not process effect in saveMode do this if the effect crashes at boot, then change effect to working effect and reboot

if (rowNr == UINT8_MAX) rowNr = 0; // in case effect without a rowNr

Expand Down
6 changes: 2 additions & 4 deletions src/App/LedModFixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,7 @@
return true; }
case onChange: {

// return true; //do this if the fixture crashes at boot, then change fixture to working fixture, recompile, reboot (WIP)
// WARNING - possible crash: (code 5) Reset (software or hardware) due to interrupt watchdog. Core#0 (code 8) watchdog; Core#1 (code 8) watchdog.
//to do save mode button...
if (mdls->saveMode) return true; //do not process fixture in saveMode do this if the fixture crashes at boot, then change fixture to working fixture and reboot

doAllocPins = true;
if (web->ws.getClients().length())
Expand Down Expand Up @@ -849,7 +847,7 @@ void LedModFixture::addPixelsPost() {
lengths[i] = 0;
}
ppf("pins[");
for (int i=0; i<NBIS2SERIALPINS; i++) {
for (int i=0; i<nb_pins; i++) {
ppf(", %d", pins[i]);
}
ppf("]\n");
Expand Down
3 changes: 2 additions & 1 deletion src/Sys/SysModPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ void SysModPrint::printf(const char * format, ...) {
toSerial = true;

if (toSerial) {
Serial.print(strncmp(pcTaskGetTaskName(nullptr), "loopTask", 9) == 0?"":"α"); //looptask λ/ asyncTCP task α
if (mdls->saveMode) Serial.print("🚑");
Serial.print(strncmp(pcTaskGetTaskName(nullptr), "loopTask", 8) == 0?"":"α"); //looptask λ/ asyncTCP task α
Serial.print(buffer);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Sys/SysModWeb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ JsonDocument * SysModWeb::getResponseDoc() {
// ppf("response wsevent core %d %s\n", xPortGetCoreID(), pcTaskGetTaskName(nullptr));

// return responseDocLoopTask;
return strncmp(pcTaskGetTaskName(nullptr), "loopTask", 9) == 0?responseDocLoopTask:responseDocAsyncTCP;
return strncmp(pcTaskGetTaskName(nullptr), "loopTask", 8) == 0?responseDocLoopTask:responseDocAsyncTCP;
}

JsonObject SysModWeb::getResponseObject() {
Expand All @@ -670,7 +670,7 @@ JsonObject SysModWeb::getResponseObject() {
void SysModWeb::sendResponseObject(WebClient * client) {
JsonObject responseObject = getResponseObject();
if (responseObject.size()) {
// if (strncmp(pcTaskGetTaskName(nullptr), "loopTask", 9) != 0) {
// if (strncmp(pcTaskGetTaskName(nullptr), "loopTask", 8) != 0) {
// ppf("send ");
// char sep[3] = "";
// for (JsonPair pair: responseObject) {
Expand Down
32 changes: 32 additions & 0 deletions src/SysModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,22 @@
#include "Sys/SysModUI.h"
#include "Sys/SysModWeb.h"
#include "Sys/SysModModel.h"
#include "Sys/SysModPins.h"
#include "Sys/SysModSystem.h"

SysModules::SysModules() = default;

void SysModules::setup() {
#ifdef STARBASE_BOOT_BUTTON_PIN
pinsM->allocatePin(STARBASE_BOOT_BUTTON_PIN, "Buttons", "Boot");

if (digitalRead(STARBASE_BOOT_BUTTON_PIN) == 0) {
saveMode = !isConnected;
ppf("saveMode %s\n", saveMode?"on":"off");
}

#endif

for (SysModule *module:modules) {
module->setup();
}
Expand Down Expand Up @@ -134,6 +146,26 @@ void SysModules::loop() {
module->cpuTime = (ESP.getCycleCount() - cycles);
}
}

#ifdef STARBASE_BOOT_BUTTON_PIN
if (digitalRead(STARBASE_BOOT_BUTTON_PIN) == 0 && saveMode) {
saveMode = false;
ppf("saveMode %s\n", saveMode?"on":"off");
}

if (digitalRead(STARBASE_BOOT_BUTTON_PIN) == 0) { //pressed
if (buttonPressedTime == 0) //if not pressed before
buttonPressedTime = sys->now; //set start of press
} else //not pressed
buttonPressedTime = 0;

if (buttonPressedTime && (sys->now - buttonPressedTime) > 600) {
//longpress
ppf("longpress boot\n");
buttonPressedTime = 0;
}
#endif

if (newConnection) {
newConnection = false;
isConnected = true;
Expand Down
2 changes: 2 additions & 0 deletions src/SysModules.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class SysModules {
public:
bool newConnection = false;
bool isConnected = false;
uint32_t buttonPressedTime = 0;
bool saveMode = false;

SysModules();

Expand Down

0 comments on commit b797fea

Please sign in to comment.