Skip to content

Commit

Permalink
Merge pull request #167 from tobozo/1.1.8
Browse files Browse the repository at this point in the history
1.1.8
  • Loading branch information
tobozo authored Dec 11, 2021
2 parents 6a630f6 + 59c9e5d commit e159479
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 155 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/LibraryBuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- M5Core2-SD-Menu
- M5Fire-SD-Menu
- OdroidGo-SD-Menu
#- TTGO-LoRa32-V2-SDLoader-Snippet

include:
- matrix-context: M5Core2-SDLoader-Snippet
Expand Down Expand Up @@ -66,6 +67,11 @@ jobs:
sketch-names: M5Stack-SD-Menu.ino
bin-name: OdroidGo-Launcher.bin
required-libraries: "ESP32-Chimera-Core,LovyanGFX,ArduinoJson"
#- matrix-context: TTGO-LoRa32-V2-SDLoader-Snippet
#arduino-boards-fqbn: esp32:esp32:ttgo-lora32-v2
#sketch-names: TTGO-SDLoader-Snippet.ino
#required-libraries: "ESP32-Chimera-Core,LovyanGFX,ArduinoJson"


fail-fast: false

Expand Down
77 changes: 70 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ The snippet of code in the `M5Stack-SDLoader-Snippet.ino` sketch can be used as
// #include <M5GFX.h>
// #include <ESP32-Chimera-Core.h>
// #include <M5StickC.h>
// #include <M5Unified.h>

```

Expand Down Expand Up @@ -168,7 +169,21 @@ The snippet of code in the `M5Stack-SDLoader-Snippet.ino` sketch can be used as

SDUCfg.setCSPin( TFCARD_CS_PIN );
SDUCfg.setFS( &SD );
SDUCfg.setWaitForActionCb( mySerialActionTrigger ); // set your own serial input trigger

// set your own button response trigger

static int buttonState;

SDUCfg.setSDUBtnA( []() {
return buttonState==LOW ? true : false;
});

SDUCfg.setSDUBtnPoller( []() {
buttonState = digitalRead( 16 );
});

// Or set your own serial input trigger
// SDUCfg.setWaitForActionCb( mySerialActionTrigger );

SDUpdater sdUpdater( &SDUCfg );

Expand Down Expand Up @@ -206,6 +221,7 @@ The snippet of code in the `M5Stack-SDLoader-Snippet.ino` sketch can be used as
As a result, any atypical setup (e.g. headless+LittleFS) should make use of those callback setters:
```C++
SDUCfg.setCSPin ( TFCARD_CS_PIN ); // const int
SDUCfg.setFS ( &FS ); // fs::FS* (SD, SD_MMC, SPIFFS, LittleFS, PSRamFS)
SDUCfg.setProgressCb ( myProgress ); // void (*myProgress)( int state, int size )
SDUCfg.setMessageCb ( myDrawMsg ); // void (*myDrawMsg)( const String& label )
Expand All @@ -215,8 +231,12 @@ The snippet of code in the `M5Stack-SDLoader-Snippet.ino` sketch can be used as
SDUCfg.setSplashPageCb( myDrawSplashPage ); // void (*myDrawSplashPage)( const char* msg )
SDUCfg.setButtonDrawCb( myDrawPushButton ); // void (*myDrawPushButton)( const char* label, uint8_t position, uint16_t outlinecolor, uint16_t fillcolor, uint16_t textcolor )
SDUCfg.setWaitForActionCb( myActionTrigger ); // int (*myActionTrigger)( char* labelLoad, char* labelSkip, unsigned long waitdelay )
```
SDUCfg.setSDUBtnPoller( myButtonPoller ); // void (*myButtonPoller)()
SDUCfg.setSDUBtnA( myBtnAPushedcb ); // bool (*myBtnAPushedcb )()
SDUCfg.setSDUBtnB( myBtnBPushedcb ); // bool (*myBtnBPushedcb )()
SDUCfg.setSDUBtnC( myBtnCPushedcb ); // bool (*myBtnCPushedcb )()
```



Expand All @@ -225,6 +245,33 @@ Set custom action trigger for `update`, `rollback`, `save` and `skip` lobby opti
// int myActionTrigger( char* labelLoad, char* labelSkip, unsigned long waitdelay )
// return values: 1=update, 0=rollback, -1=skip
SDUCfg.setWaitForActionCb( myActionTrigger );

// Or separately if a UI is available:

static int buttonAState;
static int buttonBState;
static int buttonCState;

SDUCfg.setSDUBtnPoller( []() {
buttonAState = digitalRead( 32 );
buttonBState = digitalRead( 33 );
buttonCState = digitalRead( 13 );
delay(50);
});

SDUCfg.setSDUBtnA( []() {
return buttonState==LOW ? true : false;
});

SDUCfg.setSDUBtnB( []() {
return buttonState==LOW ? true : false;
});

SDUCfg.setSDUBtnC( []() {
return buttonState==LOW ? true : false;
});


```
Example:
Expand All @@ -237,10 +284,10 @@ static int myActionTrigger( char* labelLoad, char* labelSkip, char* labelSave,
do {
if( Serial.available() ) {
String out = Serial.readStringUntil('\n');
if( out == "update" ) return 1; // load "/menu.bin"
else if( out == "rollback") return 0; // rollback to other OTA partition
else if( out == "save") return 2; // save current sketch to SD card
else if( out == "skip" ) return -1; // do nothing
if( out == "update" ) return SDU_BTNA_MENU; // load "/menu.bin"
else if( out == "rollback") return SDU_BTNA_ROLLBACK; // rollback to other OTA partition
else if( out == "save") return SDU_BTNC_SAVE; // save current sketch to SD card
else if( out == "skip" ) return SDU_BTNB_SKIP; // do nothing
else Serial.printf("Ignored command: %s\n", out.c_str() );
}
} while( msec > int64_t( millis() ) - int64_t( waitdelay ) );
Expand All @@ -252,6 +299,7 @@ void setup()
Serial.begin(115200);
SDUCfg.setAppName( "My Application" ); // lobby screen label: application name
SDUCfg.setAuthorName( "by @myself" ); // lobby screen label: application author
SDUCfg.setBinFileName( "/MyApplication.bin" ); // if file path to bin is set for this app, it will be checked at boot and created if not exist
SDUCfg.setWaitForActionCb( myActionTrigger );
Expand Down Expand Up @@ -304,6 +352,21 @@ Set buttons drawing function (useful with Touch displays)
SDUCfg.setButtonDrawCb( myDrawPushButton );
```

Set buttons state polling function (typically M5.update()
```C++
// void(*myButtonPollCb)();
SDUCfg.setSDUBtnPoller( myButtonPollCb );
```

Set each button state getter function, it must return true when the state is "pushed".
```C++
SDUCfg.setSDUBtnA( myBtnAPushedcb ); // bool (*myBtnAPushedcb )()
SDUCfg.setSDUBtnB( myBtnBPushedcb ); // bool (*myBtnBPushedcb )()
SDUCfg.setSDUBtnC( myBtnCPushedcb ); // bool (*myBtnCPushedcb )()
```



<br />
<br />

Expand Down Expand Up @@ -357,7 +420,7 @@ The default SD-Menu application will scan for these file types:
🔘 OPTIONAL:
------------

- The lobby screen at boot can be customized using `SDUCfg.setAppName` and `SDUCfg.setBinFileName`.
- The lobby screen at boot can be customized using `SDUCfg.setAppName`, `SDUCfg.setAuthorName` and `SDUCfg.setBinFileName`.
When set, the app name and the binary path will be visible on the lobby screen, and an extra button `Button C` labelled `Save` is added to the UI.
Pushing this button while the M5Stack is booting will create or overwrite the sketch binary to the SD Card.
This can be triggered manually by using `saveSketchToFS(SD, fileName, TFCARD_CS_PIN)`.
Expand Down
45 changes: 15 additions & 30 deletions examples/LGFX-SDLoader-Snippet/LGFX-SDLoader-Snippet.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// #define LGFX M5GFX // just alias to LGFX for SD-Updater

#include "M5Stack_Buttons.h" // stolen from M5Stack Core
#define TFCARD_CS_PIN 4
#define TFCARD_CS_PIN 22

#define LGFX_ONLY
#define SDU_APP_NAME "LGFX Loader Snippet"
Expand All @@ -19,63 +19,48 @@ static Button *BtnA;
static Button *BtnB;
static Button *BtnC;

bool buttonAPressed() { return BtnA->isPressed(); }
bool buttonBPressed() { return BtnB->isPressed(); }
bool buttonCPressed() { return BtnC->isPressed(); }

void ButtonUpdate()
{
BtnA->read();
BtnB->read();
BtnC->read();
}

static int myActionTrigger( char* labelLoad, char* labelSkip, char* labelSave, unsigned long waitdelay )
{
if( waitdelay > 100 ) { // show button labels
//SDUCfg.onBefore();
SDUCfg.onSplashPage( "SD Updater Options" );
BtnStyles btns; // use default theme from library
SDUCfg.onButtonDraw( labelLoad, 0, btns.Load.BorderColor, btns.Load.FillColor, btns.Load.TextColor, btns.Load.ShadowColor );
SDUCfg.onButtonDraw( labelSkip, 1, btns.Skip.BorderColor, btns.Skip.FillColor, btns.Skip.TextColor, btns.Skip.ShadowColor );
#if defined SDU_APP_PATH
if( SDU_APP_PATH!=nullptr ) {
SDUCfg.onButtonDraw( labelSave, 1, btns.Save.BorderColor, btns.Save.FillColor, btns.Save.TextColor, btns.Save.ShadowColor );
}
#endif
}
auto msec = millis();
do {
ButtonUpdate();
if( BtnA->isPressed() ) return 1; // SD-Load menu (or rollback if avaiblable)
if( BtnB->isPressed() ) return 0; // skip SD Loader screen
if( BtnB->isPressed() ) return 2; // save sketch to FS
} while (millis() - msec < waitdelay);
return -1;
}

void setup()
{
Serial.begin(115200);

tft.init();

BtnA = new Button(39, true, 10);
BtnB = new Button(38, true, 10);
BtnC = new Button(37, true, 10);
BtnA = new Button(32, true, 10);
BtnB = new Button(33, true, 10);
BtnC = new Button(13, true, 10);
ButtonUpdate();

setSDUGfx( &tft ); // attach LGFX to SD-Updater
SDUCfg.setSDUBtnA( &buttonAPressed );
SDUCfg.setSDUBtnB( &buttonBPressed );
SDUCfg.setSDUBtnC( &buttonCPressed );
SDUCfg.setSDUBtnPoller( &ButtonUpdate );

// SDUCfg.setProgressCb ( myProgress ); // void (*onProgress)( int state, int size )
// SDUCfg.setMessageCb ( myDrawMsg ); // void (*onMessage)( const String& label )
// SDUCfg.setErrorCb ( myErrorMsg ); // void (*onError)( const String& message, unsigned long delay )
// SDUCfg.setBeforeCb ( myBeforeCb ); // void (*onBefore)()
// SDUCfg.setAfterCb ( myAfterCb ); // void (*onAfter)()
// SDUCfg.setSplashPageCb( myDrawSplashPage ); // void (*onSplashPage)( const char* msg )
// SDUCfg.setButtonDrawCb( myDrawPushButton ); // void (*onButtonDraw)( const char* label, uint8_t position, uint16_t outlinecolor, uint16_t fillcolor, uint16_t textcolor )
SDUCfg.setWaitForActionCb( myActionTrigger ); // int (*onWaitForAction)( char* labelLoad, char* labelSkip, unsigned long waitdelay )

// SDUCfg.setWaitForActionCb( myActionTrigger ); // int (*onWaitForAction)( char* labelLoad, char* labelSkip, unsigned long waitdelay )

checkSDUpdater(
SD, // filesystem (default=SD)
MENU_BIN, // path to binary (default=/menu.bin, empty string=rollback only)
2000, // wait delay, (default=0, will be forced to 2000 upon ESP.restart() )
10000, // wait delay, (default=0, will be forced to 2000 upon ESP.restart() )
TFCARD_CS_PIN // (usually default=4 but your mileage may vary)
);

Expand Down
8 changes: 6 additions & 2 deletions examples/M5Unified/M5Unified.ino
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <SD.h>
#include <M5Unified.h>
//#define TFCARD_CS_PIN 4
#include <M5StackUpdater.h>
Expand All @@ -7,7 +8,7 @@ void setup(void)
M5.begin();
Serial.begin(115200);

SDUCfg.setLabelMenu("< Menu"); // BtnA label: load menu.bin
SDUCfg.setLabelMenu("< Menu"); // BtnA label: load menu.bin
SDUCfg.setLabelSkip("Launch"); // BtnB label: skip the lobby countdown and run the app
SDUCfg.setLabelSave("Save"); // BtnC label: save the sketch to the SD
SDUCfg.setAppName("M5Unified test"); // lobby screen label: application name
Expand All @@ -16,13 +17,16 @@ void setup(void)
checkSDUpdater(
SD, // filesystem (default=SD)
MENU_BIN, // path to binary (default=/menu.bin, empty string=rollback only)
150000, // wait delay, (default=0, will be forced to 2000 upon ESP.restart() )
15000, // wait delay, (default=0, will be forced to 2000 upon ESP.restart() )
TFCARD_CS_PIN // usually default=4 but your mileage may vary
);

M5.Display.print("M5Unified test");
}

void loop(void)
{
// do your stuff

}

2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"type": "git",
"url": "https://github.com/tobozo/M5Stack-SD-Updater.git"
},
"version": "1.1.7",
"version": "1.1.8",
"framework": "arduino",
"headers": "M5StackUpdater.h",
"platforms": "espressif32"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=M5Stack-SD-Updater
version=1.1.7
version=1.1.8
author=tobozo
maintainer[email protected]
sentence=SD Card Loader for M5 Stack
Expand Down
Loading

0 comments on commit e159479

Please sign in to comment.