Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creation of tags with filament color alpha channel value #41

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions firmware/conf.d/automation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ 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<JsonObject>();

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();
Expand Down Expand Up @@ -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();
Expand Down
83 changes: 74 additions & 9 deletions firmware/conf.d/filament.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion firmware/conf.d/pn532_rfid-solo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,12 @@ button:
JsonObject root = doc.to<JsonObject>();
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;
Expand Down