Przeglądaj źródła

Add main menu (empty for now)

k4be 2 lat temu
rodzic
commit
8ac05ad0d0
6 zmienionych plików z 55 dodań i 8 usunięć
  1. 25 6
      soft/display.c
  2. 1 0
      soft/display.h
  3. 5 0
      soft/main.c
  4. 7 0
      soft/main.h
  5. 15 2
      soft/working_modes.c
  6. 2 0
      soft/working_modes.h

+ 25 - 6
soft/display.c

@@ -97,22 +97,34 @@ void disp_func_start_message(__attribute__ ((unused)) unsigned char changed) {
 	}
 }
 
+__flash const char _gps_wait[] =		"Czekam na GPS...";
+__flash const char _gps_ok[] =			"GPS OK!";
+__flash const char _card_ok[] =			"Karta OK!";
+__flash const char _logging_active[] =	"Zapis aktywny";
+
 void disp_func_card_ok(__attribute__ ((unused)) unsigned char changed) {
-	strcpy_P(disp.line1, PSTR("Karta OK!"));
-	strcpy_P(disp.line2, PSTR("Czekam na GPS..."));
+	strcpy_P(disp.line1, _card_ok);
+	strcpy_P(disp.line2, _gps_wait);
 }
 
 void disp_func_file_open(__attribute__ ((unused)) unsigned char changed) {
-	strcpy_P(disp.line2, PSTR("Zapis aktywny"));
+	strcpy_P(disp.line2, _logging_active);
 }
 
 void disp_func_file_closed(__attribute__ ((unused)) unsigned char changed) {
 	strcpy_P(disp.line2, PSTR("Pliki zamkniete"));
 }
 
-void disp_func_main_default(unsigned char changed) {
-	disp.line1[0] = '\0';
-	disp_func_file_open(changed);
+void disp_func_main_default(__attribute__ ((unused)) unsigned char changed) {
+	if (FLAGS & F_FILEOPEN)
+		strcpy_P(disp.line1, _logging_active);
+	else
+		strcpy_P(disp.line1, _card_ok);
+
+	if (FLAGS & F_GPSOK)
+		strcpy_P(disp.line2, _gps_ok);
+	else
+		strcpy_P(disp.line2, _gps_wait);
 }
 
 void disp_func_coord(__attribute__ ((unused)) unsigned char changed) {
@@ -134,6 +146,12 @@ void disp_func_ele_sat(__attribute__ ((unused)) unsigned char changed) {
 	xsprintf(disp.line2, PSTR("%d satelit"), System.satellites_used);
 }
 
+void disp_func_main_menu(__attribute__ ((unused)) unsigned char changed) {
+	strcpy_P(disp.line1, PSTR("  *** MENU *** "));
+	disp.line2[0] = '>';
+	disp.line2[1] = '\0';
+}
+
 void (*__flash const disp_funcs[])(unsigned char) = {
 	[DISPLAY_STATE_STARTUP] = disp_func_startup,
 	[DISPLAY_STATE_POWEROFF] = disp_func_poweroff,
@@ -145,6 +163,7 @@ void (*__flash const disp_funcs[])(unsigned char) = {
 	[DISPLAY_STATE_MAIN_DEFAULT] = disp_func_main_default,
 	[DISPLAY_STATE_COORD] = disp_func_coord,
 	[DISPLAY_STATE_ELE_SAT] = disp_func_ele_sat,
+	[DISPLAY_STATE_MAIN_MENU] = disp_func_main_menu,
 };
 
 void display_refresh(unsigned char newstate) {

+ 1 - 0
soft/display.h

@@ -11,6 +11,7 @@
 #define DISPLAY_STATE_MAIN_DEFAULT	8
 #define DISPLAY_STATE_COORD	9
 #define DISPLAY_STATE_ELE_SAT	10
+#define DISPLAY_STATE_MAIN_MENU	11
 
 void display_refresh(unsigned char newstate);
 void display_state(unsigned char newstate);

+ 5 - 0
soft/main.c

@@ -105,6 +105,7 @@ ISR(TIMER1_COMPA_vect)
 			FLAGS |= F_POWEROFF;
 			power_sw++;
 		}
+		System.timers.backlight = ms(BACKLIGHT_TIME);
 	} else {
 		power_sw = 0;
 	}
@@ -558,6 +559,10 @@ int main (void)
 			display_refresh(DISPLAY_STATE_NO_CHANGE);
 			gettemp();
 			key_process();
+			if (System.timers.backlight)
+				LEDW_ON();
+			else
+				LEDW_OFF();
 
 			if (!(FLAGS & F_GPSOK))
 				xputs_P(PSTR("Waiting for GPS\r\n"));

+ 7 - 0
soft/main.h

@@ -9,6 +9,7 @@
 
 #define	IVT_SYNC	180			/* f_sync() interval (0:no periodic sync) [sec] */
 #define POWER_SW_TIME	300		/* power switch hold time to power off [10ms] */
+#define BACKLIGHT_TIME	10000
 
 //#define	VI_LVL		4.2			/* Blackout threshold [volt] */
 //#define	VI_LVH		4.8			/* Recharge threshold [volt] */
@@ -58,6 +59,9 @@
 #define LEDB_PORT		1 /* expander */
 #define LEDB			_BV(5)
 
+#define LEDW_PORT		1 /* expander */
+#define LEDW			_BV(7)
+
 /* on/off macros */
 
 #define	BEEP_ON()		{BUZZER_PORT |= BUZZER;}
@@ -68,6 +72,8 @@
 #define	LEDG_OFF()		expander_set_bit(LEDG_PORT, LEDG, 0)
 #define	LEDB_ON()		expander_set_bit(LEDB_PORT, LEDB, 1)
 #define	LEDB_OFF()		expander_set_bit(LEDB_PORT, LEDB, 0)
+#define	LEDW_ON()		expander_set_bit(LEDW_PORT, LEDW, 1)
+#define	LEDW_OFF()		expander_set_bit(LEDW_PORT, LEDW, 0)
 #define GPS_ON()		{GPS_DIS_PORT &= ~GPS_DIS;}
 #define GPS_OFF()		{GPS_DIS_PORT |= GPS_DIS;}
 #define POWEROFF()		{POWER_ON_PORT &= ~POWER_ON;}
@@ -119,6 +125,7 @@ struct timers {
 	unsigned int recv_timeout;
 	unsigned int system_log;
 	unsigned int lcd;
+	unsigned int backlight;
 };
 
 struct system_s {

+ 15 - 2
soft/working_modes.c

@@ -4,6 +4,8 @@
 #include "HD44780-I2C.h"
 #include "xprintf.h"
 
+static signed char display_mode_index;
+
 __flash const unsigned char main_display_modes[] = {
 	DISPLAY_STATE_MAIN_DEFAULT,
 	DISPLAY_STATE_COORD,
@@ -11,13 +13,11 @@ __flash const unsigned char main_display_modes[] = {
 };
 
 void change_display_mode(signed char dir) {
-	static signed char display_mode_index;
 	display_mode_index += dir;
 	if (display_mode_index < 0)
 		display_mode_index = sizeof(main_display_modes) - 1;
 	if (display_mode_index >= (signed char)sizeof(main_display_modes))
 		display_mode_index = 0;
-	display_state(main_display_modes[display_mode_index]);
 }
 
 unsigned char working_mode_default(unsigned char k) {
@@ -28,12 +28,25 @@ unsigned char working_mode_default(unsigned char k) {
 		case K_DOWN:
 			change_display_mode(1);
 			break;
+		case K_RIGHT:
+			return MODE_MAIN_MENU;
+	}
+	display_state(main_display_modes[display_mode_index]);
+	return MODE_NO_CHANGE;
+}
+
+unsigned char working_mode_main_menu(unsigned char k) {
+	switch (k) {
+		case K_LEFT:
+			return MODE_DEFAULT;
 	}
+	display_state(DISPLAY_STATE_MAIN_MENU);
 	return MODE_NO_CHANGE;
 }
 
 unsigned char (*__flash const working_modes[])(unsigned char) = {
 	working_mode_default,
+	working_mode_main_menu,
 };
 
 void key_process(void) {

+ 2 - 0
soft/working_modes.h

@@ -1,6 +1,8 @@
 #pragma once
 
 #define MODE_NO_CHANGE	0xff
+#define MODE_DEFAULT	0
+#define MODE_MAIN_MENU	1
 
 
 void key_process(void);