OSDN Git Service

[UI][MENU] Improve power-save on Volume/CALL-USER-CH menu.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sat, 31 Aug 2013 10:14:03 +0000 (19:14 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sat, 31 Aug 2013 10:14:03 +0000 (19:14 +0900)
backlight.c
backlight.h
main.c
menu.c
menu_memoryfreq.c
ui_updown.c

index 80c5133..496e67f 100644 (file)
 
 #include "backlight.h"
 #include "idle.h"
+#include "menu.h"
+#include "power.h"
+
+int backlight_counter;
+
 
 void lcd_setbacklight(unsigned char flag, unsigned char level)
 {
@@ -90,3 +95,43 @@ void lcd_setbacklight(unsigned char flag, unsigned char level)
 #endif
 }
 
+void backlight_reset(unsigned char ctlword)
+{
+    if(ctlword == charcode_e){
+        if(backlight_counter != 0){
+           backlight_counter = 0;
+        } else {
+           backlight_counter = setup.backlight_long;
+        }
+        return;
+    }
+   if((ctlword >= charcode_1) && (ctlword <= charcode_f)) {
+            backlight_counter = setup.backlight_long;
+            lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
+    }
+}
+
+
+unsigned char backlight_dec(unsigned char dispf)
+{
+    unsigned char pbutton;
+    unsigned char stat = dispf;
+
+    pbutton = chk_powerbutton(); // 48ms
+    if(pbutton != 0) shutdown(1); // Button pressed.
+
+       if(backlight_counter > 0) {
+          if(dispf == 0) {
+              acm1602_resume(LCD_I2CADDR);
+               stat = 0xff;
+           }
+
+           backlight_counter--;
+           lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
+       } else {
+           lcd_setbacklight(0x00, 0); // Turn OFF
+           acm1602_suspend(LCD_I2CADDR);
+           stat = 0;
+        }
+    return stat;
+}
\ No newline at end of file
index 9a81780..fddb039 100644 (file)
 extern "C" {
 #endif
 
+extern int backlight_counter;
+
 extern void lcd_setbacklight(unsigned char flag, unsigned char level);
+extern unsigned char backlight_dec(unsigned char dispf);
+extern void backlight_reset(unsigned char ctlword);
 
 #ifdef __cplusplus
 }
diff --git a/main.c b/main.c
index 92f12aa..047bb1d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -94,7 +94,6 @@ unsigned int batlevel_6955;
 unsigned int battlevel;
 
 int recv_signal;
-int backlight_counter;
 unsigned char pollkeybuf[33];
 
 //#define _LCD_DEBUG 1
@@ -290,15 +289,8 @@ int main(void)
     intadc_init();
     set_powerlamp(1);
     valinit();
-#if 1
     acm1602_init(0xa0, 1); //Init LCD
-//    idle_time_ms(125);
-//    _LOCATE(0,0);  // It's BAD-KNOWHOW, but needs AKIZUKI'S LCD :(
- //   _PUTCHAR(' '); //
- //   _LOCATE(0,1);
-//    printstr("Hello;-)");
     lcd_setbacklight(0xff, 255);
-//    idle_time_ms(1000);
     /* Check EEPROM */
     check_eeprom();
   /* Push default parameters to AKC6955*/
@@ -309,7 +301,6 @@ int main(void)
     update_status();
     update_display();
     ClrWdt();
-    lcd_setbacklight(0xff, 255);
     do {
             if(battlevel <= 340) { // 3.4V
                 lvcount++;
@@ -324,10 +315,8 @@ int main(void)
                 lvcount = 0;
             }
         /* Main routine*/
-//           c = pollkeys(pollkeybuf, 19, 1); // 23*19=437ms
             c = pollkey_single_timeout(41, 1); // 23*41 = 943ms
            p = 0;
-//            while(c > 0) {
             if(c != charcode_null) {
                 ClrWdt();
                 if(dispf == 0) {
@@ -335,68 +324,13 @@ int main(void)
                     dispf = 0xff;
                 }
                 setfreq_updown(c);
-
-//                setfreq_updown(pollkeybuf[p]);
-              //  c--;
-              //  p++;
             }
-//            _LOCATE(0,0);
-            pbutton = chk_powerbutton(); // 48ms
-            if(pbutton != 0) shutdown(1); // Button pressed.
             ClrWdt();
             update_status();
-            if(backlight_counter > 0) {
-                if(dispf == 0) {
-                    acm1602_resume(LCD_I2CADDR);
-                    dispf = 0xff;
-                }
-                backlight_counter--;
-                lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
-                update_display();
-            } else {
-                lcd_setbacklight(0x00, 0); // Turn OFF
-                acm1602_suspend(LCD_I2CADDR);
-                dispf = 0;
-        }
+            dispf = backlight_dec(dispf); // 48ms
+            if(dispf != 0)  update_display();
             idle_time_ms(9); // Pad 9ms, 1Loop = 1000ms.
         ClrWdt();
     } while(1);
-#else // EEPROM TEST
-    acm1602_init(0xa0, 1); //Init LCD
-    lcd_setbacklight(0xff, 255);
-    _CLS();
-    {
-        unsigned int addr;
-        unsigned char i;
-        unsigned char pages[32];
-        addr = 0;
-        do {
-            _CLS();
-            print_numeric_nosupress(addr, 5);
-            _PUTCHAR(' ');
-            for(i = 0; i < 2; i++) {
-                c = i2c_eeprom_byteread(0xa0, addr);
-                idle_time_ms(10);
-                print_numeric_nosupress(c, 3);
-                _PUTCHAR(' ');
-                addr++;
-                if(addr > 0x1fff) addr = 0;
-            }
-            _LOCATE(0,1);
-            printstr("  ");
-            for(i = 0; i < 3; i++) {
-                c = i2c_eeprom_byteread(0xa0, addr);
-                idle_time_ms(10);
-                print_numeric_nosupress(c, 3);
-                _PUTCHAR(' ');
-                addr++;
-                if(addr > 0x1fff) addr = 0;
-            }
-            ClrWdt();
-            do {
-            } while(pollkey_single() != charcode_f);
-        } while(1);
-    } 
-#endif
 }
 
diff --git a/menu.c b/menu.c
index c72577b..5778e01 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -30,7 +30,7 @@
 #include "menu_memoryfreq.h"
 #include "power.h"
 #include "commondef.h"
-
+#include "backlight.h"
 
 void toggle_amfm(void)
 {
@@ -83,42 +83,47 @@ void set_volume(void)
 {
     unsigned char c;
     unsigned char d;
-    unsigned char p;
     unsigned char fact;
+    unsigned char dispf = 0xff;
 
     _CLS();
     do {
-    _LOCATE(0,0);
-     d = akc6955_getvolumemode();
-      if(d == 0){
-         _PUTCHAR('D');
-       } else {
-         _PUTCHAR('K');
-       }
-     printstr(" Vol:");
-     print_numeric_nosupress(setup.volume, 2);
-     printstr("  F:Exit");
-     _LOCATE(0,1);
-     printstr("Pre:");
-     _PUTCHAR('0' + (setup.prevolume & 3));
-     _LOCATE(16-4, 1);
-     if(setup.lowboost == 0x00){
-         printstr("   ");
-     } else {
-         printstr("LOW");
-     }
-     _HOME();
-//     c = pollkeys(pollkeybuf, 5, 1);
- //    p = 0;
-     c = pollkey_single_timeout(22, 1); // 506ms
+        if(dispf != 0) {
+            _LOCATE(0,0);
+             d = akc6955_getvolumemode();
+            if(d == 0){
+                 _PUTCHAR('D');
+            } else {
+                 _PUTCHAR('K');
+            }
+            printstr(" Vol:");
+            print_numeric_nosupress(setup.volume, 2);
+            printstr("  F:Exit");
+            _LOCATE(0,1);
+            printstr("Pre:");
+            _PUTCHAR('0' + (setup.prevolume & 3));
+            _LOCATE(16-4, 1);
+            if(setup.lowboost == 0x00){
+                 printstr("   ");
+            } else {
+                 printstr("LOW");
+         }
+            _HOME();
+        }
+     c = pollkey_single_timeout(41, 1); // 943ms
+     backlight_reset(c);
+     dispf = backlight_dec(dispf);
+
      switch(c) {
              case charcode_6:
                  setup.volume++;
                  if(setup.volume > 63) setup.volume = 63;
+                 akc6955_setvolume(setup.volume);
                  break;
              case charcode_4:
                  setup.volume--;
                  if(setup.volume < 23) setup.volume = 23;
+                 akc6955_setvolume(setup.volume);
                  break;
              case charcode_f:
                  _CLS();
@@ -129,11 +134,13 @@ void set_volume(void)
                      fact = 0x00;
                  }
                  akc6955_setvolumemode(fact);
+                 akc6955_setvolume(setup.volume);
                  break;
              case charcode_b:
                  setup.prevolume++;
                  if(setup.prevolume > 3) setup.prevolume = 0;
                  akc6955_set_prevolume(setup.prevolume);
+                 akc6955_setvolume(setup.volume);
                  break;
              case charcode_d:
                  fact = 0x00;
@@ -142,6 +149,7 @@ void set_volume(void)
                  }
                  setup.lowboost = fact;
                  akc6955_set_lowboost(setup.lowboost);
+                 akc6955_setvolume(setup.volume);
                  break;
              default:
                  break;
@@ -151,8 +159,7 @@ void set_volume(void)
         } else {
              set_examp_mute(0);
         }
-        akc6955_setvolume(setup.volume);
-//    _HOME();
+        idle_time_ms(9); // Pad.
     } while(1);
 }
 
@@ -167,10 +174,7 @@ void scan_start(void)
     do {
         do {
              c = pollkey_single_timeout(20, 0) ; // 23*20 = 460ms
-//            n = pollkeys(pollkeybuf, 19, 1);
             update_status();
-//            _HOME();
-//            _LOCATE(0,0);
             cc = ' ';
             if((akc6955_chk_donescan() == 0) && (scanflag != 0)){
                 cc = '>';
index faebacd..50fd912 100644 (file)
@@ -30,7 +30,7 @@
 #include "power.h"
 #include "commondef.h"
 #include "eeprom.h"
-
+#include "backlight.h"
 
 void call_freqbank(unsigned int num)
 {
@@ -135,8 +135,8 @@ void on_updown_userfreq(void)
     unsigned char _fm;
     unsigned char _band;
     unsigned char _userband;
-    unsigned char n;
     unsigned char c;
+    unsigned char dispf = 0xff;
 
     _fm = setup.fm;
     _freq = setup.amfreq;
@@ -150,14 +150,19 @@ void on_updown_userfreq(void)
 
     _CLS();
     do {
-        _LOCATE(0,0);
-        printstr("CH:");
-        print_numeric_nosupress(setup.memorynum, 3);
-        printstr(" 8/2/A");
-        update_status();
-        print_freq(1);
-        _HOME();
-        c = pollkey_single_timeout(44, 1); // About 1s
+       if(dispf != 0)  {
+            _LOCATE(0,0);
+            printstr("CH:");
+            print_numeric_nosupress(setup.memorynum, 3);
+            printstr(" 8/2/A");
+            update_status();
+            print_freq(1);
+            _HOME();
+       }
+       c = pollkey_single_timeout(41, 1); // 23*41 = 943ms
+       backlight_reset(c);
+       dispf = backlight_dec(dispf);
+
        switch(c) {
            case charcode_7: // UP 1CH
                 setup.memorynum++;
@@ -223,10 +228,11 @@ void on_updown_userfreq(void)
            case charcode_a:
                 goto _l0;
                 break;
+           case charcode_e: // Set Light
            default:
                break;
            }
-//       _HOME();
+            idle_time_ms(9); // Pad 9ms, 1Loop = 1000ms.
     } while(1);
 _l0:
     _CLS();
index 1567914..a51cec5 100644 (file)
@@ -122,18 +122,9 @@ static void setband_updown(unsigned char updown)
 void setfreq_updown(unsigned char ctlword)
 {
     unsigned int freq;
-    if((ctlword != charcode_e) && (ctlword >= charcode_1)
-            && (ctlword <= charcode_f)) {
-            backlight_counter = setup.backlight_long;
-            lcd_setbacklight(0xff, setup.backlight_level); // Turn ON
-    } else if(ctlword == charcode_e){
-        if(backlight_counter != 0){
-            backlight_counter = 0;
-        } else {
-            backlight_counter = setup.backlight_long;
-        }
-        return;
-    }
+
+    backlight_reset(ctlword);
+
 
     update_status();
     switch(ctlword){
@@ -236,13 +227,4 @@ void setfreq_updown(unsigned char ctlword)
         default:
             break;
     }
-//    if(fm == 0){
-//        akc6955_get_amband(amband);
-//        amfreq = akc6955_get_freq();
-//        amfreq_bank[amband] = amfreq;
-//    } else {
-//        akc6955_get_fmband(fmband);
-//        fmfreq = akc6955_get_freq();
-//        fmfreq_bank[fmband] = fmfreq;
-//    }
 }