@@ -129,7 +129,29 @@ void reverse_set(homekit_value_t value) {
129
129
130
130
homekit_characteristic_t reversed = HOMEKIT_CHARACTERISTIC_ (CUSTOM_REVERSED , 0 , .setter = reverse_set , .getter = reverse_get );
131
131
132
-
132
+ struct _report {
133
+ int position ;
134
+ int direction ;
135
+ //int data4;
136
+ int status ;
137
+ //int data6;
138
+ //int data7;
139
+ //int data8;
140
+ int calibr ;
141
+ } report ;
142
+
143
+ QueueHandle_t reportQueue = NULL ;
144
+ void report_track (void * pvParameters ){
145
+ struct _report rep ;
146
+ if ( reportQueue == 0 ) {LOG ("NO QUEUE!\n" );vTaskDelete (NULL );}
147
+ while (1 ) {
148
+ if ( xQueueReceive ( reportQueue , (void * )& rep , (TickType_t ) 100 ) ) {
149
+ //do things
150
+ LOG ("pos=%02x,dir=%02x,sta=%02x,cal=%02x\n" ,rep .position ,rep .direction ,rep .status ,rep .calibr );
151
+ }
152
+ //send a position request
153
+ }
154
+ }
133
155
134
156
void uart_send_output (void * pvParameters ){
135
157
int i ;
@@ -138,9 +160,9 @@ void uart_send_output(void *pvParameters){
138
160
char pause []= {0x55 ,0xfe ,0xfe ,0x03 ,0x03 ,0x38 ,0xe5 };
139
161
vTaskDelay (1000 ); //wait 10 seconds
140
162
while (1 ) {
141
- LOG (" open\n" );for (i = 0 ;i < 7 ;i ++ ) uart_putc (1 , open [i ]);uart_flush_txfifo (1 );vTaskDelay (500 );
142
- LOG ("close\n" );for (i = 0 ;i < 7 ;i ++ ) uart_putc (1 ,close [i ]);uart_flush_txfifo (1 );vTaskDelay (500 );
143
- LOG ("pause\n" );for (i = 0 ;i < 7 ;i ++ ) uart_putc (1 ,pause [i ]);uart_flush_txfifo (1 );vTaskDelay (500 );
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 );
144
166
}
145
167
}
146
168
@@ -162,6 +184,13 @@ void parse(int positions) {
162
184
else {
163
185
for (i = 3 ;i < positions - 2 ;i ++ ) LOG ("%02x" ,buff [i ]);
164
186
LOG ("\n" );
187
+ if (buff [3 ]== 0x04 && buff [4 ]== 0x02 && buff [5 ]== 0x08 ) {
188
+ report .position = buff [6 ];
189
+ report .direction = buff [7 ];
190
+ report .status = buff [9 ];
191
+ report .calibr = buff [13 ];
192
+ xQueueSend ( reportQueue , (void * ) & report , ( TickType_t ) 0 );
193
+ }
165
194
}
166
195
}
167
196
@@ -230,8 +259,9 @@ void motor_init() {
230
259
uart_set_baud (0 , 9600 );
231
260
232
261
xTaskCreate (uart_parse_input , "parse" , 256 , NULL , 1 , NULL );
233
- xTaskCreate (uart_send_output , "send" , 256 , NULL , 1 , NULL );
234
- //xTaskCreate(motor_loop_task, "loop", 512, NULL, 1, NULL);
262
+ reportQueue = xQueueCreate (3 , sizeof (struct _report ));
263
+ xTaskCreate (report_track , "track" , 512 , NULL , 2 , NULL );
264
+ //xTaskCreate(uart_send_output, "send", 256, NULL, 1, NULL);
235
265
}
236
266
237
267
homekit_value_t obstruction_get () {
0 commit comments