diff options
| author | Cameron Adamez <cameron.adamez@sprighealth.com> | 2013-06-06 15:34:03 -0700 |
|---|---|---|
| committer | Cameron Adamez <cameron.adamez@sprighealth.com> | 2013-06-06 15:34:03 -0700 |
| commit | dd2f87dc0fd5d67a245290931f0a1d0bf173c75a (patch) | |
| tree | 5d85466a6a9ae063391d98e438b886ca4124c7a1 | |
| parent | f5a22694a2cf745d1858ebbd67df18de2820e675 (diff) | |
Display now indicates minutes until arrival of bus/train
| -rw-r--r-- | sketches/trackdisplay1/trimet.lua | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/sketches/trackdisplay1/trimet.lua b/sketches/trackdisplay1/trimet.lua index 7a32f17..ded41c3 100644 --- a/sketches/trackdisplay1/trimet.lua +++ b/sketches/trackdisplay1/trimet.lua @@ -10,7 +10,11 @@ checktime=0 estimates={} scheduled={} -if io.popen("uname -m"):read("*l") == 'i386' then +-- 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' @@ -51,23 +55,23 @@ function mysink(chunk,src_err) arrival=string.sub(mycontent,i,string.find(mycontent,">",j)) --print(arrival) status=string.match(arrival,'status="(%a+)') - print(status) + --print(status) local thetime=0 - local marker="*" + local marker="~" if string.find(status,'estimated') then - marker="!" + marker="" thetime=string.match(arrival,'estimated="(%d+)') else thetime=string.match(arrival,'scheduled="(%d+)') end - --irb(main):011:0> Time.at('1368871373735'[0,10].to_i) - --=> 2013-05-18 03:02:53 -0700 - local timerep=os.date("%c", string.sub(thetime,1,10) ) - print(os.date("%c", os.difftime(os.time(), (string.sub(thetime,1,10))))) - --print(timerep) - print("----------------------") - --print(status.."("..thetime..")="..timerep ) - --io.write(" ".. marker .. os.date("%I:%M", string.sub(thetime,1,10) ) .." ") + thetime = string.sub(thetime,1,10) + local timerep=os.date("%c", thetime ) + local minutes_till = string.format("%i min", (os.difftime(thetime, os.time()) / 60)) + print(status.."("..thetime..")="..timerep ) + if minutes_till == '0min' then + minutes_till = 'Due' + end + io.write(" ".. marker .. minutes_till .." ") end return true end |
