Identity active/inactive#
Example: Toggle the active state of an identity.
-
led green if active
-
led off if inactive
Example: Toggle identity active state and set to default if switching to enabled
-
led green if active and default
-
led orange if inactive
-
led off if active but not default
local active local current
-- called on changes to the configuration -- get the active state and current identity and set the led local function onConfigChange() active = config.get(config_path_active) == "true" current = config.get(config_path_current .. "/id") if active then if current == identity then key.setLed("green") else key.setLed("off") end else key.setLed("orange") end end
-- called when the key is pressed -- check the current state and set to the other -- set the default identity also when setting to enabled function onKeyUp() if active then config.set(config_path_active, "false") else config.set(config_path_active, "true") config.set(config_path_current .. "/id", identity) end end
config.register(config_path_active, onConfigChange)
config.register(config_path_current, onConfigChange)
-- trigger once to get the current state
onConfigChange()
```