Skip to content

Commit

Permalink
1.1版,修复一些群里提到的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
diylxy committed Dec 1, 2023
1 parent e992fa5 commit 04458db
Show file tree
Hide file tree
Showing 22 changed files with 34 additions and 19 deletions.
1 change: 1 addition & 0 deletions include/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class HAL
bool noDeepSleep = false;
bool SleepUpdateMutex = false;
bool _hookButton = false; // 不要修改这个
bool wakeUpFromDeepSleep = false;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int _wakeupIO[2] = {PIN_BUTTONC, PIN_BUTTONL};

Expand Down
1 change: 1 addition & 0 deletions include/peripherals.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Peripherals
{
return (peripherals_load & PERIPHERALS_SD_BIT) == PERIPHERALS_SD_BIT;
}
void load_append(uint16_t bitmask);
// 下面是传感器实例
Adafruit_AHTX0 aht;
Adafruit_BMP280 bmp;
Expand Down
2 changes: 1 addition & 1 deletion src/apps/appBuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void AppBuzzer::setup()
{
while (1)
{
const char *path = GUI::fileDialog("请选择要播放的文件");
const char *path = GUI::fileDialog("请选择要播放的文件", false, "buz");
if (path == NULL)
{
appManager.goBack();
Expand Down
4 changes: 1 addition & 3 deletions src/apps/appClock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,15 @@ static AppClock app;
static RTC_DATA_ATTR uint8_t NTPCounter = 0;
void appclock_wakeup()
{
appManager.parameter = "p";
app.setup();
appManager.parameter = "";
}
void AppClock::setup()
{
exit = appclock_exit;
deepsleep = appclock_deepsleep;
wakeup = appclock_wakeup;
int ntp_interval = hal.getNTPMinute();
if (appManager.parameter == "p")
if (hal.wakeUpFromDeepSleep)
{
++NTPCounter;
if (NTPCounter < ntp_interval)
Expand Down
16 changes: 10 additions & 6 deletions src/apps/appEBook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AppEBook : public AppBase
char currentFilename[256];
bool __eof = false;
};
RTC_DATA_ATTR uint32_t currentPage = 0; // 0:第一页
RTC_DATA_ATTR uint32_t currentPage = -1; // 0:第一页
static AppEBook app;
static void appebook_exit()
{
Expand Down Expand Up @@ -83,7 +83,7 @@ void AppEBook::setup()
app.currentFilename[0] = 0;
display.clearScreen();
size_t s = hal.pref.getBytes(SETTINGS_PARAM_LAST_EBOOK, app.currentFilename, 256);
if (appManager.parameter == "")
if (hal.wakeUpFromDeepSleep == false || currentPage == -1)
{
currentPage = hal.pref.getInt(SETTINGS_PARAM_LAST_EBOOK_PAGE, 0);
if (s == 0)
Expand Down Expand Up @@ -208,12 +208,14 @@ bool AppEBook::indexFile()
}
while (true)
{
start:
c = fgetc(currentFileHandle);
if (c == EOF)
{
break;
}
while(c == '\n')continue;
while (c == '\n' && x == 0 && y == 0)
goto start;
offset++;
int utf_bytes = 0;
if (c & 0x80)
Expand Down Expand Up @@ -293,7 +295,7 @@ bool AppEBook::indexFile()
if (y >= 128 - 14)
{
page++;
x = add_pending;
x = 0;
y = 0;
uint32_t pageOffset = offset - utf_bytes - 1;
fwrite(&pageOffset, 4, 1, indexFileHandle);
Expand Down Expand Up @@ -383,13 +385,15 @@ void AppEBook::drawCurrentPage()
// 自动换行
while (true)
{
start:
int c = fgetc(currentFileHandle);
if (c == EOF)
{
__eof = true;
break;
}
while(c == '\n')continue;
while (c == '\n' && x == 0 && y == 0)
goto start;
int utf_bytes = 0;
if (c & 0x80)
{
Expand Down Expand Up @@ -427,7 +431,7 @@ void AppEBook::drawCurrentPage()
}
else
{
GUI::msgbox("读文件错误", "非预期的UTF8编码");
Serial.println("非预期的UTF8编码");
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/apps/appSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ void AppSettings::menu_alarm()
break;
if (res == 6)
{
const char *str = GUI::fileDialog("请选择闹钟铃声文件", false, ".buz");
const char *str = GUI::fileDialog("请选择闹钟铃声文件", false, "buz");
if (str)
{
hal.pref.putString(SETTINGS_PARAM_ALARM_TONE, String(str));
Expand Down
1 change: 1 addition & 0 deletions src/lua/modules/lua_peri_aht.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern const char *err_invalid_param;
int peri_aht_get(lua_State *L)
{
sensors_event_t humidity, temp;
peripherals.load_append(PERIPHERALS_AHT20_BIT);
peripherals.aht.getEvent(&humidity, &temp); // populate temp and humidity objects with fresh data
lua_pushnumber(L, temp.temperature);
lua_pushnumber(L, humidity.relative_humidity);
Expand Down
1 change: 1 addition & 0 deletions src/lua/modules/lua_peri_bmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ extern const char *err_invalid_param;
int peri_bmp_get(lua_State *L)
{
float sea_press = weather.realtime.pressure;
peripherals.load_append(PERIPHERALS_BMP280_BIT);
if(lua_gettop(L) == 1)
{
if(lua_isnumber(L, 1))
Expand Down
5 changes: 5 additions & 0 deletions src/lua/modules/lua_peri_sgp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ extern const char *err_invalid_param;

int sgp_get(lua_State *L)
{
peripherals.load_append(PERIPHERALS_SGP30_BIT);
if (peripherals.sgp.IAQmeasure())
{
lua_pushinteger(L, peripherals.sgp.TVOC);
Expand All @@ -19,6 +20,7 @@ int sgp_get(lua_State *L)

int sgp_getRaw(lua_State *L)
{
peripherals.load_append(PERIPHERALS_SGP30_BIT);
if (peripherals.sgp.IAQmeasureRaw())
{
lua_pushinteger(L, peripherals.sgp.rawH2);
Expand All @@ -35,6 +37,7 @@ int sgp_getRaw(lua_State *L)
int sgp_getIAQBaseline(lua_State *L)
{
uint16_t TVOC_base, eCO2_base;
peripherals.load_append(PERIPHERALS_SGP30_BIT);
if (peripherals.sgp.getIAQBaseline(&eCO2_base, &TVOC_base))
{
lua_pushinteger(L, eCO2_base);
Expand All @@ -50,6 +53,7 @@ int sgp_getIAQBaseline(lua_State *L)

int sgp_setIAQBaseline(lua_State *L)
{
peripherals.load_append(PERIPHERALS_SGP30_BIT);
if (lua_gettop(L) == 2)
{
if (lua_isnumber(L, 1) && lua_isnumber(L, 2))
Expand Down Expand Up @@ -81,6 +85,7 @@ static uint32_t getAbsoluteHumidity(float temperature, float humidity)

int sgp_setHumidity(lua_State *L)
{
peripherals.load_append(PERIPHERALS_SGP30_BIT);
if (lua_gettop(L) == 2)
{
if (lua_isnumber(L, 1) && lua_isnumber(L, 2))
Expand Down
8 changes: 3 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void setup()
ledcAttachPin(PIN_BUZZER, 0);
ledcWriteTone(0, 0);
ledcDetachPin(PIN_BUZZER);
bool initResult = hal.init();
hal.init();
alarms.load();
alarms.check();
Serial.println(ESP.getFreeHeap());
Expand All @@ -46,13 +46,11 @@ void setup()
}
hal.checkNightSleep();
}
if (initResult == false)
{
appManager.parameter = "p";
}
bool recoverLast = false;
hal.wakeUpFromDeepSleep = false;
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_UNDEFINED)
{
hal.wakeUpFromDeepSleep = true;
recoverLast = appManager.recover(appManager.getRealClock());
}
if (recoverLast == false)
Expand Down
7 changes: 7 additions & 0 deletions src/peripherals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,13 @@ bool Peripherals::load(uint16_t bitmask)
peripherals_load = bitmask;
return true;
}
void Peripherals::load_append(uint16_t bitmask)
{
int tmp = peripherals_load;
if(tmp | bitmask == tmp)
return;
peripherals.load(bitmask | tmp);
}

void Peripherals::sleep()
{
Expand Down
Binary file added tools/midi/测试用midi/Summer.mid
Binary file not shown.
Binary file not shown.
Binary file added tools/midi/测试用midi/天空之城.mid
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
Binary file added tools/midi/测试用midi/献给爱丽丝.mid
Binary file not shown.
Binary file added tools/midi/测试用midi/荷塘月色.mid
Binary file not shown.
Binary file added tools/midi/测试用midi/野蜂飞舞.mid
Binary file not shown.
Binary file added tools/midi/测试用midi/隐形的翅膀.mid
Binary file not shown.
Binary file added tools/midi/测试用midi/雨的印记.mid
Binary file not shown.
4 changes: 1 addition & 3 deletions unused/appClock_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ static AppClockDemo app;
static RTC_DATA_ATTR uint8_t NTPCounter = 0;
void AppClockDemo_wakeup()
{
appManager.parameter = "p";
app.setup();
appManager.parameter = "";
}
void AppClockDemo::setup()
{
Expand All @@ -193,7 +191,7 @@ void AppClockDemo::setup()
tmp_minute += 1;
hal.global_hour_offset = tmp_minute / 60 - 15;
if(tmp_minute == 1440)hal.powerOff();
if (appManager.parameter == "p")
if (hal.wakeUpFromDeepSleep)
{
if (force_full_update == false && part_refresh_count1 <= 20)
{
Expand Down

0 comments on commit 04458db

Please sign in to comment.