[OpenBIOS] r523 - dev/olpc/kb3700

svn at openbios.org svn at openbios.org
Fri Aug 3 02:59:36 CEST 2007


Author: wmb
Date: 2007-08-03 02:59:36 +0200 (Fri, 03 Aug 2007)
New Revision: 523

Modified:
   dev/olpc/kb3700/battery.fth
   dev/olpc/kb3700/ecio.fth
Log:
OLPC watch-battery - improved watch-battery by adding extra info like
the battery manufacturer and type, and improving the formatting.


Modified: dev/olpc/kb3700/battery.fth
===================================================================
--- dev/olpc/kb3700/battery.fth	2007-08-03 00:57:32 UTC (rev 522)
+++ dev/olpc/kb3700/battery.fth	2007-08-03 00:59:36 UTC (rev 523)
@@ -13,7 +13,6 @@
 : eram-w@  h# f400 + dup 1+ ec@ swap ec@ bwjoin ;
 \ Base unit for temperature is 1/256 degrees C
 : >degrees-c 7 rshift 1+ 2/  ;  \ Round to nearest degree 
-: .%  ( n -- )  .d ." %" ;
 \ : uvolt@ 0 bat-w@ d# 9760 d# 32 */ ;
 \ : cur@ 2 bat-w@ wextend  d# 15625 d# 120 */ ;
 \ : pcb-temp 8 bat-w@ >degrees-c  ;
@@ -57,18 +56,18 @@
   ," abnormal: "
 end-string-array
 
-: .bat-status
-   bat-status@
-   ." AC "  dup h# 10 and  if  ." on  "  else  ." off  "  then
+: .bat-type  ( -- )
+   bat-type@  dup 4 rshift  case   ( type )
+      1  of  ." GPB "  endof
+      2  of  ." BYD "  endof
+      ." UnknownVendor "
+   endcase                         ( type )
 
-   dup 1 and  if
-      dup 2 and  if  ." Battery full  "  then
-      dup 4 and  if  ." Battery low   "  then
-      dup 8 and  if  ." Battery destroyed  "  then
-   else
-      ." No battery"
-   then
-   drop
+   h# 0f and  case                 ( )
+      1  of  ." NiMH  "     endof
+      2  of  ." LiFePO4  "  endof
+      ." UnknownType  "
+   endcase
 ;
 
 : .milli  ( -- )
@@ -76,18 +75,33 @@
    dup abs  d# 10,000 /  <# u# u# [char] . hold u#s swap sign u#> type
    pop-base
 ;
+: 2.d  ( n -- )  push-decimal <# u# u#s u#>  type  pop-base  ;
+: .%  ( n -- )  2.d ." %" ;
 : .bat  ( -- )
-   ." Battery: "
-   soc .%   ."   "
-   uvolt@  .milli  ."  V  "
-   cur@  .milli  ."  A  "
-   bat-temp .d ." C    "
-   .bat-status
-   ."   (PCB "  pcb-temp .d ." C)"
+   bat-status@  ( stat )
+   ." AC: "  dup h# 10 and  if  ." on   "  else  ." off  "  then  ( stat )
+   ." PCB: "  pcb-temp 2.d ." C  "
+
+   dup 1 and  if
+      ." Battery: "
+      .bat-type
+      soc .%   ."   "
+      uvolt@  .milli  ." V  "
+      cur@  .milli  ." A  "
+      bat-temp 2.d ." C  "
+      dup 2 and  if  ." full "  then
+      dup 4 and  if  ." low "  then
+      dup 8 and  if  ." error "  then
+      dup h# 20 and  if  ." charging "  then
+      dup h# 40 and  if  ." discharging "  then
+   else
+      ." No battery"
+   then
+   drop
 ;
 : watch-battery  ( -- )
    cursor-off
-   begin  (cr .bat d# 100 ms  key?  until
+   begin  (cr .bat kill-line  d# 1000 ms  key?  until
    key drop
    cursor-on
 ;

Modified: dev/olpc/kb3700/ecio.fth
===================================================================
--- dev/olpc/kb3700/ecio.fth	2007-08-03 00:57:32 UTC (rev 522)
+++ dev/olpc/kb3700/ecio.fth	2007-08-03 00:59:36 UTC (rev 523)
@@ -63,6 +63,7 @@
 : bat-soc@       ( -- b )  h# 16 ec-cmd-b@  ;
 : bat-gauge-id@  ( -- sn0 .. sn7 )  h# 17 ec-cmd-out  8 0  do ec-rb  loop  ;
 : bat-gauge@     ( -- b )  h# 18 ec-cmd-out  h# 31 ec-wb  ec-rb  ;  \ 31 is the EEPROM address
+: bat-type@      ( -- b )  h# 18 ec-cmd-out  h# 5f ec-wb  ec-rb  ;  \ 5f is the EEPROM address
 : board-id@      ( -- b )  h# 19 ec-cmd-b@  ;
 : sci-source@    ( -- b )  h# 1a ec-cmd-b@  ;
 : sci-mask!      ( b -- )  h# 1b ec-cmd-b!  ;




More information about the OpenBIOS mailing list