|
|
@@ -12,7 +12,6 @@
|
|
|
/*
|
|
|
This is a modified version of the default clock app intended for use overnight
|
|
|
Up / Down controls the displays brightness. Down at brightness 0 turns the notification LED on and off.
|
|
|
- Default clock button actions replaced with long presses.
|
|
|
*/
|
|
|
|
|
|
int brightness = 5;
|
|
|
@@ -49,14 +48,14 @@ static const NotificationSequence led_reset = {
|
|
|
NULL,
|
|
|
};
|
|
|
|
|
|
-void set_backlight_brightness(float brightness){
|
|
|
+void set_backlight_brightness(float brightness) {
|
|
|
notif->settings.display_brightness = brightness;
|
|
|
notification_message(notif, &sequence_display_backlight_on);
|
|
|
}
|
|
|
|
|
|
-void handle_up(){
|
|
|
+void handle_up() {
|
|
|
dspBrightnessBarFrames = dspBrightnessBarDisplayFrames;
|
|
|
- if(brightness < 100){
|
|
|
+ if(brightness < 100) {
|
|
|
led = false;
|
|
|
notification_message(notif, &led_off);
|
|
|
brightness += 5;
|
|
|
@@ -64,19 +63,21 @@ void handle_up(){
|
|
|
set_backlight_brightness((float)(brightness / 100.f));
|
|
|
}
|
|
|
|
|
|
-void handle_down(){
|
|
|
+void handle_down() {
|
|
|
dspBrightnessBarFrames = dspBrightnessBarDisplayFrames;
|
|
|
- if(brightness > 0){
|
|
|
+ if(brightness > 0) {
|
|
|
brightness -= 5;
|
|
|
- if(brightness == 0){ //trigger only on the first brightness 5 -> 0 transition
|
|
|
+ if(brightness == 0) { //trigger only on the first brightness 5 -> 0 transition
|
|
|
led = true;
|
|
|
notification_message(notif, &led_on);
|
|
|
}
|
|
|
- }
|
|
|
- else if(brightness == 0){ //trigger on every down press afterwards
|
|
|
+ } else if(brightness == 0) { //trigger on every down press afterwards
|
|
|
led = !led;
|
|
|
- if(led){ notification_message(notif, &led_on); }
|
|
|
- else{ notification_message(notif, &led_off); }
|
|
|
+ if(led) {
|
|
|
+ notification_message(notif, &led_on);
|
|
|
+ } else {
|
|
|
+ notification_message(notif, &led_off);
|
|
|
+ }
|
|
|
}
|
|
|
set_backlight_brightness((float)(brightness / 100.f));
|
|
|
}
|
|
|
@@ -88,7 +89,12 @@ static void clock_input_callback(InputEvent* input_event, FuriMessageQueue* even
|
|
|
}
|
|
|
|
|
|
//do you are have stupid?
|
|
|
-void elements_progress_bar_vertical(Canvas* canvas, uint8_t x, uint8_t y, uint8_t height, float progress) {
|
|
|
+void elements_progress_bar_vertical(
|
|
|
+ Canvas* canvas,
|
|
|
+ uint8_t x,
|
|
|
+ uint8_t y,
|
|
|
+ uint8_t height,
|
|
|
+ float progress) {
|
|
|
furi_assert(canvas);
|
|
|
furi_assert((progress >= 0) && (progress <= 1.0));
|
|
|
uint8_t width = 9;
|
|
|
@@ -112,8 +118,7 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {
|
|
|
//avoids a bug with the brightness being reverted after the backlight-off period
|
|
|
set_backlight_brightness((float)(brightness / 100.f));
|
|
|
|
|
|
-
|
|
|
- if(dspBrightnessBarFrames > 0){
|
|
|
+ if(dspBrightnessBarFrames > 0) {
|
|
|
elements_progress_bar_vertical(canvas, 119, 1, 62, (float)(brightness / 100.f));
|
|
|
dspBrightnessBarFrames--;
|
|
|
}
|
|
|
@@ -126,9 +131,9 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- FuriHalRtcDateTime curr_dt;
|
|
|
+ DateTime curr_dt;
|
|
|
furi_hal_rtc_get_datetime(&curr_dt);
|
|
|
- uint32_t curr_ts = furi_hal_rtc_datetime_to_timestamp(&curr_dt);
|
|
|
+ uint32_t curr_ts = datetime_datetime_to_timestamp(&curr_dt);
|
|
|
|
|
|
char time_string[TIME_LEN];
|
|
|
char date_string[DATE_LEN];
|
|
|
@@ -218,14 +223,14 @@ static void clock_tick(void* ctx) {
|
|
|
furi_message_queue_put(event_queue, &event, 0);
|
|
|
}
|
|
|
|
|
|
-void timer_start_stop(ClockState* plugin_state){
|
|
|
+void timer_start_stop(ClockState* plugin_state) {
|
|
|
// START/STOP TIMER
|
|
|
- FuriHalRtcDateTime curr_dt;
|
|
|
+ DateTime curr_dt;
|
|
|
furi_hal_rtc_get_datetime(&curr_dt);
|
|
|
- uint32_t curr_ts = furi_hal_rtc_datetime_to_timestamp(&curr_dt);
|
|
|
+ uint32_t curr_ts = datetime_datetime_to_timestamp(&curr_dt);
|
|
|
|
|
|
if(plugin_state->timer_running) {
|
|
|
- // Update stopped seconds
|
|
|
+ // Update stopped seconds
|
|
|
plugin_state->timer_stopped_seconds = curr_ts - plugin_state->timer_start_timestamp;
|
|
|
} else {
|
|
|
if(plugin_state->timer_start_timestamp == 0) {
|
|
|
@@ -240,7 +245,7 @@ void timer_start_stop(ClockState* plugin_state){
|
|
|
plugin_state->timer_running = !plugin_state->timer_running;
|
|
|
}
|
|
|
|
|
|
-void timer_reset_seconds(ClockState* plugin_state){
|
|
|
+void timer_reset_seconds(ClockState* plugin_state) {
|
|
|
if(plugin_state->timer_start_timestamp != 0) {
|
|
|
// Reset seconds
|
|
|
plugin_state->timer_running = false;
|
|
|
@@ -272,12 +277,20 @@ int32_t clock_app(void* p) {
|
|
|
|
|
|
clock_state_init(plugin_state);
|
|
|
|
|
|
+ notif = furi_record_open(RECORD_NOTIFICATION);
|
|
|
+ float tmpBrightness = notif->settings.display_brightness;
|
|
|
+ brightness = tmpBrightness * 100; // Keep current brightness by default
|
|
|
+
|
|
|
+ notification_message(notif, &sequence_display_backlight_enforce_on);
|
|
|
+ notification_message(notif, &led_off);
|
|
|
+
|
|
|
// Set system callbacks
|
|
|
ViewPort* view_port = view_port_alloc();
|
|
|
view_port_draw_callback_set(view_port, clock_render_callback, plugin_state);
|
|
|
view_port_input_callback_set(view_port, clock_input_callback, plugin_state->event_queue);
|
|
|
|
|
|
- FuriTimer* timer = furi_timer_alloc(clock_tick, FuriTimerTypePeriodic, plugin_state->event_queue);
|
|
|
+ FuriTimer* timer =
|
|
|
+ furi_timer_alloc(clock_tick, FuriTimerTypePeriodic, plugin_state->event_queue);
|
|
|
|
|
|
if(timer == NULL) {
|
|
|
FURI_LOG_E(TAG, "Cannot create timer");
|
|
|
@@ -295,12 +308,6 @@ int32_t clock_app(void* p) {
|
|
|
furi_timer_start(timer, furi_kernel_get_tick_frequency());
|
|
|
//FURI_LOG_D(TAG, "Timer started");
|
|
|
|
|
|
- notif = furi_record_open(RECORD_NOTIFICATION);
|
|
|
- float tmpBrightness = notif->settings.display_brightness;
|
|
|
-
|
|
|
- notification_message(notif, &sequence_display_backlight_enforce_on);
|
|
|
- notification_message(notif, &led_off);
|
|
|
-
|
|
|
// Main loop
|
|
|
PluginEvent event;
|
|
|
for(bool processing = true; processing;) {
|
|
|
@@ -311,48 +318,43 @@ int32_t clock_app(void* p) {
|
|
|
if(furi_mutex_acquire(plugin_state->mutex, FuriWaitForever) != FuriStatusOk) continue;
|
|
|
// press events
|
|
|
if(event.type == EventTypeKey) {
|
|
|
- if(event.input.type == InputTypeLong) {
|
|
|
+ if(event.input.type == InputTypeShort) {
|
|
|
switch(event.input.key) {
|
|
|
- case InputKeyLeft:
|
|
|
- // Reset seconds
|
|
|
- timer_reset_seconds(plugin_state);
|
|
|
- break;
|
|
|
- case InputKeyOk:
|
|
|
- // Toggle timer
|
|
|
- timer_start_stop(plugin_state);
|
|
|
- break;
|
|
|
- case InputKeyBack:
|
|
|
- // Exit the plugin
|
|
|
- processing = false;
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- else if(event.input.type == InputTypeShort) {
|
|
|
- switch(event.input.key) {
|
|
|
- case InputKeyUp:
|
|
|
- handle_up();
|
|
|
- break;
|
|
|
- case InputKeyDown:
|
|
|
- handle_down();
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
+ case InputKeyLeft:
|
|
|
+ // Reset seconds
|
|
|
+ timer_reset_seconds(plugin_state);
|
|
|
+ break;
|
|
|
+ case InputKeyOk:
|
|
|
+ // Toggle timer
|
|
|
+ timer_start_stop(plugin_state);
|
|
|
+ break;
|
|
|
+ case InputKeyBack:
|
|
|
+ // Exit the plugin
|
|
|
+ processing = false;
|
|
|
+ break;
|
|
|
+ case InputKeyUp:
|
|
|
+ handle_up();
|
|
|
+ break;
|
|
|
+ case InputKeyDown:
|
|
|
+ handle_down();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
} /*else if(event.type == EventTypeTick) {
|
|
|
furi_hal_rtc_get_datetime(&plugin_state->datetime);
|
|
|
}*/
|
|
|
|
|
|
- view_port_update(view_port);
|
|
|
furi_mutex_release(plugin_state->mutex);
|
|
|
+ view_port_update(view_port);
|
|
|
}
|
|
|
|
|
|
furi_timer_free(timer);
|
|
|
view_port_enabled_set(view_port, false);
|
|
|
gui_remove_view_port(gui, view_port);
|
|
|
furi_record_close(RECORD_GUI);
|
|
|
+ furi_record_close(RECORD_NOTIFICATION);
|
|
|
view_port_free(view_port);
|
|
|
furi_message_queue_free(plugin_state->event_queue);
|
|
|
furi_mutex_free(plugin_state->mutex);
|