Skip to content

Commit

Permalink
Commit accelerometer demo
Browse files Browse the repository at this point in the history
  • Loading branch information
samkumar committed May 19, 2015
1 parent d75fb1a commit 8d52ca0
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
75 changes: 75 additions & 0 deletions demo/accelerometerDemo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require "cord"
require "svcd"
sh = require "stormsh"

ACC = require "accel"

-- start a coroutine that provides a REPL
sh.start()

MyDeviceName = "Accelerometer Demo"

cord.new(function()
cord.await(SVCD.init, MyDeviceName)
-- The second parameter specifies verbose mode.
-- BEARCAST.init(MyDeviceName, true)

--here you can add extra services or extra logic
--for example, display a mesage after a while:
--[[storm.os.invokeLater(10*storm.os.SECOND, function()
cord.new(function()
BEARCAST.postToClosestDisplay(MyDeviceName.." has started up")
end)
end)]]--

-- or add an echo service that will appear on 15.4 and bluetooth
-- the service numbers are listed in the manifest:
-- https://github.com/UCB-IoET/svc/blob/master/manifest.json
-- Feel free to add new ones by sending pull requests
local echomsg = "unset"
SVCD.add_service(0x300c)
-- Attributes are similarly listed in the manifest
SVCD.add_attribute(0x300c, 0x4018, function(value)
-- this function is executed when the attribute is changed
echomsg = value
-- notify future readers and currently subscribed clients of the
-- new value
SVCD.notify(0x300c, 0x4018, echomsg)
-- also for fun send it to the nearest monitor
--[[cord.new(function()
BEARCAST.postToClosestDisplay("Got echo msg '"..echomsg.."'")
end)]]--
end)

-- DEVICE-SPECIFIC CODE
SVCD.add_service(0x3005)
SVCD.add_attribute(0x3005, 0x4009, function (value, srcip, srcport)
--cord.new(function ()
print("Attempt to change reading to " .. value)
--end)]]
end)

local acc = ACC:new()
acc:init()
local arr = storm.array.create(6, storm.array.INT16)
-- Notify the accelerometer reading every second
cord.new(function ()
while true do
local ax, ay, az, mx, my, mz
ax, ay, az, mx, my, mz = acc:get()
arr:set(1, ax)
arr:set(2, ay)
arr:set(3, az)
arr:set(4, mx)
arr:set(5, my)
arr:set(6, mz)
SVCD.notify(0x3005, 0x4009, arr:as_str())
cord.await(storm.os.invokeLater, storm.os.SECOND)
end
end)
end)


-- enter the main event loop. This puts the processor to sleep
-- in between events
cord.enter_loop()
41 changes: 41 additions & 0 deletions demo/build_accelerometerDemo.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env lua

-- RUN THIS FILE FROM THE ROOT DIRECTORY (containing contrib, toolchain etc)

-- This is the build configuration file.

-- this file will be automatically run on startup. If it terminates, the node
-- will drop to a debug shell. If this file is not specified, the node will
-- enter the shell immediately.
autorun = "ioet_contrib/demo/accelerometerDemo.lua"

-- These are files that will be available as libraries. The name sets how they
-- are 'require()'ed.
libs = { --<< EDIT ME
cord = "ioet_contrib/lib/cord.lua",
stormsh = "ioet_contrib/lib/stormsh.lua",
svcd = "ioet_contrib/lib/svcd/svcd.lua",
bearcast = "ioet_contrib/lib/bearCast/bearcast.lua",
reg = "ioet_contrib/lib/i2creg.lua",
accel = "ioet_contrib/lib/accelerometer.lua"
}


-- If this is true, the toolchains will automatically check for updates when
-- you program
autoupdate = true

-- if true, this will reflash the kernel. This slows down programming, and is
-- not necessary unless you have been told there are kernel updates.
reflash_kernel = true

-- these get passed to the kernel makefile
kernel_opts = {
quiet = true, -- if set to false, you will see kernel debug messages
eth_shield = false -- set to true to enable the ethernet shield
}


----
dofile("toolchains/storm_elua/build_support.lua")
go_build()

0 comments on commit 8d52ca0

Please sign in to comment.