timed-remote

Flipper Zero app for sending delayed IR commands
git clone git://src.adamsgaard.dk/timed-remote # fast
git clone https://src.adamsgaard.dk/timed-remote.git # slow
Log | Files | Refs | README | LICENSE Back to index

time_helper.c (1271B)


      1 #ifndef TIMED_REMOTE_TEST_BUILD
      2 #include <furi_hal.h>
      3 #include <stdio.h>
      4 #endif
      5 
      6 #include "time_helper.h"
      7 
      8 uint32_t
      9 time_hms_sec(uint8_t h, uint8_t m, uint8_t s)
     10 {
     11 	return (uint32_t)h * 3600 + (uint32_t)m * 60 + (uint32_t)s;
     12 }
     13 
     14 void
     15 time_sec_hms(uint32_t total_seconds, uint8_t *h, uint8_t *m, uint8_t *s)
     16 {
     17 	/* Wrap values >= 24 hours into a single day. */
     18 	total_seconds %= 24 * 3600;
     19 
     20 	*h = (uint8_t)(total_seconds / 3600);
     21 	total_seconds %= 3600;
     22 	*m = (uint8_t)(total_seconds / 60);
     23 	*s = (uint8_t)(total_seconds % 60);
     24 }
     25 
     26 #ifndef TIMED_REMOTE_TEST_BUILD
     27 uint32_t
     28 time_until(uint8_t target_h, uint8_t target_m, uint8_t target_s)
     29 {
     30 	DateTime now;
     31 	uint32_t now_seconds;
     32 	uint32_t target_seconds;
     33 
     34 	furi_hal_rtc_get_datetime(&now);
     35 
     36 	now_seconds = time_hms_sec(now.hour, now.minute, now.second);
     37 	target_seconds = time_hms_sec(target_h, target_m, target_s);
     38 
     39 	if (target_seconds < now_seconds)
     40 		return (24 * 3600 - now_seconds) + target_seconds;
     41 
     42 	return target_seconds - now_seconds;
     43 }
     44 
     45 void
     46 time_name(char *buffer, size_t buffer_size)
     47 {
     48 	DateTime now;
     49 
     50 	furi_hal_rtc_get_datetime(&now);
     51 
     52 	snprintf(buffer,
     53 	    buffer_size,
     54 	    "IR_%04d%02d%02d_%02d%02d%02d",
     55 	    now.year,
     56 	    now.month,
     57 	    now.day,
     58 	    now.hour,
     59 	    now.minute,
     60 	    now.second);
     61 }
     62 #endif