@@ -49,7 +49,32 @@ 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 ,state = 2 ; //homekit values
52
+ int target = 0 ,current = 0 ; //homekit values
53
+
54
+ #define SEND (message ,n ,i ) do {LOG(#message "\n"); \
55
+ uart_putc(1,0x55);uart_putc(1,0xfe);uart_putc(1,0xfe); \
56
+ for (i=0;i<n;i++) uart_putc(1,_ ## message[i]); \
57
+ uart_flush_txfifo(1);\
58
+ } while(0)
59
+
60
+ char _open []= {0x03 ,0x01 ,0xb9 ,0x24 }; //n=4
61
+ char _close []= {0x03 ,0x02 ,0xf9 ,0x25 }; //n=4
62
+ char _pause []= {0x03 ,0x03 ,0x38 ,0xe5 }; //n=4
63
+ char _uncal []= {0x03 ,0x07 ,0x39 ,0x26 }; //n=4
64
+ char _reqpos []= {0x01 ,0x02 ,0x01 ,0x85 ,0x42 }; //n=5
65
+ char _reqdir []= {0x01 ,0x03 ,0x01 ,0x84 ,0xd2 }; //n=5
66
+ char _reqda4 []= {0x01 ,0x04 ,0x01 ,0x86 ,0xe2 }; //n=5
67
+ char _reqsta []= {0x01 ,0x05 ,0x01 ,0x87 ,0x72 }; //n=5
68
+ //6
69
+ //7
70
+ //8
71
+ char _reqda9 []= {0x01 ,0x09 ,0x01 ,0x82 ,0x72 }; //n=5
72
+ char _setdir0 []= {0x02 ,0x03 ,0x01 ,0x00 ,0xd2 ,0x27 }; //n=6
73
+ char _setdir1 []= {0x02 ,0x03 ,0x01 ,0x01 ,0x13 ,0xe7 }; //n=6
74
+
75
+ char _setpos00 [] = {0x03 ,0x04 ,0x00 ,0xe6 ,0xe2 }; //n=5
76
+ char _setpos50 [] = {0x03 ,0x04 ,0x32 ,0x67 ,0x37 }; //n=5
77
+ char _setpos100 []= {0x03 ,0x04 ,0x64 ,0xe7 ,0x09 }; //n=5
53
78
54
79
// add this section to make your device OTA capable
55
80
// create the extra characteristic &ota_trigger, at the end of the primary service (before the NULL)
@@ -69,6 +94,9 @@ homekit_characteristic_t revision = HOMEKIT_CHARACTERISTIC_(FIRMWARE_REVISIO
69
94
// config.accessories[0]->config_number=c_hash;
70
95
// end of OTA add-in instructions
71
96
97
+ homekit_characteristic_t state = HOMEKIT_CHARACTERISTIC_ (POSITION_STATE , 2 );
98
+
99
+
72
100
73
101
homekit_value_t calibrate_get () {
74
102
return HOMEKIT_BOOL (calibrate );
@@ -142,27 +170,18 @@ struct _report {
142
170
143
171
QueueHandle_t reportQueue = NULL ;
144
172
void report_track (void * pvParameters ){
173
+ int i ;
145
174
struct _report rep ;
146
175
if ( reportQueue == 0 ) {LOG ("NO QUEUE!\n" );vTaskDelete (NULL );}
147
176
while (1 ) {
148
177
if ( xQueueReceive ( reportQueue , (void * )& rep , (TickType_t ) 100 ) ) {
149
178
//do things
179
+ if (rep .status == 0 ){state .value .int_value = 2 ;homekit_characteristic_notify (& state ,HOMEKIT_UINT8 (state .value .int_value ));} //stopped
180
+ if (rep .status == 1 ){state .value .int_value = 0 ;homekit_characteristic_notify (& state ,HOMEKIT_UINT8 (state .value .int_value ));} //going min
181
+ if (rep .status == 2 ){state .value .int_value = 1 ;homekit_characteristic_notify (& state ,HOMEKIT_UINT8 (state .value .int_value ));} //going max
150
182
LOG ("pos=%02x,dir=%02x,sta=%02x,cal=%02x\n" ,rep .position ,rep .direction ,rep .status ,rep .calibr );
151
183
}
152
- //send a position request
153
- }
154
- }
155
-
156
- void uart_send_output (void * pvParameters ){
157
- int i ;
158
- char open []= {0x55 ,0xfe ,0xfe ,0x03 ,0x01 ,0xb9 ,0x24 };
159
- char close []= {0x55 ,0xfe ,0xfe ,0x03 ,0x02 ,0xf9 ,0x25 };
160
- char pause []= {0x55 ,0xfe ,0xfe ,0x03 ,0x03 ,0x38 ,0xe5 };
161
- vTaskDelay (1000 ); //wait 10 seconds
162
- while (1 ) {
163
- LOG (" open\n" );for (i = 0 ;i < 7 ;i ++ ) uart_putc (1 , open [i ]);uart_flush_txfifo (1 );vTaskDelay (1000 );
164
- LOG ("close\n" );for (i = 0 ;i < 7 ;i ++ ) uart_putc (1 ,close [i ]);uart_flush_txfifo (1 );vTaskDelay (1000 );
165
- LOG ("pause\n" );for (i = 0 ;i < 7 ;i ++ ) uart_putc (1 ,pause [i ]);uart_flush_txfifo (1 );vTaskDelay (1000 );
184
+ SEND (reqpos ,5 ,i );
166
185
}
167
186
}
168
187
@@ -310,20 +329,6 @@ void current_set(homekit_value_t value) {
310
329
changed = 1 ;
311
330
}
312
331
313
- homekit_value_t state_get () {
314
- return HOMEKIT_UINT8 (state );
315
- }
316
- void state_set (homekit_value_t value ) {
317
- if (value .format != homekit_format_uint8 ) {
318
- printf ("Invalid state-value format: %d\n" , value .format );
319
- return ;
320
- }
321
- //printf("S:%3d @ %d\n",value.int_value,sdk_system_get_time());
322
- printf ("S:%3d\n" ,value .int_value );
323
- state = value .int_value ;
324
- changed = 1 ;
325
- }
326
-
327
332
void identify_task (void * _args ) {
328
333
vTaskDelay (5000 / portTICK_PERIOD_MS ); //5 sec
329
334
vTaskDelete (NULL );
@@ -363,11 +368,7 @@ homekit_accessory_t *accessories[] = {
363
368
.getter = target_get ,
364
369
.setter = target_set
365
370
),
366
- HOMEKIT_CHARACTERISTIC (
367
- POSITION_STATE , 2 ,
368
- .getter = state_get ,
369
- .setter = state_set
370
- ),
371
+ & state ,
371
372
HOMEKIT_CHARACTERISTIC (
372
373
HOLD_POSITION , 0 ,
373
374
.getter = hold_get ,
0 commit comments