From 8ef79c4fe380e590a7050f76605f304726eca664 Mon Sep 17 00:00:00 2001 From: Tobias Jahnke Date: Mon, 17 Dec 2018 16:51:56 +0100 Subject: 4a-hal-unicens: prepare import of plugin Bug-AGL: SPEC-1505 - remove all files from legacy hal binding Change-Id: I69e6d170cfa6a16d116f63263a1a5f75e2098d5b Signed-off-by: Tobias Jahnke --- conf.d/project/lua.d/onload-aaaa-03-controls.lua | 158 ----------------------- 1 file changed, 158 deletions(-) delete mode 100644 conf.d/project/lua.d/onload-aaaa-03-controls.lua (limited to 'conf.d/project/lua.d/onload-aaaa-03-controls.lua') diff --git a/conf.d/project/lua.d/onload-aaaa-03-controls.lua b/conf.d/project/lua.d/onload-aaaa-03-controls.lua deleted file mode 100644 index ae1269b..0000000 --- a/conf.d/project/lua.d/onload-aaaa-03-controls.lua +++ /dev/null @@ -1,158 +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. - - Following function are called when a control activate a label with - labeller api -> APi=label VERB=dispatch - arguments are - - source (0) when requesting the label (-1) when releasing - - label comme from config given with 'control' in onload-middlename-xxxxx.json - - control is the argument part of the query as providing by control requesting the label. - ---]] - -_CurrentHalVolume={} - - - ---[[ Apply control - * source=1 permanent change requested - * source=0 temporally request control - * source=-1 temporally release control --- ------------------------------------ --]] -local function Apply_Hal_Control(source, label, adjustment) - local HAL = _Global_Context["registry"] - - -- check we really got some data - if (adjustment == nil) then - AFB:error ("--* (Hoops) Control should provide volume adjustment") - return 1 - end - - -- loop on each HAL save current volume and push adjustment - for key,hal in pairs(_Global_Context["registry"]) do - printf ("--- HAL=%s", Dump_Table(hal)) - - -- action set loop on active HAL and get current volume - -- if label respond then do volume adjustment - - if (source >= 0) then - - -- get current volume for each HAL - local err,result= AFB:servsync(hal["api"],"ctlget", {["label"]=label}) - - -- if no error save current volume and set adjustment - if (err ~= nil) then - local response= result["response"] - printf ("--- Response %s=%s", hal["api"], Dump_Table(response)) - - if (response == nil) then - printf ("--- Fail to Activate '%s'='%s' result=%s", hal["api"], label, Dump_Table(result)) - return 1 -- unhappy - end - - -- save response in global space - _CurrentHalVolume [hal["api"]] = response - - -- finally set the new value - local query= { - ["tag"]= response["tag"], - ["val"]= adjustment - } - - -- best effort to set adjustment value - AFB:servsync(hal["api"],"ctlset",query) - end - - else -- when label is release reverse action at preempt time - - if (_CurrentHalVolume [hal["api"]] ~= nil) then - - printf("--- Restoring initial volume HAL=%s Control=%s", hal["api"], _CurrentHalVolume [hal["api"]]) - - AFB:servsync(hal["api"],"ctlset", _CurrentHalVolume [hal["api"]]) - end - end - - end - return 0 -- happy end -end - - --- Temporally adjust volume -function _Temporarily_Control(source, control, client) - - printf ("[--> _Temporarily_Control -->] source=%d control=%s client=%s", source, Dump_Table(control), Dump_Table(client)) - - -- Init should have been properly done - if (_Global_Context["registry"] == nil) then - AFB:error ("--* (Hoops) No Hal in _Global_Context=%s", Dump_Table(_Global_Context)) - return 1 - end - - -- make sure label as valid - if (control["ctl"] == nil or control["val"] == nil) then - AFB:error ("--* Action Ignore no/invalid control=%s", Dump_Table(control)) - return 1 -- unhappy - end - - if (source == 0) then - AFB:info("-- Adjust %s=%d", control["ctl"], control["val"]) - local error=Apply_Hal_Control(source, control["ctl"], control["val"]) - if (error == nil) then - return 1 -- unhappy - end - AFB:notice ("[<-- _Temporarily_Control Granted<--]") - else - Apply_Hal_Control(source, control["ctl"],0) - AFB:notice ("[<-- _Temporarily_Control Restore--]") - end - - return 0 -- happy return -end - - --- Permanent Adjust volume -function _Permanent_Control(source, control, client) - - printf ("[--> _Permanent_Control -->] source=%d control=%s client=%s", source, Dump_Table(control), Dump_Table(client)) - - -- Init should have been properly done - if (_Global_Context["registry"] == nil) then - AFB:error ("--* (Hoops) No Hal in _Global_Context=%s", Dump_Table(_Global_Context)) - return 1 - end - - -- make sure label as valid - if (control["ctl"] == nil or control["val"] == nil) then - AFB:error ("--* Action Ignore no/invalid control=%s", Dump_Table(control)) - return 1 -- unhappy - end - - if (source == 0) then - AFB:info("-- Adjust %s=%d", control["ctl"], control["val"]) - local error=Apply_Hal_Control(1, control["ctl"], control["val"]) - if (error == nil) then - return 1 -- unhappy - end - AFB:notice ("[<-- _Permanent_Control Granted<--]") - else - Apply_Hal_Control(source, control["ctl"],0) - AFB:notice ("[<-- _Permanent_Control Restore--]") - end - - return 0 -- happy return -end - -- cgit 1.2.3-korg