blob: 282ae4ede01400ecfbd05699785a6cacec0c9af1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#include "pico/stdlib.h"
#include <cstdlib>
#ifndef SDL2_BUILD
#include <stdio.h>
#include "hardware/i2c.h"
#include "hardware/rtc.h"
#include "pico/util/datetime.h"
#include "hardware/sync.h"
#else
#include <chrono>
#include <thread>
#include <iostream>
#endif
#include "init.hpp"
#include "hal/api.hpp"
#include "buttons.hpp"
#include "globals.hpp"
#include "app/app_manager.hpp"
global_status g_s;
user_settings g_user;
AppAPI app_api;
bool cb_status_check(struct repeating_timer *t) {
// Enter shallow sleep mode when needed
auto time_since_last_press = time_since_button_press();
if (!g_s.is_sleeping && time_since_last_press > g_user.sleep_delay) {
g_s.is_sleeping = true;
app_api.performance_set(AppAPI::perf_modes::ENTER_SHALLOW_SLEEP);
app_api.display_power(false);
} else if (g_s.is_sleeping && time_since_last_press < g_user.sleep_delay) {
g_s.is_sleeping = false;
app_api.performance_set(AppAPI::perf_modes::EXIT_SHALLOW_SLEEP);
app_api.display_power(true);
}
// should it be done when sleeping?
app_mgr::app_all_bgrefresh();
return true;
}
int main() {
#ifdef SDL2_BUILD
using namespace std::chrono_literals;
#endif
init_all();
printf("~~~==~~~");
std::cerr << std::endl;
init_buttons();
app_api.init();
#ifndef SDL2_BUILD
struct repeating_timer status_check_timer;
add_repeating_timer_ms(250, cb_status_check, NULL, &status_check_timer); // TODO: Execute on core1
#endif
g_s.foreground_app = app_mgr::app_init(0);
while (1) {
if (g_s.app_ready && !g_s.is_sleeping) {
app_mgr::app_render(g_s.foreground_app);
bool do_quit = app_api.display_write_backbuffer();
if (do_quit) return 0;
}
if (g_s.is_sleeping)
#ifndef SDL2_BUILD
__wfi();
#else
;//std::this_thread::sleep_for(10ms);
#endif
else if (g_s.app_switch_requested) {
app_mgr::app_switch(g_s.foreground_app, g_s.app_switch_to_app);
g_s.app_switch_requested = false;
} else
sleep_ms(g_s.foreground_app->app_get_attributes().render_interval);
}
return 0;
}
|