Skip to content

Commit

Permalink
begin support for M5 (work in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
lunokjod committed Mar 5, 2024
1 parent b71340b commit 473df7d
Show file tree
Hide file tree
Showing 121 changed files with 590 additions and 1,422 deletions.
29 changes: 25 additions & 4 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ board = ttgo-t-watch
framework = arduino
lib_deps =
https://github.com/siara-cc/esp32_arduino_sqlite3_lib.git
;../TTGO_TWatch_Library_alt/
https://github.com/lunokjod/TTGO_TWatch_Library_alt.git
rpolitex/ArduinoNvs@^2.5
ricmoo/QRCode@^0.0.1
arduino-libraries/Arduino_JSON@^0.1.0
Expand Down Expand Up @@ -50,24 +48,47 @@ build_flags =
-DLUNOKIOT_WIFI_ENABLED
;-fno-sanitize=shift-base
; -Wl,--wrap=ps_malloc
extra_scripts =
pre:./tool/generateConfig.py
;extra_scripts =
; pre:./tool/generateConfig.py


[env:m5stack-core2]
board = m5stack-core2
lib_deps = ${env.lib_deps}
m5stack/M5Core2
monitor_speed = 115200
upload_speed = 115200
build_flags =
-DM5_DEV
[BaseTwatchV1]
lib_deps = ${env.lib_deps}
earlephilhower/ESP8266Audio@^1.9.7
;Xinyuan-LilyGO/TTGO_TWatch_Library
https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library.git
;../TTGO_TWatch_Library_alt/
;https://github.com/lunokjod/TTGO_TWatch_Library_alt.git
build_flags =
-DLILYGO_DEV
-DLILYGO_WATCH_2020_V1

[BaseTwatchV2]
lib_deps = ${env.lib_deps}
;../TTGO_TWatch_Library_alt/
;https://github.com/lunokjod/TTGO_TWatch_Library_alt.git
https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library.git
build_flags =
-DLILYGO_DEV
-DLILYGO_WATCH_2020_V2

[BaseTwatchV3]
lib_deps = ${env.lib_deps}
earlephilhower/ESP8266Audio@^1.9.7
https://github.com/Xinyuan-LilyGO/TTGO_TWatch_Library.git
;Xinyuan-LilyGO/TTGO_TWatch_Library
;../TTGO_TWatch_Library_alt/
;https://github.com/lunokjod/TTGO_TWatch_Library_alt.git
build_flags =
-DLILYGO_DEV
-DLILYGO_WATCH_2020_V3
-DLUNOKIOT_BATTERY_CHECK

Expand Down
7 changes: 7 additions & 0 deletions src/UI/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
//

#include "Animation.hpp"
#include "../app/LogView.hpp"

#ifdef LILYGO_DEV
#include <LilyGoWatch.h>
extern TTGOClass *ttgo;
#endif

AnimationDescriptor::AnimationDescriptor(int32_t fromX,int32_t fromY,int32_t toX, int32_t toY, int32_t stepSize)
: fromX(fromX), fromY(fromY),toX(toX),toY(toY),stepSize(stepSize) {
Expand Down Expand Up @@ -53,5 +57,8 @@ void AnimationDescriptor::Step() {
}

void AnimationDescriptor::Draw() {
#ifdef LILYGO_DEV
tft->fillRoundRect(currentX,currentY,35,35,5,0x5DFC);
#endif
lLog("WARNING: AnimationDescriptor::Draw() only TFT_eSPI support\n");
}
6 changes: 5 additions & 1 deletion src/UI/Animation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@
* https://www.geeksforgeeks.org/mid-point-circle-drawing-algorithm/?ref=lbp
*/
#include <Arduino.h>

#ifdef LILYGO_DEV
#include <LilyGoWatch.h>
#endif
//M5_DEV

#include "lunokiot_config.hpp"
#include "../lunokiot_config.hpp"

class AnimationDescriptor {
public:
Expand Down
1 change: 0 additions & 1 deletion src/UI/AppTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
//#include <libraries/TFT_eSPI/TFT_eSPI.h>
#include "../lunokiot_config.hpp"

#include "../app/LogView.hpp" // for lLog functions
#include "../resources.hpp"

TemplateApplication::~TemplateApplication() { delete btnBack; }
Expand Down
51 changes: 39 additions & 12 deletions src/UI/BootSplash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
//

#include <Arduino.h>
#ifdef LILYGO_DEV
#include <LilyGoWatch.h>
#endif

#ifdef M5_DEV
#include <M5Core2.h>
#endif



#include <esp_task_wdt.h> // used for reset task watchdog

Expand All @@ -38,7 +46,9 @@
#include "../app/LogView.hpp" // lLog shit
#include "../resources.hpp"

#ifdef LILYGO_DEV
extern TTGOClass *ttgo; // ttgo lib
#endif

bool bootLoop = true; // this stops the animation loop
bool bootLoopEnds = false; // this is used by the splash to know bootLoop is ended
Expand Down Expand Up @@ -148,7 +158,7 @@ void SleepFanfare() {
//lLog("FANFARE TIME: %d\n",millis()-begin);
}
#endif

/*
void SplashMeanWhile(void *data) { // task to do boot animation
bootLoop=true;
lUILog("Splash loop begin\n");
Expand Down Expand Up @@ -189,7 +199,7 @@ void SplashMeanWhile(void *data) { // task to do boot animation
bootLoopEnds=true;
vTaskDelete(NULL);
}

*/
void SplashBootMode(const char *what) {
tft->setTextColor(ThCol(boot_splash_foreground),ThCol(boot_splash_background));
tft->setTextDatum(TL_DATUM);
Expand All @@ -204,8 +214,12 @@ void SplashAnnounce(const char * what) {

void SplashAnnounce() {
bootLoop=true;

ttgo->setBrightness(0); // low brightness
#ifdef LILYGO_DEV
ttgo->setBrightness(0); // low brightness
#elif M5_DEV
tft->setBrightness(0);
#endif

tft->fillScreen(ThCol(boot_splash_background));
// coords from gimp :) manual stetic-centered same as the group logo on telegram https://t.me/lunowatch!!! come with us if you read this!!! :)
tft->drawXBitmap(52,73,img_lunokiot_logo_bits, img_lunokiot_logo_width,img_lunokiot_logo_height, ThCol(boot_splash_foreground));
Expand All @@ -227,13 +241,22 @@ void SplashAnnounce() {
tft->drawString(buildNumberAsString, posX, posY);
#endif

ttgo->setBrightness(0);
ttgo->openBL(); // turn on the lights!
for(int i=0;i<255;i++) {
ttgo->setBrightness(i);
delay(5);
}
ttgo->setBrightness(BaseBackLightBrightness); // default brightness
#ifdef LILYGO_DEV
ttgo->setBrightness(0);
ttgo->openBL(); // turn on the lights!
for(int i=0;i<255;i++) {
ttgo->setBrightness(i);
delay(5);
}
ttgo->setBrightness(BaseBackLightBrightness); // default brightness
#elif M5_DEV
tft->setBrightness(0);
for(int i=0;i<255;i++) {
tft->setBrightness(i);
delay(5);
}
tft->setBrightness(BaseBackLightBrightness); // default brightness
#endif
}


Expand All @@ -255,6 +278,10 @@ void SplashAnnounceBegin() { // user eyecandy
bright++;
delay(1000/255);
if ( bright > 255 ) { break; }
ttgo->setBrightness(bright);
#ifdef LILYGO_DEV
ttgo->setBrightness(bright); // low brightness
#elif M5_DEV
tft->setBrightness(bright);
#endif
}
}
50 changes: 46 additions & 4 deletions src/UI/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
// LunokWatch. If not, see <https://www.gnu.org/licenses/>.
//


#ifdef LILYGO_DEV
#include <LilyGoWatch.h>
#elif defined(M5_DEV)
#include <M5Core2.h>
#endif

//#include <LilyGoWatch.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <esp_event.h>
Expand Down Expand Up @@ -52,8 +57,14 @@

extern SoftwareKeyboard *keyboardInstance;

#ifdef LILYGO_DEV
extern TTGOClass *ttgo; // ttgo library shit ;)
extern TFT_eSPI * tft;
#elif defined(M5_DEV)
//extern TTGOClass *ttgo; // ttgo library shit ;)
extern M5Display * tft;
#endif

bool UIlongTap=false; // used to trigger only once the long tap event
bool UILongTapOverride=false; // disable long tap to task switcher feature
extern const PROGMEM uint8_t screenshoot_sound_start[] asm("_binary_asset_screenshoot_sound_mp3_start");
Expand Down Expand Up @@ -108,7 +119,11 @@ void SetUserBrightness() {
userBright=BaseBackLightBrightness;
NVS.setInt("lBright",userBright,false);
}
#ifdef LILYGO_DEV
if ( ttgo->bl->isOn() ) { ttgo->setBrightness(userBright); }
#elif defined(M5_DEV)
tft->setBrightness(userBright);
#endif
}

void ScreenWake() {
Expand All @@ -118,6 +133,7 @@ void ScreenWake() {
lEvLog("Unable to obtain the Screen Lock!\n");
return;
}
#ifdef LILYGO_DEV
if ( false == ttgo->bl->isOn() ) {
LoT().CpuSpeed(240);
if ( ttgo->rtc->isValid() ) { ttgo->rtc->syncToSystem(); }
Expand All @@ -130,9 +146,10 @@ void ScreenWake() {
//SystemEventBootEnd(); // perform a ready (and if all is ok, launch watchface)
ttgo->bl->on();
//tft->fillScreen(TFT_BLACK); // cleanup, better than show old watchface time! (missinformation)
esp_event_post_to(uiEventloopHandle, UI_EVENTS, UI_EVENT_CONTINUE,nullptr, 0, LUNOKIOT_EVENT_IMPORTANT_TIME_TICKS);
FPS = MAXFPS;
}
#endif
esp_event_post_to(uiEventloopHandle, UI_EVENTS, UI_EVENT_CONTINUE,nullptr, 0, LUNOKIOT_EVENT_IMPORTANT_TIME_TICKS);
FPS = MAXFPS;
xSemaphoreGive(UISemaphore);
}

Expand All @@ -142,15 +159,19 @@ void ScreenSleep() {
lEvLog("Unable to obtain the Screen Lock!\n");
return;
}
#ifdef LILYGO_DEV
if ( true == ttgo->bl->isOn() ) {
ttgo->bl->off();
lUILog("Put screen to sleep now\n");
ttgo->displaySleep();
delay(1);
ttgo->touchToSleep();
#endif
esp_event_post_to(uiEventloopHandle, UI_EVENTS, UI_EVENT_STOP,nullptr, 0, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS);
LoT().CpuSpeed(80);
#ifdef LILYGO_DEV
}
#endif
xSemaphoreGive(UISemaphore);

}
Expand Down Expand Up @@ -355,6 +376,14 @@ TFT_eSprite * ScaleSprite(TFT_eSprite *view, float divisor) {
return canvas;
}

uint16_t Get16BitFromRGB(uint32_t color888) {
uint16_t r = (color888 >> 8) & 0xF800;
uint16_t g = (color888 >> 5) & 0x07E0;
uint16_t b = (color888 >> 3) & 0x001F;

return (r | g | b);
}

void GetRGBFrom16Bit(const uint16_t color, uint8_t &r, uint8_t &g, uint8_t &b) {
double pr = ((color >> 11) & 0x1F) / 31.0; // red 0.0 .. 1.0
double pg = ((color >> 5) & 0x3F) / 63.0; // green 0.0 .. 1.0
Expand Down Expand Up @@ -563,7 +592,14 @@ static void UIEventScreenRefresh(void* handler_args, esp_event_base_t base, int3
int16_t newTouchX,newTouchY;
bool newTouch=false;
if( xSemaphoreTake( I2cMutex, LUNOKIOT_UI_SHORT_WAIT) == pdFALSE ) { return; }
newTouch = ttgo->getTouch(newTouchX,newTouchY);
#ifdef LILYGO_DEV
newTouch = ttgo->getTouch(newTouchX,newTouchY);
#elif defined(M5_DEV)
Point currPt = M5.Touch.getPressPoint();
newTouch = currPt.valid();
newTouchX = currPt.x;
newTouchY = currPt.y;
#endif
xSemaphoreGive( I2cMutex );
bool updateCoords=true;
if ( ( !oldTouchState ) && ( newTouch ) ) { // thumb in
Expand Down Expand Up @@ -707,11 +743,15 @@ static void UIEventScreenTimeout(void* handler_args, esp_event_base_t base, int3
if ( UINextTimeout > millis() ) { return; }

// get a nap!
#ifdef LILYGO_DEV
if ( ttgo->bl->isOn() ) {
#endif
ScreenSleep();
esp_event_post_to(systemEventloopHandler, SYSTEM_EVENTS, SYSTEM_EVENT_STOP, nullptr, 0, LUNOKIOT_EVENT_MANDATORY_TIME_TICKS);
DoSleep();
#ifdef LILYGO_DEV
}
#endif
}

static void UIReadyEvent(void* handler_args, esp_event_base_t base, int32_t id, void* event_data) {
Expand All @@ -728,7 +768,9 @@ static void UITickTask(void* args) {

if ( false == UIRunning ) { continue; }
if ( systemSleep ) { continue; }
#ifdef LILYGO_DEV
if ( false == ttgo->bl->isOn() ) { continue; } // do not send UI tick when screen is off
#endif
esp_err_t what = esp_event_post_to(uiEventloopHandle, UI_EVENTS, UI_EVENT_TICK, nullptr, 0, LUNOKIOT_EVENT_DONTCARE_TIME_TICKS);
// Dynamic FPS... the apps receives less events per second
if (( ESP_OK != what )||( isDelayed )) {
Expand Down
20 changes: 18 additions & 2 deletions src/UI/UI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,18 @@
#define __LUNOKIOT__UI__DEFINE__

#include <Arduino.h>

#ifdef LILYGO_DEV
#include <LilyGoWatch.h>
extern TFT_eSPI * tft;
#endif

#ifdef M5_DEV
#include <M5Core2.h>
extern M5Display * tft;
#endif


#include <esp_event_base.h>
#include <functional> // callbacks

Expand All @@ -33,7 +44,6 @@ typedef std::function<void (void* payload)> UICallback; // repeated declaration
typedef std::function<void (void* payload,void* payload2)> UICallback2;
typedef std::function<void (void* payload,void* payload2,void* payload3)> UICallback3;

extern TFT_eSPI * tft;
//extern TTGOClass *ttgo; // ttgo lib
//#include "../system/Application.hpp"
// caller contains the object (must be converted)
Expand Down Expand Up @@ -95,11 +105,17 @@ extern const TemplateColorPalette * currentColorPalette;
extern const TemplateThemeScheme * currentThemeScheme;

// color utilities
uint16_t Get16BitFromRGB(uint32_t color888);
void GetRGBFrom16Bit(const uint16_t color, uint8_t &r, uint8_t &g, uint8_t &b);
uint16_t ColorSwap(uint16_t colorToSwap);
uint16_t ByteSwap(uint16_t colorToSwap);

#define ThCol(WHAT) tft->color24to16(currentThemeScheme->WHAT)
#ifdef LILYGO_DEV
#define ThCol(WHAT) Get16BitFromRGB(currentThemeScheme->WHAT)
#else
#define ThCol(WHAT) currentThemeScheme->WHAT
#endif



extern uint8_t pendingNotifications;
Expand Down
Loading

0 comments on commit 473df7d

Please sign in to comment.