time_helper.c (1486B)
1 #include "time_helper.h" 2 3 #ifndef TIMED_REMOTE_TEST_BUILD 4 #include <furi_hal.h> 5 #include <stdio.h> 6 #endif 7 8 uint32_t time_helper_hms_to_seconds(uint8_t h, uint8_t m, uint8_t s) { 9 return (uint32_t)h * 3600 + (uint32_t)m * 60 + (uint32_t)s; 10 } 11 12 void time_helper_seconds_to_hms(uint32_t total_seconds, uint8_t *h, uint8_t *m, 13 uint8_t *s) { 14 /* Handle times >= 24 hours by wrapping */ 15 total_seconds = total_seconds % (24 * 3600); 16 17 *h = (uint8_t)(total_seconds / 3600); 18 total_seconds %= 3600; 19 *m = (uint8_t)(total_seconds / 60); 20 *s = (uint8_t)(total_seconds % 60); 21 } 22 23 #ifndef TIMED_REMOTE_TEST_BUILD 24 uint32_t time_helper_seconds_until(uint8_t target_h, uint8_t target_m, 25 uint8_t target_s) { 26 DateTime now; 27 furi_hal_rtc_get_datetime(&now); 28 29 uint32_t now_seconds = 30 time_helper_hms_to_seconds(now.hour, now.minute, now.second); 31 uint32_t target_seconds = 32 time_helper_hms_to_seconds(target_h, target_m, target_s); 33 34 if (target_seconds < now_seconds) { 35 /* Roll to next day */ 36 return (24 * 3600 - now_seconds) + target_seconds; 37 } 38 39 /* Target time is now or later today */ 40 return target_seconds - now_seconds; 41 } 42 43 void time_helper_generate_signal_name(char *buffer, size_t buffer_size) { 44 DateTime now; 45 furi_hal_rtc_get_datetime(&now); 46 47 snprintf(buffer, buffer_size, "IR_%04d%02d%02d_%02d%02d%02d", now.year, 48 now.month, now.day, now.hour, now.minute, now.second); 49 } 50 #endif