mirror of
https://github.com/randybb/esphome-configs.git
synced 2026-12-06 09:06:52 +01:00
stackchan: NFC scanned from the head touch loop, taps no longer start the assistant
Every ST25R scan switches its RF field on and the si12t pads report a 50-350 ms phantom touch at any sensitivity; those started the assistant in a loop. The reader is now scanned between touch episodes every 2 s, with the pads ignored for 400 ms afterwards, and right when an episode starts so a card is still seen quickly. The assistant starts from the wake word only; a stroke shows the hearts.
This commit is contained in:
1 parent
58a5176ed3
commit
8234220765
1 file changed
+8
-28
+8
-28
@@ -129,9 +129,6 @@ globals:
|
|||||||
initial_value: 'false'
|
initial_value: 'false'
|
||||||
- id: speech
|
- id: speech
|
||||||
type: std::string
|
type: std::string
|
||||||
- id: nfc_changed_ms
|
|
||||||
type: uint32_t
|
|
||||||
initial_value: '0'
|
|
||||||
|
|
||||||
i2c:
|
i2c:
|
||||||
- id: i2c_bsp
|
- id: i2c_bsp
|
||||||
@@ -447,19 +444,6 @@ script:
|
|||||||
id(speech).clear();
|
id(speech).clear();
|
||||||
id(speaking) = false;
|
id(speaking) = false;
|
||||||
- component.update: display_tft
|
- 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
|
# stroking the head shows the in-love face for a while
|
||||||
- id: head_stroke
|
- id: head_stroke
|
||||||
mode: restart
|
mode: restart
|
||||||
@@ -501,7 +485,7 @@ interval:
|
|||||||
then:
|
then:
|
||||||
- component.update: display_tft
|
- component.update: display_tft
|
||||||
# head touch gestures: a touch episode ends after 250 ms without contact;
|
# 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
|
# 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
|
# 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).
|
# 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];
|
static uint32_t first_on[3];
|
||||||
const uint32_t now = millis();
|
const uint32_t now = millis();
|
||||||
if (!active) {
|
if (!active) {
|
||||||
if (now - last_scan >= 2000) {
|
if (now - last_scan >= 2000 && id(nfc_reader).is_ready()) {
|
||||||
last_scan = now;
|
last_scan = now;
|
||||||
id(nfc_reader).update();
|
id(nfc_reader).update();
|
||||||
return;
|
return;
|
||||||
@@ -528,8 +512,10 @@ interval:
|
|||||||
if (!active) {
|
if (!active) {
|
||||||
active = true;
|
active = true;
|
||||||
start = now;
|
start = now;
|
||||||
last_scan = now;
|
if (id(nfc_reader).is_ready()) {
|
||||||
id(nfc_reader).update();
|
last_scan = now;
|
||||||
|
id(nfc_reader).update();
|
||||||
|
}
|
||||||
first_on[0] = first_on[1] = first_on[2] = 0;
|
first_on[0] = first_on[1] = first_on[2] = 0;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
@@ -559,8 +545,6 @@ interval:
|
|||||||
|
|
||||||
if (pads >= 2 && spread >= 150 && duration >= 400) {
|
if (pads >= 2 && spread >= 150 && duration >= 400) {
|
||||||
id(head_stroke).execute();
|
id(head_stroke).execute();
|
||||||
} else if (duration <= 600) {
|
|
||||||
id(head_tap).execute();
|
|
||||||
}
|
}
|
||||||
- interval: 1s # status screen refresh until Home Assistant connects
|
- interval: 1s # status screen refresh until Home Assistant connects
|
||||||
then:
|
then:
|
||||||
@@ -914,17 +898,13 @@ st25r_i2c:
|
|||||||
i2c_id: i2c_bsp
|
i2c_id: i2c_bsp
|
||||||
update_interval: never # polled from the head touch interval, see there
|
update_interval: never # polled from the head touch interval, see there
|
||||||
on_tag:
|
on_tag:
|
||||||
- lambda: |-
|
- lambda: id(speech) = x; // UID under the face while the card lies there
|
||||||
id(nfc_changed_ms) = millis();
|
|
||||||
id(speech) = x; // UID under the face while the card lies there
|
|
||||||
- script.execute: surprise_reaction
|
- script.execute: surprise_reaction
|
||||||
- text_sensor.template.publish:
|
- text_sensor.template.publish:
|
||||||
id: nfc_tag
|
id: nfc_tag
|
||||||
state: !lambda return x;
|
state: !lambda return x;
|
||||||
on_tag_removed:
|
on_tag_removed:
|
||||||
- lambda: |-
|
- lambda: id(speech).clear();
|
||||||
id(nfc_changed_ms) = millis();
|
|
||||||
id(speech).clear();
|
|
||||||
- component.update: display_tft
|
- component.update: display_tft
|
||||||
- text_sensor.template.publish:
|
- text_sensor.template.publish:
|
||||||
id: nfc_tag
|
id: nfc_tag
|
||||||
|
|||||||
Reference in new issue
Block a user