diff options
| author | Cameron <cameron@soycow.org> | 2013-07-18 12:40:27 -0700 |
|---|---|---|
| committer | Cameron <cameron@soycow.org> | 2013-07-18 12:40:27 -0700 |
| commit | 3e1c53f699bff801297b08e8e945a077cb2b6d98 (patch) | |
| tree | 8c0d132884ff0830ea54a0a13151dc672fa960e6 /sketches | |
| parent | 94d2ba00f1604aa1ae172039bbcfc72cdf9b8d88 (diff) | |
| parent | 3577d5a8ca5c9e5ac2fd3dbc2fd59797b3ded9ad (diff) | |
Lua script shows minutes til arrival and IO goes to stdout when on a computer
Diffstat (limited to 'sketches')
| -rw-r--r-- | sketches/trackdisplay1/trimet.lua | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/sketches/trackdisplay1/trimet.lua b/sketches/trackdisplay1/trimet.lua index 99920e5..9b659a8 100644 --- a/sketches/trackdisplay1/trimet.lua +++ b/sketches/trackdisplay1/trimet.lua @@ -6,16 +6,27 @@ http = require("socket.http") -mycontent="" checktime=0 estimates={} scheduled={} -io.output('/dev/ttyATH0') +-- I want to do a list comprehension here +current_platform = io.popen("uname -m"):read("*l") +if current_platform == 'i386' then + io_output = io.stdout +elseif current_platform == 'x86_64' then + io_output = io.stdout +else + io_output = '/dev/ttyATH0' +end + +io.output(io_output) -- still trying to figure this out. -- from http://lua-users.org/wiki/FiltersSourcesAndSinks function mysink(chunk,src_err) + local mycontent="" + if chunk == nil then if src_err then -- source reports an error @@ -42,20 +53,32 @@ function mysink(chunk,src_err) i=i+1; end arrival=string.sub(mycontent,i,string.find(mycontent,">",j)) - --print(arrival) status=string.match(arrival,'status="(%a+)') - --print(status) local thetime=0 - local marker="*" + local marker="~" + local minutes_till = '' if string.find(status,'estimated') then - marker="!" + marker="" thetime=string.match(arrival,'estimated="(%d+)') else thetime=string.match(arrival,'scheduled="(%d+)') end - local timerep=os.date("%c", string.sub(thetime,1,10) ) + thetime = string.sub(thetime,1,10) + local timerep=os.date("%c", thetime ) print(status.."("..thetime..")="..timerep ) - io.write(" ".. marker .. os.date("%I:%M", string.sub(thetime,1,10) ) .." ") + + local delta = (os.difftime(thetime, os.time()) / 60) + print("delta: "..delta) + if delta > 60 then + marker = '' + minutes_till = '(z_z)' + elseif delta < 1 then + minutes_till = 'Due' + else + minutes_till = string.format("%.0f min", delta) + end + print("minutes_till: "..minutes_till) + io.write(marker .. minutes_till .." ") end return true end |
