brownplt / shim

Temporary storage for Particle core shim and tutorial doc
1 stars 0 forks source link

Delay and erratic behavior of built-in-led with FSR #3

Open k4rtik opened 8 years ago

k4rtik commented 8 years ago

With the following program, there is considerable delay observed in toggling of the LED (D7) with current version of Shim.

Also, if I try toggling it enough times the state of the LED can freeze. It could get stuck at ON state or OFF. The event log appears fine confirming correct send/receive of led events.

Possible cause: the sync mismatch between the state of the LED and the events we are sending to it because the LED didn't toggle fast enough to keep up with the toggling of the FSR.

Current fix is to press RST, rerun and restart the program (unacceptable).

import particle as P
import json as J
import world as W

import string-dict as SD
opts = [SD.string-dict: "acc", "404738f94e7cb4d723edc11094b761cc3845f34c",
  "core", "PLT-Core"]

P.configure-core([list:
    P.pc-write(P.D7, "built-in-led"),
    #P.pc-digital-read(P.D0, "fsr")
    P.pc-analog-read(P.A3, "fsr", P.ait-crosses(500))
  ], opts)

fun to-led(w):
  print(w)
  some(J.tojson(if w: 1 else: 0 end))
end

fun pressure(w,v):
  #print(v)
  if v.n > 500:
    true
  else:
    false
  end
end

fun start():
  W.big-bang(
    false,
    [list:
      P.on-particle(pressure, "fsr", opts),
      P.to-particle(to-led, "built-in-led", opts)
    ])
end
k4rtik commented 8 years ago

It gets reproduced especially at data:"500" event for the FSR