@@ -140,6 +140,7 @@ main_config_t main_config = {
140
140
141
141
.clock_ready = false,
142
142
.timetable_ready = false,
143
+ .timetable_last_minute = 60,
143
144
144
145
//.used_gpio = 0,
145
146
@@ -821,9 +822,15 @@ void save_data_history(homekit_characteristic_t* ch_target) {
821
822
822
823
ch_group_t* ch_group = main_config.ch_groups;
823
824
while (ch_group) {
824
- if (ch_group->serv_type == SERV_TYPE_DATA_HISTORY && ch_group->ch[ch_group->chs - 1] == ch_target && ch_group->main_enabled) {
825
+ if (ch_group->serv_type == SERV_TYPE_DATA_HISTORY &&
826
+ ch_group_find_by_serv(HIST_SERVICE)->ch[HIST_CH] == ch_target &&
827
+ ch_group->main_enabled) {
825
828
float value = get_hkch_value(ch_target);
826
829
830
+ if (value != value) {
831
+ continue;
832
+ }
833
+
827
834
uint32_t final_time = time;
828
835
int32_t final_data = value * FLOAT_FACTOR_SAVE_AS_INT;
829
836
@@ -834,7 +841,7 @@ void save_data_history(homekit_characteristic_t* ch_target) {
834
841
uint32_t current_ch = last_register / HIST_BLOCK_SIZE;
835
842
uint32_t current_pos = last_register % HIST_BLOCK_SIZE;
836
843
837
- if (current_ch + 1 >= ch_group->chs) {
844
+ if (current_ch >= ch_group->chs) {
838
845
current_ch = 0;
839
846
current_pos = 0;
840
847
}
@@ -856,8 +863,8 @@ void save_data_history(homekit_characteristic_t* ch_target) {
856
863
}
857
864
858
865
void data_history_timer_worker(TimerHandle_t xTimer) {
859
- homekit_characteristic_t* ch = (homekit_characteristic_t *) pvTimerGetTimerID(xTimer);
860
- save_data_history(ch );
866
+ ch_group_t* ch_group = (ch_group_t *) pvTimerGetTimerID(xTimer);
867
+ save_data_history(ch_group_find_by_serv(HIST_SERVICE)->ch[HIST_CH] );
861
868
}
862
869
863
870
void wifi_resend_arp() {
@@ -986,7 +993,7 @@ void ntp_task() {
986
993
ch_group_t* ch_group = main_config.ch_groups;
987
994
while (ch_group) {
988
995
if (ch_group->serv_type == SERV_TYPE_DATA_HISTORY && ch_group->child_enabled) {
989
- save_data_history(ch_group ->ch[ch_group->chs - 1 ]);
996
+ save_data_history(ch_group_find_by_serv(HIST_SERVICE) ->ch[HIST_CH ]);
990
997
}
991
998
992
999
ch_group = ch_group->next;
@@ -1412,18 +1419,6 @@ void hkc_custom_setup_setter(homekit_characteristic_t* ch, const homekit_value_t
1412
1419
}
1413
1420
}
1414
1421
1415
- void hk_destroy_value_timer_worker(TimerHandle_t xTimer) {
1416
- homekit_value_t* value = (homekit_value_t*) pvTimerGetTimerID(xTimer);
1417
-
1418
- homekit_value_destruct(value);
1419
-
1420
- rs_esp_timer_delete(xTimer);
1421
- }
1422
-
1423
- void hk_destroy_value_delayed(homekit_value_t* value) {
1424
- rs_esp_timer_start_forced(rs_esp_timer_create(10000, pdTRUE, (void*) value, hk_destroy_value_timer_worker));
1425
- }
1426
-
1427
1422
void hkc_custom_setup_advanced_setter(homekit_characteristic_t* ch, const homekit_value_t value) {
1428
1423
value.data_value[value.data_size - 1] = 0;
1429
1424
char* string_value = (char*) value.data_value;
@@ -1445,14 +1440,13 @@ void hkc_custom_setup_advanced_setter(homekit_characteristic_t* ch, const homeki
1445
1440
}
1446
1441
1447
1442
if (selected_advanced_opt == 1) {
1443
+ homekit_value_destruct(&ch->value);
1448
1444
char* txt_config = NULL;
1449
1445
sysparam_get_string(HAA_SCRIPT_SYSPARAM, &txt_config);
1450
1446
if (txt_config) {
1451
- ch->value.data_size = strlen(txt_config);
1452
1447
ch->value.data_value = (uint8_t*) txt_config;
1448
+ ch->value.data_size = strlen(txt_config);
1453
1449
ch->value.is_null = false;
1454
-
1455
- hk_destroy_value_delayed(&ch->value);
1456
1450
}
1457
1451
1458
1452
} else if (selected_advanced_opt == 2 ||
@@ -5087,7 +5081,7 @@ void* force_alloc(const unsigned int len) {
5087
5081
unsigned int errors = 0;
5088
5082
void* new_char = NULL;
5089
5083
5090
- while (errors < ACTION_TASK_MAX_ERRORS ) {
5084
+ while (errors < FORCE_ALLOC_MAX_ERRORS ) {
5091
5085
new_char = malloc(len);
5092
5086
if (new_char) {
5093
5087
break;
@@ -7446,7 +7440,7 @@ void do_actions(ch_group_t* ch_group, uint8_t action) {
7446
7440
7447
7441
case SERV_TYPE_DATA_HISTORY:
7448
7442
//if (value_int == 0) {
7449
- save_data_history(ch_group ->ch[ch_group->chs - 1 ]);
7443
+ save_data_history(ch_group_find_by_serv(HIST_SERVICE) ->ch[HIST_CH ]);
7450
7444
//}
7451
7445
break;
7452
7446
@@ -7559,8 +7553,14 @@ void do_actions(ch_group_t* ch_group, uint8_t action) {
7559
7553
action_set_ch_t* action_set_ch = ch_group->action_set_ch;
7560
7554
while (action_set_ch) {
7561
7555
if (action_set_ch->action == action) {
7562
- INFO("<%i> SetCh %i.%i->%i.%i", ch_group->serv_index, action_set_ch->source_serv, action_set_ch->source_ch, action_set_ch->target_serv, action_set_ch->target_ch);
7563
- const float value = get_hkch_value(ch_group_find_by_serv(action_set_ch->source_serv)->ch[action_set_ch->source_ch]);
7556
+ INFO("<%i> SetCh %g.%i->%i.%i", ch_group->serv_index, action_set_ch->source_serv, action_set_ch->source_ch, action_set_ch->target_serv, action_set_ch->target_ch);
7557
+ float value;
7558
+ if (action_set_ch->source_ch < 15) {
7559
+ value = get_hkch_value(ch_group_find_by_serv(action_set_ch->source_serv)->ch[action_set_ch->source_ch]);
7560
+ } else {
7561
+ value = action_set_ch->source_serv;
7562
+ }
7563
+
7564
7564
set_hkch_value(ch_group_find_by_serv(action_set_ch->target_serv)->ch[action_set_ch->target_ch], value);
7565
7565
}
7566
7566
@@ -7681,6 +7681,12 @@ void timetable_actions_timer_worker(TimerHandle_t xTimer) {
7681
7681
}
7682
7682
}
7683
7683
7684
+ if (main_config.timetable_last_minute == timeinfo->tm_min) {
7685
+ return;
7686
+ }
7687
+
7688
+ main_config.timetable_last_minute = timeinfo->tm_min;
7689
+
7684
7690
ch_group_t* ch_group = ch_group_find_by_serv(SERV_TYPE_ROOT_DEVICE);
7685
7691
7686
7692
if (ch_group->main_enabled) {
@@ -8246,29 +8252,33 @@ void normal_mode_init() {
8246
8252
last_action = action_set_ch;
8247
8253
8248
8254
cJSON_rsf* json_set_ch = cJSON_rsf_GetArrayItem(json_set_chs, i);
8249
- for (unsigned int j = 0 ; j < 4 ; j++ ) {
8250
- const int value = (int16_t) cJSON_rsf_GetArrayItem(json_set_ch, j)->valuefloat;
8255
+ for (int j = 3 ; j >= 0 ; j-- ) {
8256
+ const float value = cJSON_rsf_GetArrayItem(json_set_ch, j)->valuefloat;
8251
8257
8252
8258
switch (j) {
8253
- case 0:
8254
- action_set_ch->source_serv = get_absolut_index(ch_group->serv_index, value);
8255
- break;
8256
-
8257
- case 1:
8258
- action_set_ch->source_ch = value;
8259
+ case 3:
8260
+ action_set_ch->target_ch = value;
8259
8261
break;
8260
8262
8261
8263
case 2:
8262
8264
action_set_ch->target_serv = get_absolut_index(ch_group->serv_index, value);
8263
8265
break;
8264
8266
8265
- case 3:
8266
- action_set_ch->target_ch = value;
8267
+ case 1:
8268
+ action_set_ch->source_ch = value;
8269
+ break;
8270
+
8271
+ case 0:
8272
+ if (action_set_ch->source_ch < 15) {
8273
+ action_set_ch->source_serv = get_absolut_index(ch_group->serv_index, value);
8274
+ } else {
8275
+ action_set_ch->source_serv = value;
8276
+ }
8267
8277
break;
8268
8278
}
8269
8279
}
8270
8280
8271
- INFO("A%i SetCh %i .%i->%i.%i", new_int_action, action_set_ch->source_serv, action_set_ch->source_ch, action_set_ch->target_serv, action_set_ch->target_ch);
8281
+ INFO("A%i SetCh %g .%i->%i.%i", new_int_action, action_set_ch->source_serv, action_set_ch->source_ch, action_set_ch->target_serv, action_set_ch->target_ch);
8272
8282
}
8273
8283
}
8274
8284
}
@@ -12908,17 +12918,20 @@ void normal_mode_init() {
12908
12918
void new_data_history(const uint16_t accessory, uint16_t service, const uint16_t total_services, cJSON_rsf* json_context) {
12909
12919
cJSON_rsf* data_array = cJSON_rsf_GetObjectItemCaseSensitive(json_context, HIST_DATA_ARRAY_SET);
12910
12920
12911
- const unsigned int hist_accessory = get_absolut_index(service_numerator, cJSON_rsf_GetArrayItem(data_array, 0)->valuefloat);
12921
+ const unsigned int hist_service = get_absolut_index(service_numerator, cJSON_rsf_GetArrayItem(data_array, 0)->valuefloat);
12912
12922
const unsigned int hist_ch = cJSON_rsf_GetArrayItem(data_array, 1)->valuefloat;
12913
12923
const unsigned int hist_size = cJSON_rsf_GetArrayItem(data_array, 2)->valuefloat;
12914
12924
12915
- INFO("Serv %i, Ch %i, Size %i", hist_accessory , hist_ch, hist_size * HIST_REGISTERS_BY_BLOCK);
12925
+ INFO("Serv %i, Ch %i, Size %i", hist_service , hist_ch, hist_size * HIST_REGISTERS_BY_BLOCK);
12916
12926
12917
- ch_group_t* ch_group = new_ch_group(hist_size + 1, 0, 1 , 0);
12927
+ ch_group_t* ch_group = new_ch_group(hist_size, 1, 2 , 0);
12918
12928
ch_group->serv_type = SERV_TYPE_DATA_HISTORY;
12919
12929
ch_group->serv_index = service_numerator;
12920
12930
ch_group->homekit_enabled = true;
12921
12931
12932
+ HIST_SERVICE = hist_service;
12933
+ HIST_CH = hist_ch;
12934
+
12922
12935
if (cJSON_rsf_GetObjectItemCaseSensitive(json_context, HIST_READ_ON_CLOCK_READY_SET) != NULL) {
12923
12936
ch_group->child_enabled = (bool) cJSON_rsf_GetObjectItemCaseSensitive(json_context, HIST_READ_ON_CLOCK_READY_SET)->valuefloat;
12924
12937
}
@@ -12929,8 +12942,6 @@ void normal_mode_init() {
12929
12942
12930
12943
service++;
12931
12944
12932
- ch_group->ch[hist_size] = ch_group_find_by_serv(hist_accessory)->ch[hist_ch];
12933
-
12934
12945
accessories[accessory]->services[service] = calloc(1, sizeof(homekit_service_t));
12935
12946
accessories[accessory]->services[service]->id = ((service - 1) * 50) + 8;
12936
12947
//accessories[accessory]->services[service]->id = service_iid;
@@ -12965,7 +12976,7 @@ void normal_mode_init() {
12965
12976
12966
12977
const float poll_period = sensor_poll_period(json_context, 0);
12967
12978
if (poll_period > 0.f) {
12968
- rs_esp_timer_start_forced(rs_esp_timer_create(poll_period * 1000, pdTRUE, (void*) ch_group->ch[hist_size] , data_history_timer_worker));
12979
+ rs_esp_timer_start_forced(rs_esp_timer_create(poll_period * 1000, pdTRUE, (void*) ch_group, data_history_timer_worker));
12969
12980
}
12970
12981
12971
12982
set_killswitch(ch_group, json_context);
0 commit comments