diff --git a/mcu-stackchan.yaml b/mcu-stackchan.yaml index 269c3c3..0c09630 100644 --- a/mcu-stackchan.yaml +++ b/mcu-stackchan.yaml @@ -129,9 +129,6 @@ globals: initial_value: 'false' - id: speech type: std::string - - id: nfc_changed_ms - type: uint32_t - initial_value: '0' i2c: - id: i2c_bsp @@ -447,19 +444,6 @@ script: id(speech).clear(); id(speaking) = false; - component.update: display_tft - # short tap on the head starts the assistant; a card laid on or taken off the head - # touches the pads too, so a tap within 1.5 s of a tag change is ignored - - id: head_tap - mode: single - then: - - delay: 400ms # 2 NFC polls, so a card just laid on is already seen - - if: - condition: - and: - - not: voice_assistant.is_running - - lambda: return millis() - id(nfc_changed_ms) > 1500; - then: - - voice_assistant.start: # stroking the head shows the in-love face for a while - id: head_stroke mode: restart @@ -501,7 +485,7 @@ interval: then: - component.update: display_tft # head touch gestures: a touch episode ends after 250 ms without contact; - # tap = short episode, stroke = longer episode that reaches the pads one after another. + # stroke = longer episode that reaches the pads one after another (taps do nothing). # Each ST25R scan switches its RF field on and the pads report a 50-350 ms phantom touch, at any # si12t sensitivity, so the NFC reader is scanned from here: every 2 s between episodes, with the # pads ignored for 400 ms afterwards, and at once when an episode starts (a card being laid on). @@ -513,7 +497,7 @@ interval: static uint32_t first_on[3]; const uint32_t now = millis(); if (!active) { - if (now - last_scan >= 2000) { + if (now - last_scan >= 2000 && id(nfc_reader).is_ready()) { last_scan = now; id(nfc_reader).update(); return; @@ -528,8 +512,10 @@ interval: if (!active) { active = true; start = now; - last_scan = now; - id(nfc_reader).update(); + if (id(nfc_reader).is_ready()) { + last_scan = now; + id(nfc_reader).update(); + } first_on[0] = first_on[1] = first_on[2] = 0; } for (int i = 0; i < 3; i++) @@ -559,8 +545,6 @@ interval: if (pads >= 2 && spread >= 150 && duration >= 400) { id(head_stroke).execute(); - } else if (duration <= 600) { - id(head_tap).execute(); } - interval: 1s # status screen refresh until Home Assistant connects then: @@ -914,17 +898,13 @@ st25r_i2c: i2c_id: i2c_bsp update_interval: never # polled from the head touch interval, see there on_tag: - - lambda: |- - id(nfc_changed_ms) = millis(); - id(speech) = x; // UID under the face while the card lies there + - lambda: id(speech) = x; // UID under the face while the card lies there - script.execute: surprise_reaction - text_sensor.template.publish: id: nfc_tag state: !lambda return x; on_tag_removed: - - lambda: |- - id(nfc_changed_ms) = millis(); - id(speech).clear(); + - lambda: id(speech).clear(); - component.update: display_tft - text_sensor.template.publish: id: nfc_tag