From 61f0f263c335ad403c6693a1b8b6f5428ac180a8 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Wed, 16 Aug 2017 18:25:05 +0200 Subject: Fixed LUA Nested Table Issues. Added LUA2C for User Defined Plugins --- conf.d/project/config.d/onload-audio-control.json | 6 +++++- conf.d/project/lua.d/onload-audio-controls.lua | 25 ++++++++++------------- 2 files changed, 16 insertions(+), 15 deletions(-) (limited to 'conf.d/project') diff --git a/conf.d/project/config.d/onload-audio-control.json b/conf.d/project/config.d/onload-audio-control.json index 1a45f99..7180bd5 100644 --- a/conf.d/project/config.d/onload-audio-control.json +++ b/conf.d/project/config.d/onload-audio-control.json @@ -8,7 +8,11 @@ "onload": [{ "label": "onload-default", "info": "onload initialisation config", - "plugin": "ctl-audio-plugin-sample.ctlso", + "plugin": { + "label" : "MyPlug", + "sharelib": "ctl-audio-plugin-sample.ctlso", + "lua2c": ["Lua2cHelloWorld1", "Lua2cHelloWorld2"] + }, "require": ["intel-hda", "jabra-usb", "scarlett-usb"], "actions": [ { diff --git a/conf.d/project/lua.d/onload-audio-controls.lua b/conf.d/project/lua.d/onload-audio-controls.lua index b6fd811..4849632 100644 --- a/conf.d/project/lua.d/onload-audio-controls.lua +++ b/conf.d/project/lua.d/onload-audio-controls.lua @@ -21,37 +21,34 @@ function Audio_Init_CB (status, result, context) print ("--inlua:Audio_Init_CB-- result=", Dump_Table(result)) print ("--inlua:Audio_Init_CB-- context=", Dump_Table(context)) - - - -- AFB:notice ("Audio_Init_Hal result='%s' context='%s'", result, context) - -- AFB:debug ("Audio_Init_Hal result=%s context=%s", {["ret1"]=5678, ["ret2"]="abcd"}, context) - + + AFB:notice("Audio_Init_Hal_CB result='%s' context='%s'", result, context) + end -- Function call at binding load time function Audio_Init_Hal(args, query) - local nextT = { + local nested = { ["next1"]=1234, ["next2"]="nested", ["next3"]=9999, } - - local response = { + local context = { ["arg1"]=1234, - ["arg2"]=nextT, + ["arg2"]=nested, ["arg3"]=5678, } - print ("--inlua:Audio_Init-- response=", Dump_Table(response)) - - AFB:notice ("**** in-lua table='%s' ****", response) + print ("--inlua:Audio_Init-- response=", Dump_Table(responseT)) + print("myplug=", Dump_Table(MyPlug)); - AFB:notice ("--LUA:Audio_Init_Hal args=%s query=%s", args, query); + -- This routine is defined in C sample plugin + local status=MyPlug:Lua2cHelloWorld1(nested) -- query asynchronously loaded HAL - AFB:service ('alsacore', 'hallist', {}, "Audio_Init_CB", {arg1=1234, arg2="toto"}) + AFB:service ('alsacore', 'hallist', {}, "Audio_Init_CB", context) end -- cgit From a4899ab57f08aeb2741d08f74d7593c85a0ad3f4 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Wed, 16 Aug 2017 19:18:46 +0200 Subject: Fix DoScript Lua Updated Documentation. --- conf.d/project/lua.d/doscript-helloworld.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'conf.d/project') diff --git a/conf.d/project/lua.d/doscript-helloworld.lua b/conf.d/project/lua.d/doscript-helloworld.lua index b70ba8d..64bc94a 100644 --- a/conf.d/project/lua.d/doscript-helloworld.lua +++ b/conf.d/project/lua.d/doscript-helloworld.lua @@ -23,14 +23,14 @@ function helloworld (request, query) - AFB:notice ("LUA HelloWorld: simple test query=%s", query); + AFB:notice ("LUA HelloWorld: Simple test query=%s", query); if (query == nil) then - AFB:error ("LUA HelloWorld:FX query should not be empty"); + AFB:notice ("LUA HelloWorld:FX query should not be empty"); AFB:fail (request, "LUA HelloWorld: query should not be empty"); else - AFB:error ("LUA HelloWorld:OK query=%s", query); - AFB:sucess (request, {arg0="Demat", arg1="Bonjours", arg2="Gootentag", arg3="Morning"}); + AFB:notice ("LUA HelloWorld:OK query=%s", query); + AFB:success (request, {arg0="Demat", arg1="Bonjours", arg2="Gootentag", arg3="Morning"}); end end \ No newline at end of file -- cgit From 5e919fde0a4c66b0203c46b8f06f303fcceaedde Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Thu, 17 Aug 2017 00:56:43 +0200 Subject: Implemented Timer and Event from Lua --- conf.d/project/lua.d/onload-audio-oncall.lua | 31 ------------ conf.d/project/lua.d/onload-audio-timer.lua | 73 ++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 31 deletions(-) create mode 100644 conf.d/project/lua.d/onload-audio-timer.lua (limited to 'conf.d/project') diff --git a/conf.d/project/lua.d/onload-audio-oncall.lua b/conf.d/project/lua.d/onload-audio-oncall.lua index 13cda4b..08b25e5 100644 --- a/conf.d/project/lua.d/onload-audio-oncall.lua +++ b/conf.d/project/lua.d/onload-audio-oncall.lua @@ -68,34 +68,3 @@ function Test_Call_Sync (request, args) end end --- create a new event name -function Test_Event_Make (request, args) - - AFB:notice ("Test_Event_Make args=%s", args) - - local err evt_handle= AFB:event (args["evtname"]) - if (err) then - AFB:fail ("AFB:Test_Event_Make fail event=%s", args["evtname"]); - else - AFB:success (request, {}) - end - - local evtData = { - ["val1"]="My 1st private Event", - ["val2"]=5678 - } - - AFB:notify (evt_handle, evtData) -end - --- send an event on default binder event -function Test_Event_Notify (request, args) - - AFB:notice ("Test_Event_Notify args=%s", args) - local err AFB:notify (args) - if (err) then - AFB:fail ("AFB:Test_Event_Make fail event=%s", args["evtname"]); - else - AFB:success (request, {}) - end -end diff --git a/conf.d/project/lua.d/onload-audio-timer.lua b/conf.d/project/lua.d/onload-audio-timer.lua new file mode 100644 index 0000000..5f25de7 --- /dev/null +++ b/conf.d/project/lua.d/onload-audio-timer.lua @@ -0,0 +1,73 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed 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. + + + Provide Sample Timer Handing to push event from LUA +--]] + +-- Create event on Lua script load +print ("*** Create MyTestEvent ***") +MyEventHandle= AFB:evtmake("MyTestEvent") + +-- Call count time every delay/ms +function Timer_Test_CB (timer, context) + + local evtinfo= AFB:timerget(timer) + print ("timer=", Dump_Table(evtinfo)) + + --send an event an event with count as value + AFB:evtpush (MyEventHandle, {["label"]= evtinfo["label"], ["count"]=evtinfo["count"], ["info"]=context["info"]}) + + -- note when timerCB return!=0 timer is kill + return 0 + +end + +-- sendback event depending on count and delay +function Simple_Timer_Test (request, args) + + local context = { + ["info"]="My 1st private Event", + } + + -- if delay not defined default is 5s + if (args["delay"]==nil) then args["delay"]=5000 end + + -- if count is not defined default is 10 + if (args["count"]==nil) then args["count"]=10 end + + -- we could use directly args but it is a sample + local myTimer = { + ["label"]=args["label"], + ["delay"]=args["delay"], + ["count"]=args["count"], + } + AFB:notice ("Test_Timer myTimer=%s", myTimer) + + -- subscribe to event + AFB:subscribe (request, MyEventHandle) + + -- settimer take a table with delay+count as input (count==0 means infinite) + AFB:timerset (myTimer, "Timer_Test_CB", context) + + -- nothing special to return send back args + AFB:success (request, myTimer) + + return 0 +end + + + -- cgit From a7d41a6fa1e29d800ce8ac9e95e8f943814463e8 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Fri, 18 Aug 2017 01:09:56 +0200 Subject: Integration with Alsa HookPlugin is now working. --- conf.d/project/alsa.d/asoundrc.sample | 146 +++++++++++++++++++ .../project/alsa.d/ucm.sample/HDA Intel PCH.conf | 6 + conf.d/project/alsa.d/ucm.sample/HiFi.conf | 84 +++++++++++ conf.d/project/alsa.d/ucm.sample/README | 2 + conf.d/project/config.d/onload-audio-control.json | 14 +- conf.d/project/lua.d/doscript-helloworld.lua | 2 +- conf.d/project/lua.d/onload-audio-0utils.lua | 86 +++++++++++ conf.d/project/lua.d/onload-audio-controls.lua | 159 ++++++++++++++++----- conf.d/project/lua.d/onload-audio-oncall.lua | 16 +-- conf.d/project/lua.d/onload-audio-timer.lua | 10 +- conf.d/project/lua.d/onload-audio-utils.lua | 32 ----- 11 files changed, 468 insertions(+), 89 deletions(-) create mode 100644 conf.d/project/alsa.d/asoundrc.sample create mode 100644 conf.d/project/alsa.d/ucm.sample/HDA Intel PCH.conf create mode 100644 conf.d/project/alsa.d/ucm.sample/HiFi.conf create mode 100644 conf.d/project/alsa.d/ucm.sample/README create mode 100644 conf.d/project/lua.d/onload-audio-0utils.lua delete mode 100644 conf.d/project/lua.d/onload-audio-utils.lua (limited to 'conf.d/project') diff --git a/conf.d/project/alsa.d/asoundrc.sample b/conf.d/project/alsa.d/asoundrc.sample new file mode 100644 index 0000000..b208a09 --- /dev/null +++ b/conf.d/project/alsa.d/asoundrc.sample @@ -0,0 +1,146 @@ +# +# Author: Fulup Ar Foll +# Object: PCM hook type +# +# Test : Note: Jabra_USB=hw:v1340 +# Check SoundCard speaker-test -Dhw:v1340 -c2 -twav +# Check MixerPCM speaker-test -DMyMixerPCM -c2 -twav +# Check HookPCM speaker-test -DMyNavigationHook -c2 -twav +# Check NavPCM speaker-test -DMyNavPCM -c2 -twav +# MultiMedia aplay -DDMyNavPCM /usr/share/sounds/alsa/test.wav +# +# Bug/Feature: when softvol control is initialised from plugin and not +# from AGL binding. At 1st run ctl has invalid TLV and cannot be +# use. Bypass Solution: +# * start audio-binder before playing sound (binding create control before softvol plugin) +# * run a dummy aplay -DMyNavPCM "" to get a clean control +# +# References: https://www.spinics.net/lists/alsa-devel/msg54235.html +# -------------------------------------------------------------------- + +# Mixer PCM allow to play multiple stream simultaneously +# ------------------------------------------------------ +pcm.MyMixerPCM { + type dmix + ipc_key 1024 + ipc_key_add_uid false + ipc_perm 0666 # mixing for all users + + # Define target effective sound card (cannot be a plugin) + slave { + pcm "hw:v1340" #Jabra Solmate + period_time 0 + period_size 1024 + buffer_size 8192 + rate 44100 + } + + # DMIX can only map two channels + bindings { + 0 0 + 1 1 + } +} + +# Define a Hook_type with a private sharelib +# ------------------------------------------- +pcm_hook_type.MyHookPlugin { + install "AlsaInstallHook" + lib "/home/fulup/Workspace/AGL-AppFW/audio-bindings-dev/build/Alsa-Plugin/Alsa-Policy-Hook/policy_hook_cb.so" +} + + +# Define a HookedPCM that point to Hook_type sharelib +# ---------------------------------------------------- +pcm.MyNavigationHook { + type hooks + slave.pcm "MyMixerPCM" + # Defined used hook sharelib and provide arguments/config to install func + hooks.0 { + type "MyHookPlugin" + hook_args { + verbose true # print few log messages (default false); + + # Every Call should return OK in order PCM to open (default timeout 100ms) + uri "ws://localhost:1234/api?token='audio-agent-token'" + request { + # Request autorisation to write on navigation + RequestNavigation { + api "control" + verb "dispatch" + query "{'target':'navigation', 'args':{'device':'Jabra SOLEMATE v1.34.0'}}" + } + } + # map event reception to self generated signal + event { + pause 30 + resume 31 + stop 3 + } + } + } +} + +# If hardware does not support mixer emulate it with softvol +# ----------------------------------------------------------- +pcm.MyMultimediaPCM { + type softvol + + # Point Slave on HOOK for policies control + slave.pcm "MyNavigationHook" + + # resolution=HAL(valMax+1) (default=256) + resolution 256 + + # name should match with HAL but do not set card=xx + control.name "Playback Navigation" + + # Make this plugin visible from aplay -L + hint { + show on + description "Navigation SolftVol PCM" + } +} + +# If hardware does not support mixer emulate it with softvol +# ----------------------------------------------------------- +pcm.MyNavPCM { + type softvol + + # Point Slave on HOOK for policies control + slave.pcm "MyNavigationHook" + + # resolution=HAL(valMax+1) (default=256) + resolution 256 + + # name should match with HAL but do not set card=xx + control.name "Playback Navigation" + + # Make this plugin visible from aplay -L + hint { + show on + description "Navigation SolftVol PCM" + } +} + +# If hardware does not support mixer emulate it with softvol +# ----------------------------------------------------------- +pcm.MyAlarmPCM { + type softvol + + # Point Slave on HOOK for policies control + slave.pcm "MyNavigationHook" + + # resolution=HAL(valMax+1) (default=256) + resolution 256 + + # name should match with HAL but do not set card=xx + control.name "Playback Navigation" + + # Make this plugin visible from aplay -L + hint { + show on + description "Navigation SolftVol PCM" + } +} + diff --git a/conf.d/project/alsa.d/ucm.sample/HDA Intel PCH.conf b/conf.d/project/alsa.d/ucm.sample/HDA Intel PCH.conf new file mode 100644 index 0000000..f6608a0 --- /dev/null +++ b/conf.d/project/alsa.d/ucm.sample/HDA Intel PCH.conf @@ -0,0 +1,6 @@ +Comment "Leon internal card" + +SectionUseCase."HiFi" { + File "HiFi.conf" + Comment "Default" +} diff --git a/conf.d/project/alsa.d/ucm.sample/HiFi.conf b/conf.d/project/alsa.d/ucm.sample/HiFi.conf new file mode 100644 index 0000000..9a53c8c --- /dev/null +++ b/conf.d/project/alsa.d/ucm.sample/HiFi.conf @@ -0,0 +1,84 @@ +SectionVerb { + EnableSequence [ + cdev "hw:PCH" + + cset "name='Master Playback Switch' on" + cset "name='Headphone Playback Switch' off" + cset "name='Speaker Playback Switch' on" + + cset "name='Capture Switch' on" + cset "name='Capture Volume' 39" + cset "name='Mic Boost Volume' 2" + cset "name='Internal Mic Boost Volume' 0" + #cset "name='Capture Source' 0" + ] + DisableSequence [ + ] + Value { + TQ "Music" + OutputDspName "speaker_eq" + PlaybackPCM "hw:PCH,0" + } +} + +SectionDevice."Headphone".0 { + Value { + JackName "Headphone Jack" + OutputDspName "Jheadphone" + } + EnableSequence [ + cdev "hw:PCH" + + cset "name='Speaker Playback Switch' off" + cset "name='Headphone Playback Switch' on" + ] + DisableSequence [ + cdev "hw:PCH" + + cset "name='Headphone Playback Switch' off" + cset "name='Speaker Playback Switch' on" + ] +} + +SectionDevice."Mic".0 { + Value { + JackName "Mic Jack" + } + EnableSequence [ + cdev "hw:PCH" + + #cset "name='Capture Source' 1" + ] + DisableSequence [ + cdev "hw:PCH" + + cset "name='Capture Source' 0" + ] +} + +SectionModifier."RecordMedia".0 { + SupportedDevice [ + "Headphone" + ] + EnableSequence [ + cdev "hw:PCH" + ] + + DisableSequence [ + cdev "hw:PCH" + ] + + TransitionSequence."ToModifierName" [ + cdev "hw:PCH" + ] + + # Optional TQ and ALSA PCMs + Value { + TQ Voice + CapturePCM "hw:1" + PlaybackVolume "name='Master Playback Volume',index=2" + PlaybackSwitch "name='Master Playback Switch',index=2" + } + +} + diff --git a/conf.d/project/alsa.d/ucm.sample/README b/conf.d/project/alsa.d/ucm.sample/README new file mode 100644 index 0000000..e7f08ae --- /dev/null +++ b/conf.d/project/alsa.d/ucm.sample/README @@ -0,0 +1,2 @@ +Should match sound card name ex: "HDA Intel PCH" +cp -r . /usr/share/alsa/ucm diff --git a/conf.d/project/config.d/onload-audio-control.json b/conf.d/project/config.d/onload-audio-control.json index 7180bd5..77a8fce 100644 --- a/conf.d/project/config.d/onload-audio-control.json +++ b/conf.d/project/config.d/onload-audio-control.json @@ -9,7 +9,7 @@ "label": "onload-default", "info": "onload initialisation config", "plugin": { - "label" : "MyPlug", + "label" : "_MyPlug", "sharelib": "ctl-audio-plugin-sample.ctlso", "lua2c": ["Lua2cHelloWorld1", "Lua2cHelloWorld2"] }, @@ -28,11 +28,11 @@ "info": "Assert AlsaCore Presence", "api": "alsacore", "verb": "ping", - "args": "test" + "args": {"data": "none"} }, { "label": "onload-hal-lua", "info": "Load avaliable HALs", - "lua": "Audio_Init_Hal" + "lua": "_Alsa_Get_Hal" } ] }], @@ -43,20 +43,20 @@ "actions": { "label": "multimedia-control-lua", "info": "Call Lua Script function Test_Lua_Engin", - "lua": "Audio_Set_Multimedia" + "lua": "_Audio_Set_Multimedia" } }, { "label": "navigation", "actions": { "label": "navigation-control-lua", "info": "Call Lua Script to set Navigation", - "lua": "Audio_Set_Navigation" + "lua": "_Audio_Set_Navigation" } }, { "label": "emergency", "actions": { "label": "emergency-control-ucm", - "lua": "Audio_Set_Emergency" + "lua": "_Audio_Set_Emergency" } }, { "label": "multi-step-sample", @@ -79,7 +79,7 @@ }, { "label": "navigation-control-lua", "info": "Call Lua Script to set Navigation", - "lua": "Audio_Set_Navigation" + "lua": "_Audio_Set_Navigation" }] } ], diff --git a/conf.d/project/lua.d/doscript-helloworld.lua b/conf.d/project/lua.d/doscript-helloworld.lua index 64bc94a..a06c3db 100644 --- a/conf.d/project/lua.d/doscript-helloworld.lua +++ b/conf.d/project/lua.d/doscript-helloworld.lua @@ -21,7 +21,7 @@ --]] -function helloworld (request, query) +local function helloworld (request, query) AFB:notice ("LUA HelloWorld: Simple test query=%s", query); diff --git a/conf.d/project/lua.d/onload-audio-0utils.lua b/conf.d/project/lua.d/onload-audio-0utils.lua new file mode 100644 index 0000000..b8ecd7e --- /dev/null +++ b/conf.d/project/lua.d/onload-audio-0utils.lua @@ -0,0 +1,86 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed 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. + + Note: this file should be called before any other to assert declare function + is loaded before anything else. + + References: + http://lua-users.org/wiki/DetectingUndefinedVariables + +--]] + + +--=================================================== +--= Niklas Frykholm +-- basically if user tries to create global variable +-- the system will not let them!! +-- call GLOBAL_lock(_G) +-- +--=================================================== +function GLOBAL_lock(t) + local mt = getmetatable(t) or {} + mt.__newindex = lock_new_index + setmetatable(t, mt) +end + +--=================================================== +-- call GLOBAL_unlock(_G) +-- to change things back to normal. +--=================================================== +function GLOBAL_unlock(t) + local mt = getmetatable(t) or {} + mt.__newindex = unlock_new_index + setmetatable(t, mt) +end + +function lock_new_index(t, k, v) + if (string.sub(k,1,1) ~= "_") then + GLOBAL_unlock(_G) + error("GLOBALS are locked -- " .. k .. + " must be declared local or prefix with '_' for globals.", 2) + else + rawset(t, k, v) + end +end + +function unlock_new_index(t, k, v) + rawset(t, k, v) +end + +-- return serialised version of printable table +function Dump_Table(o) + if type(o) == 'table' then + local s = '{ ' + for k,v in pairs(o) do + if type(k) ~= 'number' then k = '"'..k..'"' end + s = s .. '['..k..'] = ' .. Dump_Table(v) .. ',' + end + return s .. '} ' + else + return tostring(o) + end +end + + +-- simulate C prinf function +printf = function(s,...) + io.write(s:format(...)) + io.write("\n") + return +end + +-- lock global variable +GLOBAL_lock(_G) diff --git a/conf.d/project/lua.d/onload-audio-controls.lua b/conf.d/project/lua.d/onload-audio-controls.lua index 4849632..24c4f71 100644 --- a/conf.d/project/lua.d/onload-audio-controls.lua +++ b/conf.d/project/lua.d/onload-audio-controls.lua @@ -18,54 +18,145 @@ Provide sample policy function for AGL Advance Audio Agent --]] -function Audio_Init_CB (status, result, context) - print ("--inlua:Audio_Init_CB-- result=", Dump_Table(result)) - print ("--inlua:Audio_Init_CB-- context=", Dump_Table(context)) - - AFB:notice("Audio_Init_Hal_CB result='%s' context='%s'", result, context) +-- Global HAL registry +_Audio_Hal_Registry={} + +-- Callback when receiving HAL registry +function _Alsa_Get_Hal_CB (error, result, context) + -- Initialise an empty table + local registry={} + + -- Only process when response is valid + if (error) then + AFB_ErrOr ("[Audio_Init_CB] ErrOr result=%s", result) + return + end + + -- Extract response from result + local response=result["response"] + + -- Index HAL Bindings APIs by shortname + for key,value in pairs(response) do + registry[value["shortname"]]=value["api"] + end + + -- store Exiting HAL for further use + printf ("-- [Audio_Init_CB] -- Audio_register_Hal=%s", Dump_Table(registry)) + _Audio_Hal_Registry=registry end -- Function call at binding load time -function Audio_Init_Hal(args, query) +function _Alsa_Get_Hal(args) - local nested = { - ["next1"]=1234, - ["next2"]="nested", - ["next3"]=9999, - } - local context = { - ["arg1"]=1234, - ["arg2"]=nested, - ["arg3"]=5678, - } + printf ("[-- Audio_Get_Hal --] args=%s", Dump_Table(argsT)) + + -- Query AlsaCore for Active HALs (no query, no context) + AFB:service ('alsacore', 'hallist', {}, "_Alsa_Get_Hal_CB", {}) + +end - print ("--inlua:Audio_Init-- response=", Dump_Table(responseT)) +-- In sample configuration Query/Args parsing is common to all audio control +local function Audio_Parse_Request (source, args, query) - print("myplug=", Dump_Table(MyPlug)); + local apihal={} - -- This routine is defined in C sample plugin - local status=MyPlug:Lua2cHelloWorld1(nested) - - -- query asynchronously loaded HAL - AFB:service ('alsacore', 'hallist', {}, "Audio_Init_CB", context) - + -- In this test we expect targeted device to be given from query (could come for args as well) + if (query == nil ) then + AFB:error ("--LUA:Audio_Set_Navigation query should contain and args with targeted apihal|device") + return -- refuse control + end + + -- Alsa Hook plugin asound sample config provides target sound card by name + if (query["device"] ~= nil) then + apihal=_Audio_Hal_Registry[query["device"]] + end + + -- HTML5 test page provides directly HAL api. + if (query["apihal"] ~= nil) then + apihal= query["apihal"] + end + + -- if requested HAL is not found then deny the control + if (apihal == nil) then + AFB:error ("--LUA:Audio_Set_Navigation No Active HAL Found") + return -- refuse control + end + + -- return api or nil when not found + return apihal end -function Audio_Set_Navigation(args, query) +-- Set Navigation lower sound when play +function _Audio_Set_Navigation(source, args, query) + + -- in strict mode every variables should be declared + local err=0 + local ctlhal={} + local response={} + local apihal={} + + AFB:notice ("LUA:Audio_Set_Use_Case source=%d args=%s query=%s", source, args, query); + + -- Parse Query/Args and if HAL not found then refuse access + apihal= Audio_Parse_Request (source, args, query) + if (apihal == nil) then return 1 end + - AFB:notice ("LUA:Audio_Set_Use_Case args=%s query=%s", args, query); + -- if source < 0 then Alsa HookPlugin is closing PCM + if (source < 0) then + -- Ramp Up Multimedia channel synchronously + ctlhal={['label']='Master_Playback_Volume', ['val']=100} + err, response= AFB:servsync (apihal, 'ctlset',ctlhal) + else + -- Ramp Down Multimedia channel synchronously + ctlhal={['label']='Master_Playback_Volume', ['val']=50} + err, response= AFB:servsync (apihal, 'ctlset',ctlhal) + end - -- synchronous call to alsacore service - local error,data= AFB:callsync ('alsacore', 'ping', {}) - if (error) then - AFB:error ("LUA:Audio_Set_Use_Case FAIL args=%s", args) - else - AFB:notice ("--LUA:Audio_Set_Use_Case DONE args=%s response=%s", args, data["response"]) + if (err) then + AFB:error("--LUA:Audio_Set_Navigation halapi=%s refuse ctl=%s", apihal, ctlhal) + return 1 -- control refused end - -- return OK - return 0 + + return 0 -- control accepted end +-- Select Multimedia mode +function _Audio_Set_Multimedia (source, args, query) + + -- in strict mode every variables should be declared + local err=0 + local ctlhal={} + local response={} + local apihal={} + + AFB:notice ("LUA:Audio_Set_Use_Case source=%d args=%s query=%s", source, args, query); + + -- Parse Query/Args and if HAL not found then refuse access + apihal= Audio_Parse_Request (source, args, query) + if (apihal == nil) then return 1 end + + + -- if Mumtimedia control only increase volume on open + if (source >= 0) then + -- Ramp Down Multimedia channel synchronously + ctlhal={['label']='Master_Playback_Volume', ['val']=100} + err, response= AFB:servsync (apihal, 'ctlset',ctlhal) + end + + if (err) then + AFB:error("--LUA:Audio_Set_Navigation halapi=%s refuse ctl=%s", apihal, ctlhal) + return 1 -- control refused + end + + + return 0 -- control accepted +end + +-- Select Emergency Mode +function _Audio_Set_Emergency(source, args, query) + return 1 -- Always refuse in this test +end diff --git a/conf.d/project/lua.d/onload-audio-oncall.lua b/conf.d/project/lua.d/onload-audio-oncall.lua index 08b25e5..23b538e 100644 --- a/conf.d/project/lua.d/onload-audio-oncall.lua +++ b/conf.d/project/lua.d/onload-audio-oncall.lua @@ -18,18 +18,18 @@ Provide sample LUA routines to be used with AGL control "lua_docall" API --]] --- global counter to keep track of calls -count=0 +--global counter to keep track of calls +_count=0 -- Display receive arguments and echo them to caller -function Simple_Echo_Args (request, args) - count=count+1 +function _Simple_Echo_Args (request, args) + _count=_count+1 AFB:notice("LUA OnCall Echo Args count=%d args=%s", count, args) print ("--inlua-- args=", Dump_Table(args)) local response={ - ["count"]=count, + ["count"]=_count, ["args"]=args, } @@ -37,7 +37,7 @@ function Simple_Echo_Args (request, args) AFB:success (request, {["func"]="Simple_Echo_Args", ["ret1"]=5678, ["ret2"]="abcd"}) end -function Test_Async_CB (request, result, context) +local function Test_Async_CB (request, result, context) response={ ["result"]=result, ["context"]=context, @@ -47,7 +47,7 @@ function Test_Async_CB (request, result, context) AFB:success (request, response) end -function Test_Call_Async (request, args) +function _Test_Call_Async (request, args) local context={ ["value1"]="abcd", ["value2"]=1234 @@ -57,7 +57,7 @@ function Test_Call_Async (request, args) AFB:service("alsacore","ping", "Test_Async_CB", context) end -function Test_Call_Sync (request, args) +function _Test_Call_Sync (request, args) AFB:notice ("Test_Call_Sync args=%s", args) local err, response= AFB:service_sync ("alsacore","ping", args) diff --git a/conf.d/project/lua.d/onload-audio-timer.lua b/conf.d/project/lua.d/onload-audio-timer.lua index 5f25de7..db7a937 100644 --- a/conf.d/project/lua.d/onload-audio-timer.lua +++ b/conf.d/project/lua.d/onload-audio-timer.lua @@ -19,11 +19,10 @@ --]] -- Create event on Lua script load -print ("*** Create MyTestEvent ***") -MyEventHandle= AFB:evtmake("MyTestEvent") +local MyEventHandle=AFB:evtmake("MyTestEvent") -- Call count time every delay/ms -function Timer_Test_CB (timer, context) +local function Timer_Test_CB (timer, context) local evtinfo= AFB:timerget(timer) print ("timer=", Dump_Table(evtinfo)) @@ -37,7 +36,7 @@ function Timer_Test_CB (timer, context) end -- sendback event depending on count and delay -function Simple_Timer_Test (request, args) +function _Simple_Timer_Test (request, args) local context = { ["info"]="My 1st private Event", @@ -68,6 +67,3 @@ function Simple_Timer_Test (request, args) return 0 end - - - diff --git a/conf.d/project/lua.d/onload-audio-utils.lua b/conf.d/project/lua.d/onload-audio-utils.lua deleted file mode 100644 index 40ef8a3..0000000 --- a/conf.d/project/lua.d/onload-audio-utils.lua +++ /dev/null @@ -1,32 +0,0 @@ ---[[ - Copyright (C) 2016 "IoT.bzh" - Author Fulup Ar Foll - - Licensed 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. - ---]] - - --- return serialised version of printable table -function Dump_Table(o) - if type(o) == 'table' then - local s = '{ ' - for k,v in pairs(o) do - if type(k) ~= 'number' then k = '"'..k..'"' end - s = s .. '['..k..'] = ' .. Dump_Table(v) .. ',' - end - return s .. '} ' - else - return tostring(o) - end -end -- cgit From 082d083a96f4be23ea6f54fc26eeaece7cfa4507 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Fri, 18 Aug 2017 01:43:18 +0200 Subject: Documented Controller standalone mode and provided a sample config. --- .../project/config.d/onload-daemon-standalone.json | 72 ++++++++++++++++++ .../lua.d/standalone-sample/onload-daemon-00.lua | 86 ++++++++++++++++++++++ .../lua.d/standalone-sample/onload-daemon-01.lua | 57 ++++++++++++++ 3 files changed, 215 insertions(+) create mode 100644 conf.d/project/config.d/onload-daemon-standalone.json create mode 100644 conf.d/project/lua.d/standalone-sample/onload-daemon-00.lua create mode 100644 conf.d/project/lua.d/standalone-sample/onload-daemon-01.lua (limited to 'conf.d/project') diff --git a/conf.d/project/config.d/onload-daemon-standalone.json b/conf.d/project/config.d/onload-daemon-standalone.json new file mode 100644 index 0000000..de52c22 --- /dev/null +++ b/conf.d/project/config.d/onload-daemon-standalone.json @@ -0,0 +1,72 @@ +{ + "$schema": "ToBeDone", + "metadata": { + "label": "sample-standalone-control", + "info": "Minimal Standalone Controller Config", + "version": "1.0" + }, + "onload": [{ + "label": "onload-default", + "info": "onload initialisation config", + "actions": + { + "label": "control-init", + "lua": "_Control_Init" + } + }], + "controls": + [ + { + "label": "Button-1", + "actions": { + "label": "Action on Button One", + "lua": "_Button_Press", + "args": { + "button": 1 + } + } + }, { + "label": "Button-1", + "actions": { + "label": "Action on Button Two", + "lua": "_Button_Press", + "args": { + "button": 2 + } + } + }, { + "label": "Button-1", + "actions": { + "label": "Action on Button Three", + "lua": "_Button_Press", + "args": { + "button": 3 + } + } + } + ], + "events": + [ + { + "label": "Event1", + "actions": { + "label": "Action Event 1", + "lua": "_Event_Received", + "args": { + "evtname": "xxx" + } + } + }, + { + "label": "Event2", + "actions": { + "label": "Action Event 2", + "lua": "_Event_Received", + "args": { + "evtname": "yyy" + } + } + } + ] +} + diff --git a/conf.d/project/lua.d/standalone-sample/onload-daemon-00.lua b/conf.d/project/lua.d/standalone-sample/onload-daemon-00.lua new file mode 100644 index 0000000..b8ecd7e --- /dev/null +++ b/conf.d/project/lua.d/standalone-sample/onload-daemon-00.lua @@ -0,0 +1,86 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed 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. + + Note: this file should be called before any other to assert declare function + is loaded before anything else. + + References: + http://lua-users.org/wiki/DetectingUndefinedVariables + +--]] + + +--=================================================== +--= Niklas Frykholm +-- basically if user tries to create global variable +-- the system will not let them!! +-- call GLOBAL_lock(_G) +-- +--=================================================== +function GLOBAL_lock(t) + local mt = getmetatable(t) or {} + mt.__newindex = lock_new_index + setmetatable(t, mt) +end + +--=================================================== +-- call GLOBAL_unlock(_G) +-- to change things back to normal. +--=================================================== +function GLOBAL_unlock(t) + local mt = getmetatable(t) or {} + mt.__newindex = unlock_new_index + setmetatable(t, mt) +end + +function lock_new_index(t, k, v) + if (string.sub(k,1,1) ~= "_") then + GLOBAL_unlock(_G) + error("GLOBALS are locked -- " .. k .. + " must be declared local or prefix with '_' for globals.", 2) + else + rawset(t, k, v) + end +end + +function unlock_new_index(t, k, v) + rawset(t, k, v) +end + +-- return serialised version of printable table +function Dump_Table(o) + if type(o) == 'table' then + local s = '{ ' + for k,v in pairs(o) do + if type(k) ~= 'number' then k = '"'..k..'"' end + s = s .. '['..k..'] = ' .. Dump_Table(v) .. ',' + end + return s .. '} ' + else + return tostring(o) + end +end + + +-- simulate C prinf function +printf = function(s,...) + io.write(s:format(...)) + io.write("\n") + return +end + +-- lock global variable +GLOBAL_lock(_G) diff --git a/conf.d/project/lua.d/standalone-sample/onload-daemon-01.lua b/conf.d/project/lua.d/standalone-sample/onload-daemon-01.lua new file mode 100644 index 0000000..7b22db0 --- /dev/null +++ b/conf.d/project/lua.d/standalone-sample/onload-daemon-01.lua @@ -0,0 +1,57 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed 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. + + Note: this file should be called before any other to assert declare function + is loaded before anything else. + + References: + http://lua-users.org/wiki/DetectingUndefinedVariables + +--]] + +-- Set Navigation lower sound when play +function _Control_Init(source, args) + + -- in strict mode every variables should be declared + local err=0 + + AFB:notice ("Control_Init args=%s", args); + + return 0 -- control accepted +end + +-- Set Navigation lower sound when play +function _Button_Press(source, args, query) + + -- in strict mode every variables should be declared + local err=0 + + AFB:notice ("Button_Press button=%s", args["button"]); + + return 0 -- control accepted +end + +-- Set Navigation lower sound when play +function _Event_Received(source, args, query) + + -- in strict mode every variables should be declared + local err=0 + + AFB:notice ("Event_Received event=%s", args["evtname"]); + + return 0 -- control accepted +end + -- cgit From 3648e16e17a908e7f08bde789fefe3abc6981544 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Fri, 18 Aug 2017 10:45:11 +0200 Subject: Latest app-templates features integration - CMake >= 3.6 mandatory - Change DATA and HTDOCS targets methods to use macro add_input_files() - header generated from OpenAPI file using BINDINGV2 label and set_openapi_filename() macro. - Adjusted README to reflect new cmake requirement Change-Id: I8da515b98c1877d5be5e51f2bf94d691ac3cefb7 Signed-off-by: Romain Forlot --- conf.d/project/config.d/CMakeLists.txt | 16 ++++------------ conf.d/project/lua.d/CMakeLists.txt | 16 ++++------------ 2 files changed, 8 insertions(+), 24 deletions(-) (limited to 'conf.d/project') diff --git a/conf.d/project/config.d/CMakeLists.txt b/conf.d/project/config.d/CMakeLists.txt index 229cf2d..8070997 100644 --- a/conf.d/project/config.d/CMakeLists.txt +++ b/conf.d/project/config.d/CMakeLists.txt @@ -24,17 +24,9 @@ PROJECT_TARGET_ADD(ctl-config.d) file(GLOB XML_FILES "*.json") - add_custom_target(${TARGET_NAME} - DEPENDS ${PROJECT_PKG_BUILD_DIR}/${TARGET_NAME} - ) + add_input_files("${XML_FILES}") - # check XML schema before pushing config - add_custom_command( - DEPENDS ${XML_FILES} - OUTPUT ${PROJECT_PKG_BUILD_DIR}/${TARGET_NAME} - # COMMAND xmllint -schema ${XML_SCHEMA} ${XML_FILES} --noout (Fulup we miss this for JSON) - COMMAND mkdir -p ${PROJECT_PKG_BUILD_DIR}/${TARGET_NAME} - COMMAND touch ${PROJECT_PKG_BUILD_DIR}/${TARGET_NAME} - COMMAND cp -r ${XML_FILES} ${PROJECT_PKG_BUILD_DIR}/${TARGET_NAME} + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES + LABELS "DATA" + OUTPUT_NAME ${TARGET_NAME} ) - diff --git a/conf.d/project/lua.d/CMakeLists.txt b/conf.d/project/lua.d/CMakeLists.txt index ecf1e6d..5cd61f2 100644 --- a/conf.d/project/lua.d/CMakeLists.txt +++ b/conf.d/project/lua.d/CMakeLists.txt @@ -24,17 +24,9 @@ PROJECT_TARGET_ADD(ctl-lua.d) file(GLOB LUA_FILES "*.lua") - add_custom_target(${TARGET_NAME} - DEPENDS ${PROJECT_PKG_BUILD_DIR}/${TARGET_NAME} - ) + add_input_files("${LUA_FILES}") - # check XML schema before pushing config - add_custom_command( - DEPENDS ${LUA_FILES} - OUTPUT ${PROJECT_PKG_BUILD_DIR}/${TARGET_NAME} - COMMAND ${LUA_COMPILER} ${LUA_FILES} - COMMAND mkdir -p ${PROJECT_PKG_BUILD_DIR}/${TARGET_NAME} - COMMAND touch ${PROJECT_PKG_BUILD_DIR}/${TARGET_NAME} - COMMAND cp -r ${LUA_FILES} ${PROJECT_PKG_BUILD_DIR}/${TARGET_NAME} + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES + LABELS "DATA" + OUTPUT_NAME ${TARGET_NAME} ) - -- cgit From d51d083be8e34000cd00ce979445eacb45a16e97 Mon Sep 17 00:00:00 2001 From: Fulup Ar Foll Date: Sun, 20 Aug 2017 17:16:28 +0200 Subject: Updated to latest App Template --- conf.d/project/config.d/CMakeLists.txt | 32 ---- conf.d/project/config.d/onload-audio-control.json | 128 ---------------- .../project/config.d/onload-daemon-standalone.json | 72 --------- conf.d/project/json.d/CMakeLists.txt | 32 ++++ conf.d/project/json.d/onload-audio-control.json | 128 ++++++++++++++++ .../project/json.d/onload-daemon-standalone.json | 72 +++++++++ conf.d/project/lua.d/onload-aaaa-00-utils.lua | 86 +++++++++++ conf.d/project/lua.d/onload-aaaa-01-controls.lua | 162 +++++++++++++++++++++ conf.d/project/lua.d/onload-aaaa-02-timer.lua | 69 +++++++++ conf.d/project/lua.d/onload-aaaa-03-oncall.lua | 70 +++++++++ conf.d/project/lua.d/onload-audio-0utils.lua | 86 ----------- conf.d/project/lua.d/onload-audio-controls.lua | 162 --------------------- conf.d/project/lua.d/onload-audio-oncall.lua | 70 --------- conf.d/project/lua.d/onload-audio-timer.lua | 69 --------- 14 files changed, 619 insertions(+), 619 deletions(-) delete mode 100644 conf.d/project/config.d/CMakeLists.txt delete mode 100644 conf.d/project/config.d/onload-audio-control.json delete mode 100644 conf.d/project/config.d/onload-daemon-standalone.json create mode 100644 conf.d/project/json.d/CMakeLists.txt create mode 100644 conf.d/project/json.d/onload-audio-control.json create mode 100644 conf.d/project/json.d/onload-daemon-standalone.json create mode 100644 conf.d/project/lua.d/onload-aaaa-00-utils.lua create mode 100644 conf.d/project/lua.d/onload-aaaa-01-controls.lua create mode 100644 conf.d/project/lua.d/onload-aaaa-02-timer.lua create mode 100644 conf.d/project/lua.d/onload-aaaa-03-oncall.lua delete mode 100644 conf.d/project/lua.d/onload-audio-0utils.lua delete mode 100644 conf.d/project/lua.d/onload-audio-controls.lua delete mode 100644 conf.d/project/lua.d/onload-audio-oncall.lua delete mode 100644 conf.d/project/lua.d/onload-audio-timer.lua (limited to 'conf.d/project') diff --git a/conf.d/project/config.d/CMakeLists.txt b/conf.d/project/config.d/CMakeLists.txt deleted file mode 100644 index 8070997..0000000 --- a/conf.d/project/config.d/CMakeLists.txt +++ /dev/null @@ -1,32 +0,0 @@ -########################################################################### -# Copyright 2017 IoT.bzh -# -# author: Fulup Ar Foll -# -# Licensed 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. -########################################################################### - - -################################################## -# Control Policy Config file -################################################## -PROJECT_TARGET_ADD(ctl-config.d) - - file(GLOB XML_FILES "*.json") - - add_input_files("${XML_FILES}") - - SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES - LABELS "DATA" - OUTPUT_NAME ${TARGET_NAME} - ) diff --git a/conf.d/project/config.d/onload-audio-control.json b/conf.d/project/config.d/onload-audio-control.json deleted file mode 100644 index 77a8fce..0000000 --- a/conf.d/project/config.d/onload-audio-control.json +++ /dev/null @@ -1,128 +0,0 @@ -{ - "$schema": "ToBeDone", - "metadata": { - "label": "sample-audio-control", - "info": "Provide Default Audio Policy for Multimedia, Navigation and Emergency", - "version": "1.0" - }, - "onload": [{ - "label": "onload-default", - "info": "onload initialisation config", - "plugin": { - "label" : "_MyPlug", - "sharelib": "ctl-audio-plugin-sample.ctlso", - "lua2c": ["Lua2cHelloWorld1", "Lua2cHelloWorld2"] - }, - "require": ["intel-hda", "jabra-usb", "scarlett-usb"], - "actions": [ - { - "label": "onload-sample-cb", - "info": "Call control sharelib install entrypoint", - "callback": "SamplePolicyInit", - "args": { - "arg1": "first_arg", - "nextarg": "second arg value" - } - }, { - "label": "onload-sample-api", - "info": "Assert AlsaCore Presence", - "api": "alsacore", - "verb": "ping", - "args": {"data": "none"} - }, { - "label": "onload-hal-lua", - "info": "Load avaliable HALs", - "lua": "_Alsa_Get_Hal" - } - ] - }], - "controls": - [ - { - "label": "multimedia", - "actions": { - "label": "multimedia-control-lua", - "info": "Call Lua Script function Test_Lua_Engin", - "lua": "_Audio_Set_Multimedia" - } - }, { - "label": "navigation", - "actions": { - "label": "navigation-control-lua", - "info": "Call Lua Script to set Navigation", - "lua": "_Audio_Set_Navigation" - } - }, { - "label": "emergency", - "actions": { - "label": "emergency-control-ucm", - "lua": "_Audio_Set_Emergency" - } - }, { - "label": "multi-step-sample", - "info" : "all actions must succeed for control to be accepted", - "actions": [{ - "label": "multimedia-control-cb", - "info": "Call Sharelib Sample Callback", - "callback": "sampleControlNavigation", - "args": { - "arg1": "snoopy", - "arg2": "toto" - } - }, { - "label": "navigation-control-ucm", - "api": "alsacore", - "verb": "ping", - "args": { - "test": "navigation" - } - }, { - "label": "navigation-control-lua", - "info": "Call Lua Script to set Navigation", - "lua": "_Audio_Set_Navigation" - }] - } - ], - "events": - [ - { - "label": "SampleEvent1", - "info": "define action when receiving a given event", - "actions": [ - { - "label": "Event Callback-1", - "callback": "SampleControlEvent", - "args": { - "arg": "action-1" - } - }, { - "label": "Event Callback-2", - "callback": "SampleControlEvent", - "args": { - "arg": "action-2" - } - } - ] - }, - { - "label": "SampleEvent2", - "info": "define action when receiving a given event", - "actions": [ - { - "label": "Event Callback-1", - "callback": "SampleControlEvent", - "args": { - "arg": "action-1" - } - }, { - "label": "Event Callback-2", - "callback": "SampleControlEvent", - "args": { - "arg": "action-2" - } - } - ] - } - ] -} - diff --git a/conf.d/project/config.d/onload-daemon-standalone.json b/conf.d/project/config.d/onload-daemon-standalone.json deleted file mode 100644 index de52c22..0000000 --- a/conf.d/project/config.d/onload-daemon-standalone.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "$schema": "ToBeDone", - "metadata": { - "label": "sample-standalone-control", - "info": "Minimal Standalone Controller Config", - "version": "1.0" - }, - "onload": [{ - "label": "onload-default", - "info": "onload initialisation config", - "actions": - { - "label": "control-init", - "lua": "_Control_Init" - } - }], - "controls": - [ - { - "label": "Button-1", - "actions": { - "label": "Action on Button One", - "lua": "_Button_Press", - "args": { - "button": 1 - } - } - }, { - "label": "Button-1", - "actions": { - "label": "Action on Button Two", - "lua": "_Button_Press", - "args": { - "button": 2 - } - } - }, { - "label": "Button-1", - "actions": { - "label": "Action on Button Three", - "lua": "_Button_Press", - "args": { - "button": 3 - } - } - } - ], - "events": - [ - { - "label": "Event1", - "actions": { - "label": "Action Event 1", - "lua": "_Event_Received", - "args": { - "evtname": "xxx" - } - } - }, - { - "label": "Event2", - "actions": { - "label": "Action Event 2", - "lua": "_Event_Received", - "args": { - "evtname": "yyy" - } - } - } - ] -} - diff --git a/conf.d/project/json.d/CMakeLists.txt b/conf.d/project/json.d/CMakeLists.txt new file mode 100644 index 0000000..8070997 --- /dev/null +++ b/conf.d/project/json.d/CMakeLists.txt @@ -0,0 +1,32 @@ +########################################################################### +# Copyright 2017 IoT.bzh +# +# author: Fulup Ar Foll +# +# Licensed 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. +########################################################################### + + +################################################## +# Control Policy Config file +################################################## +PROJECT_TARGET_ADD(ctl-config.d) + + file(GLOB XML_FILES "*.json") + + add_input_files("${XML_FILES}") + + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES + LABELS "DATA" + OUTPUT_NAME ${TARGET_NAME} + ) diff --git a/conf.d/project/json.d/onload-audio-control.json b/conf.d/project/json.d/onload-audio-control.json new file mode 100644 index 0000000..77a8fce --- /dev/null +++ b/conf.d/project/json.d/onload-audio-control.json @@ -0,0 +1,128 @@ +{ + "$schema": "ToBeDone", + "metadata": { + "label": "sample-audio-control", + "info": "Provide Default Audio Policy for Multimedia, Navigation and Emergency", + "version": "1.0" + }, + "onload": [{ + "label": "onload-default", + "info": "onload initialisation config", + "plugin": { + "label" : "_MyPlug", + "sharelib": "ctl-audio-plugin-sample.ctlso", + "lua2c": ["Lua2cHelloWorld1", "Lua2cHelloWorld2"] + }, + "require": ["intel-hda", "jabra-usb", "scarlett-usb"], + "actions": [ + { + "label": "onload-sample-cb", + "info": "Call control sharelib install entrypoint", + "callback": "SamplePolicyInit", + "args": { + "arg1": "first_arg", + "nextarg": "second arg value" + } + }, { + "label": "onload-sample-api", + "info": "Assert AlsaCore Presence", + "api": "alsacore", + "verb": "ping", + "args": {"data": "none"} + }, { + "label": "onload-hal-lua", + "info": "Load avaliable HALs", + "lua": "_Alsa_Get_Hal" + } + ] + }], + "controls": + [ + { + "label": "multimedia", + "actions": { + "label": "multimedia-control-lua", + "info": "Call Lua Script function Test_Lua_Engin", + "lua": "_Audio_Set_Multimedia" + } + }, { + "label": "navigation", + "actions": { + "label": "navigation-control-lua", + "info": "Call Lua Script to set Navigation", + "lua": "_Audio_Set_Navigation" + } + }, { + "label": "emergency", + "actions": { + "label": "emergency-control-ucm", + "lua": "_Audio_Set_Emergency" + } + }, { + "label": "multi-step-sample", + "info" : "all actions must succeed for control to be accepted", + "actions": [{ + "label": "multimedia-control-cb", + "info": "Call Sharelib Sample Callback", + "callback": "sampleControlNavigation", + "args": { + "arg1": "snoopy", + "arg2": "toto" + } + }, { + "label": "navigation-control-ucm", + "api": "alsacore", + "verb": "ping", + "args": { + "test": "navigation" + } + }, { + "label": "navigation-control-lua", + "info": "Call Lua Script to set Navigation", + "lua": "_Audio_Set_Navigation" + }] + } + ], + "events": + [ + { + "label": "SampleEvent1", + "info": "define action when receiving a given event", + "actions": [ + { + "label": "Event Callback-1", + "callback": "SampleControlEvent", + "args": { + "arg": "action-1" + } + }, { + "label": "Event Callback-2", + "callback": "SampleControlEvent", + "args": { + "arg": "action-2" + } + } + ] + }, + { + "label": "SampleEvent2", + "info": "define action when receiving a given event", + "actions": [ + { + "label": "Event Callback-1", + "callback": "SampleControlEvent", + "args": { + "arg": "action-1" + } + }, { + "label": "Event Callback-2", + "callback": "SampleControlEvent", + "args": { + "arg": "action-2" + } + } + ] + } + ] +} + diff --git a/conf.d/project/json.d/onload-daemon-standalone.json b/conf.d/project/json.d/onload-daemon-standalone.json new file mode 100644 index 0000000..de52c22 --- /dev/null +++ b/conf.d/project/json.d/onload-daemon-standalone.json @@ -0,0 +1,72 @@ +{ + "$schema": "ToBeDone", + "metadata": { + "label": "sample-standalone-control", + "info": "Minimal Standalone Controller Config", + "version": "1.0" + }, + "onload": [{ + "label": "onload-default", + "info": "onload initialisation config", + "actions": + { + "label": "control-init", + "lua": "_Control_Init" + } + }], + "controls": + [ + { + "label": "Button-1", + "actions": { + "label": "Action on Button One", + "lua": "_Button_Press", + "args": { + "button": 1 + } + } + }, { + "label": "Button-1", + "actions": { + "label": "Action on Button Two", + "lua": "_Button_Press", + "args": { + "button": 2 + } + } + }, { + "label": "Button-1", + "actions": { + "label": "Action on Button Three", + "lua": "_Button_Press", + "args": { + "button": 3 + } + } + } + ], + "events": + [ + { + "label": "Event1", + "actions": { + "label": "Action Event 1", + "lua": "_Event_Received", + "args": { + "evtname": "xxx" + } + } + }, + { + "label": "Event2", + "actions": { + "label": "Action Event 2", + "lua": "_Event_Received", + "args": { + "evtname": "yyy" + } + } + } + ] +} + diff --git a/conf.d/project/lua.d/onload-aaaa-00-utils.lua b/conf.d/project/lua.d/onload-aaaa-00-utils.lua new file mode 100644 index 0000000..b8ecd7e --- /dev/null +++ b/conf.d/project/lua.d/onload-aaaa-00-utils.lua @@ -0,0 +1,86 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed 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. + + Note: this file should be called before any other to assert declare function + is loaded before anything else. + + References: + http://lua-users.org/wiki/DetectingUndefinedVariables + +--]] + + +--=================================================== +--= Niklas Frykholm +-- basically if user tries to create global variable +-- the system will not let them!! +-- call GLOBAL_lock(_G) +-- +--=================================================== +function GLOBAL_lock(t) + local mt = getmetatable(t) or {} + mt.__newindex = lock_new_index + setmetatable(t, mt) +end + +--=================================================== +-- call GLOBAL_unlock(_G) +-- to change things back to normal. +--=================================================== +function GLOBAL_unlock(t) + local mt = getmetatable(t) or {} + mt.__newindex = unlock_new_index + setmetatable(t, mt) +end + +function lock_new_index(t, k, v) + if (string.sub(k,1,1) ~= "_") then + GLOBAL_unlock(_G) + error("GLOBALS are locked -- " .. k .. + " must be declared local or prefix with '_' for globals.", 2) + else + rawset(t, k, v) + end +end + +function unlock_new_index(t, k, v) + rawset(t, k, v) +end + +-- return serialised version of printable table +function Dump_Table(o) + if type(o) == 'table' then + local s = '{ ' + for k,v in pairs(o) do + if type(k) ~= 'number' then k = '"'..k..'"' end + s = s .. '['..k..'] = ' .. Dump_Table(v) .. ',' + end + return s .. '} ' + else + return tostring(o) + end +end + + +-- simulate C prinf function +printf = function(s,...) + io.write(s:format(...)) + io.write("\n") + return +end + +-- lock global variable +GLOBAL_lock(_G) diff --git a/conf.d/project/lua.d/onload-aaaa-01-controls.lua b/conf.d/project/lua.d/onload-aaaa-01-controls.lua new file mode 100644 index 0000000..24c4f71 --- /dev/null +++ b/conf.d/project/lua.d/onload-aaaa-01-controls.lua @@ -0,0 +1,162 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed 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. + + + Provide sample policy function for AGL Advance Audio Agent +--]] + +-- Global HAL registry +_Audio_Hal_Registry={} + +-- Callback when receiving HAL registry +function _Alsa_Get_Hal_CB (error, result, context) + -- Initialise an empty table + local registry={} + + -- Only process when response is valid + if (error) then + AFB_ErrOr ("[Audio_Init_CB] ErrOr result=%s", result) + return + end + + -- Extract response from result + local response=result["response"] + + -- Index HAL Bindings APIs by shortname + for key,value in pairs(response) do + registry[value["shortname"]]=value["api"] + end + + -- store Exiting HAL for further use + printf ("-- [Audio_Init_CB] -- Audio_register_Hal=%s", Dump_Table(registry)) + _Audio_Hal_Registry=registry + +end + +-- Function call at binding load time +function _Alsa_Get_Hal(args) + + printf ("[-- Audio_Get_Hal --] args=%s", Dump_Table(argsT)) + + -- Query AlsaCore for Active HALs (no query, no context) + AFB:service ('alsacore', 'hallist', {}, "_Alsa_Get_Hal_CB", {}) + +end + +-- In sample configuration Query/Args parsing is common to all audio control +local function Audio_Parse_Request (source, args, query) + + local apihal={} + + -- In this test we expect targeted device to be given from query (could come for args as well) + if (query == nil ) then + AFB:error ("--LUA:Audio_Set_Navigation query should contain and args with targeted apihal|device") + return -- refuse control + end + + -- Alsa Hook plugin asound sample config provides target sound card by name + if (query["device"] ~= nil) then + apihal=_Audio_Hal_Registry[query["device"]] + end + + -- HTML5 test page provides directly HAL api. + if (query["apihal"] ~= nil) then + apihal= query["apihal"] + end + + -- if requested HAL is not found then deny the control + if (apihal == nil) then + AFB:error ("--LUA:Audio_Set_Navigation No Active HAL Found") + return -- refuse control + end + + -- return api or nil when not found + return apihal +end + +-- Set Navigation lower sound when play +function _Audio_Set_Navigation(source, args, query) + + -- in strict mode every variables should be declared + local err=0 + local ctlhal={} + local response={} + local apihal={} + + AFB:notice ("LUA:Audio_Set_Use_Case source=%d args=%s query=%s", source, args, query); + + -- Parse Query/Args and if HAL not found then refuse access + apihal= Audio_Parse_Request (source, args, query) + if (apihal == nil) then return 1 end + + + -- if source < 0 then Alsa HookPlugin is closing PCM + if (source < 0) then + -- Ramp Up Multimedia channel synchronously + ctlhal={['label']='Master_Playback_Volume', ['val']=100} + err, response= AFB:servsync (apihal, 'ctlset',ctlhal) + else + -- Ramp Down Multimedia channel synchronously + ctlhal={['label']='Master_Playback_Volume', ['val']=50} + err, response= AFB:servsync (apihal, 'ctlset',ctlhal) + end + + if (err) then + AFB:error("--LUA:Audio_Set_Navigation halapi=%s refuse ctl=%s", apihal, ctlhal) + return 1 -- control refused + end + + + return 0 -- control accepted +end + + +-- Select Multimedia mode +function _Audio_Set_Multimedia (source, args, query) + + -- in strict mode every variables should be declared + local err=0 + local ctlhal={} + local response={} + local apihal={} + + AFB:notice ("LUA:Audio_Set_Use_Case source=%d args=%s query=%s", source, args, query); + + -- Parse Query/Args and if HAL not found then refuse access + apihal= Audio_Parse_Request (source, args, query) + if (apihal == nil) then return 1 end + + + -- if Mumtimedia control only increase volume on open + if (source >= 0) then + -- Ramp Down Multimedia channel synchronously + ctlhal={['label']='Master_Playback_Volume', ['val']=100} + err, response= AFB:servsync (apihal, 'ctlset',ctlhal) + end + + if (err) then + AFB:error("--LUA:Audio_Set_Navigation halapi=%s refuse ctl=%s", apihal, ctlhal) + return 1 -- control refused + end + + + return 0 -- control accepted +end + +-- Select Emergency Mode +function _Audio_Set_Emergency(source, args, query) + return 1 -- Always refuse in this test +end diff --git a/conf.d/project/lua.d/onload-aaaa-02-timer.lua b/conf.d/project/lua.d/onload-aaaa-02-timer.lua new file mode 100644 index 0000000..db7a937 --- /dev/null +++ b/conf.d/project/lua.d/onload-aaaa-02-timer.lua @@ -0,0 +1,69 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed 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. + + + Provide Sample Timer Handing to push event from LUA +--]] + +-- Create event on Lua script load +local MyEventHandle=AFB:evtmake("MyTestEvent") + +-- Call count time every delay/ms +local function Timer_Test_CB (timer, context) + + local evtinfo= AFB:timerget(timer) + print ("timer=", Dump_Table(evtinfo)) + + --send an event an event with count as value + AFB:evtpush (MyEventHandle, {["label"]= evtinfo["label"], ["count"]=evtinfo["count"], ["info"]=context["info"]}) + + -- note when timerCB return!=0 timer is kill + return 0 + +end + +-- sendback event depending on count and delay +function _Simple_Timer_Test (request, args) + + local context = { + ["info"]="My 1st private Event", + } + + -- if delay not defined default is 5s + if (args["delay"]==nil) then args["delay"]=5000 end + + -- if count is not defined default is 10 + if (args["count"]==nil) then args["count"]=10 end + + -- we could use directly args but it is a sample + local myTimer = { + ["label"]=args["label"], + ["delay"]=args["delay"], + ["count"]=args["count"], + } + AFB:notice ("Test_Timer myTimer=%s", myTimer) + + -- subscribe to event + AFB:subscribe (request, MyEventHandle) + + -- settimer take a table with delay+count as input (count==0 means infinite) + AFB:timerset (myTimer, "Timer_Test_CB", context) + + -- nothing special to return send back args + AFB:success (request, myTimer) + + return 0 +end diff --git a/conf.d/project/lua.d/onload-aaaa-03-oncall.lua b/conf.d/project/lua.d/onload-aaaa-03-oncall.lua new file mode 100644 index 0000000..23b538e --- /dev/null +++ b/conf.d/project/lua.d/onload-aaaa-03-oncall.lua @@ -0,0 +1,70 @@ +--[[ + Copyright (C) 2016 "IoT.bzh" + Author Fulup Ar Foll + + Licensed 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. + + + Provide sample LUA routines to be used with AGL control "lua_docall" API +--]] + +--global counter to keep track of calls +_count=0 + +-- Display receive arguments and echo them to caller +function _Simple_Echo_Args (request, args) + _count=_count+1 + AFB:notice("LUA OnCall Echo Args count=%d args=%s", count, args) + + print ("--inlua-- args=", Dump_Table(args)) + + local response={ + ["count"]=_count, + ["args"]=args, + } + + -- fulup Embdeded table ToeDone AFB:success (request, response) + AFB:success (request, {["func"]="Simple_Echo_Args", ["ret1"]=5678, ["ret2"]="abcd"}) +end + +local function Test_Async_CB (request, result, context) + response={ + ["result"]=result, + ["context"]=context, + } + + AFB:notice ("Test_Async_CB result=%s context=%s", result, context) + AFB:success (request, response) +end + +function _Test_Call_Async (request, args) + local context={ + ["value1"]="abcd", + ["value2"]=1234 + } + + AFB:notice ("Test_Call_Async args=%s cb=Test_Async_CB", args) + AFB:service("alsacore","ping", "Test_Async_CB", context) +end + +function _Test_Call_Sync (request, args) + + AFB:notice ("Test_Call_Sync args=%s", args) + local err, response= AFB:service_sync ("alsacore","ping", args) + if (err) then + AFB:fail ("AFB:service_call_sync fail"); + else + AFB:success (request, response) + end +end + diff --git a/conf.d/project/lua.d/onload-audio-0utils.lua b/conf.d/project/lua.d/onload-audio-0utils.lua deleted file mode 100644 index b8ecd7e..0000000 --- a/conf.d/project/lua.d/onload-audio-0utils.lua +++ /dev/null @@ -1,86 +0,0 @@ ---[[ - Copyright (C) 2016 "IoT.bzh" - Author Fulup Ar Foll - - Licensed 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. - - Note: this file should be called before any other to assert declare function - is loaded before anything else. - - References: - http://lua-users.org/wiki/DetectingUndefinedVariables - ---]] - - ---=================================================== ---= Niklas Frykholm --- basically if user tries to create global variable --- the system will not let them!! --- call GLOBAL_lock(_G) --- ---=================================================== -function GLOBAL_lock(t) - local mt = getmetatable(t) or {} - mt.__newindex = lock_new_index - setmetatable(t, mt) -end - ---=================================================== --- call GLOBAL_unlock(_G) --- to change things back to normal. ---=================================================== -function GLOBAL_unlock(t) - local mt = getmetatable(t) or {} - mt.__newindex = unlock_new_index - setmetatable(t, mt) -end - -function lock_new_index(t, k, v) - if (string.sub(k,1,1) ~= "_") then - GLOBAL_unlock(_G) - error("GLOBALS are locked -- " .. k .. - " must be declared local or prefix with '_' for globals.", 2) - else - rawset(t, k, v) - end -end - -function unlock_new_index(t, k, v) - rawset(t, k, v) -end - --- return serialised version of printable table -function Dump_Table(o) - if type(o) == 'table' then - local s = '{ ' - for k,v in pairs(o) do - if type(k) ~= 'number' then k = '"'..k..'"' end - s = s .. '['..k..'] = ' .. Dump_Table(v) .. ',' - end - return s .. '} ' - else - return tostring(o) - end -end - - --- simulate C prinf function -printf = function(s,...) - io.write(s:format(...)) - io.write("\n") - return -end - --- lock global variable -GLOBAL_lock(_G) diff --git a/conf.d/project/lua.d/onload-audio-controls.lua b/conf.d/project/lua.d/onload-audio-controls.lua deleted file mode 100644 index 24c4f71..0000000 --- a/conf.d/project/lua.d/onload-audio-controls.lua +++ /dev/null @@ -1,162 +0,0 @@ ---[[ - Copyright (C) 2016 "IoT.bzh" - Author Fulup Ar Foll - - Licensed 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. - - - Provide sample policy function for AGL Advance Audio Agent ---]] - --- Global HAL registry -_Audio_Hal_Registry={} - --- Callback when receiving HAL registry -function _Alsa_Get_Hal_CB (error, result, context) - -- Initialise an empty table - local registry={} - - -- Only process when response is valid - if (error) then - AFB_ErrOr ("[Audio_Init_CB] ErrOr result=%s", result) - return - end - - -- Extract response from result - local response=result["response"] - - -- Index HAL Bindings APIs by shortname - for key,value in pairs(response) do - registry[value["shortname"]]=value["api"] - end - - -- store Exiting HAL for further use - printf ("-- [Audio_Init_CB] -- Audio_register_Hal=%s", Dump_Table(registry)) - _Audio_Hal_Registry=registry - -end - --- Function call at binding load time -function _Alsa_Get_Hal(args) - - printf ("[-- Audio_Get_Hal --] args=%s", Dump_Table(argsT)) - - -- Query AlsaCore for Active HALs (no query, no context) - AFB:service ('alsacore', 'hallist', {}, "_Alsa_Get_Hal_CB", {}) - -end - --- In sample configuration Query/Args parsing is common to all audio control -local function Audio_Parse_Request (source, args, query) - - local apihal={} - - -- In this test we expect targeted device to be given from query (could come for args as well) - if (query == nil ) then - AFB:error ("--LUA:Audio_Set_Navigation query should contain and args with targeted apihal|device") - return -- refuse control - end - - -- Alsa Hook plugin asound sample config provides target sound card by name - if (query["device"] ~= nil) then - apihal=_Audio_Hal_Registry[query["device"]] - end - - -- HTML5 test page provides directly HAL api. - if (query["apihal"] ~= nil) then - apihal= query["apihal"] - end - - -- if requested HAL is not found then deny the control - if (apihal == nil) then - AFB:error ("--LUA:Audio_Set_Navigation No Active HAL Found") - return -- refuse control - end - - -- return api or nil when not found - return apihal -end - --- Set Navigation lower sound when play -function _Audio_Set_Navigation(source, args, query) - - -- in strict mode every variables should be declared - local err=0 - local ctlhal={} - local response={} - local apihal={} - - AFB:notice ("LUA:Audio_Set_Use_Case source=%d args=%s query=%s", source, args, query); - - -- Parse Query/Args and if HAL not found then refuse access - apihal= Audio_Parse_Request (source, args, query) - if (apihal == nil) then return 1 end - - - -- if source < 0 then Alsa HookPlugin is closing PCM - if (source < 0) then - -- Ramp Up Multimedia channel synchronously - ctlhal={['label']='Master_Playback_Volume', ['val']=100} - err, response= AFB:servsync (apihal, 'ctlset',ctlhal) - else - -- Ramp Down Multimedia channel synchronously - ctlhal={['label']='Master_Playback_Volume', ['val']=50} - err, response= AFB:servsync (apihal, 'ctlset',ctlhal) - end - - if (err) then - AFB:error("--LUA:Audio_Set_Navigation halapi=%s refuse ctl=%s", apihal, ctlhal) - return 1 -- control refused - end - - - return 0 -- control accepted -end - - --- Select Multimedia mode -function _Audio_Set_Multimedia (source, args, query) - - -- in strict mode every variables should be declared - local err=0 - local ctlhal={} - local response={} - local apihal={} - - AFB:notice ("LUA:Audio_Set_Use_Case source=%d args=%s query=%s", source, args, query); - - -- Parse Query/Args and if HAL not found then refuse access - apihal= Audio_Parse_Request (source, args, query) - if (apihal == nil) then return 1 end - - - -- if Mumtimedia control only increase volume on open - if (source >= 0) then - -- Ramp Down Multimedia channel synchronously - ctlhal={['label']='Master_Playback_Volume', ['val']=100} - err, response= AFB:servsync (apihal, 'ctlset',ctlhal) - end - - if (err) then - AFB:error("--LUA:Audio_Set_Navigation halapi=%s refuse ctl=%s", apihal, ctlhal) - return 1 -- control refused - end - - - return 0 -- control accepted -end - --- Select Emergency Mode -function _Audio_Set_Emergency(source, args, query) - return 1 -- Always refuse in this test -end diff --git a/conf.d/project/lua.d/onload-audio-oncall.lua b/conf.d/project/lua.d/onload-audio-oncall.lua deleted file mode 100644 index 23b538e..0000000 --- a/conf.d/project/lua.d/onload-audio-oncall.lua +++ /dev/null @@ -1,70 +0,0 @@ ---[[ - Copyright (C) 2016 "IoT.bzh" - Author Fulup Ar Foll - - Licensed 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. - - - Provide sample LUA routines to be used with AGL control "lua_docall" API ---]] - ---global counter to keep track of calls -_count=0 - --- Display receive arguments and echo them to caller -function _Simple_Echo_Args (request, args) - _count=_count+1 - AFB:notice("LUA OnCall Echo Args count=%d args=%s", count, args) - - print ("--inlua-- args=", Dump_Table(args)) - - local response={ - ["count"]=_count, - ["args"]=args, - } - - -- fulup Embdeded table ToeDone AFB:success (request, response) - AFB:success (request, {["func"]="Simple_Echo_Args", ["ret1"]=5678, ["ret2"]="abcd"}) -end - -local function Test_Async_CB (request, result, context) - response={ - ["result"]=result, - ["context"]=context, - } - - AFB:notice ("Test_Async_CB result=%s context=%s", result, context) - AFB:success (request, response) -end - -function _Test_Call_Async (request, args) - local context={ - ["value1"]="abcd", - ["value2"]=1234 - } - - AFB:notice ("Test_Call_Async args=%s cb=Test_Async_CB", args) - AFB:service("alsacore","ping", "Test_Async_CB", context) -end - -function _Test_Call_Sync (request, args) - - AFB:notice ("Test_Call_Sync args=%s", args) - local err, response= AFB:service_sync ("alsacore","ping", args) - if (err) then - AFB:fail ("AFB:service_call_sync fail"); - else - AFB:success (request, response) - end -end - diff --git a/conf.d/project/lua.d/onload-audio-timer.lua b/conf.d/project/lua.d/onload-audio-timer.lua deleted file mode 100644 index db7a937..0000000 --- a/conf.d/project/lua.d/onload-audio-timer.lua +++ /dev/null @@ -1,69 +0,0 @@ ---[[ - Copyright (C) 2016 "IoT.bzh" - Author Fulup Ar Foll - - Licensed 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. - - - Provide Sample Timer Handing to push event from LUA ---]] - --- Create event on Lua script load -local MyEventHandle=AFB:evtmake("MyTestEvent") - --- Call count time every delay/ms -local function Timer_Test_CB (timer, context) - - local evtinfo= AFB:timerget(timer) - print ("timer=", Dump_Table(evtinfo)) - - --send an event an event with count as value - AFB:evtpush (MyEventHandle, {["label"]= evtinfo["label"], ["count"]=evtinfo["count"], ["info"]=context["info"]}) - - -- note when timerCB return!=0 timer is kill - return 0 - -end - --- sendback event depending on count and delay -function _Simple_Timer_Test (request, args) - - local context = { - ["info"]="My 1st private Event", - } - - -- if delay not defined default is 5s - if (args["delay"]==nil) then args["delay"]=5000 end - - -- if count is not defined default is 10 - if (args["count"]==nil) then args["count"]=10 end - - -- we could use directly args but it is a sample - local myTimer = { - ["label"]=args["label"], - ["delay"]=args["delay"], - ["count"]=args["count"], - } - AFB:notice ("Test_Timer myTimer=%s", myTimer) - - -- subscribe to event - AFB:subscribe (request, MyEventHandle) - - -- settimer take a table with delay+count as input (count==0 means infinite) - AFB:timerset (myTimer, "Timer_Test_CB", context) - - -- nothing special to return send back args - AFB:success (request, myTimer) - - return 0 -end -- cgit