OSDN Git Service

Update ecrobot to nxtOSEK_v212.zip
[nxt-jsp/etrobo-atk.git] / nxtOSEK / ecrobot / c / ecrobot.c
similarity index 92%
rename from nxtOSEK/ecrobot/ecrobot.c
rename to nxtOSEK/ecrobot/c/ecrobot.c
index f0e4029..1405266 100644 (file)
@@ -56,6 +56,12 @@ extern void lejos_osek_run(void);
 #include "cpu_insn.h"
 #endif
 
+/* If there was no operation on the NXT within SLEEP_TIME
+ * after starting the system, turn the NXT into sleep (shut down)
+ * to avoid battery discharge.
+ */
+#define SLEEP_TIME (1000*60*10) /* 10min */
+
 SINT main(void)
 {
        U32 st;
@@ -64,6 +70,7 @@ SINT main(void)
 
        init_OS_flag(); /* this should be called before device init */
        nxt_device_init();
+       ecrobot_init_nxtstate();
        show_splash_screen();
        show_main_screen();
        display_status_bar(1); /* clear status bar */
@@ -111,7 +118,20 @@ SINT main(void)
                        else
                        {
                                flash_req_cnt = 0;
-                               if (ecrobot_get_button_state() == RUN_PRESSED)
+                               if ((ecrobot_get_button_state() == EXIT_PRESSED) || (systick_get_ms() > SLEEP_TIME))
+                               {
+                                       /* shut down the NXT */
+                                       ecrobot_device_terminate();
+                                       display_clear(1);
+                                       systick_wait_ms(10);
+                                       nxt_lcd_power_down(); /* reset LCD hardware */
+                                       systick_wait_ms(10);
+                                       while(1)
+                                       {
+                                               nxt_avr_power_down();
+                                       }
+                               }
+                               else if (ecrobot_get_button_state() == RUN_PRESSED)
                                {
                                        nxt_motor_set_count(NXT_PORT_A, 0);
                                        nxt_motor_set_count(NXT_PORT_B, 0);
@@ -132,19 +152,6 @@ SINT main(void)
 #endif
                                        /* never reached here */
                                }
-                               else if (ecrobot_get_button_state() == EXIT_PRESSED)
-                               {
-                                       /* shut down the NXT */
-                                       ecrobot_device_terminate();
-                                       display_clear(1);
-                                       systick_wait_ms(10);
-                                       nxt_lcd_power_down(); /* reset LCD hardware */
-                                       systick_wait_ms(10);
-                                       while(1)
-                                       {
-                                               nxt_avr_power_down();
-                                       }
-                               }
                        }
                }
     }