# Edge detector

Process
Edge detector
I
O

# 入力

ID略称名前デフォルト説明
inputIinputBOOLEANfalse

# 出力

ID略称名前デフォルト説明
outputOoutputBOOLEANfalse

# 設定

ID名前デフォルト単位説明
directiondirectionENUM0

詳細:

値: Rising, Falling, Both
pulse_durationpulse_durationNUMBER0.1s

詳細:

> 0
startup_delaystartup_delayNUMBER0s

詳細:

≥ 0

# 状態

ID名前デフォルト単位説明
prev_inputprev_inputBOOLEANfalse
initializedinitializedBOOLEANfalse

# ソースコード

Volang ソースを表示
channel = input::channel()
value = input::value()

extern fn onPulseEnd() {
    output::set("output", false)
}

if (channel == "input") {
    prev_input = state::get("prev_input")
    initialized = state::get("initialized")

    if (!initialized) {
        state::set("prev_input", value)
        state::set("initialized", true)
        return
    }

    startup_delay = config::get("startup_delay")
    if (startup_delay > 0 and time::uptime() < startup_delay) {
        state::set("prev_input", value)
        return
    }

    direction = config::get("direction") // 0=Rising, 1=Falling, 2=Both
    edge_detected = false

    if (direction == 0) {
        edge_detected = value and !prev_input
    } else if (direction == 1) {
        edge_detected = !value and prev_input
    } else {
        edge_detected = (value and !prev_input) or (!value and prev_input)
    }

    state::set("prev_input", value)

    if (edge_detected) {
        callback::clear()
        output::set("output", true)
        pulse_ms = math::round(config::get("pulse_duration") * 1000)
        callback::set(pulse_ms, "onPulseEnd")
    }
}
Voldeno スマートホーム自動化における Edge detector Logic Block の動作、用途、設定方法を説明します。