Skip to content

Commit

Permalink
Merge pull request #9 from bmorcelli/dev-stickC
Browse files Browse the repository at this point in the history
Dev stick c
  • Loading branch information
bmorcelli authored Mar 27, 2024
2 parents b69c363 + 8f518df commit 6395ebb
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 46 deletions.
Binary file added Compatible BINs/M5Stick-C/Marauder.bin
Binary file not shown.
137 changes: 94 additions & 43 deletions Launcher/Launcher.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// #define CARDPUTER // 8Mb of Flash Memory -> Need custom partitioning (mandatory)
// ================================== Flawless Victory ==================================

#define LAUNCHER_VERSION "1.2.0"
#define LAUNCHER_VERSION "1.2.1"

#if !defined(CARDPUTER) && !defined(STICK_C_PLUS2) && !defined(STICK_C_PLUS) && !defined(STICK_C)
#define STICK_C_PLUS2
Expand All @@ -27,11 +27,8 @@
#include "M5Launcher-image.h"
#endif

#if defined(STICK_C)
// #include <M5StackUpdater.h> // This one must be the last to declare in all devices, except STICK_C! such a noughty boy!
#endif
#if defined(STICK_C)

#if defined(STICK_C)
#include <M5StickC.h>
#define LNSD_CLK_PIN 0
#define LNSD_MISO_PIN 36
Expand Down Expand Up @@ -69,9 +66,6 @@
#define LNDISP M5Cardputer.Display
#endif

#ifndef STICK_C
// #include <M5StackUpdater.h> // This one must be the last to declare in all devices, except STICK_C! such a noughty boy!
#endif

#define MAX_FILES 256
#define MAX_FOLDERS 256
Expand Down Expand Up @@ -202,14 +196,19 @@ void setup() {
slope=map(data.accel.x*100,-30,100,0,50);
if (slope>11) { rot=1; }
else { rot=3; }
#else
#elif defined(STICK_C_PLUS)
M5.begin();
auto imu_update = M5.Imu.Init();
M5.IMU.getAccelData(&accX, &accY, &accZ);
slope=map(accX*100,-30,100,0,50);
if (slope>11) { rot=1; }
else { rot=3; }
#endif

#elif defined(STICK_C)
M5.begin();
slope=0;
rot = 3;
#endif

// Print SplashScreen
#if defined(STICK_C_PLUS2) || defined(CARDPUTER)
Expand All @@ -236,15 +235,15 @@ void setup() {
LNDISP.print("> Press Enter or M5 <");
LNDISP.setRotation(rot);
LNDISP.setTextSize(2);
#else
#elif defined(STICK_C)
LNDISP.fillScreen(WHITE);
LNDISP.setCursor(0, 0);
LNDISP.setTextSize(2);
LNDISP.setTextSize(1);
LNDISP.setTextColor(BLACK);
LNDISP.println(" -## M5Launcher ##- ");
LNDISP.println(" Press M5 ");
LNDISP.println(" to start Launcher ");
LNDISP.print (" v.");
LNDISP.println("\n\n -## M5Launcher ##- ");
LNDISP.println(" Press M5 ");
LNDISP.println(" to start Launcher ");
LNDISP.print (" v.");
LNDISP.printf("%s", LAUNCHER_VERSION);
#endif

Expand All @@ -261,16 +260,30 @@ int battery_percent = 0;
battery_percent = ((b - 3.0) / 1.2) * 100;
#endif

int battery_percent_norm = (battery_percent * 38) / 100; // 38 pixels wide square
LNDISP.drawRect(197,0,43,11,0);
LNDISP.fillRect(197,0,43,11,0);
LNDISP.drawRect(198,0,42,10,WHITE);
LNDISP.fillRect(200,2,38,6,WHITE);

if(battery_percent<26) { LNDISP.fillRect(200,2,battery_percent_norm,6,RED); }
if(battery_percent>25 || battery_percent<50) { LNDISP.fillRect(200,2,battery_percent_norm,6,YELLOW); }
if(battery_percent>49) { LNDISP.fillRect(200,2,battery_percent_norm,6,CYAN); }

#if defined(STICK_C)
int battery_percent_norm = (battery_percent * 20) / 100; // 20 pixels wide square
LNDISP.drawRect(135,0,25,11,0);
LNDISP.fillRect(135,0,25,11,0);
LNDISP.drawRect(136,0,24,10,WHITE);
LNDISP.fillRect(138,2,20,6,WHITE);

if(battery_percent<26) { LNDISP.fillRect(138,2,battery_percent_norm,6,RED); }
if(battery_percent>25 || battery_percent<50) { LNDISP.fillRect(138,2,battery_percent_norm,6,YELLOW); }
if(battery_percent>49) { LNDISP.fillRect(138,2,battery_percent_norm,6,CYAN); }

#else

int battery_percent_norm = (battery_percent * 38) / 100; // 38 pixels wide square
LNDISP.drawRect(197,0,43,11,0);
LNDISP.fillRect(197,0,43,11,0);
LNDISP.drawRect(198,0,42,10,WHITE);
LNDISP.fillRect(200,2,38,6,WHITE);

if(battery_percent<26) { LNDISP.fillRect(200,2,battery_percent_norm,6,RED); }
if(battery_percent>25 || battery_percent<50) { LNDISP.fillRect(200,2,battery_percent_norm,6,YELLOW); }
if(battery_percent>49) { LNDISP.fillRect(200,2,battery_percent_norm,6,CYAN); }
#endif
// End of Battery draw


Expand Down Expand Up @@ -332,9 +345,9 @@ if(battery_percent>49) { LNDISP.fillRect(200,2,battery_percent_norm,6,CYAN); }
#if defined(M5_BUTTON_MENU)
pinMode(M5_BUTTON_MENU, INPUT);
#endif

#ifndef STICK_C
LNDISP.setTextSize(2);
#endif
// Verify if SD Hat or SD card is connected..
int i = 0;
SPI2_SD.begin(LNSD_CLK_PIN, LNSD_MISO_PIN, LNSD_MOSI_PIN, LNSD_CS_PIN);
Expand All @@ -360,12 +373,17 @@ void loop() {
auto imu_update = M5.Imu.update();
auto data = M5.Imu.getImuData();
slope=map(data.accel.x*100,-30,100,0,50);
#elif defined(STICK_C_PLUS) || defined(STICK_C)
#elif defined(STICK_C_PLUS)
M5.begin();
// Detect rotation of M5StickCs
auto imu_update = M5.Imu.Init();
M5.IMU.getAccelData(&accX, &accY, &accZ);
slope=map(accX*100,-30,100,0,50);
#elif defined(STICK_C)
M5.begin();
rot = 3;
newrot=3;
slope=0;
#endif

#ifndef CARDPUTER
Expand Down Expand Up @@ -467,16 +485,29 @@ void loop() {
battery_percent = ((b - 3.0) / 1.2) * 100;
#endif

int battery_percent_norm = (battery_percent * 38) / 100; // 38 pixels wide square
LNDISP.drawRect(197,0,43,17,0);
LNDISP.fillRect(197,0,43,17,0);
LNDISP.drawRect(198,0,42,16,WHITE);
LNDISP.fillRect(200,2,38,12,0);

if(battery_percent<26) { LNDISP.fillRect(200,2,battery_percent_norm,12,RED); }
if(battery_percent>25 || battery_percent<50) { LNDISP.fillRect(200,2,battery_percent_norm,12,YELLOW); }
if(battery_percent>49) { LNDISP.fillRect(200,2,battery_percent_norm,12,GREEN); }



#if defined(STICK_C)
int battery_percent_norm = (battery_percent * 20) / 100; // 20 pixels wide square
LNDISP.drawRect(135,0,25,11,0);
LNDISP.fillRect(135,0,25,11,0);
LNDISP.drawRect(136,0,24,10,WHITE);
LNDISP.fillRect(138,2,20,6,WHITE);

if(battery_percent<26) { LNDISP.fillRect(138,2,battery_percent_norm,6,RED); }
if(battery_percent>25 || battery_percent<50) { LNDISP.fillRect(138,2,battery_percent_norm,6,YELLOW); }
if(battery_percent>49) { LNDISP.fillRect(138,2,battery_percent_norm,6,CYAN); }
#else
int battery_percent_norm = (battery_percent * 38) / 100; // 38 pixels wide square
LNDISP.drawRect(197,0,43,17,0);
LNDISP.fillRect(197,0,43,17,0);
LNDISP.drawRect(198,0,42,16,WHITE);
LNDISP.fillRect(200,2,38,12,0);

if(battery_percent<26) { LNDISP.fillRect(200,2,battery_percent_norm,12,RED); }
if(battery_percent>25 || battery_percent<50) { LNDISP.fillRect(200,2,battery_percent_norm,12,YELLOW); }
if(battery_percent>49) { LNDISP.fillRect(200,2,battery_percent_norm,12,GREEN); }
#endif
// End of Battery draw
needRedraw = false;
delay(150);
Expand Down Expand Up @@ -614,13 +645,23 @@ M5.update();
LNDISP.fillScreen(BLACK);
LNDISP.setCursor(0, 0);
LNDISP.setTextColor(WHITE);
LNDISP.println("\n -## M5Launcher ##- \n Installing ");
LNDISP.setTextSize(1);
#if defined(STICK_C)
LNDISP.println("\n -## M5Launcher ##- \n Installing ");
#else
LNDISP.println("\n -## M5Launcher ##- \n Installing ");
LNDISP.setTextSize(1);
#endif
LNDISP.setTextColor(GREEN);
LNDISP.println("\nApp : " + fileList[selectIndex - folderListCount - 1]);

#if defined(STICK_C)
LNDISP.drawRect(10,48,138,15,WHITE);
LNDISP.fillRect(12,50,134,11,0);
#else
LNDISP.drawRect(18,78,204,19,WHITE);
LNDISP.fillRect(20,80,200,15,0);
#endif


performUpdate(file, file.size(), U_FLASH); // ----------------------------------------------------------------- Install Flash app

Expand Down Expand Up @@ -693,7 +734,7 @@ M5.update();
LNDISP.fillScreen(BLACK);
LNDISP.setCursor(0, 0);
LNDISP.setTextColor(WHITE);
LNDISP.println(" -## M5Launcher ##- \n\n Binary is too big \n should I continue? \n\nEnter/M5 to continue\n\ any key to cancel ");
LNDISP.println(" -## M5Launcher ##- \n Binary is too big \n should I continue? \nEnter/M5 to continue\n\ any key to cancel ");
delay(500); // to avoid jumping verifications

while(1) {
Expand Down Expand Up @@ -800,13 +841,23 @@ M5.update();
LNDISP.fillScreen(BLACK);
LNDISP.setCursor(0, 0);
LNDISP.setTextColor(WHITE);
#if defined(STICK_C)
LNDISP.println("\n -## M5Launcher ##- \n Installing ");
#else
LNDISP.println("\n -## M5Launcher ##- \n Installing ");
LNDISP.setTextSize(1);
#endif

LNDISP.setTextColor(GREEN);
LNDISP.println("App : " + fileList[selectIndex - folderListCount - 1]);

LNDISP.drawRect(18,78,204,19,WHITE);

#if defined(STICK_C)
LNDISP.drawRect(10,48,138,15,WHITE);
LNDISP.fillRect(12,50,134,11,0);
#else
LNDISP.drawRect(18,78,204,19,WHITE);
LNDISP.fillRect(20,80,200,15,0);
#endif

performUpdate(file, PartitionSize, U_FLASH); // ----------------------------------------------------------------- Install Flash app

Expand Down
4 changes: 4 additions & 0 deletions Launcher/update_functions.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include "Update.h"

void DrawPercentage(int percent) {
#ifndef STICK_C
LNDISP.fillRect(20,80,percent*2,15,WHITE);
#else
LNDISP.fillRect(12,50,percent*1.34,11,WHITE);
#endif
}


Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ Where/How do I find Binaries to launch -> [Obtaining binaries to launch](https:/
* Copy the binary generated in `~Launcher/build/{your-device}/Launcher.ino.bin` the the folder `~support_files/` (there are some binaries inside there)
* use esptool to flash in your device
* M5StickC and M5StickC Plus
* Run in "~support_files\" folder: `esptool -p COMx -b 460800 --before default_reset --after hard_reset --chip esp32 write_flash --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader_4Mb.bin 0x8000 partition-table_4Mb.bin 0x10000 Launcher.ino.bin`
* Run in "~support_files\" folder: `esptool -p COMx -b 115200 --before default_reset --after hard_reset --chip esp32 write_flash --flash_mode dio --flash_freq 40m --flash_size detect 0x1000 bootloader_4Mb.bin 0x8000 partition-table_4Mb.bin 0x10000 Launcher.ino.bin`
* M5StickC Plus 2
* Run in "~support_files\" folder: `esptool -p COMx -b 460800 --before default_reset --after hard_reset --chip esp32 write_flash --flash_mode dio --flash_freq 80m --flash_size detect 0x1000 bootloader_8Mb.bin 0x8000 partition-table_8Mb.bin 0x10000 Launcher.ino.bin`
* Run in "~support_files\" folder: `esptool -p COMx -b 115200 --before default_reset --after hard_reset --chip esp32 write_flash --flash_mode dio --flash_freq 80m --flash_size detect 0x1000 bootloader_8Mb.bin 0x8000 partition-table_8Mb.bin 0x10000 Launcher.ino.bin`
* Cardputer
* Run in "~support_files\" folder: `esptool -p COMx -b 460800 --before default_reset --after hard_reset --chip esp32s3 write_flash --flash_mode dio --flash_freq 80m --flash_size detect 0x0 bootloader_CP.bin 0x8000 partition-table_8Mb.bin 0x10000 Launcher.ino.bin`
* Run in "~support_files\" folder: `esptool -p COMx -b 115200 --before default_reset --after hard_reset --chip esp32s3 write_flash --flash_mode dio --flash_freq 80m --flash_size detect 0x0 bootloader_CP.bin 0x8000 partition-table_8Mb.bin 0x10000 Launcher.ino.bin`

## Changelog
* 1.2.1:
* Launcher now lower the LCD power and fill the screen black before restart, to prevent lcd burn when using apps that don't use the Screen
* Fixed display things and positions for the M5StickC
* 1.2.0:
* Excluded ota_data.bin file as it is not needed
* Excluded StartApp application
Expand Down

0 comments on commit 6395ebb

Please sign in to comment.