@@ -49,7 +49,7 @@ void log_send(void *pvParameters){
49
49
50
50
bool hold = 0 ,calibrate = 0 ,reverse = 0 ,obstruction = 0 ;
51
51
bool changed = 0 ;
52
- int target = 0 , current = 0 ; //homekit values
52
+ int target = 0 ; //homekit values
53
53
54
54
#define SEND (message ,n ,i ) do {LOG(#message "\n"); \
55
55
uart_putc(1,0x55);uart_putc(1,0xfe);uart_putc(1,0xfe); \
@@ -94,7 +94,8 @@ homekit_characteristic_t revision = HOMEKIT_CHARACTERISTIC_(FIRMWARE_REVISIO
94
94
// config.accessories[0]->config_number=c_hash;
95
95
// end of OTA add-in instructions
96
96
97
- homekit_characteristic_t state = HOMEKIT_CHARACTERISTIC_ (POSITION_STATE , 2 );
97
+ homekit_characteristic_t state = HOMEKIT_CHARACTERISTIC_ (POSITION_STATE , 2 );
98
+ homekit_characteristic_t current = HOMEKIT_CHARACTERISTIC_ (CURRENT_POSITION , 0 );
98
99
99
100
100
101
@@ -170,16 +171,17 @@ struct _report {
170
171
171
172
QueueHandle_t reportQueue = NULL ;
172
173
void report_track (void * pvParameters ){
173
- int i ;
174
+ int i , timer = 1500 ;
174
175
struct _report rep ;
175
176
if ( reportQueue == 0 ) {LOG ("NO QUEUE!\n" );vTaskDelete (NULL );}
176
177
while (1 ) {
177
- if ( xQueueReceive ( reportQueue , (void * )& rep , (TickType_t ) 100 ) ) {
178
- //do things
179
- if (rep .status == 0 ){state .value .int_value = 2 ;homekit_characteristic_notify (& state ,HOMEKIT_UINT8 (state .value .int_value ));} //stopped
178
+ if ( xQueueReceive ( reportQueue , (void * )& rep , (TickType_t ) timer ) ) {
179
+ timer = 100 ;
180
180
if (rep .status == 1 ){state .value .int_value = 0 ;homekit_characteristic_notify (& state ,HOMEKIT_UINT8 (state .value .int_value ));} //going min
181
181
if (rep .status == 2 ){state .value .int_value = 1 ;homekit_characteristic_notify (& state ,HOMEKIT_UINT8 (state .value .int_value ));} //going max
182
+ if (rep .status == 0 ){state .value .int_value = 2 ;homekit_characteristic_notify (& state ,HOMEKIT_UINT8 (state .value .int_value ));timer = 1500 ;} //stopped
182
183
LOG ("pos=%02x,dir=%02x,sta=%02x,cal=%02x\n" ,rep .position ,rep .direction ,rep .status ,rep .calibr );
184
+ LOG ("state: %d\n" ,state .value .int_value );
183
185
}
184
186
SEND (reqpos ,5 ,i );
185
187
}
@@ -199,6 +201,7 @@ void shift_buff(int positions) {
199
201
200
202
void parse (int positions ) {
201
203
int i = 0 ;
204
+ static int j = 0 ; //remove, debug only
202
205
if (positions < 4 ) LOG ("%02x%02x\n" ,buff [0 ],buff [1 ]);
203
206
else {
204
207
for (i = 3 ;i < positions - 2 ;i ++ ) LOG ("%02x" ,buff [i ]);
@@ -210,6 +213,17 @@ void parse(int positions) {
210
213
report .calibr = buff [13 ];
211
214
xQueueSend ( reportQueue , (void * ) & report , ( TickType_t ) 0 );
212
215
}
216
+ if (buff [3 ]== 0x01 && buff [4 ]== 0x02 && buff [5 ]== 0x01 ) {
217
+ if (buff [6 ]== 0xff ){
218
+ current .value .int_value = j ++ ;
219
+ homekit_characteristic_notify (& current ,HOMEKIT_UINT8 (current .value .int_value ));
220
+ LOG ("current: %d\n" ,current .value .int_value );
221
+ }
222
+ else {
223
+ current .value .int_value = buff [6 ];
224
+ homekit_characteristic_notify (& current ,HOMEKIT_UINT8 (current .value .int_value ));
225
+ }
226
+ }
213
227
}
214
228
}
215
229
@@ -315,20 +329,6 @@ void target_set(homekit_value_t value) {
315
329
changed = 1 ;
316
330
}
317
331
318
- homekit_value_t current_get () {
319
- return HOMEKIT_UINT8 (current );
320
- }
321
- void current_set (homekit_value_t value ) {
322
- if (value .format != homekit_format_uint8 ) {
323
- printf ("Invalid current-value format: %d\n" , value .format );
324
- return ;
325
- }
326
- //printf("C:%3d @ %d\n",value.int_value,sdk_system_get_time());
327
- printf ("C:%3d\n" ,value .int_value );
328
- current = value .int_value ;
329
- changed = 1 ;
330
- }
331
-
332
332
void identify_task (void * _args ) {
333
333
vTaskDelay (5000 / portTICK_PERIOD_MS ); //5 sec
334
334
vTaskDelete (NULL );
@@ -358,11 +358,7 @@ homekit_accessory_t *accessories[] = {
358
358
HOMEKIT_SERVICE (WINDOW_COVERING , .primary = true,
359
359
.characteristics = (homekit_characteristic_t * []){
360
360
HOMEKIT_CHARACTERISTIC (NAME , "Curtain" ),
361
- HOMEKIT_CHARACTERISTIC (
362
- CURRENT_POSITION , 0 ,
363
- .getter = current_get ,
364
- .setter = current_set
365
- ),
361
+ & current ,
366
362
HOMEKIT_CHARACTERISTIC (
367
363
TARGET_POSITION , 0 ,
368
364
.getter = target_get ,
0 commit comments