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
12 changes: 12 additions & 0 deletions non_catalog_apps/FlipperNightStand_clock/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

## 1.1

- Fix the 12-hour clock showing midnight as `00:xx AM` instead of `12:xx AM`
- Fix the brightness control so the red LED nightlight stays reachable from every starting brightness: round the inherited system brightness to the nearest step and clamp brightness to 0-100 (previously levels such as 35/45/65/70/90/95% started off-grid, so Down skipped 0 and the nightlight could never be switched on)
- Restore the notification settings before releasing the notification record when exiting
- Free the view_port and notification record (and restore the display settings) if the periodic timer fails to allocate on startup

## 1.0

- Initial release: overnight clock with screen-brightness control, red LED nightlight, and a stopwatch
2 changes: 1 addition & 1 deletion non_catalog_apps/FlipperNightStand_clock/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ App(
fap_category="Tools",
fap_author="@nymda & @Willy-JL",
fap_weburl="https://github.com/nymda/FlipperNightStand",
fap_version="1.0",
fap_version="1.1",
fap_description="Clock with screen brightness controls",
)
24 changes: 14 additions & 10 deletions non_catalog_apps/FlipperNightStand_clock/clock_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void handle_up() {
led = false;
notification_message(notif, &led_off);
brightness += 5;
if(brightness > 100) brightness = 100;
}
set_backlight_brightness((float)(brightness / 100.f));
}
Expand All @@ -68,6 +69,7 @@ void handle_down() {
dspBrightnessBarFrames = dspBrightnessBarDisplayFrames;
if(brightness > 0) {
brightness -= 5;
if(brightness < 0) brightness = 0;
if(brightness == 0) { //trigger only on the first brightness 5 -> 0 transition
led = true;
notification_message(notif, &led_on);
Expand Down Expand Up @@ -150,15 +152,10 @@ static void clock_render_callback(Canvas* const canvas, void* ctx) {
snprintf(
time_string, TIME_LEN, CLOCK_TIME_FORMAT, curr_dt.hour, curr_dt.minute, curr_dt.second);
} else {
bool pm = curr_dt.hour > 12;
bool pm12 = curr_dt.hour >= 12;
snprintf(
time_string,
TIME_LEN,
CLOCK_TIME_FORMAT,
pm ? curr_dt.hour - 12 : curr_dt.hour,
curr_dt.minute,
curr_dt.second);
uint8_t hour12 = curr_dt.hour % 12;
if(hour12 == 0) hour12 = 12;
snprintf(time_string, TIME_LEN, CLOCK_TIME_FORMAT, hour12, curr_dt.minute, curr_dt.second);

snprintf(
meridian_string,
Expand Down Expand Up @@ -309,7 +306,7 @@ int32_t clock_app(void* p) {
notif = furi_record_open(RECORD_NOTIFICATION);

float SavedBrightness = notif->settings.display_brightness;
brightness = SavedBrightness * 100; // Keep current brightness by default
brightness = (int)roundf(SavedBrightness * 100.f); // Keep current brightness by default

uint32_t Saved_display_off_delay_ms = notif->settings.display_off_delay_ms;
notif->settings.display_off_delay_ms = 0;
Expand All @@ -327,6 +324,12 @@ int32_t clock_app(void* p) {

if(timer == NULL) {
FURI_LOG_E(TAG, "Cannot create timer");
//restore the notification settings mutated above before bailing out
notif->settings.display_off_delay_ms = Saved_display_off_delay_ms;
notification_message(notif, &sequence_display_backlight_enforce_auto);
notification_message(notif, &led_reset);
furi_record_close(RECORD_NOTIFICATION);
view_port_free(view_port);
furi_mutex_free(plugin_state->mutex);
furi_message_queue_free(plugin_state->event_queue);
free(plugin_state);
Expand Down Expand Up @@ -387,7 +390,6 @@ int32_t clock_app(void* p) {
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);
Expand All @@ -400,5 +402,7 @@ int32_t clock_app(void* p) {
set_backlight_brightness(SavedBrightness);
notification_message(notif, &led_reset);

furi_record_close(RECORD_NOTIFICATION);

return 0;
}
Loading