Power Status (was Re: Because LC can't do two things at once.)

Mark Wieder mwieder at ahsoftware.net
Sat Mar 7 01:27:26 EST 2015


Michael-

Friday, March 6, 2015, 1:33:14 PM, you wrote:

> Let hope this is the final.... kind makes me want to go get a linux 
> laptop.  ;-)

>           return
> caseSwitch(tStatus,"discharging=Battery","charging,unknown,full=AC","*=*")


Getting very close.
If you're going to prefix the functions with "__" then you need to do
it everywhere.

  return __caseSwitch(tStatus, ... etc

...and unfortunately BAT0 isn't a folder or a file... it's a symbolic
link, and LiveCode doesn't recognize it as an OS thing. Checking for
either a folder or a file will fail. What works for me is

      default
         -- Unix, thanks to Richard Gaskin, use-LC list
         constant kBatteryStatus0 = "/sys/class/power_supply/BAT0/status"
         constant kBatteryStatus1 = "/sys/class/power_supply/BAT0/status"
         if there is a file (kBatteryStatus0) then
            open file (kBatteryStatus0) for read
            read from file (kBatteryStatus0) until eof
            put it into tStatus
            close file  (kBatteryStatus0)
         else if there is a file (kBatteryStatus1) then
            open file (kBatteryStatus1) for read
            read from file (kBatteryStatus1) until eof
            put it into tStatus
            close file  (kBatteryStatus1)
         else
            return "AC"
            -- no battery, must be running off external power
         end if
         put word 1 of tStatus into tStatus
         if tStatus = empty then return empty
         return
__caseSwitch(tStatus,"discharging=Battery","charging,unknown,full=AC","*=*")
         -- if tStatus = empty, returns empty --
         --    Unix users please test: should this return some value??
         -- if tStatus is not in "discharging,charging,unknown,full" then
         --    just returns whatever "/sys/class/power_supply/BATx" reports
   end switch

-- 
-Mark Wieder
 ahsoftware at gmail.com

This communication may be unlawfully collected and stored by the National 
Security Agency (NSA) in secret. The parties to this email do not 
consent to the retrieving or storing of this communication and any 
related metadata, as well as printing, copying, re-transmitting, 
disseminating, or otherwise using it. If you believe you have received 
this communication in error, please delete it immediately.





More information about the use-livecode mailing list