# Toggle
Toggle
TG
ON
OFF
O
ON
OFF
# 入力
| ID | 略称 | 名前 | 型 | デフォルト | 説明 |
|---|---|---|---|---|---|
input | TG | input | BOOLEAN | false | |
on | ON | on | BOOLEAN | false | |
off | OFF | off | BOOLEAN | false |
# 出力
| ID | 略称 | 名前 | 型 | デフォルト | 説明 |
|---|---|---|---|---|---|
output | O | output | BOOLEAN | false | |
on | ON | on | BOOLEAN | false | |
off | OFF | off | BOOLEAN | false |
# 状態
| ID | 名前 | 型 | デフォルト | 単位 | 説明 |
|---|---|---|---|---|---|
last_input_state | last_input_state | BOOLEAN | false | ||
last_on_state | last_on_state | BOOLEAN | false | ||
last_off_state | last_off_state | BOOLEAN | false |
# ソースコード
Volang ソースを表示
pulse_ms = 100
channel = input::channel()
value = input::value()
// Single callback handler - resets both pulse outputs
// Only one callback can be active at a time per block
extern fn onCallback(unused) {
output::set("on", false)
output::set("off", false)
}
// Handle "off" input first (dominant input)
if (channel == "off") {
last_off_state = state::get("last_off_state")
if (value and !last_off_state) {
// Rising edge on off input - turn off output
prev = output::get("output")
if (prev) {
output::set("output", false)
callback::clear()
output::set("on", false)
output::set("off", true)
callback::set(pulse_ms, "onCallback", 0)
}
}
state::set("last_off_state", value)
return
}
// If off input is held high, block is locked - ignore other inputs
// Still track input states to avoid false edges after unlock
if (state::get("last_off_state")) {
if (channel == "input") {
state::set("last_input_state", value)
} else if (channel == "on") {
state::set("last_on_state", value)
}
return
}
// Handle "on" input
if (channel == "on") {
last_on_state = state::get("last_on_state")
if (value and !last_on_state) {
// Rising edge on "on" input - turn on output
prev = output::get("output")
if (!prev) {
output::set("output", true)
callback::clear()
output::set("off", false)
output::set("on", true)
callback::set(pulse_ms, "onCallback", 0)
}
}
state::set("last_on_state", value)
return
}
// Handle toggle input
if (channel == "input") {
last_input_state = state::get("last_input_state")
// Only react to rising edge (false -> true)
if (value and !last_input_state) {
prev = output::get("output")
output::toggle("output")
callback::clear()
output::set("on", false)
output::set("off", false)
if (prev) {
// Was on, now off - emit off pulse
output::set("off", true)
} else {
// Was off, now on - emit on pulse
output::set("on", true)
}
callback::set(pulse_ms, "onCallback", 0)
}
state::set("last_input_state", value)
}
