Skip to content

Commit 712bf90

Browse files
0.0.4 test current PUSH
1 parent 236a469 commit 712bf90

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

main.c

+21-25
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void log_send(void *pvParameters){
4949

5050
bool hold=0,calibrate=0,reverse=0,obstruction=0;
5151
bool changed=0;
52-
int target=0,current=0; //homekit values
52+
int target=0; //homekit values
5353

5454
#define SEND(message,n,i) do {LOG(#message "\n"); \
5555
uart_putc(1,0x55);uart_putc(1,0xfe);uart_putc(1,0xfe); \
@@ -94,7 +94,8 @@ homekit_characteristic_t revision = HOMEKIT_CHARACTERISTIC_(FIRMWARE_REVISIO
9494
// config.accessories[0]->config_number=c_hash;
9595
// end of OTA add-in instructions
9696

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);
9899

99100

100101

@@ -170,16 +171,17 @@ struct _report {
170171

171172
QueueHandle_t reportQueue = NULL;
172173
void report_track(void *pvParameters){
173-
int i;
174+
int i,timer=1500;
174175
struct _report rep;
175176
if( reportQueue == 0 ) {LOG("NO QUEUE!\n");vTaskDelete(NULL);}
176177
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;
180180
if (rep.status==1){state.value.int_value=0;homekit_characteristic_notify(&state,HOMEKIT_UINT8(state.value.int_value));} //going min
181181
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
182183
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);
183185
}
184186
SEND(reqpos,5,i);
185187
}
@@ -199,6 +201,7 @@ void shift_buff(int positions) {
199201

200202
void parse(int positions) {
201203
int i=0;
204+
static int j=0; //remove, debug only
202205
if (positions<4) LOG("%02x%02x\n",buff[0],buff[1]);
203206
else {
204207
for (i=3;i<positions-2;i++) LOG("%02x",buff[i]);
@@ -210,6 +213,17 @@ void parse(int positions) {
210213
report.calibr=buff[13];
211214
xQueueSend( reportQueue, (void *) &report, ( TickType_t ) 0 );
212215
}
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+
}
213227
}
214228
}
215229

@@ -315,20 +329,6 @@ void target_set(homekit_value_t value) {
315329
changed=1;
316330
}
317331

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-
332332
void identify_task(void *_args) {
333333
vTaskDelay(5000 / portTICK_PERIOD_MS); //5 sec
334334
vTaskDelete(NULL);
@@ -358,11 +358,7 @@ homekit_accessory_t *accessories[] = {
358358
HOMEKIT_SERVICE(WINDOW_COVERING, .primary=true,
359359
.characteristics=(homekit_characteristic_t*[]){
360360
HOMEKIT_CHARACTERISTIC(NAME, "Curtain"),
361-
HOMEKIT_CHARACTERISTIC(
362-
CURRENT_POSITION, 0,
363-
.getter=current_get,
364-
.setter=current_set
365-
),
361+
&current,
366362
HOMEKIT_CHARACTERISTIC(
367363
TARGET_POSITION, 0,
368364
.getter=target_get,

0 commit comments

Comments
 (0)