Skip to content

Commit 2e29bc1

Browse files
committed
Home Accessory Architect v12.14.13 Merlin
1 parent 95b21e3 commit 2e29bc1

File tree

4 files changed

+70
-57
lines changed

4 files changed

+70
-57
lines changed

HAA/HAA_Installer/main/header.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
#include "../../common/common_headers.h"
1212

1313
#define INSTALLER_BETA_REVISION "" // Format: "b01"
14-
#define INSTALLER_VERSION "7.12.7"INSTALLER_BETA_REVISION
14+
#define INSTALLER_VERSION "7.12.8"INSTALLER_BETA_REVISION
1515

1616
#endif // __HAA_OTA_HEADER_H__

HAA/HAA_Main/main/header.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "../../common/common_headers.h"
1212

1313
// Version
14-
#define HAA_FIRMWARE_VERSION "12.14.12"
14+
#define HAA_FIRMWARE_VERSION "12.14.13"
1515
#define HAA_FIRMWARE_BETA_REVISION "" // Format: "b01"
1616
#define HAA_FIRMWARE_CODENAME "Merlin"
1717

@@ -663,6 +663,8 @@
663663
#define HIST_DATA_ARRAY_SET "h"
664664
#define HIST_READ_ON_CLOCK_READY_SET "x"
665665
#define HIST_LAST_REGISTER ch_group->num_f[0]
666+
#define HIST_SERVICE ch_group->num_f[1]
667+
#define HIST_CH ch_group->num_i[0]
666668
#define HIST_TIME_SIZE (4) // (sizeof(uint32_t))
667669
#define HIST_DATA_SIZE (4) // (sizeof(int32_t))
668670
#define HIST_REGISTER_SIZE (HIST_TIME_SIZE + HIST_DATA_SIZE)
@@ -791,16 +793,13 @@
791793
#define SETUP_MODE_ACTIVATE_COUNT "z"
792794
#define SETUP_MODE_DEFAULT_ACTIVATE_COUNT (8)
793795
#define SETUP_MODE_TOGGLE_TIME_MS (1050)
794-
#define CUSTOM_HAA_COMMAND "ks"
796+
#define CUSTOM_HAA_COMMAND "mc"
795797
#define CUSTOM_HAA_ADVANCED_COMMAND_LEN (2)
796798
#define HAA_SETUP_ACCESSORY_SET "s"
797799

798800
#define IRRF_CAPTURE_BUFFER_SIZE (2048)
799801

800-
#define ACTION_TASK_TYPE_UART (0)
801-
#define ACTION_TASK_TYPE_NETWORK (1)
802-
#define ACTION_TASK_TYPE_IRRF (2)
803-
#define ACTION_TASK_MAX_ERRORS (10)
802+
#define FORCE_ALLOC_MAX_ERRORS (10)
804803

805804
#define SAVE_STATES_TIMER ch_group_find_by_serv(SERV_TYPE_ROOT_DEVICE)->timer
806805
#define WIFI_WATCHDOG_TIMER ch_group_find_by_serv(SERV_TYPE_ROOT_DEVICE)->timer2

HAA/HAA_Main/main/main.c

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ main_config_t main_config = {
140140

141141
.clock_ready = false,
142142
.timetable_ready = false,
143+
.timetable_last_minute = 60,
143144

144145
//.used_gpio = 0,
145146

@@ -821,9 +822,15 @@ void save_data_history(homekit_characteristic_t* ch_target) {
821822

822823
ch_group_t* ch_group = main_config.ch_groups;
823824
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) {
825828
float value = get_hkch_value(ch_target);
826829

830+
if (value != value) {
831+
continue;
832+
}
833+
827834
uint32_t final_time = time;
828835
int32_t final_data = value * FLOAT_FACTOR_SAVE_AS_INT;
829836

@@ -834,7 +841,7 @@ void save_data_history(homekit_characteristic_t* ch_target) {
834841
uint32_t current_ch = last_register / HIST_BLOCK_SIZE;
835842
uint32_t current_pos = last_register % HIST_BLOCK_SIZE;
836843

837-
if (current_ch + 1 >= ch_group->chs) {
844+
if (current_ch >= ch_group->chs) {
838845
current_ch = 0;
839846
current_pos = 0;
840847
}
@@ -856,8 +863,8 @@ void save_data_history(homekit_characteristic_t* ch_target) {
856863
}
857864

858865
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]);
861868
}
862869

863870
void wifi_resend_arp() {
@@ -986,7 +993,7 @@ void ntp_task() {
986993
ch_group_t* ch_group = main_config.ch_groups;
987994
while (ch_group) {
988995
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]);
990997
}
991998

992999
ch_group = ch_group->next;
@@ -1412,18 +1419,6 @@ void hkc_custom_setup_setter(homekit_characteristic_t* ch, const homekit_value_t
14121419
}
14131420
}
14141421

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-
14271422
void hkc_custom_setup_advanced_setter(homekit_characteristic_t* ch, const homekit_value_t value) {
14281423
value.data_value[value.data_size - 1] = 0;
14291424
char* string_value = (char*) value.data_value;
@@ -1445,14 +1440,13 @@ void hkc_custom_setup_advanced_setter(homekit_characteristic_t* ch, const homeki
14451440
}
14461441

14471442
if (selected_advanced_opt == 1) {
1443+
homekit_value_destruct(&ch->value);
14481444
char* txt_config = NULL;
14491445
sysparam_get_string(HAA_SCRIPT_SYSPARAM, &txt_config);
14501446
if (txt_config) {
1451-
ch->value.data_size = strlen(txt_config);
14521447
ch->value.data_value = (uint8_t*) txt_config;
1448+
ch->value.data_size = strlen(txt_config);
14531449
ch->value.is_null = false;
1454-
1455-
hk_destroy_value_delayed(&ch->value);
14561450
}
14571451

14581452
} else if (selected_advanced_opt == 2 ||
@@ -5087,7 +5081,7 @@ void* force_alloc(const unsigned int len) {
50875081
unsigned int errors = 0;
50885082
void* new_char = NULL;
50895083

5090-
while (errors < ACTION_TASK_MAX_ERRORS) {
5084+
while (errors < FORCE_ALLOC_MAX_ERRORS) {
50915085
new_char = malloc(len);
50925086
if (new_char) {
50935087
break;
@@ -7446,7 +7440,7 @@ void do_actions(ch_group_t* ch_group, uint8_t action) {
74467440

74477441
case SERV_TYPE_DATA_HISTORY:
74487442
//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]);
74507444
//}
74517445
break;
74527446

@@ -7559,8 +7553,14 @@ void do_actions(ch_group_t* ch_group, uint8_t action) {
75597553
action_set_ch_t* action_set_ch = ch_group->action_set_ch;
75607554
while (action_set_ch) {
75617555
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+
75647564
set_hkch_value(ch_group_find_by_serv(action_set_ch->target_serv)->ch[action_set_ch->target_ch], value);
75657565
}
75667566

@@ -7681,6 +7681,12 @@ void timetable_actions_timer_worker(TimerHandle_t xTimer) {
76817681
}
76827682
}
76837683

7684+
if (main_config.timetable_last_minute == timeinfo->tm_min) {
7685+
return;
7686+
}
7687+
7688+
main_config.timetable_last_minute = timeinfo->tm_min;
7689+
76847690
ch_group_t* ch_group = ch_group_find_by_serv(SERV_TYPE_ROOT_DEVICE);
76857691

76867692
if (ch_group->main_enabled) {
@@ -8246,29 +8252,33 @@ void normal_mode_init() {
82468252
last_action = action_set_ch;
82478253

82488254
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;
82518257

82528258
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;
82598261
break;
82608262

82618263
case 2:
82628264
action_set_ch->target_serv = get_absolut_index(ch_group->serv_index, value);
82638265
break;
82648266

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+
}
82678277
break;
82688278
}
82698279
}
82708280

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);
82728282
}
82738283
}
82748284
}
@@ -12908,17 +12918,20 @@ void normal_mode_init() {
1290812918
void new_data_history(const uint16_t accessory, uint16_t service, const uint16_t total_services, cJSON_rsf* json_context) {
1290912919
cJSON_rsf* data_array = cJSON_rsf_GetObjectItemCaseSensitive(json_context, HIST_DATA_ARRAY_SET);
1291012920

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);
1291212922
const unsigned int hist_ch = cJSON_rsf_GetArrayItem(data_array, 1)->valuefloat;
1291312923
const unsigned int hist_size = cJSON_rsf_GetArrayItem(data_array, 2)->valuefloat;
1291412924

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

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);
1291812928
ch_group->serv_type = SERV_TYPE_DATA_HISTORY;
1291912929
ch_group->serv_index = service_numerator;
1292012930
ch_group->homekit_enabled = true;
1292112931

12932+
HIST_SERVICE = hist_service;
12933+
HIST_CH = hist_ch;
12934+
1292212935
if (cJSON_rsf_GetObjectItemCaseSensitive(json_context, HIST_READ_ON_CLOCK_READY_SET) != NULL) {
1292312936
ch_group->child_enabled = (bool) cJSON_rsf_GetObjectItemCaseSensitive(json_context, HIST_READ_ON_CLOCK_READY_SET)->valuefloat;
1292412937
}
@@ -12929,8 +12942,6 @@ void normal_mode_init() {
1292912942

1293012943
service++;
1293112944

12932-
ch_group->ch[hist_size] = ch_group_find_by_serv(hist_accessory)->ch[hist_ch];
12933-
1293412945
accessories[accessory]->services[service] = calloc(1, sizeof(homekit_service_t));
1293512946
accessories[accessory]->services[service]->id = ((service - 1) * 50) + 8;
1293612947
//accessories[accessory]->services[service]->id = service_iid;
@@ -12965,7 +12976,7 @@ void normal_mode_init() {
1296512976

1296612977
const float poll_period = sensor_poll_period(json_context, 0);
1296712978
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));
1296912980
}
1297012981

1297112982
set_killswitch(ch_group, json_context);

HAA/HAA_Main/main/types.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,19 +136,21 @@ typedef struct _action_pwm {
136136
typedef struct _action_set_ch {
137137
uint8_t action;
138138

139-
uint8_t source_ch;
140-
uint8_t target_ch;
139+
uint8_t source_ch: 4;
140+
uint8_t target_ch: 4;
141141

142-
uint16_t source_serv;
143142
uint16_t target_serv;
144143

144+
float source_serv;
145+
145146
struct _action_set_ch* next;
146147
} action_set_ch_t;
147148

148149
typedef struct _wildcard_action {
149150
uint8_t index;
150151
uint8_t target_action;
151152
bool repeat; // 1 bit
153+
152154
float value;
153155

154156
struct _wildcard_action* next;
@@ -366,11 +368,11 @@ typedef struct _pwmh_channel {
366368
#endif
367369

368370
typedef struct _main_config {
369-
uint8_t wifi_status: 2;
370-
uint8_t wifi_channel: 4;
371+
uint8_t wifi_status: 2; // 2 bits
372+
uint8_t wifi_channel: 4; // 4 bits
371373
bool ir_tx_inv: 1;
372374
bool rf_tx_inv: 1;
373-
uint8_t ir_tx_gpio: 6;
375+
uint8_t ir_tx_gpio: 6; // 6 bits
374376
bool timetable_ready: 1;
375377
bool clock_ready: 1;
376378
int8_t setup_mode_toggle_counter;
@@ -386,11 +388,12 @@ typedef struct _main_config {
386388
uint8_t wifi_ip;
387389
uint8_t wifi_ping_max_errors;
388390
uint8_t wifi_error_count;
389-
uint8_t rf_tx_gpio: 7;
391+
uint8_t rf_tx_gpio: 7; // 7 bits
390392
bool enable_homekit_server: 1;
391393

392-
uint8_t wifi_mode; // 3 bits
393-
uint8_t ir_tx_freq; // 6 bits
394+
uint8_t timetable_last_minute: 6; // 6 bits
395+
uint8_t wifi_mode: 3; // 3 bits
396+
uint8_t ir_tx_freq: 7; // 6 bits
394397
uint8_t wifi_arp_count;
395398
uint8_t wifi_arp_count_max;
396399

0 commit comments

Comments
 (0)