k4be 1 рік тому
батько
коміт
0650cfd704
3 змінених файлів з 20 додано та 2 видалено
  1. 16 0
      soft/display.c
  2. 3 2
      soft/display.h
  3. 1 0
      soft/working_modes.c

+ 16 - 0
soft/display.c

@@ -4,6 +4,7 @@
 #include "HD44780-I2C.h"
 #include "xprintf.h"
 #include "working_modes.h"
+#include "timec.h"
 
 __flash const unsigned char battery_states[][8] = {
 	{
@@ -196,6 +197,20 @@ void disp_speed(__attribute__ ((unused)) unsigned char changed) {
 	}
 }
 
+void disp_time(__attribute__ ((unused)) unsigned char changed) {
+	if (utc == 0) {
+		strcpy_P(disp.line1, PSTR("?"));
+		strcpy_P(disp.line2, PSTR("?"));
+		return;
+	}
+	time_t time = utc;
+	time += local_time_diff(time) * (signed int)3600;
+	struct tm *ct = gmtime(&time);
+
+	xsprintf(disp.line1, PSTR("%d.%02d.%4d"), ct->tm_mday, ct->tm_mon+1, ct->tm_year+1900);
+	xsprintf(disp.line2, PSTR("%d:%02d:%02d"), ct->tm_hour, ct->tm_min, ct->tm_sec);
+}
+
 void disp_func_main_menu(__attribute__ ((unused)) unsigned char changed) {
 	display_main_menu_item();
 }
@@ -217,6 +232,7 @@ void (*__flash const disp_funcs[])(unsigned char) = {
 	[DISPLAY_STATE_ELE_SAT] = disp_func_ele_sat,
 	[DISPLAY_STATE_DIST_TIME] = disp_distance_and_time,
 	[DISPLAY_STATE_SPEED] = disp_speed,
+	[DISPLAY_STATE_TIME] = disp_time,
 	[DISPLAY_STATE_MAIN_MENU] = disp_func_main_menu,
 	[DISPLAY_STATE_SETTINGS_MENU] = disp_func_settings_menu,
 };

+ 3 - 2
soft/display.h

@@ -13,8 +13,9 @@
 #define DISPLAY_STATE_ELE_SAT	10
 #define DISPLAY_STATE_DIST_TIME	11
 #define DISPLAY_STATE_SPEED	12
-#define DISPLAY_STATE_MAIN_MENU	13
-#define DISPLAY_STATE_SETTINGS_MENU	14
+#define DISPLAY_STATE_TIME	13
+#define DISPLAY_STATE_MAIN_MENU	14
+#define DISPLAY_STATE_SETTINGS_MENU	15
 
 struct disp_s {
 	char line1[16];

+ 1 - 0
soft/working_modes.c

@@ -15,6 +15,7 @@ __flash const unsigned char main_display_modes[] = {
 	DISPLAY_STATE_ELE_SAT,
 	DISPLAY_STATE_DIST_TIME,
 	DISPLAY_STATE_SPEED,
+	DISPLAY_STATE_TIME,
 };
 
 const char *enter_settings_get_name(void) {