Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions app/bearCastExample/keyValueDevice.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "storm"
require "cord"
require "bearcast"
ACC = require "accel"

acc = ACC:new()

ACCEL_GVALUE = 1

acc_calibrate = function()
local ax, ay, az, mx, my, mz = acc:get()
ACCEL_GVALUE = az
end

acc_get_mg = function()
local ax, ay, az, mx, my, mz = acc:get()
return ax*1000 / ACCEL_GVALUE, ay*1000 / ACCEL_GVALUE, az*1000 / ACCEL_GVALUE
end

cord.new(function()
acc:init()
acc_calibrate()
SVCD.init("bearcast", function() end)
BEARCAST.init("Jack's Accelerometer", true)
print("done init")
while true do
ax, ay, az = acc_get_mg()
print(string.format("ax: %d, ay: %d, az: %d", ax, ay, az))
mag = math.sqrt(ax*ax+ay*ay+az*az)
datatype = {'string', 'string', 'number' }
data = {"Acceleration", "Magnitude(mg)", tostring(mag)}
template = "oneKeyValueTemplate.html"
BEARCAST.sendDeviceData(datatype, data, template)
cord.await(storm.os.invokeLater, 1000*storm.os.MILLISECOND)
end
end)


cord.enter_loop()
34 changes: 34 additions & 0 deletions app/bearCastExample/pushBeeper.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require("storm") -- libraries for interfacing with the board and kernel
require("cord") -- scheduler / fiber library
require("bearcast")
shield = require("starter") -- interfaces for resources on starter shield

print ("BearCast Button Event test ")

cord.new(function()
SVCD.init("bearcast", function() end)
BEARCAST.init("Jack's Push Beeper", true)
shield.Button.start() -- enable LEDs
shield.LED.start()
end)

leds = {"blue","green","red"}

function buttonAction(button,mode)
return function()
print("button", button, mode)
cord.new(function()
BEARCAST.postToClosestDisplay('beep' .. button .. " " .. mode)
end)
end
end

shield.Button.whenever(1, "FALLING", buttonAction(1,"down"))
shield.Button.whenever(2, "RISING", buttonAction(2,"up"))
shield.Button.whenever(3, "CHANGE", buttonAction(3,"change"))

cord.enter_loop() -- start event/sleep loop




2 changes: 1 addition & 1 deletion lib/bearCast/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ msg: the msg to be posted to the message section of the bearCast display
Send device data to the device specific section on the bearCast display
```
Data Type: A list of the types of each data point, must match the template requirement in string format
-- e.g. datatype : {"str", "image", "html"}
-- e.g. datatype : {"string", "image", "html"}
Data: A list of actual data being sent, must match the data type in string format
-- e.g. data: {"hello", "http://shell.storm.pm/test.jpg", "http://shell.storm.pm/hi.html"}
Template: The template used to render the data, could be an URL or a preset KEY
Expand Down