Skip to content
This repository has been archived by the owner on Jul 1, 2018. It is now read-only.

Commit

Permalink
Implement PiEMOS protocol in runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
zentner-kyle committed Nov 24, 2014
1 parent b9d46f8 commit 94896c7
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
78 changes: 78 additions & 0 deletions vm/lua/tenshi-runtime/src/lua/piemos.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
-- Licensed to Pioneers in Engineering under one
-- or more contributor license agreements. See the NOTICE file
-- distributed with this work for additional information
-- regarding copyright ownership. Pioneers in Engineering licenses
-- this file to you under the Apache License, Version 2.0 (the
-- "License"); you may not use this file except in compliance
-- with the License. You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing,
-- software distributed under the License is distributed on an
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-- KIND, either express or implied. See the License for the
-- specific language governing permissions and limitations
-- under the License

local piemos = {}

local channels = {
digital = {},
analog = {}
}

-- Initialize all the channels.
for i = 1, 7 do
channels.analog[i] = { value = 0.0 }
end

for i = 1, 8 do
channels.digital[i] = { value = false }
end


function piemos.get_axis(idx)
return channels.analog[idx].value
end

function piemos.get_button(idx)
return channels.digital[idx].value
end

function piemos.get_channel(name)
-- Name should be of the form PiEMOSAnalogVals-1 throught
-- PiEMOSAnalogVals-7 or PiEMOSDigitalVals-1 through PiEMOSDigitalVals-8.
local dashidx = name:find("-")
local array = name:sub(1, dashidx - 1)
local idx = tonumber(name:sub(dashidx + 1))

if array == 'PiEMOSAnalogVals' then
return channels.analog[idx]
elseif array == 'PiEMOSDigitalVals' then
return channels.digital[idx]
end
end

function piemos.__process_radio()

for i = 1, 7 do
local s = channels.analog[i]
s.value = __runtimeinternal.get_piemos_analog_val(i)
-- If there is a __downstream mailbox, send data to it
if s.__downstream then
s.__downstream:send({val})
end
end

for i = 1, 8 do
local s = channels.digital[i]
s.value = __runtimeinternal.get_piemos_digital_val(i)
-- If there is a __downstream mailbox, send data to it
if s.__downstream then
s.__downstream:send({val})
end
end
end

return piemos
1 change: 1 addition & 0 deletions vm/lua/tenshi-runtime/src/lua/sensor_actor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ for s,_ in pairs(changed_sensors) do
changed_sensors[s] = nil
end

piemos.__process_radio()
pieles.__process_radio()
8 changes: 8 additions & 0 deletions vm/lua/tenshi-runtime/src/runtime_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "../game.lc.h" // NOLINT(build/include)
#include "../get_device.lc.h" // NOLINT(build/include)
#include "../pieles.lc.h" // NOLINT(build/include)
#include "../piemos.lc.h" // NOLINT(build/include)
#include "../sensor_actor.lc.h" // NOLINT(build/include)
#include "../trap_global.lc.h" // NOLINT(build/include)
#include "../triggers.lc.h" // NOLINT(build/include)
Expand Down Expand Up @@ -133,6 +134,12 @@ static int tenshi_open_pieles(lua_State *L) {
return 1;
}

static int tenshi_open_piemos(lua_State *L) {
luaL_loadbuffer(L, piemos_lc, sizeof(piemos_lc), "piemos.lua");
lua_pcall(L, 0, LUA_MULTRET, 0);
return 1;
}

static int tenshi_open_game(lua_State *L) {
luaL_loadbuffer(L, game_lc, sizeof(game_lc), "game.lua");
lua_pcall(L, 0, LUA_MULTRET, 0);
Expand Down Expand Up @@ -191,6 +198,7 @@ static const luaL_Reg tenshi_loadedlibs_phase2[] = {
{"__actuators", tenshi_open_actuators},
{"triggers", tenshi_open_triggers},
{"pieles", tenshi_open_pieles},
{"piemos", tenshi_open_piemos},
{"game", tenshi_open_game},
{"ubjson", tenshi_open_ubjson},
{NULL, NULL}
Expand Down

0 comments on commit 94896c7

Please sign in to comment.