Skip to content

Commit 00f3671

Browse files
committed
Fix selected_slot and led selection
1 parent d482301 commit 00f3671

File tree

4 files changed

+41
-31
lines changed

4 files changed

+41
-31
lines changed

firmware/common-manual-ams.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ esphome:
6565
# id(my_ota).set_auth_password("New password");
6666
on_shutdown:
6767
then:
68-
- script.execute: set_leds_off
68+
- light.turn_off:
69+
id: neopixel_light
6970
esp32:
7071
framework:
7172
type: esp-idf

firmware/conf.d/bambu_ams.yaml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
globals:
2+
- id: selected_slot
3+
type: int
4+
restore_value: yes
5+
initial_value: "0"
6+
7+
script:
8+
- id: update_selected_slot
9+
then:
10+
- lambda: |-
11+
if (id(ams_number).state == 0) {
12+
id(selected_slot) = 0;
13+
} else {
14+
id(selected_slot) = (id(ams_number).state - 1) * 4 + id(slot_number).state;
15+
}
16+
- script.execute: update_leds
17+
118
number:
219
- platform: template
320
name: "Number of AMS units"
@@ -9,7 +26,6 @@ number:
926
max_value: 4
1027
step: 1
1128
initial_value: 1
12-
mode: box
1329
set_action:
1430
then:
1531
- lambda: |-
@@ -36,7 +52,6 @@ number:
3652
max_value: 4
3753
step: 1
3854
initial_value: 1
39-
mode: box
4055
set_action:
4156
then:
4257
- lambda: |-
@@ -49,10 +64,15 @@ number:
4964
id(ams_number).publish_state(x);
5065
}
5166
}
67+
- script.execute: update_selected_slot
5268
on_value:
5369
then:
5470
- lambda: |-
5571
ESP_LOGD("AMS", "AMS selected: %d", (int)x);
72+
// If AMS is 0, ensure slot is forced to 1
73+
if (x == 0 && id(slot_number).state != 1) {
74+
id(slot_number).publish_state(1);
75+
}
5676
web_server:
5777
sorting_group_id: sorting_group_ams
5878

@@ -75,9 +95,14 @@ number:
7595
} else {
7696
id(slot_number).publish_state(x);
7797
}
98+
- script.execute: update_selected_slot
7899
on_value:
79100
then:
80101
- lambda: |-
81102
ESP_LOGD("AMS", "Slot selected: %d", (int)x);
103+
// If AMS is 0, ensure slot is forced to 1
104+
if (id(ams_number).state == 0 && x != 1) {
105+
id(slot_number).publish_state(1);
106+
}
82107
web_server:
83108
sorting_group_id: sorting_group_ams

firmware/conf.d/led-external.yaml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,22 @@ light:
5252
# - state: FALSE
5353
# duration: 50ms
5454
script:
55+
- id: update_leds
56+
then:
57+
- lambda: |-
58+
// Clear all LEDs first
59+
for (int i = 0; i < 17; i++) {
60+
id(set_led_off).execute(i);
61+
}
62+
ESP_LOGD("LED", "LED index: %d", (int)id(selected_slot));
63+
//id(set_leds_off).execute();
64+
id(set_led_blue).execute(id(selected_slot));
5565
- id: set_led_red
5666
parameters:
5767
led_number: int8_t
5868
then:
5969
- light.addressable_set:
6070
id: neopixel_light
61-
color_brightness: 50%
6271
range_from: !lambda "return led_number < 0 ? 0 : led_number;"
6372
range_to: !lambda "return led_number < 0 ? ${led_count} : led_number;"
6473
red: 100%
@@ -70,7 +79,6 @@ script:
7079
then:
7180
- light.addressable_set:
7281
id: neopixel_light
73-
color_brightness: 50%
7482
range_from: !lambda "return led_number < 0 ? 0 : led_number;"
7583
range_to: !lambda "return led_number < 0 ? ${led_count} : led_number;"
7684
red: 0%
@@ -82,7 +90,6 @@ script:
8290
then:
8391
- light.addressable_set:
8492
id: neopixel_light
85-
color_brightness: 50%
8693
range_from: !lambda "return led_number < 0 ? 0 : led_number;"
8794
range_to: !lambda "return led_number < 0 ? ${led_count} : led_number;"
8895
red: 0%
@@ -94,7 +101,6 @@ script:
94101
then:
95102
- light.addressable_set:
96103
id: neopixel_light
97-
color_brightness: 50%
98104
range_from: !lambda "return led_number < 0 ? 0 : led_number;"
99105
range_to: !lambda "return led_number < 0 ? ${led_count} : led_number;"
100106
red: 0%
@@ -106,7 +112,6 @@ script:
106112
then:
107113
- light.addressable_set:
108114
id: neopixel_light
109-
color_brightness: 50%
110115
range_from: !lambda "return led_number < 0 ? 0 : led_number;"
111116
range_to: !lambda "return led_number < 0 ? ${led_count} : led_number;"
112117
red: 100%
@@ -118,7 +123,6 @@ script:
118123
then:
119124
- light.addressable_set:
120125
id: neopixel_light
121-
color_brightness: 50%
122126
range_from: !lambda "return led_number < 0 ? 0 : led_number;"
123127
range_to: !lambda "return led_number < 0 ? ${led_count} : led_number;"
124128
red: 100%
@@ -130,7 +134,6 @@ script:
130134
then:
131135
- light.addressable_set:
132136
id: neopixel_light
133-
color_brightness: 50%
134137
range_from: !lambda "return led_number < 0 ? 0 : led_number;"
135138
range_to: !lambda "return led_number < 0 ? ${led_count} : led_number;"
136139
red: 100%
@@ -152,7 +155,6 @@ script:
152155
- light.turn_on:
153156
id: neopixel_light
154157
effect: none
155-
brightness: 50%
156158
red: 100%
157159
green: 100%
158160
blue: 100%
@@ -174,16 +176,13 @@ script:
174176
- light.turn_on:
175177
id: neopixel_light
176178
effect: Breathing Blue
177-
brightness: 100%
178179
- id: set_led_breathing_green
179180
then:
180181
- light.turn_on:
181182
id: neopixel_light
182183
effect: Breathing Green
183-
brightness: 100%
184184
- id: set_led_apple_breathing
185185
then:
186186
- light.turn_on:
187187
id: neopixel_light
188188
effect: Apple Breathing
189-
brightness: 100%

firmware/conf.d/pn532_rfid-manual-ams.yaml

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,7 @@ substitutions:
33
spi_data_rate: 200kHz
44
update_interval: "750ms"
55

6-
globals:
7-
- id: selected_slot
8-
type: int
9-
restore_value: yes
10-
initial_value: "0"
11-
126
script:
13-
- id: update_leds
14-
then:
15-
- lambda: |-
16-
for (int i = 0; i < id(ams_units).state * 4; i++) {
17-
if (i == id(selected_slot)) {
18-
id(set_led_blue).execute(i);
19-
} else {
20-
id(set_led_off).execute(i);
21-
}
22-
}
237
- id: publish_filament_data_to_mqtt
248
parameters:
259
payload_data: string
@@ -79,7 +63,7 @@ sensor:
7963
} else {
8064
id(slot_number).publish_state(id(slot_number).state + 1);
8165
}
82-
- script.execute: update_leds
66+
- script.execute: update_selected_slot
8367
on_anticlockwise:
8468
then:
8569
- lambda: |-
@@ -94,6 +78,7 @@ sensor:
9478
}
9579
9680
- script.execute: update_leds
81+
- script.execute: update_selected_slot
9782

9883
binary_sensor:
9984
- platform: template

0 commit comments

Comments
 (0)