From 8d52ca0cbb75b379d69afaeaa46cc327c1d93313 Mon Sep 17 00:00:00 2001 From: Sam Kumar Date: Tue, 19 May 2015 15:30:36 -0700 Subject: [PATCH] Commit accelerometer demo --- demo/accelerometerDemo.lua | 75 ++++++++++++++++++++++++++++++++ demo/build_accelerometerDemo.lua | 41 +++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 demo/accelerometerDemo.lua create mode 100755 demo/build_accelerometerDemo.lua diff --git a/demo/accelerometerDemo.lua b/demo/accelerometerDemo.lua new file mode 100644 index 0000000..c279d89 --- /dev/null +++ b/demo/accelerometerDemo.lua @@ -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() diff --git a/demo/build_accelerometerDemo.lua b/demo/build_accelerometerDemo.lua new file mode 100755 index 0000000..91e17f6 --- /dev/null +++ b/demo/build_accelerometerDemo.lua @@ -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()