Добавить прошивку 1.4 с выключением на паузе

This commit is contained in:
AidarKC
2026-10-30 14:01:45 +03:00
parent 09c3eb2806
commit 2761b44ab2
4 changed files with 15 additions and 9 deletions
@@ -47,6 +47,7 @@ static constexpr uint32_t LVGL_TICK_MS = 2, UI_MS = 120;
static constexpr uint32_t DEBOUNCE_MS = 45, BATT_MS = 5000;
static constexpr uint32_t QUIET_START_MS = 30000, LOUD_START_MS = 60000;
static constexpr uint32_t SLOW_LOUD_MS = 90000, POWER_OFF_MS = 390000;
static constexpr uint32_t PAUSE_POWER_OFF_MS = 15UL * 60UL * 1000UL;
static constexpr uint16_t LIMITS[] = {5, 7, 10, 15, 20};
static constexpr uint32_t SCREEN_TIMEOUTS[] = {10000, 30000, 60000, 0};
static const char *SCREEN_TIMEOUT_NAMES[] = {"10 sec", "30 sec", "60 sec", "Always on"};
@@ -81,7 +82,7 @@ static bool gScreenOn = true, gPaused = false;
enum class BreathState : uint8_t { Waiting, Inhale, Exhale };
static BreathState gBreath = BreathState::Waiting;
static uint64_t gCompletedMs = 0;
static uint32_t gPhaseStarted = 0, gCycleStarted = 0, gLastActivity = 0, gLastUi = 0, gLastBatt = 0, gLastReminder = 0;
static uint32_t gPhaseStarted = 0, gCycleStarted = 0, gPauseStarted = 0, gLastActivity = 0, gLastUi = 0, gLastBatt = 0, gLastReminder = 0;
static uint8_t gLimit = 2, gTick = 3, gAlert = 10, gScreenTimeout = 1;
static uint32_t gCycles[5] = {}; static uint8_t gCycleCount = 0, gCycleNext = 0, gShortStreak = 0;
static lv_disp_draw_buf_t gDrawBuf; static lv_color_t *gBuf1 = nullptr, *gBuf2 = nullptr;
@@ -130,7 +131,7 @@ static String workerMessage(){char local[128];portENTER_CRITICAL(&gWorkerMux);st
// Production HTTPS: this CA trusts Let's Encrypt certificates, including Caddy's default.
// If Caddy uses a different issuer, replace this PEM and rebuild the firmware.
static const char SERVER_URL[]="https://breathmonitor.shineup.me";
static const char FIRMWARE_VERSION[]="1.3";
static const char FIRMWARE_VERSION[]="1.4";
static const char ROOT_CA[] PROGMEM = R"CERT(
-----BEGIN CERTIFICATE-----
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
@@ -398,8 +399,8 @@ static void quiet() { beep(880,480,TICK_VOLUME[gTick]); } static void loud(){bee
static void batteryUi() { if(!gBatteryText)return; int p=battery(); char t[8]; snprintf(t,sizeof(t),p<0?"--":"%d%%",p); lv_label_set_text(gBatteryText,t); if(gBatteryFill)lv_obj_set_width(gBatteryFill,p>0?max(2,min(26,p*26/100)):0); if(gBolt)lv_obj_set_style_opa(gBolt,(gPowerReady&&gPower.isCharging())?LV_OPA_COVER:LV_OPA_TRANSP,0); }
static lv_obj_t *button(lv_obj_t *,const char *,int,int,int,int,uint32_t,lv_event_cb_t,void * = nullptr);
static void togglePause(){
if(gPaused){gPaused=false;gBreath=BreathState::Waiting;gRotationArmed=false;gOrientation=-1;gScreenEdgeOrientation=-1;gScreenEdgeCandidate=-1;appendEvent(5);}
else {gPaused=true;gBreath=BreathState::Waiting;gCycleStarted=0;gPhaseStarted=0;gRotationArmed=false;gOrientation=-1;gScreenEdgeOrientation=-1;gScreenEdgeCandidate=-1;appendEvent(4);}
if(gPaused){gPaused=false;gPauseStarted=0;gBreath=BreathState::Waiting;gRotationArmed=false;gOrientation=-1;gScreenEdgeOrientation=-1;gScreenEdgeCandidate=-1;appendEvent(5);}
else {gPaused=true;gPauseStarted=millis();gBreath=BreathState::Waiting;gCycleStarted=0;gPhaseStarted=0;gRotationArmed=false;gOrientation=-1;gScreenEdgeOrientation=-1;gScreenEdgeCandidate=-1;appendEvent(4);}
}
static void pauseClicked(lv_event_t *){togglePause();}
static void topBar(const char *title) {
@@ -622,6 +623,10 @@ static void reminders(){
if(age<LOUD_START_MS)quiet();else if(age<POWER_OFF_MS)loud();
else{appendEvent(3);gfx->setBrightness(0);if(gPowerReady)gPower.shutdown();esp_deep_sleep_start();}
}
static void pausePowerOff(){
if(!gPaused || gPauseStarted==0 || millis()-gPauseStarted<PAUSE_POWER_OFF_MS)return;
appendEvent(3);gfx->setBrightness(0);if(gPowerReady)gPower.shutdown();esp_deep_sleep_start();
}
// Wi-Fi credentials use the same key layout as shine_homeserver_main.ino,
// but an isolated Preferences namespace to avoid modifying the other application.
@@ -1226,4 +1231,4 @@ void setup(){Serial.begin(115200);Wire.begin(PIN_I2C_SDA,PIN_I2C_SCL);initPower(
gAccountLogin=gAccountPrefs.getString("login","");gAccountPassword=gAccountPrefs.getString("password","");gDeviceToken=gAccountPrefs.getString("token","");
uint64_t chip=ESP.getEfuseMac();char ident[20];snprintf(ident,sizeof(ident),"%012llX",(unsigned long long)chip);gDeviceId=ident;
lv_init();gBuf1=(lv_color_t *)heap_caps_malloc(DISP_W*40*sizeof(lv_color_t),MALLOC_CAP_DMA);gBuf2=(lv_color_t *)heap_caps_malloc(DISP_W*40*sizeof(lv_color_t),MALLOC_CAP_DMA);lv_disp_draw_buf_init(&gDrawBuf,gBuf1,gBuf2,DISP_W*40);static lv_disp_drv_t dd;lv_disp_drv_init(&dd);dd.hor_res=DISP_W;dd.ver_res=DISP_H;dd.flush_cb=flush;dd.rounder_cb=rounder;dd.draw_buf=&gDrawBuf;lv_disp_drv_register(&dd);static lv_indev_drv_t id;lv_indev_drv_init(&id);id.type=LV_INDEV_TYPE_POINTER;id.read_cb=touchRead;lv_indev_drv_register(&id);const esp_timer_create_args_t ta={.callback=&tick,.name="lvgl_tick"};esp_timer_handle_t timer;esp_timer_create(&ta,&timer);esp_timer_start_periodic(timer,LVGL_TICK_MS*1000);gLastActivity=millis();if(gFileMountFailed)formatPromptScreen();else enterMonitor(nullptr);}
void loop(){uint32_t now=millis();poll(gInhale,true);poll(gExhale,false);pollPowerKey();pollOrientation();usbCommands();wifiTick();ntpTick();networkFinishTick();reminders();if(now-gLastUi>=UI_MS){gLastUi=now;refresh();timeUiTick();networkUiTick();}if(now-gLastBatt>=BATT_MS){gLastBatt=now;batteryUi();}uint32_t timeout=SCREEN_TIMEOUTS[gScreenTimeout];if(gScreenOn&&!(gRotation && gImuOk && gScreenEdgeOrientation==2)&&gScreen!=Screen::Settings&&gScreen!=Screen::Wifi&&gScreen!=Screen::WifiPassword&&gScreen!=Screen::Time&&gScreen!=Screen::ManualTime&&gScreen!=Screen::Online&&gScreen!=Screen::Account&&(int32_t)(now-gKey1WakeUntil)>=0&&timeout&&now-gLastActivity>=timeout){gScreenOn=false;gfx->setBrightness(0);}lv_timer_handler();applyRotationScreenPolicy();if((int32_t)(millis()-gKey1WakeUntil)<0){gScreenOn=true;gfx->setBrightness(220);}delay(5);}
void loop(){uint32_t now=millis();poll(gInhale,true);poll(gExhale,false);pollPowerKey();pollOrientation();usbCommands();wifiTick();ntpTick();networkFinishTick();reminders();pausePowerOff();if(now-gLastUi>=UI_MS){gLastUi=now;refresh();timeUiTick();networkUiTick();}if(now-gLastBatt>=BATT_MS){gLastBatt=now;batteryUi();}uint32_t timeout=SCREEN_TIMEOUTS[gScreenTimeout];if(gScreenOn&&!(gRotation && gImuOk && gScreenEdgeOrientation==2)&&gScreen!=Screen::Settings&&gScreen!=Screen::Wifi&&gScreen!=Screen::WifiPassword&&gScreen!=Screen::Time&&gScreen!=Screen::ManualTime&&gScreen!=Screen::Online&&gScreen!=Screen::Account&&(int32_t)(now-gKey1WakeUntil)>=0&&timeout&&now-gLastActivity>=timeout){gScreenOn=false;gfx->setBrightness(0);}lv_timer_handler();applyRotationScreenPolicy();if((int32_t)(millis()-gKey1WakeUntil)<0){gScreenOn=true;gfx->setBrightness(220);}delay(5);}