aboutsummaryrefslogtreecommitdiffstats
path: root/conf.d/project/lua.d/onload-aaaa-03-controls.lua
diff options
context:
space:
mode:
authorFulup Ar Foll <fulup@iot.bzh>2017-08-27 18:09:54 +0200
committerFulup Ar Foll <fulup@iot.bzh>2017-08-27 18:09:54 +0200
commit1dd19ac494da7b223bc919a85c0e6c16502e9a77 (patch)
treef37e3ff2b39bbe44fd863ad3ffd5724275b002d1 /conf.d/project/lua.d/onload-aaaa-03-controls.lua
parente9b532488dff41b1215a8c92820a55fe6847e2f1 (diff)
Fix Alsacore ctlget in form ctl={id:xxx}
Diffstat (limited to 'conf.d/project/lua.d/onload-aaaa-03-controls.lua')
-rw-r--r--conf.d/project/lua.d/onload-aaaa-03-controls.lua44
1 files changed, 42 insertions, 2 deletions
diff --git a/conf.d/project/lua.d/onload-aaaa-03-controls.lua b/conf.d/project/lua.d/onload-aaaa-03-controls.lua
index 6c7c8a5..ae1269b 100644
--- a/conf.d/project/lua.d/onload-aaaa-03-controls.lua
+++ b/conf.d/project/lua.d/onload-aaaa-03-controls.lua
@@ -26,6 +26,12 @@
_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"]
@@ -41,7 +47,8 @@ local function Apply_Hal_Control(source, label, adjustment)
-- action set loop on active HAL and get current volume
-- if label respond then do volume adjustment
- if (source == 0) then
+
+ if (source >= 0) then
-- get current volume for each HAL
local err,result= AFB:servsync(hal["api"],"ctlget", {["label"]=label})
@@ -84,7 +91,7 @@ local function Apply_Hal_Control(source, label, adjustment)
end
--- Simple Happy(granted) Control
+-- 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))
@@ -116,3 +123,36 @@ function _Temporarily_Control(source, control, client)
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
+