Skip to content

Commit e8260b1

Browse files
authored
Merge pull request #41 from raihei/main
Allow creation of tags with filament color alpha channel value
2 parents 8e0f54d + 21af6d8 commit e8260b1

File tree

3 files changed

+94
-13
lines changed

3 files changed

+94
-13
lines changed

firmware/conf.d/automation.yaml

+14-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,20 @@ script:
55
- text_sensor.template.publish:
66
id: nfc_preview
77
state: !lambda |-
8+
id(filament_color_hexaa).publish_state(id(filament_color_hex).state + id(filament_alpha).state);
89
auto pretty_json = [=]() -> std::string {
910
StaticJsonDocument<256> doc;
1011
JsonObject root = doc.to<JsonObject>();
1112
1213
root["protocol"] = "openspool";
1314
root["version"] = "1.0";
1415
root["brand"] = id(filament_brand).state.c_str();
15-
root["color_hex"] = id(filament_color_hex).state.c_str();
16+
if (id(filament_include_alpha).state == true){
17+
root["color_hex"] = id(filament_color_hexaa).state.c_str();
18+
}
19+
else{
20+
root["color_hex"] = id(filament_color_hex).state.c_str();
21+
}
1622
root["min_temp"] = id(filament_min_temp).state;
1723
root["max_temp"] = id(filament_max_temp).state;
1824
root["type"] = id(filament_type).state.c_str();
@@ -95,8 +101,13 @@ script:
95101
print["command"] = "ams_filament_setting";
96102
print["ams_id"] = 255; //TODO: support multiple AMS
97103
print["tray_id"] = 254; //TODO: support multiple trays
98-
std::string color = id(filament_color_hex).state + "FF";
99-
print["tray_color"] = color;
104+
if (id(filament_include_alpha).state == true){
105+
print["tray_color"] = id(filament_color_hexaa).state;
106+
}
107+
else{
108+
std::string color = id(filament_color_hex).state + "FF";
109+
print["tray_color"] = color;
110+
}
100111
print["nozzle_temp_min"] = int8_t(id(filament_min_temp).state);
101112
print["nozzle_temp_max"] = int8_t(id(filament_max_temp).state);
102113
print["tray_type"] = id(filament_type).state.c_str();

firmware/conf.d/filament.yaml

+74-9
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,30 @@ select:
183183
return "";
184184
}
185185
- script.execute: preview_rfid_data
186+
switch:
187+
- platform: template
188+
name: "Include alpha value in filament color"
189+
id: filament_include_alpha
190+
state_topic:
191+
icon: "mdi:palette-outline"
192+
optimistic: true
193+
web_server:
194+
sorting_group_id: sorting_group_filament_settings
195+
sorting_weight: 70
196+
turn_on_action:
197+
then:
198+
- lambda: |-
199+
id(filament_include_alpha).publish_state(true);
200+
char hexStr[3];
201+
sprintf(hexStr, "%02X", (int)id(filament_alpha_int).state);
202+
id(filament_alpha).publish_state(hexStr);
203+
- script.execute: preview_rfid_data
204+
turn_off_action:
205+
then:
206+
- lambda: |-
207+
id(filament_include_alpha).publish_state(false);
208+
id(filament_alpha).publish_state("");
209+
- script.execute: preview_rfid_data
186210
number:
187211
- platform: template
188212
name: "Filament Min Temp"
@@ -231,6 +255,29 @@ number:
231255
on_value:
232256
then:
233257
- script.execute: preview_rfid_data
258+
- platform: template
259+
name: "Filament alpha value"
260+
id: filament_alpha_int
261+
state_topic:
262+
min_value: 0
263+
max_value: 255
264+
initial_value: 255
265+
step: 5
266+
icon: mdi:palette-outline
267+
optimistic: true
268+
web_server:
269+
sorting_group_id: sorting_group_filament_settings
270+
sorting_weight: 90
271+
set_action:
272+
then:
273+
- lambda: |-
274+
id(filament_alpha_int).publish_state(int(round(x)));
275+
char hexStr[3];
276+
sprintf(hexStr, "%02X", (int)id(filament_alpha_int).state);
277+
id(filament_alpha).publish_state(hexStr);
278+
on_value:
279+
then:
280+
- script.execute: preview_rfid_data
234281
text_sensor:
235282
- platform: template
236283
name: "Filament Brand Code"
@@ -240,20 +287,32 @@ text_sensor:
240287
web_server:
241288
sorting_group_id: sorting_group_filament_settings
242289
sorting_weight: 110
243-
on_value:
244-
then:
245-
- script.execute: preview_rfid_data
290+
# on_value: #not needed?
291+
# then:
292+
# - script.execute: preview_rfid_data
246293
- platform: template
247294
name: "Filament Color Hex"
248295
id: filament_color_hex
249296
state_topic:
250297
icon: mdi:hexagon-outline
298+
internal: true
251299
web_server:
252300
sorting_group_id: sorting_group_filament_settings
253301
sorting_weight: 100
254-
on_value:
255-
then:
256-
- script.execute: preview_rfid_data
302+
# on_value: #not needed?
303+
# then:
304+
# - script.execute: preview_rfid_data
305+
- platform: template
306+
name: "Filament Color Hex"
307+
id: filament_color_hexaa
308+
state_topic:
309+
icon: mdi:hexagon-outline
310+
web_server:
311+
sorting_group_id: sorting_group_filament_settings
312+
sorting_weight: 105
313+
# on_value: #not needed?
314+
# then:
315+
# - script.execute: preview_rfid_data
257316
- platform: template
258317
name: Filament Sub Brand
259318
id: filament_sub_brand
@@ -262,9 +321,15 @@ text_sensor:
262321
web_server:
263322
sorting_group_id: sorting_group_filament_settings
264323
sorting_weight: 120
265-
on_value:
266-
then:
267-
- script.execute: preview_rfid_data
324+
# on_value: #not needed?
325+
# then:
326+
# - script.execute: preview_rfid_data
327+
- platform: template
328+
name: Filament alpha
329+
id: filament_alpha
330+
state_topic:
331+
icon: mdi:label
332+
internal: true
268333
button:
269334
- platform: template
270335
name: Upload Settings

firmware/conf.d/pn532_rfid-solo.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,12 @@ button:
268268
JsonObject root = doc.to<JsonObject>();
269269
root["version"] = "1.0";
270270
root["protocol"] = "openspool";
271-
root["color_hex"] = id(filament_color_hex).state;
271+
if (id(filament_include_alpha).state == true){
272+
root["color_hex"] = id(filament_color_hexaa).state;
273+
}
274+
else{
275+
root["color_hex"] = id(filament_color_hex).state;
276+
}
272277
root["type"] = id(filament_type).state;
273278
root["min_temp"] = id(filament_min_temp).state;
274279
root["max_temp"] = id(filament_max_temp).state;

0 commit comments

Comments
 (0)