Explorar el Código

Display update, code cleanup

k4be hace 1 año
padre
commit
a55c204975
Se han modificado 8 ficheros con 84 adiciones y 98 borrados
  1. 16 0
      soft/display.c
  2. 4 0
      soft/display.h
  3. 4 3
      soft/main.c
  4. 0 1
      soft/main.h
  5. 9 8
      soft/menu.c
  6. 1 1
      soft/menu.h
  7. 44 70
      soft/working_modes.c
  8. 6 15
      soft/working_modes.h

+ 16 - 0
soft/display.c

@@ -114,6 +114,10 @@ __flash const char _file_close_error[] =	"Blad zamk.pliku!";
 __flash const char _file_open_error[] =	"Blad otw. pliku!";
 __flash const char _files_closed[] =	"Pliki zamkniete";
 __flash const char _files_open[] =		"Pliki otwarte";
+__flash const char _tracking_paused[] =	"Wstrzymano!";
+__flash const char _tracking_resumed[] =	"Wznowiono!";
+__flash const char _point_saved[] =		"Zapisano!";
+__flash const char _point_not_saved[] =	"Nie zapisano!";
 
 void display_event(unsigned char event) { /* overrides display with current messages */
 	switch (event) {
@@ -148,6 +152,18 @@ void display_event(unsigned char event) { /* overrides display with current mess
 		case DISPLAY_EVENT_FILE_OPEN:
 			strcpy_P(disp.line2, _files_open);
 			break;
+		case DISPLAY_EVENT_TRACKING_PAUSED:
+			strcpy_P(disp.line2, _tracking_paused);
+			break;
+		case DISPLAY_EVENT_TRACKING_RESUMED:
+			strcpy_P(disp.line2, _tracking_resumed);
+			break;
+		case DISPLAY_EVENT_POINT_SAVED:
+			strcpy_P(disp.line2, _point_saved);
+			break;
+		case DISPLAY_EVENT_POINT_NOT_SAVED:
+			strcpy_P(disp.line2, _point_not_saved);
+			break;
 	}
 	display_refresh(1);
 }

+ 4 - 0
soft/display.h

@@ -7,6 +7,10 @@
 #define DISPLAY_EVENT_CARD_INITIALIZED	4
 #define DISPLAY_EVENT_FILE_OPEN		5
 #define DISPLAY_EVENT_FILE_CLOSED	6
+#define DISPLAY_EVENT_TRACKING_PAUSED	7
+#define DISPLAY_EVENT_TRACKING_RESUMED	8
+#define DISPLAY_EVENT_POINT_SAVED	9
+#define	DISPLAY_EVENT_POINT_NOT_SAVED	10
 
 struct disp_s {
 	char line1[16];

+ 4 - 3
soft/main.c

@@ -352,13 +352,14 @@ int main (void)
 		System.gps_initialized = 0;
 		
 		if (!already_logging && !get_flag(CONFFLAG_LOGGING_AFTER_BOOT)) {
-			tracking_pause();
+			tracking_pause(TRACKING_PAUSE_CMD_PAUSE, 0);
 		}
 
 		for (;;) { /* main loop */
 			wdt_reset();
 			gettemp();
-			display_refresh(menu());
+			menu();
+			display_refresh(0);
 			if (no_menu())
 				menu_push(default_menu); /* returned from top-level */
 
@@ -421,7 +422,7 @@ int main (void)
 					close_files(1);
 					System.open_new_file = 0;
 					if (!System.tracking_paused)
-						tracking_pause();
+						tracking_pause(TRACKING_PAUSE_CMD_PAUSE, 0);
 				}
 				if (!System.tracking_paused)
 					already_logging = 1; /* to avoid pausing on any reset caused by some error */

+ 0 - 1
soft/main.h

@@ -127,7 +127,6 @@ struct timers {
 	unsigned int system_log;
 	unsigned int lcd;
 	unsigned int backlight;
-	unsigned int info_display;
 };
 
 struct system_s {

+ 9 - 8
soft/menu.c

@@ -140,17 +140,11 @@ unsigned char menu(void) {
 			break;
 		case MENU_TYPE_FUNCTION:
 			if (k == K_RIGHT) {
-				pos.func();
-				display_changed = 1;
+				display_changed = pos.func();
 			}
 			break;
 	}
 	
-	if (pos.allow_back && k == K_LEFT) {
-		menu_pop();
-		return 0;
-	}
-	
 	if (display_line1_as_string) {
 		if (pos.name) {
 			strcpy_P(disp.line1, pos.name);
@@ -158,9 +152,16 @@ unsigned char menu(void) {
 			strcpy_P(disp.line1, _NULL_STRING);
 		}
 	}
+
+	if (pos.allow_back && k == K_LEFT) {
+		menu_pop();
+		display_changed = 1;
+	}
 	
-	if (display_changed)
+	if (display_changed) {
+		display_refresh(1);
 		set_timer(lcd, 50); /* ensure update on next iteration */
+	}
 	return 1;
 }
 

+ 1 - 1
soft/menu.h

@@ -34,7 +34,7 @@ struct menu_pos {
 	};
 	unsigned char index;			// index when IS_SETTING()
 	void (* changed)(void);			// what to call on changed value when IS_SETTING()
-	void (* func)(void);			// what to call on MENU_DISPLAY_TYPE_NAME_FUNCTION
+	unsigned char (* func)(void);			// what to call on MENU_DISPLAY_TYPE_NAME_FUNCTION; returns true if display refresh is needed
 	unsigned char allow_back;		// left arrow will return to level up
 };
 

+ 44 - 70
soft/working_modes.c

@@ -8,93 +8,67 @@
 #include "gpx.h"
 #include "menu.h"
 
-
-struct menu_params_s mp;
-
-void tracking_pause(void) {
-	System.tracking_paused = !System.tracking_paused;
-	if (System.tracking_paused)
+void tracking_pause(unsigned char cmd, unsigned char display) {
+	switch (cmd) {
+		case TRACKING_PAUSE_CMD_TOGGLE:
+			System.tracking_paused = !System.tracking_paused;
+			break;
+		case TRACKING_PAUSE_CMD_RESUME:
+			System.tracking_paused = 0;
+			break;
+		case TRACKING_PAUSE_CMD_PAUSE:
+			System.tracking_paused = 1;
+			break;
+	}
+	if (System.tracking_paused) {
 		LEDB_ON();
-	else
+		if (display)
+			display_event(DISPLAY_EVENT_TRACKING_PAUSED);
+	} else {
 		LEDB_OFF();
+		if (display)
+			display_event(DISPLAY_EVENT_TRACKING_RESUMED);
+	}
 }
 
-__flash const char *pause_tracking_get_name(void) {
-	static unsigned char state = STATE_PAUSE_TRACKING_NOTPAUSED;
-	switch (state) {
-		default:
-		case STATE_PAUSE_TRACKING_NOTPAUSED:
-			if (System.tracking_paused) {
-				set_timer(info_display, 2000);
-				state = STATE_PAUSE_TRACKING_JUSTPAUSED;
-			}
-			return PSTR("> Wstrzymaj rej.");
-		case STATE_PAUSE_TRACKING_JUSTPAUSED:
-			if (timer_expired(info_display))
-				state = STATE_PAUSE_TRACKING_PAUSED;
-			if (!System.tracking_paused) {
-				set_timer(info_display, 2000);
-				state = STATE_PAUSE_TRACKING_JUSTUNPAUSED;
-			}
-			return PSTR("Wstrzymano!");
-		case STATE_PAUSE_TRACKING_PAUSED:
-			if (!System.tracking_paused) {
-				set_timer(info_display, 2000);
-				state = STATE_PAUSE_TRACKING_JUSTUNPAUSED;
-			}
-			return PSTR("> Wznow rejestr.");
-		case STATE_PAUSE_TRACKING_JUSTUNPAUSED:
-			if (System.tracking_paused) {
-				set_timer(info_display, 2000);
-				state = STATE_PAUSE_TRACKING_JUSTPAUSED;
-			}
-			if (timer_expired(info_display))
-				state = STATE_PAUSE_TRACKING_NOTPAUSED;
-			return PSTR("Wznowiono!");
-	}
+unsigned char tracking_pause_cmd(void) {
+	tracking_pause(TRACKING_PAUSE_CMD_TOGGLE, 1);
+	return 0;
 }
 
-__flash const char *save_point_get_name(void) {
-	switch (mp.point_save_state) {
-		default:
-			return PSTR("> Zapisz punkt");
-		case STATE_POINT_SAVE_NOT_DONE:
-			if (timer_expired(info_display))
-				mp.point_save_state = STATE_POINT_SAVE_READY;
-			return PSTR("Nie zapisano!");
-		case STATE_POINT_SAVE_DONE:
-			if (timer_expired(info_display))
-				mp.point_save_state = STATE_POINT_SAVE_READY;
-			return PSTR("Zapisano!");
-	}
+__flash const char *pause_tracking_get_name(void) {
+	if (System.tracking_paused)
+		return PSTR("> Wznow rejestr.");
+	else
+		return PSTR("> Wstrzymaj rej.");
 }
 
-void save_point(void) {
-	if (timer_expired(info_display)) { /* don't save too often */
-		if (System.location_valid) {
-			gpx_save_single_point(&location);
-			mp.point_save_state = STATE_POINT_SAVE_DONE;
-		} else {
-			mp.point_save_state = STATE_POINT_SAVE_NOT_DONE;
-		}
+unsigned char save_point(void) {
+	if (System.location_valid) {
+		gpx_save_single_point(&location);
+		display_event(DISPLAY_EVENT_POINT_SAVED);
+	} else {
+		display_event(DISPLAY_EVENT_POINT_NOT_SAVED);
 	}
-	set_timer(info_display, 2000);
+	return 0;
 }
 
-void new_file(void) {
+unsigned char new_file(void) {
 	System.open_new_file = 1;
+	return 0;
 }
 
 __flash const char _menu_header[] = "  *** MENU *** ";
 __flash const char _settings[] = "> Ustawienia";
 __flash const char _new_file[] = "> Nowy plik";
+__flash const char _save_point[] = "> Zapisz punkt";
 
 __flash const struct menu_pos main_menu_list[] = {
 	{
 		.type = MENU_TYPE_FUNCTION,
-		.display_type = MENU_DISPLAY_TYPE_NAME_CSFUNCTION,
+		.display_type = MENU_DISPLAY_TYPE_STRING,
 		.name = _menu_header,
-		.csdisplay = save_point_get_name,
+		.value = _save_point,
 		.func = save_point,
 		.allow_back = 1,
 	},
@@ -111,7 +85,7 @@ __flash const struct menu_pos main_menu_list[] = {
 		.display_type = MENU_DISPLAY_TYPE_NAME_CSFUNCTION,
 		.name = _menu_header,
 		.csdisplay = pause_tracking_get_name,
-		.func = tracking_pause,
+		.func = tracking_pause_cmd,
 		.allow_back = 1,
 	},
 	{
@@ -180,13 +154,13 @@ __flash const struct menu_struct default_menu = {
 };
 
 
-void enter_settings(void) {
-	xprintf(PSTR("ENTER SETTINGS MENU, %d\r\n"), (int)__menu_num);
+unsigned char enter_settings(void) {
 	menu_push(settings_menu);
+	return 1;
 }
 
-void enter_main_menu(void) {
-	xprintf(PSTR("ENTER MAIN MENU, %d\r\n"), (int)__menu_num);
+unsigned char enter_main_menu(void) {
 	menu_push(main_menu);
+	return 1;
 }
 

+ 6 - 15
soft/working_modes.h

@@ -1,9 +1,8 @@
 #pragma once
 
-#define STATE_PAUSE_TRACKING_NOTPAUSED	0
-#define STATE_PAUSE_TRACKING_JUSTPAUSED	1
-#define STATE_PAUSE_TRACKING_PAUSED		2
-#define STATE_PAUSE_TRACKING_JUSTUNPAUSED	3
+#define TRACKING_PAUSE_CMD_PAUSE	0
+#define TRACKING_PAUSE_CMD_RESUME	1
+#define TRACKING_PAUSE_CMD_TOGGLE	2
 
 #define STATE_POINT_SAVE_READY	0
 #define STATE_POINT_SAVE_NOT_DONE	1
@@ -11,16 +10,8 @@
 
 extern __flash const struct menu_struct default_menu;
 
-struct menu_params_s {
-	unsigned char point_save_state;
-};
-
-extern struct menu_params_s mp;
-
-
 void key_process(void);
-void enter_settings(void);
-void enter_main_menu(void);
-
-void tracking_pause(void);
+unsigned char enter_settings(void);
+unsigned char enter_main_menu(void);
+void tracking_pause(unsigned char cmd, unsigned char display);