diff options
Diffstat (limited to 'src/js/buttons.js')
-rw-r--r-- | src/js/buttons.js | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/js/buttons.js b/src/js/buttons.js index 76d2143..c593445 100644 --- a/src/js/buttons.js +++ b/src/js/buttons.js @@ -14,15 +14,6 @@ * limitations under the License. */ - - -var values = { - ac: false, - recirculation: false, - rear: false, - front: false -}; - var paths = { ac: PATHS.airConditioning, recirculation: PATHS.recirculation, @@ -30,7 +21,7 @@ var paths = { front: PATHS.frontDefroster, }; -var nodes = {} +var nodes = new Map(); export function init() { nodes[PATHS.airConditioning] = document.getElementById('ac'); @@ -40,10 +31,15 @@ export function init() { nodes['up'] = document.getElementById('up'); nodes['down'] = document.getElementById('down'); nodes['right'] = document.getElementById('right'); + + nodes.forEach(function(node, path) { + node.setAttribute('value', false); + }); } -export function update(path, value) { +export function update(path, dp) { if (path == PATHS.leftAirDistribution) { + var value = dp.getString(); if (value == 'UP') { nodes['up'].setAttribute('value', true); nodes['down'].setAttribute('value', false); @@ -60,20 +56,25 @@ export function update(path, value) { } } else { var node = nodes[path]; + var value = dp.getBool(); node.setAttribute('value', value); } } export function toggle(node) { var key = node.getAttribute('key'); - values[key] = !values[key]; + if (KUKSA.isLocked(paths[key])) { + return; + } + if (key == 'up') { - KUKSA.set(PATHS.leftAirDistribution, 'UP'); + KUKSA.setString(PATHS.leftAirDistribution, 'UP'); } else if (key == 'down') { - KUKSA.set(PATHS.leftAirDistribution, 'DOWN'); + KUKSA.setString(PATHS.leftAirDistribution, 'DOWN'); } else if (key == 'right') { - KUKSA.set(PATHS.leftAirDistribution, 'MIDDLE'); + KUKSA.setString(PATHS.leftAirDistribution, 'MIDDLE'); } else { - KUKSA.set(paths[key], values[key]); + var value = node.getAttribute('value').toLowerCase() == 'true'; + KUKSA.setBool(paths[key], !value); } } |