From 5c3a6d9170f56350fa867a2ed2ab8d7633733734 Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Tue, 6 Jun 2023 18:28:49 +0200 Subject: [PATCH] Matter fix illuminance (#18806) --- ...Matter_Plugin_Bridge_Sensor_Illuminance.be | 6 +++- .../Matter_Plugin_Sensor_Illuminance.be | 6 +++- ..._Matter_Plugin_Bridge_Sensor_Illuminance.h | 35 ++++++++++++------- ...idified_Matter_Plugin_Sensor_Illuminance.h | 35 ++++++++++++------- 4 files changed, 56 insertions(+), 26 deletions(-) diff --git a/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Bridge_Sensor_Illuminance.be b/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Bridge_Sensor_Illuminance.be index ff92f6fcc..d19d89a8f 100644 --- a/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Bridge_Sensor_Illuminance.be +++ b/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Bridge_Sensor_Illuminance.be @@ -50,7 +50,11 @@ class Matter_Plugin_Bridge_Sensor_Illuminance : Matter_Plugin_Bridge_Sensor # This must be overriden. # This allows to convert the raw sensor value to the target one, typically int def pre_value(val) - return val != nil ? int(val) : nil # value in lux + if val == nil return nil end + import math + + if val < 1 val = 1 end + return math.log10(val) * 10000 + 1 end ############################################################# diff --git a/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_Illuminance.be b/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_Illuminance.be index 0907b431b..c40b77f44 100644 --- a/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_Illuminance.be +++ b/lib/libesp32/berry_matter/src/embedded/Matter_Plugin_Sensor_Illuminance.be @@ -40,7 +40,11 @@ class Matter_Plugin_Sensor_Illuminance : Matter_Plugin_Sensor # This must be overriden. # This allows to convert the raw sensor value to the target one, typically int def pre_value(val) - return val != nil ? int(val) : nil # value in lux + if val == nil return nil end + import math + + if val < 1 val = 1 end + return math.log10(val) * 10000 + 1 end ############################################################# diff --git a/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Bridge_Sensor_Illuminance.h b/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Bridge_Sensor_Illuminance.h index 2db6b0396..56eb9dec2 100644 --- a/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Bridge_Sensor_Illuminance.h +++ b/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Bridge_Sensor_Illuminance.h @@ -11,27 +11,38 @@ extern const bclass be_class_Matter_Plugin_Bridge_Sensor_Illuminance; ********************************************************************/ be_local_closure(Matter_Plugin_Bridge_Sensor_Illuminance_pre_value, /* name */ be_nested_proto( - 4, /* nstack */ + 6, /* nstack */ 2, /* argc */ 2, /* varg */ 0, /* has upvals */ NULL, /* no upvals */ 0, /* has sup protos */ NULL, /* no sub protos */ - 0, /* has constants */ - NULL, /* no const */ + 1, /* has constants */ + ( &(const bvalue[ 3]) { /* constants */ + /* K0 */ be_nested_str_weak(math), + /* K1 */ be_const_int(1), + /* K2 */ be_nested_str_weak(log10), + }), be_str_weak(pre_value), &be_const_str_solidified, - ( &(const binstruction[ 9]) { /* code */ + ( &(const binstruction[16]) { /* code */ 0x4C080000, // 0000 LDNIL R2 - 0x20080202, // 0001 NE R2 R1 R2 - 0x780A0003, // 0002 JMPF R2 #0007 - 0x60080009, // 0003 GETGBL R2 G9 - 0x5C0C0200, // 0004 MOVE R3 R1 - 0x7C080200, // 0005 CALL R2 1 - 0x70020000, // 0006 JMP #0008 - 0x4C080000, // 0007 LDNIL R2 - 0x80040400, // 0008 RET 1 R2 + 0x1C080202, // 0001 EQ R2 R1 R2 + 0x780A0001, // 0002 JMPF R2 #0005 + 0x4C080000, // 0003 LDNIL R2 + 0x80040400, // 0004 RET 1 R2 + 0xA40A0000, // 0005 IMPORT R2 K0 + 0x140C0301, // 0006 LT R3 R1 K1 + 0x780E0000, // 0007 JMPF R3 #0009 + 0x58040001, // 0008 LDCONST R1 K1 + 0x8C0C0502, // 0009 GETMET R3 R2 K2 + 0x5C140200, // 000A MOVE R5 R1 + 0x7C0C0400, // 000B CALL R3 2 + 0x5412270F, // 000C LDINT R4 10000 + 0x080C0604, // 000D MUL R3 R3 R4 + 0x000C0701, // 000E ADD R3 R3 K1 + 0x80040600, // 000F RET 1 R3 }) ) ); diff --git a/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_Illuminance.h b/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_Illuminance.h index 99cba6068..ff0488cb6 100644 --- a/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_Illuminance.h +++ b/lib/libesp32/berry_matter/src/solidify/solidified_Matter_Plugin_Sensor_Illuminance.h @@ -121,27 +121,38 @@ be_local_closure(Matter_Plugin_Sensor_Illuminance_read_attribute, /* name */ ********************************************************************/ be_local_closure(Matter_Plugin_Sensor_Illuminance_pre_value, /* name */ be_nested_proto( - 4, /* nstack */ + 6, /* nstack */ 2, /* argc */ 2, /* varg */ 0, /* has upvals */ NULL, /* no upvals */ 0, /* has sup protos */ NULL, /* no sub protos */ - 0, /* has constants */ - NULL, /* no const */ + 1, /* has constants */ + ( &(const bvalue[ 3]) { /* constants */ + /* K0 */ be_nested_str_weak(math), + /* K1 */ be_const_int(1), + /* K2 */ be_nested_str_weak(log10), + }), be_str_weak(pre_value), &be_const_str_solidified, - ( &(const binstruction[ 9]) { /* code */ + ( &(const binstruction[16]) { /* code */ 0x4C080000, // 0000 LDNIL R2 - 0x20080202, // 0001 NE R2 R1 R2 - 0x780A0003, // 0002 JMPF R2 #0007 - 0x60080009, // 0003 GETGBL R2 G9 - 0x5C0C0200, // 0004 MOVE R3 R1 - 0x7C080200, // 0005 CALL R2 1 - 0x70020000, // 0006 JMP #0008 - 0x4C080000, // 0007 LDNIL R2 - 0x80040400, // 0008 RET 1 R2 + 0x1C080202, // 0001 EQ R2 R1 R2 + 0x780A0001, // 0002 JMPF R2 #0005 + 0x4C080000, // 0003 LDNIL R2 + 0x80040400, // 0004 RET 1 R2 + 0xA40A0000, // 0005 IMPORT R2 K0 + 0x140C0301, // 0006 LT R3 R1 K1 + 0x780E0000, // 0007 JMPF R3 #0009 + 0x58040001, // 0008 LDCONST R1 K1 + 0x8C0C0502, // 0009 GETMET R3 R2 K2 + 0x5C140200, // 000A MOVE R5 R1 + 0x7C0C0400, // 000B CALL R3 2 + 0x5412270F, // 000C LDINT R4 10000 + 0x080C0604, // 000D MUL R3 R3 R4 + 0x000C0701, // 000E ADD R3 R3 K1 + 0x80040600, // 000F RET 1 R3 }) ) );