From 236a4695371f4b3c7f3211e04709e01aaa21dd98 Mon Sep 17 00:00:00 2001 From: HomeACcessoryKid Date: Sat, 27 Oct 2018 17:00:25 +0200 Subject: [PATCH] 0.0.3 SEND macro and state event --- main.c | 69 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/main.c b/main.c index faa301b..2b1714b 100644 --- a/main.c +++ b/main.c @@ -49,7 +49,32 @@ void log_send(void *pvParameters){ bool hold=0,calibrate=0,reverse=0,obstruction=0; bool changed=0; -int target=0,current=0,state=2; //homekit values +int target=0,current=0; //homekit values + +#define SEND(message,n,i) do {LOG(#message "\n"); \ + uart_putc(1,0x55);uart_putc(1,0xfe);uart_putc(1,0xfe); \ + for (i=0;iconfig_number=c_hash; // end of OTA add-in instructions +homekit_characteristic_t state = HOMEKIT_CHARACTERISTIC_(POSITION_STATE, 2); + + homekit_value_t calibrate_get() { return HOMEKIT_BOOL(calibrate); @@ -142,27 +170,18 @@ struct _report { QueueHandle_t reportQueue = NULL; void report_track(void *pvParameters){ + int i; struct _report rep; if( reportQueue == 0 ) {LOG("NO QUEUE!\n");vTaskDelete(NULL);} while(1) { if( xQueueReceive( reportQueue, (void*)&rep, (TickType_t) 100 ) ) { //do things + if (rep.status==0){state.value.int_value=2;homekit_characteristic_notify(&state,HOMEKIT_UINT8(state.value.int_value));} //stopped + if (rep.status==1){state.value.int_value=0;homekit_characteristic_notify(&state,HOMEKIT_UINT8(state.value.int_value));} //going min + if (rep.status==2){state.value.int_value=1;homekit_characteristic_notify(&state,HOMEKIT_UINT8(state.value.int_value));} //going max LOG("pos=%02x,dir=%02x,sta=%02x,cal=%02x\n",rep.position,rep.direction,rep.status,rep.calibr); } - //send a position request - } -} - -void uart_send_output(void *pvParameters){ - int i; - char open[]={0x55,0xfe,0xfe,0x03,0x01,0xb9,0x24}; - char close[]={0x55,0xfe,0xfe,0x03,0x02,0xf9,0x25}; - char pause[]={0x55,0xfe,0xfe,0x03,0x03,0x38,0xe5}; - vTaskDelay(1000); //wait 10 seconds - while(1) { - LOG(" open\n");for (i=0;i<7;i++) uart_putc(1, open[i]);uart_flush_txfifo(1);vTaskDelay(1000); - LOG("close\n");for (i=0;i<7;i++) uart_putc(1,close[i]);uart_flush_txfifo(1);vTaskDelay(1000); - LOG("pause\n");for (i=0;i<7;i++) uart_putc(1,pause[i]);uart_flush_txfifo(1);vTaskDelay(1000); + SEND(reqpos,5,i); } } @@ -310,20 +329,6 @@ void current_set(homekit_value_t value) { changed=1; } -homekit_value_t state_get() { - return HOMEKIT_UINT8(state); -} -void state_set(homekit_value_t value) { - if (value.format != homekit_format_uint8) { - printf("Invalid state-value format: %d\n", value.format); - return; - } - //printf("S:%3d @ %d\n",value.int_value,sdk_system_get_time()); - printf("S:%3d\n",value.int_value); - state = value.int_value; - changed=1; -} - void identify_task(void *_args) { vTaskDelay(5000 / portTICK_PERIOD_MS); //5 sec vTaskDelete(NULL); @@ -363,11 +368,7 @@ homekit_accessory_t *accessories[] = { .getter=target_get, .setter=target_set ), - HOMEKIT_CHARACTERISTIC( - POSITION_STATE, 2, - .getter=state_get, - .setter=state_set - ), + &state, HOMEKIT_CHARACTERISTIC( HOLD_POSITION, 0, .getter=hold_get,