-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.eslintrc | ||
.prettierrc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
wb-mqtt-dac (1.2.3) stable; urgency=medium | ||
|
||
* Format source code. No functional changes | ||
|
||
-- Nikolay Korotkiy <[email protected]> Fri, 09 Jun 2023 17:30:00 +0400 | ||
|
||
wb-mqtt-dac (1.2.2) stable; urgency=medium | ||
|
||
* Do not init if config file not found | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,94 @@ | ||
(function() { //don't touch this line | ||
(function () { | ||
//don't touch this line | ||
// prepare iio device list | ||
var iioChannelOfNodeMap={}; | ||
var iioChannelOfNodeMap = {}; | ||
|
||
function init() { | ||
var virt_device_params = { | ||
cells: { } | ||
cells: {}, | ||
}; | ||
|
||
var config = {}; | ||
try { | ||
config = readConfig("/var/lib/wb-mqtt-dac/conf.d/system.conf", {"logErrorOnNoFile": false}); | ||
config = readConfig('/var/lib/wb-mqtt-dac/conf.d/system.conf', { logErrorOnNoFile: false }); | ||
} catch (err) { | ||
try { | ||
config = readConfig("/etc/wb-mqtt-dac.conf", {"logErrorOnNoFile": false}); | ||
config = readConfig('/etc/wb-mqtt-dac.conf', { logErrorOnNoFile: false }); | ||
} catch (err) { | ||
log.warning("DAC: no config file"); | ||
log.warning('DAC: no config file'); | ||
return; | ||
} | ||
} | ||
|
||
var channels_by_id = {}; | ||
virt_device_params.title = config.device_name; | ||
for (var i=0; i <config.channels.length; ++i) { | ||
for (var i = 0; i < config.channels.length; ++i) { | ||
var channel = config.channels[i]; | ||
|
||
if (channel.iio_of_name) { | ||
var keys = Object.keys(iioChannelOfNodeMap); | ||
for (var j=0; j<keys.length; j++) { | ||
var ofNodeName=iioChannelOfNodeMap[keys[j]] | ||
for (var j = 0; j < keys.length; j++) { | ||
var ofNodeName = iioChannelOfNodeMap[keys[j]]; | ||
if (ofNodeName == channel.iio_of_name) { | ||
channel.iio_device=keys[j]; | ||
channel.iio_device = keys[j]; | ||
} | ||
} | ||
} | ||
|
||
if (channel.iio_device) { | ||
virt_device_params.cells[channel.id] = {"type": "range", "value" : 0}; | ||
virt_device_params.cells[channel.id] = { type: 'range', value: 0 }; | ||
virt_device_params.cells[channel.id].max = channel.max_value_mv; | ||
channels_by_id[channel.id] = channel; | ||
} else { | ||
log.warning("DAC: {}: IIO device not found, skipping".format(channel.id)); | ||
log.warning('DAC: {}: IIO device not found, skipping'.format(channel.id)); | ||
} | ||
} | ||
|
||
// virtual device with controls has to be created before calling defineRule | ||
if (Object.keys(virt_device_params.cells).length > 0) { | ||
defineVirtualDevice("wb-dac", virt_device_params); | ||
defineVirtualDevice('wb-dac', virt_device_params); | ||
} | ||
|
||
var channelIds = Object.keys(channels_by_id); | ||
for (var i=0; i < channelIds.length; ++i) { | ||
for (var i = 0; i < channelIds.length; ++i) { | ||
var channel = channels_by_id[channelIds[i]]; | ||
|
||
defineRule("_dac_change_" + channel.id, { | ||
whenChanged: "wb-dac/" + channel.id, | ||
defineRule('_dac_change_' + channel.id, { | ||
whenChanged: 'wb-dac/' + channel.id, | ||
then: function (newValue, devName, cellName) { | ||
var channel = channels_by_id[cellName]; | ||
var value_raw = Math.round(newValue / channel.multiplier); | ||
runShellCommand("echo {} > /sys/bus/iio/devices/iio\:device{}/out_voltage{}_raw".format(value_raw, channel.iio_device, channel.iio_channel)); | ||
} | ||
runShellCommand( | ||
'echo {} > /sys/bus/iio/devices/iio:device{}/out_voltage{}_raw'.format( | ||
value_raw, | ||
channel.iio_device, | ||
channel.iio_channel | ||
) | ||
); | ||
}, | ||
}); | ||
} | ||
|
||
}; | ||
} | ||
|
||
/* Get of_node name for each IIO device */ | ||
runShellCommand("for i in /sys/bus/iio/devices/iio:device*/of_node/name; do echo -n $i; echo ' '`cat $i`; done", { | ||
runShellCommand( | ||
"for i in /sys/bus/iio/devices/iio:device*/of_node/name; do echo -n $i; echo ' '`cat $i`; done", | ||
{ | ||
captureOutput: true, | ||
exitCallback: function (exitCode, capturedOutput) { | ||
var strList=capturedOutput.split("\n") | ||
for (var i=0; i<strList.length; ++i) { | ||
var strParts=strList[i].split(" ", 2); | ||
var strList = capturedOutput.split('\n'); | ||
for (var i = 0; i < strList.length; ++i) { | ||
var strParts = strList[i].split(' ', 2); | ||
if (strParts.length == 2) { | ||
var path = strParts[0]; | ||
var ofNodeName = strParts[1]; | ||
var num=path[path.length-"/of_node/name".length-1]; | ||
iioChannelOfNodeMap[num]=ofNodeName; | ||
var num = path[path.length - '/of_node/name'.length - 1]; | ||
iioChannelOfNodeMap[num] = ofNodeName; | ||
} | ||
} | ||
|
||
init(); | ||
} | ||
}); | ||
|
||
|
||
}, | ||
} | ||
); | ||
})(); | ||
|
||
|