Skip to content

Commit

Permalink
Merge pull request #41 from raihei/main
Browse files Browse the repository at this point in the history
Allow creation of tags with filament color alpha channel value
  • Loading branch information
spuder authored Jan 29, 2025
2 parents 8e0f54d + 21af6d8 commit e8260b1
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 13 deletions.
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

0 comments on commit e8260b1

Please sign in to comment.