Ugly but working playback code
This commit is contained in:
@@ -22,6 +22,14 @@ wifi:
|
|||||||
password: "SediaChinita@Terrazzo2017"
|
password: "SediaChinita@Terrazzo2017"
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------- Global variables ----------------------
|
||||||
|
|
||||||
|
globals:
|
||||||
|
- id: current_folder
|
||||||
|
type: int
|
||||||
|
restore_value: no
|
||||||
|
initial_value: '0'
|
||||||
|
|
||||||
|
|
||||||
# ---------------------- PN532 NFC Reader ----------------------
|
# ---------------------- PN532 NFC Reader ----------------------
|
||||||
|
|
||||||
@@ -35,13 +43,7 @@ pn532_i2c:
|
|||||||
update_interval: 1s
|
update_interval: 1s
|
||||||
on_tag:
|
on_tag:
|
||||||
then:
|
then:
|
||||||
# - logger.log:
|
- !lambda |-
|
||||||
# format: "NFC Tag found: %s"
|
|
||||||
# args: [ 'tag.get_ndef_message()->get_records()[0]->get_payload().c_str()' ]
|
|
||||||
- dfplayer.play_folder:
|
|
||||||
loop: True
|
|
||||||
# Crashes somewhere here in the lambda
|
|
||||||
folder: !lambda |-
|
|
||||||
if (tag.has_ndef_message()) {
|
if (tag.has_ndef_message()) {
|
||||||
const auto &message = tag.get_ndef_message();
|
const auto &message = tag.get_ndef_message();
|
||||||
const auto &records = message->get_records();
|
const auto &records = message->get_records();
|
||||||
@@ -54,11 +56,18 @@ pn532_i2c:
|
|||||||
// Note: exception handling is disabled in ESPHome: the following line may crash the microcontroller if a tag with a textual record if scanned
|
// Note: exception handling is disabled in ESPHome: the following line may crash the microcontroller if a tag with a textual record if scanned
|
||||||
int folderId = std::stoi(record->get_payload());
|
int folderId = std::stoi(record->get_payload());
|
||||||
ESP_LOGD("Fabula", " Found valid record in tag: playing folder %d", folderId);
|
ESP_LOGD("Fabula", " Found valid record in tag: playing folder %d", folderId);
|
||||||
|
id(current_folder) = folderId;
|
||||||
return folderId;
|
return folderId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ESP_LOGD("Fabula", " No valid record found in tag. Please add a text field containing the folder number, e.g. 001");
|
ESP_LOGD("Fabula", " No valid record found in tag. Please add a text field containing the folder number, e.g. 001");
|
||||||
|
id(current_folder) = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
# - logger.log:
|
||||||
|
# format: "NFC Tag found: %s"
|
||||||
|
# args: [ 'tag.get_ndef_message()->get_records()[0]->get_payload().c_str()' ]
|
||||||
|
- dfplayer.play_folder:
|
||||||
|
folder:
|
||||||
on_tag_removed:
|
on_tag_removed:
|
||||||
then:
|
then:
|
||||||
- logger.log: "NFC Tag removed"
|
- logger.log: "NFC Tag removed"
|
||||||
|
|||||||
Reference in New Issue
Block a user