Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
vad7 committed Feb 22, 2021
1 parent 4110ec8 commit f2e4beb
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/include/power_meter.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ uint32 Web_ChMD; // ~ChMD~, Chart max days for historyall.htm
uint8 Web_ShowBy; // ~ShowBy~ : 0 - all, 1 - by day, 2 - by hour
uint32 Fram_SaveCountdown;
uint8 Fram_halted;
uint16 sleep_after_errors_cnt; // sec
volatile uint32 sleep_after_errors_cnt; // sec
//
void user_initialize(uint8 index) ICACHE_FLASH_ATTR;
void FRAM_Store_Init(void) ICACHE_FLASH_ATTR;
Expand Down
23 changes: 16 additions & 7 deletions app/user/mercury.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void ICACHE_FLASH_ATTR pwmt_read_time_array(uint8 arr)

void ICACHE_FLASH_ATTR uart_receive_timer_func(void) // call every cfg_glo.pwmt_read_timeout
{
if(uart_queue_len && !sleep_after_errors_cnt) {
if(uart_queue_len && sleep_after_errors_cnt == 0) {
uint32 dt = system_get_time() - uart_queue[0].time;
uint8 fl = uart_queue[0].flag;
if(fl == UART_SEND_WAITING) {
Expand Down Expand Up @@ -361,10 +361,17 @@ void ICACHE_FLASH_ATTR uart_receive_timer_func(void) // call every cfg_glo.pwmt_
GPIO_OUT_W1TC = (1<<0);//I2C_SCL_PIN);
}

if(pwmt_connect_status == PWMT_CONNECTING || pwmt_repeat_on_error_cnt > 0) { // reconnect after cfg_glo.pwmt_delay_after_err
if(pwmt_connect_status != PWMT_CONNECTING) pwmt_repeat_on_error_cnt--;
uart_queue[0].flag = UART_SEND_WAITING;
uart_queue[0].time = system_get_time();
if(pwmt_connect_status != PWMT_CONNECTED || pwmt_repeat_on_error_cnt > 0) { // reconnect after cfg_glo.pwmt_delay_after_err
if(pwmt_repeat_on_error_cnt == 0 && cfg_glo.sleep_after_series_errors != 0) { // UART0 off
sleep_after_errors_cnt = cfg_glo.sleep_after_series_errors;
dbg_printf("ErrSleepC\n");
uart_drv_close();
disable_mux_uart0();
} else {
uart_queue[0].flag = UART_SEND_WAITING;
uart_queue[0].time = system_get_time();
}
if(pwmt_repeat_on_error_cnt) pwmt_repeat_on_error_cnt--;
} else {
pwmt_repeat_on_error_cnt = cfg_glo.pwmt_on_error_repeat_cnt;
dbg_printf("Eu%u,%u:%d,%d=", dbg_next_time(), dt, pwmt_last_response, UART_Buffer_idx);
Expand All @@ -375,8 +382,9 @@ void ICACHE_FLASH_ATTR uart_receive_timer_func(void) // call every cfg_glo.pwmt_
//dbg_printf("\n");
dbg_printf(", del\n");
uart_queue[0].flag = UART_DELETED;
if(cfg_glo.sleep_after_series_errors) { // UART0 off
if(cfg_glo.sleep_after_series_errors != 0) { // UART0 off
sleep_after_errors_cnt = cfg_glo.sleep_after_series_errors;
dbg_printf("ErrSleep\n");
uart_drv_close();
disable_mux_uart0();
} else pwmt_send_to_uart();
Expand Down Expand Up @@ -520,7 +528,7 @@ void ICACHE_FLASH_ATTR uart_receive_timer_func(void) // call every cfg_glo.pwmt_

void ICACHE_FLASH_ATTR pwmt_request_timer_func(void) // call every: cfg_glo.request_period
{
if(sleep_after_errors_cnt) return;
if(sleep_after_errors_cnt != 0) return;
uint8 autosend = !uart_queue_len;
if((uart_queue_len == 0 && pwmt_connect_status == PWMT_NOT_CONNECTED)
|| (pwmt_last_response == 6 && pwmt_connect_status != PWMT_CONNECTING)) {
Expand All @@ -538,6 +546,7 @@ void ICACHE_FLASH_ATTR irda_init(void)
pwmt_connect_status = PWMT_NOT_CONNECTED;
pwmt_time_was_corrected_today = 0;
pwmt_repeated_errors = 0;
pwmt_repeat_on_error_cnt = cfg_glo.pwmt_on_error_repeat_cnt;
uart_queue_len = 0;
ets_timer_disarm(&uart_receive_timer);
os_timer_setfn(&uart_receive_timer, (os_timer_func_t *)uart_receive_timer_func, NULL);
Expand Down
12 changes: 9 additions & 3 deletions app/user/power_meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,15 @@ void ICACHE_FLASH_ATTR update_cnt_timer_func(void) // repeat every 1 sec
}
}
}
if(sleep_after_errors_cnt) if(--sleep_after_errors_cnt == 0) {
update_mux_uart0();
pwmt_send_to_uart();
if(sleep_after_errors_cnt != 0) {
sleep_after_errors_cnt--;
if(sleep_after_errors_cnt == 0) {
dbg_printf("ErrWake\n");
update_mux_uart0();
if(pwmt_connect_status == PWMT_CONNECTED) uart_queue[0].flag = UART_DELETED;
pwmt_repeat_on_error_cnt = cfg_glo.pwmt_on_error_repeat_cnt;
pwmt_send_to_uart();
}
}
if(pwmt_cur.Time == 0) return; else pwmt_cur.Time++;
if(!(pwmt_cur.Time >= fram_store.ByMin.LastTime + TIME_STEP_SEC) || FRAM_Status) return; // dont passed 1 min
Expand Down
5 changes: 3 additions & 2 deletions app/web/uart_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ void ICACHE_FLASH_ATTR update_rts0(void)

void ICACHE_FLASH_ATTR disable_mux_uart0(void)
{
MUX_TX_UART0 = (1<<GPIO_MUX_FUN_BIT0) | (1<<GPIO_MUX_FUN_BIT1) | (1<<GPIO_MUX_PULLDOWN_BIT); // VAL_MUX_TX_UART0_OFF;
GPIO_OUT_W1TC = (1<<1); // GPIO1
MUX_TX_UART0 = (1<<GPIO_MUX_FUN_BIT0) | (1<<GPIO_MUX_FUN_BIT1); // VAL_MUX_TX_UART0_OFF;
GPIO_OUT_W1TC = (1<<1); // GPIO1 low
GPIO_ENABLE_W1TS = (1<<1); // GPIO1 OUT
MUX_RX_UART0 = VAL_MUX_RX_UART0_OFF;
// MUX_RTS_UART0 = VAL_MUX_RTS_UART0_OFF;
// MUX_CTS_UART0 = VAL_MUX_CTS_UART0_OFF;
Expand Down
Binary file modified bin/0x00000.bin
Binary file not shown.
Binary file modified bin/0x07000.bin
Binary file not shown.
Binary file modified bin/firmware.bin
Binary file not shown.

0 comments on commit f2e4beb

Please sign in to comment.