Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions main/apps/app_power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void AppPower::onRunning()
update_bat_voltage();
update_icon_chg();
update_shut_down_button();
check_low_battery_power_off();
}

void AppPower::update_bat_voltage()
Expand Down Expand Up @@ -71,3 +72,26 @@ void AppPower::update_shut_down_button()
GetHAL().powerOff();
}
}

void AppPower::check_low_battery_power_off()
{
// Only auto power off when wifi start scanning
if (!AppWifi::is_wifi_start_scanning()) {
return;
}

if (GetHAL().millis() - _time_count.lowBat > 2000) {
bool is_usb_connected = GetHAL().isUsbConnected();
float battery_voltage = GetHAL().getBatteryVoltage();

if (!is_usb_connected && (battery_voltage < 3.8)) {
GetHAL().display.setEpdMode(epd_mode_t::epd_quality);
GetHAL().display.drawPng(img_logo_start, img_logo_end - img_logo_start, 0, 0);
GetHAL().delay(2000);

GetHAL().powerOff();
}

_time_count.lowBat = GetHAL().millis();
}
}
11 changes: 9 additions & 2 deletions main/apps/app_wifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

using namespace mooncake;

static bool _is_wifi_start_scanning = false;
bool AppWifi::is_wifi_start_scanning()
{
return _is_wifi_start_scanning;
}

void AppWifi::onCreate()
{
setAppInfo().name = "AppWifi";
Expand Down Expand Up @@ -95,8 +101,9 @@ void AppWifi::handle_state_first_scan()
_scanning_mutex.unlock();

if (!is_scanning) {
_state = STATE_SCANNING_RESULT;
_time_count = 0;
_state = STATE_SCANNING_RESULT;
_is_wifi_start_scanning = true;
_time_count = 0;
return;
}

Expand Down
4 changes: 4 additions & 0 deletions main/apps/apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ class AppPower : public mooncake::AppAbility {
struct UpdateTimeCount_t {
uint32_t batVoltage = 0;
uint32_t iconChg = 0;
uint32_t lowBat = 0;
};
UpdateTimeCount_t _time_count;
bool _current_icon_chg = false;

void update_bat_voltage();
void update_icon_chg();
void update_shut_down_button();
void check_low_battery_power_off();
};

/**
Expand Down Expand Up @@ -92,6 +94,8 @@ class AppWifi : public mooncake::AppAbility {
void onCreate() override;
void onRunning() override;

static bool is_wifi_start_scanning();

private:
enum State_t {
STATE_IDLE = 0,
Expand Down
22 changes: 22 additions & 0 deletions main/hal/hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void Hal::init()
M5.begin();
M5.Display.setRotation(1);

rtc_init();
power_init();
sd_card_init();
wifi_init();
Expand All @@ -57,6 +58,27 @@ void Hal::feedTheDog()
vTaskDelay(5);
}

/* -------------------------------------------------------------------------- */
/* RTC */
/* -------------------------------------------------------------------------- */
void Hal::rtc_init()
{
mclog::tagInfo(_tag, "rtc init");

m5::rtc_date_t date;
date.year = 2077;
date.month = 1;
date.date = 1;
date.weekDay = 1;

m5::rtc_time_t time;
time.hours = 12;
time.minutes = 0;
time.seconds = 0;

M5.Rtc.setDateTime(&date, &time);
}

/* -------------------------------------------------------------------------- */
/* Power */
/* -------------------------------------------------------------------------- */
Expand Down
1 change: 1 addition & 0 deletions main/hal/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Hal {
WifiScanResult_t _wifi_scan_result;
SdCardTestResult_t _sd_card_test_result;

void rtc_init();
void power_init();
void sd_card_init();
void wifi_init();
Expand Down
21 changes: 20 additions & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,28 @@

using namespace mooncake;

void draw_gray_scale_bars()
void draw_firmware_version()
{
GetHAL().display.setEpdMode(epd_mode_t::epd_quality);
GetHAL().display.loadFont(font_montserrat_medium_36);
GetHAL().display.setTextDatum(middle_center);
GetHAL().display.setTextColor(TFT_BLACK);
GetHAL().display.drawString("FactoryTest: V0.4", GetHAL().display.width() / 2, GetHAL().display.height() / 2);
}

void draw_gray_scale_bars()
{
std::vector<uint32_t> colors = {0xffffff, 0xeeeeee, 0xdddddd, 0xcccccc, 0xbbbbbb, 0xaaaaaa, 0x999999, 0x888888,
0x777777, 0x666666, 0x555555, 0x444444, 0x333333, 0x222222, 0x111111, 0x000000};

GetHAL().display.setEpdMode(epd_mode_t::epd_quality);
GetHAL().display.fillScreen(TFT_BLACK);
GetHAL().delay(800);
GetHAL().display.startWrite();
for (int i = 0; i < 16; i++) {
GetHAL().display.fillRect(i * 60, 0, 60, 540, colors[i]);
}
GetHAL().display.endWrite();
}

void check_full_display_refresh_request(bool force = false)
Expand All @@ -42,8 +56,13 @@ void check_full_display_refresh_request(bool force = false)

extern "C" void app_main(void)
{
mclog::set_time_format(mclog::time_format_unix_seconds);

GetHAL().init();

draw_firmware_version();
GetHAL().delay(2000);

draw_gray_scale_bars();
GetHAL().delay(3000);

Expand Down