Skip to content

Commit b16b385

Browse files
authored
Matter add FanSpeed255 (#21638)
1 parent 2cf0eda commit b16b385

File tree

2 files changed

+108
-60
lines changed

2 files changed

+108
-60
lines changed

lib/libesp32/berry_matter/src/embedded/Matter_Plugin_2_Fan.be

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Matter_Plugin_Fan : Matter_Plugin_Device
3434
# 0x0005: inherited # Scenes 1.4 p.30 - no writable
3535
0x0202: [0,1,2,3], # Fan
3636
})
37-
static var UPDATE_COMMANDS = matter.UC_LIST(_class, "FanMode", "FanSpeed")
37+
static var UPDATE_COMMANDS = matter.UC_LIST(_class, "FanMode", "FanSpeed", "FanSpeed255")
3838
static var TYPES = { 0x002B: 2 } # Fan
3939

4040
# Inherited
@@ -156,7 +156,7 @@ class Matter_Plugin_Fan : Matter_Plugin_Device
156156
if attribute == 0x0000 # ---------- FanMode / enum8 ----------
157157
if type(write_data) == 'int'
158158
self.set_fan_mode(write_data)
159-
self.publish_command('FanMode', self.shadow_fan_mode, 'FanSpeed', self.shadow_fan_speed_pct)
159+
self.publish_command('FanMode', self.shadow_fan_mode, 'FanSpeed', self.shadow_fan_speed_pct, 'FanSpeed255', tasmota.scale_uint(self.shadow_fan_speed_pct, 0, 100, 0, 255))
160160
return true
161161
else
162162
ctx.status = matter.CONSTRAINT_ERROR
@@ -165,7 +165,7 @@ class Matter_Plugin_Fan : Matter_Plugin_Device
165165
elif attribute == 0x0002 # ---------- PercentSetting / enum8 ----------
166166
if type(write_data) == 'int'
167167
self.set_fan_speed_pct(write_data)
168-
self.publish_command('FanMode', self.shadow_fan_mode, 'FanSpeed', self.shadow_fan_speed_pct)
168+
self.publish_command('FanMode', self.shadow_fan_mode, 'FanSpeed', self.shadow_fan_speed_pct, 'FanSpeed255', tasmota.scale_uint(self.shadow_fan_speed_pct, 0, 100, 0, 255))
169169
return true
170170
else
171171
ctx.status = matter.CONSTRAINT_ERROR
@@ -187,6 +187,10 @@ class Matter_Plugin_Fan : Matter_Plugin_Device
187187
if val_fan_mode != nil
188188
self.set_fan_mode(int(val_fan_mode))
189189
end
190+
var val_fan_speed255 = payload.find("FanSpeed255")
191+
if val_fan_speed255 != nil
192+
self.set_fan_speed_pct(tasmota.scale_uint(int(val_fan_speed255), 0, 255, 0, 100))
193+
end
190194
var val_fan_speed = payload.find("FanSpeed")
191195
if val_fan_speed != nil
192196
self.set_fan_speed_pct(int(val_fan_speed))

lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_2_Fan.h

Lines changed: 101 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,28 @@ be_local_closure(class_Matter_Plugin_Fan_set_fan_mode, /* name */
9393
extern const bclass be_class_Matter_Plugin_Fan;
9494
be_local_closure(class_Matter_Plugin_Fan_update_virtual, /* name */
9595
be_nested_proto(
96-
8, /* nstack */
96+
13, /* nstack */
9797
2, /* argc */
9898
2, /* varg */
9999
0, /* has upvals */
100100
NULL, /* no upvals */
101101
0, /* has sup protos */
102102
&be_class_Matter_Plugin_Fan,
103103
1, /* has constants */
104-
( &(const bvalue[ 5]) { /* constants */
104+
( &(const bvalue[ 9]) { /* constants */
105105
/* K0 */ be_nested_str_weak(find),
106106
/* K1 */ be_nested_str_weak(FanMode),
107107
/* K2 */ be_nested_str_weak(set_fan_mode),
108-
/* K3 */ be_nested_str_weak(FanSpeed),
108+
/* K3 */ be_nested_str_weak(FanSpeed255),
109109
/* K4 */ be_nested_str_weak(set_fan_speed_pct),
110+
/* K5 */ be_nested_str_weak(tasmota),
111+
/* K6 */ be_nested_str_weak(scale_uint),
112+
/* K7 */ be_const_int(0),
113+
/* K8 */ be_nested_str_weak(FanSpeed),
110114
}),
111115
be_str_weak(update_virtual),
112116
&be_const_str_solidified,
113-
( &(const binstruction[23]) { /* code */
117+
( &(const binstruction[41]) { /* code */
114118
0x8C080300, // 0000 GETMET R2 R1 K0
115119
0x58100001, // 0001 LDCONST R4 K1
116120
0x7C080400, // 0002 CALL R2 2
@@ -127,13 +131,31 @@ be_local_closure(class_Matter_Plugin_Fan_update_virtual, /* name */
127131
0x7C0C0400, // 000D CALL R3 2
128132
0x4C100000, // 000E LDNIL R4
129133
0x20100604, // 000F NE R4 R3 R4
130-
0x78120004, // 0010 JMPF R4 #0016
134+
0x7812000B, // 0010 JMPF R4 #001D
131135
0x8C100104, // 0011 GETMET R4 R0 K4
132-
0x60180009, // 0012 GETGBL R6 G9
133-
0x5C1C0600, // 0013 MOVE R7 R3
134-
0x7C180200, // 0014 CALL R6 1
135-
0x7C100400, // 0015 CALL R4 2
136-
0x80000000, // 0016 RET 0
136+
0xB81A0A00, // 0012 GETNGBL R6 K5
137+
0x8C180D06, // 0013 GETMET R6 R6 K6
138+
0x60200009, // 0014 GETGBL R8 G9
139+
0x5C240600, // 0015 MOVE R9 R3
140+
0x7C200200, // 0016 CALL R8 1
141+
0x58240007, // 0017 LDCONST R9 K7
142+
0x542A00FE, // 0018 LDINT R10 255
143+
0x582C0007, // 0019 LDCONST R11 K7
144+
0x54320063, // 001A LDINT R12 100
145+
0x7C180C00, // 001B CALL R6 6
146+
0x7C100400, // 001C CALL R4 2
147+
0x8C100300, // 001D GETMET R4 R1 K0
148+
0x58180008, // 001E LDCONST R6 K8
149+
0x7C100400, // 001F CALL R4 2
150+
0x4C140000, // 0020 LDNIL R5
151+
0x20140805, // 0021 NE R5 R4 R5
152+
0x78160004, // 0022 JMPF R5 #0028
153+
0x8C140104, // 0023 GETMET R5 R0 K4
154+
0x601C0009, // 0024 GETGBL R7 G9
155+
0x5C200800, // 0025 MOVE R8 R4
156+
0x7C1C0200, // 0026 CALL R7 1
157+
0x7C140400, // 0027 CALL R5 2
158+
0x80000000, // 0028 RET 0
137159
})
138160
)
139161
);
@@ -222,15 +244,15 @@ be_local_closure(class_Matter_Plugin_Fan_set_fan_speed_pct, /* name */
222244
extern const bclass be_class_Matter_Plugin_Fan;
223245
be_local_closure(class_Matter_Plugin_Fan_write_attribute, /* name */
224246
be_nested_proto(
225-
13, /* nstack */
247+
21, /* nstack */
226248
4, /* argc */
227249
2, /* varg */
228250
0, /* has upvals */
229251
NULL, /* no upvals */
230252
0, /* has sup protos */
231253
&be_class_Matter_Plugin_Fan,
232254
1, /* has constants */
233-
( &(const bvalue[17]) { /* constants */
255+
( &(const bvalue[20]) { /* constants */
234256
/* K0 */ be_nested_str_weak(matter),
235257
/* K1 */ be_nested_str_weak(TLV),
236258
/* K2 */ be_nested_str_weak(cluster),
@@ -244,30 +266,33 @@ be_local_closure(class_Matter_Plugin_Fan_write_attribute, /* name */
244266
/* K10 */ be_nested_str_weak(shadow_fan_mode),
245267
/* K11 */ be_nested_str_weak(FanSpeed),
246268
/* K12 */ be_nested_str_weak(shadow_fan_speed_pct),
247-
/* K13 */ be_nested_str_weak(status),
248-
/* K14 */ be_nested_str_weak(CONSTRAINT_ERROR),
249-
/* K15 */ be_const_int(2),
250-
/* K16 */ be_nested_str_weak(set_fan_speed_pct),
269+
/* K13 */ be_nested_str_weak(FanSpeed255),
270+
/* K14 */ be_nested_str_weak(tasmota),
271+
/* K15 */ be_nested_str_weak(scale_uint),
272+
/* K16 */ be_nested_str_weak(status),
273+
/* K17 */ be_nested_str_weak(CONSTRAINT_ERROR),
274+
/* K18 */ be_const_int(2),
275+
/* K19 */ be_nested_str_weak(set_fan_speed_pct),
251276
}),
252277
be_str_weak(write_attribute),
253278
&be_const_str_solidified,
254-
( &(const binstruction[60]) { /* code */
279+
( &(const binstruction[78]) { /* code */
255280
0xB8120000, // 0000 GETNGBL R4 K0
256281
0x88100901, // 0001 GETMBR R4 R4 K1
257282
0x88140502, // 0002 GETMBR R5 R2 K2
258283
0x88180503, // 0003 GETMBR R6 R2 K3
259284
0x541E0201, // 0004 LDINT R7 514
260285
0x1C1C0A07, // 0005 EQ R7 R5 R7
261-
0x781E0032, // 0006 JMPF R7 #003A
286+
0x781E0044, // 0006 JMPF R7 #004C
262287
0x8C1C0104, // 0007 GETMET R7 R0 K4
263288
0x7C1C0200, // 0008 CALL R7 1
264289
0x1C1C0D05, // 0009 EQ R7 R6 K5
265-
0x781E0016, // 000A JMPF R7 #0022
290+
0x781E001F, // 000A JMPF R7 #002B
266291
0x601C0004, // 000B GETGBL R7 G4
267292
0x5C200600, // 000C MOVE R8 R3
268293
0x7C1C0200, // 000D CALL R7 1
269294
0x1C1C0F06, // 000E EQ R7 R7 K6
270-
0x781E000B, // 000F JMPF R7 #001C
295+
0x781E0014, // 000F JMPF R7 #0025
271296
0x8C1C0107, // 0010 GETMET R7 R0 K7
272297
0x5C240600, // 0011 MOVE R9 R3
273298
0x7C1C0400, // 0012 CALL R7 2
@@ -276,42 +301,60 @@ be_local_closure(class_Matter_Plugin_Fan_write_attribute, /* name */
276301
0x8828010A, // 0015 GETMBR R10 R0 K10
277302
0x582C000B, // 0016 LDCONST R11 K11
278303
0x8830010C, // 0017 GETMBR R12 R0 K12
279-
0x7C1C0A00, // 0018 CALL R7 5
280-
0x501C0200, // 0019 LDBOOL R7 1 0
281-
0x80040E00, // 001A RET 1 R7
282-
0x70020004, // 001B JMP #0021
283-
0xB81E0000, // 001C GETNGBL R7 K0
284-
0x881C0F0E, // 001D GETMBR R7 R7 K14
285-
0x900A1A07, // 001E SETMBR R2 K13 R7
286-
0x501C0000, // 001F LDBOOL R7 0 0
287-
0x80040E00, // 0020 RET 1 R7
288-
0x70020017, // 0021 JMP #003A
289-
0x1C1C0D0F, // 0022 EQ R7 R6 K15
290-
0x781E0015, // 0023 JMPF R7 #003A
291-
0x601C0004, // 0024 GETGBL R7 G4
292-
0x5C200600, // 0025 MOVE R8 R3
293-
0x7C1C0200, // 0026 CALL R7 1
294-
0x1C1C0F06, // 0027 EQ R7 R7 K6
295-
0x781E000B, // 0028 JMPF R7 #0035
296-
0x8C1C0110, // 0029 GETMET R7 R0 K16
297-
0x5C240600, // 002A MOVE R9 R3
298-
0x7C1C0400, // 002B CALL R7 2
299-
0x8C1C0108, // 002C GETMET R7 R0 K8
300-
0x58240009, // 002D LDCONST R9 K9
301-
0x8828010A, // 002E GETMBR R10 R0 K10
302-
0x582C000B, // 002F LDCONST R11 K11
303-
0x8830010C, // 0030 GETMBR R12 R0 K12
304-
0x7C1C0A00, // 0031 CALL R7 5
305-
0x501C0200, // 0032 LDBOOL R7 1 0
306-
0x80040E00, // 0033 RET 1 R7
307-
0x70020004, // 0034 JMP #003A
308-
0xB81E0000, // 0035 GETNGBL R7 K0
309-
0x881C0F0E, // 0036 GETMBR R7 R7 K14
310-
0x900A1A07, // 0037 SETMBR R2 K13 R7
311-
0x501C0000, // 0038 LDBOOL R7 0 0
312-
0x80040E00, // 0039 RET 1 R7
313-
0x4C1C0000, // 003A LDNIL R7
314-
0x80040E00, // 003B RET 1 R7
304+
0x5834000D, // 0018 LDCONST R13 K13
305+
0xB83A1C00, // 0019 GETNGBL R14 K14
306+
0x8C381D0F, // 001A GETMET R14 R14 K15
307+
0x8840010C, // 001B GETMBR R16 R0 K12
308+
0x58440005, // 001C LDCONST R17 K5
309+
0x544A0063, // 001D LDINT R18 100
310+
0x584C0005, // 001E LDCONST R19 K5
311+
0x545200FE, // 001F LDINT R20 255
312+
0x7C380C00, // 0020 CALL R14 6
313+
0x7C1C0E00, // 0021 CALL R7 7
314+
0x501C0200, // 0022 LDBOOL R7 1 0
315+
0x80040E00, // 0023 RET 1 R7
316+
0x70020004, // 0024 JMP #002A
317+
0xB81E0000, // 0025 GETNGBL R7 K0
318+
0x881C0F11, // 0026 GETMBR R7 R7 K17
319+
0x900A2007, // 0027 SETMBR R2 K16 R7
320+
0x501C0000, // 0028 LDBOOL R7 0 0
321+
0x80040E00, // 0029 RET 1 R7
322+
0x70020020, // 002A JMP #004C
323+
0x1C1C0D12, // 002B EQ R7 R6 K18
324+
0x781E001E, // 002C JMPF R7 #004C
325+
0x601C0004, // 002D GETGBL R7 G4
326+
0x5C200600, // 002E MOVE R8 R3
327+
0x7C1C0200, // 002F CALL R7 1
328+
0x1C1C0F06, // 0030 EQ R7 R7 K6
329+
0x781E0014, // 0031 JMPF R7 #0047
330+
0x8C1C0113, // 0032 GETMET R7 R0 K19
331+
0x5C240600, // 0033 MOVE R9 R3
332+
0x7C1C0400, // 0034 CALL R7 2
333+
0x8C1C0108, // 0035 GETMET R7 R0 K8
334+
0x58240009, // 0036 LDCONST R9 K9
335+
0x8828010A, // 0037 GETMBR R10 R0 K10
336+
0x582C000B, // 0038 LDCONST R11 K11
337+
0x8830010C, // 0039 GETMBR R12 R0 K12
338+
0x5834000D, // 003A LDCONST R13 K13
339+
0xB83A1C00, // 003B GETNGBL R14 K14
340+
0x8C381D0F, // 003C GETMET R14 R14 K15
341+
0x8840010C, // 003D GETMBR R16 R0 K12
342+
0x58440005, // 003E LDCONST R17 K5
343+
0x544A0063, // 003F LDINT R18 100
344+
0x584C0005, // 0040 LDCONST R19 K5
345+
0x545200FE, // 0041 LDINT R20 255
346+
0x7C380C00, // 0042 CALL R14 6
347+
0x7C1C0E00, // 0043 CALL R7 7
348+
0x501C0200, // 0044 LDBOOL R7 1 0
349+
0x80040E00, // 0045 RET 1 R7
350+
0x70020004, // 0046 JMP #004C
351+
0xB81E0000, // 0047 GETNGBL R7 K0
352+
0x881C0F11, // 0048 GETMBR R7 R7 K17
353+
0x900A2007, // 0049 SETMBR R2 K16 R7
354+
0x501C0000, // 004A LDBOOL R7 0 0
355+
0x80040E00, // 004B RET 1 R7
356+
0x4C1C0000, // 004C LDNIL R7
357+
0x80040E00, // 004D RET 1 R7
315358
})
316359
)
317360
);
@@ -459,10 +502,11 @@ be_local_class(Matter_Plugin_Fan,
459502
{ be_const_key_weak(read_attribute, 3), be_const_closure(class_Matter_Plugin_Fan_read_attribute_closure) },
460503
{ be_const_key_weak(TYPE, 0), be_nested_str_weak(fan) },
461504
{ be_const_key_weak(UPDATE_COMMANDS, -1), be_const_simple_instance(be_nested_simple_instance(&be_class_list, {
462-
be_const_list( * be_nested_list(2,
505+
be_const_list( * be_nested_list(3,
463506
( (struct bvalue*) &(const bvalue[]) {
464507
be_nested_str_weak(FanMode),
465508
be_nested_str_weak(FanSpeed),
509+
be_nested_str_weak(FanSpeed255),
466510
})) ) } )) },
467511
{ be_const_key_weak(shadow_fan_speed_pct, -1), be_const_var(1) },
468512
{ be_const_key_weak(set_fan_speed_pct, -1), be_const_closure(class_Matter_Plugin_Fan_set_fan_speed_pct_closure) },

0 commit comments

Comments
 (0)