From 21af6d835eacea2bf7fa9e823ab708406752d33d Mon Sep 17 00:00:00 2001 From: raihei Date: Mon, 27 Jan 2025 20:52:08 +0100 Subject: [PATCH] Allow creation of tags with filament color alpha channel value --- firmware/conf.d/automation.yaml | 17 +++++- firmware/conf.d/filament.yaml | 83 +++++++++++++++++++++++++--- firmware/conf.d/pn532_rfid-solo.yaml | 7 ++- 3 files changed, 94 insertions(+), 13 deletions(-) diff --git a/firmware/conf.d/automation.yaml b/firmware/conf.d/automation.yaml index 8504a3c..1f124dd 100644 --- a/firmware/conf.d/automation.yaml +++ b/firmware/conf.d/automation.yaml @@ -5,6 +5,7 @@ script: - text_sensor.template.publish: id: nfc_preview state: !lambda |- + id(filament_color_hexaa).publish_state(id(filament_color_hex).state + id(filament_alpha).state); auto pretty_json = [=]() -> std::string { StaticJsonDocument<256> doc; JsonObject root = doc.to(); @@ -12,7 +13,12 @@ script: root["protocol"] = "openspool"; root["version"] = "1.0"; root["brand"] = id(filament_brand).state.c_str(); - root["color_hex"] = id(filament_color_hex).state.c_str(); + if (id(filament_include_alpha).state == true){ + root["color_hex"] = id(filament_color_hexaa).state.c_str(); + } + else{ + root["color_hex"] = id(filament_color_hex).state.c_str(); + } root["min_temp"] = id(filament_min_temp).state; root["max_temp"] = id(filament_max_temp).state; root["type"] = id(filament_type).state.c_str(); @@ -95,8 +101,13 @@ script: print["command"] = "ams_filament_setting"; print["ams_id"] = 255; //TODO: support multiple AMS print["tray_id"] = 254; //TODO: support multiple trays - std::string color = id(filament_color_hex).state + "FF"; - print["tray_color"] = color; + if (id(filament_include_alpha).state == true){ + print["tray_color"] = id(filament_color_hexaa).state; + } + else{ + std::string color = id(filament_color_hex).state + "FF"; + print["tray_color"] = color; + } print["nozzle_temp_min"] = int8_t(id(filament_min_temp).state); print["nozzle_temp_max"] = int8_t(id(filament_max_temp).state); print["tray_type"] = id(filament_type).state.c_str(); diff --git a/firmware/conf.d/filament.yaml b/firmware/conf.d/filament.yaml index 712ebfb..7fce2c6 100644 --- a/firmware/conf.d/filament.yaml +++ b/firmware/conf.d/filament.yaml @@ -183,6 +183,30 @@ select: return ""; } - script.execute: preview_rfid_data +switch: + - platform: template + name: "Include alpha value in filament color" + id: filament_include_alpha + state_topic: + icon: "mdi:palette-outline" + optimistic: true + web_server: + sorting_group_id: sorting_group_filament_settings + sorting_weight: 70 + turn_on_action: + then: + - lambda: |- + id(filament_include_alpha).publish_state(true); + char hexStr[3]; + sprintf(hexStr, "%02X", (int)id(filament_alpha_int).state); + id(filament_alpha).publish_state(hexStr); + - script.execute: preview_rfid_data + turn_off_action: + then: + - lambda: |- + id(filament_include_alpha).publish_state(false); + id(filament_alpha).publish_state(""); + - script.execute: preview_rfid_data number: - platform: template name: "Filament Min Temp" @@ -231,6 +255,29 @@ number: on_value: then: - script.execute: preview_rfid_data +- platform: template + name: "Filament alpha value" + id: filament_alpha_int + state_topic: + min_value: 0 + max_value: 255 + initial_value: 255 + step: 5 + icon: mdi:palette-outline + optimistic: true + web_server: + sorting_group_id: sorting_group_filament_settings + sorting_weight: 90 + set_action: + then: + - lambda: |- + id(filament_alpha_int).publish_state(int(round(x))); + char hexStr[3]; + sprintf(hexStr, "%02X", (int)id(filament_alpha_int).state); + id(filament_alpha).publish_state(hexStr); + on_value: + then: + - script.execute: preview_rfid_data text_sensor: - platform: template name: "Filament Brand Code" @@ -240,20 +287,32 @@ text_sensor: web_server: sorting_group_id: sorting_group_filament_settings sorting_weight: 110 - on_value: - then: - - script.execute: preview_rfid_data + # on_value: #not needed? + # then: + # - script.execute: preview_rfid_data - platform: template name: "Filament Color Hex" id: filament_color_hex state_topic: icon: mdi:hexagon-outline + internal: true web_server: sorting_group_id: sorting_group_filament_settings sorting_weight: 100 - on_value: - then: - - script.execute: preview_rfid_data + # on_value: #not needed? + # then: + # - script.execute: preview_rfid_data +- platform: template + name: "Filament Color Hex" + id: filament_color_hexaa + state_topic: + icon: mdi:hexagon-outline + web_server: + sorting_group_id: sorting_group_filament_settings + sorting_weight: 105 + # on_value: #not needed? + # then: + # - script.execute: preview_rfid_data - platform: template name: Filament Sub Brand id: filament_sub_brand @@ -262,9 +321,15 @@ text_sensor: web_server: sorting_group_id: sorting_group_filament_settings sorting_weight: 120 - on_value: - then: - - script.execute: preview_rfid_data + # on_value: #not needed? + # then: + # - script.execute: preview_rfid_data +- platform: template + name: Filament alpha + id: filament_alpha + state_topic: + icon: mdi:label + internal: true button: - platform: template name: Upload Settings diff --git a/firmware/conf.d/pn532_rfid-solo.yaml b/firmware/conf.d/pn532_rfid-solo.yaml index c291669..4a11a4a 100644 --- a/firmware/conf.d/pn532_rfid-solo.yaml +++ b/firmware/conf.d/pn532_rfid-solo.yaml @@ -268,7 +268,12 @@ button: JsonObject root = doc.to(); root["version"] = "1.0"; root["protocol"] = "openspool"; - root["color_hex"] = id(filament_color_hex).state; + if (id(filament_include_alpha).state == true){ + root["color_hex"] = id(filament_color_hexaa).state; + } + else{ + root["color_hex"] = id(filament_color_hex).state; + } root["type"] = id(filament_type).state; root["min_temp"] = id(filament_min_temp).state; root["max_temp"] = id(filament_max_temp).state;