Skip to content

Commit f2e4beb

Browse files
committed
upd
1 parent 4110ec8 commit f2e4beb

File tree

7 files changed

+29
-13
lines changed

7 files changed

+29
-13
lines changed

app/include/power_meter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ uint32 Web_ChMD; // ~ChMD~, Chart max days for historyall.htm
8484
uint8 Web_ShowBy; // ~ShowBy~ : 0 - all, 1 - by day, 2 - by hour
8585
uint32 Fram_SaveCountdown;
8686
uint8 Fram_halted;
87-
uint16 sleep_after_errors_cnt; // sec
87+
volatile uint32 sleep_after_errors_cnt; // sec
8888
//
8989
void user_initialize(uint8 index) ICACHE_FLASH_ATTR;
9090
void FRAM_Store_Init(void) ICACHE_FLASH_ATTR;

app/user/mercury.c

+16-7
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void ICACHE_FLASH_ATTR pwmt_read_time_array(uint8 arr)
312312

313313
void ICACHE_FLASH_ATTR uart_receive_timer_func(void) // call every cfg_glo.pwmt_read_timeout
314314
{
315-
if(uart_queue_len && !sleep_after_errors_cnt) {
315+
if(uart_queue_len && sleep_after_errors_cnt == 0) {
316316
uint32 dt = system_get_time() - uart_queue[0].time;
317317
uint8 fl = uart_queue[0].flag;
318318
if(fl == UART_SEND_WAITING) {
@@ -361,10 +361,17 @@ void ICACHE_FLASH_ATTR uart_receive_timer_func(void) // call every cfg_glo.pwmt_
361361
GPIO_OUT_W1TC = (1<<0);//I2C_SCL_PIN);
362362
}
363363

364-
if(pwmt_connect_status == PWMT_CONNECTING || pwmt_repeat_on_error_cnt > 0) { // reconnect after cfg_glo.pwmt_delay_after_err
365-
if(pwmt_connect_status != PWMT_CONNECTING) pwmt_repeat_on_error_cnt--;
366-
uart_queue[0].flag = UART_SEND_WAITING;
367-
uart_queue[0].time = system_get_time();
364+
if(pwmt_connect_status != PWMT_CONNECTED || pwmt_repeat_on_error_cnt > 0) { // reconnect after cfg_glo.pwmt_delay_after_err
365+
if(pwmt_repeat_on_error_cnt == 0 && cfg_glo.sleep_after_series_errors != 0) { // UART0 off
366+
sleep_after_errors_cnt = cfg_glo.sleep_after_series_errors;
367+
dbg_printf("ErrSleepC\n");
368+
uart_drv_close();
369+
disable_mux_uart0();
370+
} else {
371+
uart_queue[0].flag = UART_SEND_WAITING;
372+
uart_queue[0].time = system_get_time();
373+
}
374+
if(pwmt_repeat_on_error_cnt) pwmt_repeat_on_error_cnt--;
368375
} else {
369376
pwmt_repeat_on_error_cnt = cfg_glo.pwmt_on_error_repeat_cnt;
370377
dbg_printf("Eu%u,%u:%d,%d=", dbg_next_time(), dt, pwmt_last_response, UART_Buffer_idx);
@@ -375,8 +382,9 @@ void ICACHE_FLASH_ATTR uart_receive_timer_func(void) // call every cfg_glo.pwmt_
375382
//dbg_printf("\n");
376383
dbg_printf(", del\n");
377384
uart_queue[0].flag = UART_DELETED;
378-
if(cfg_glo.sleep_after_series_errors) { // UART0 off
385+
if(cfg_glo.sleep_after_series_errors != 0) { // UART0 off
379386
sleep_after_errors_cnt = cfg_glo.sleep_after_series_errors;
387+
dbg_printf("ErrSleep\n");
380388
uart_drv_close();
381389
disable_mux_uart0();
382390
} else pwmt_send_to_uart();
@@ -520,7 +528,7 @@ void ICACHE_FLASH_ATTR uart_receive_timer_func(void) // call every cfg_glo.pwmt_
520528

521529
void ICACHE_FLASH_ATTR pwmt_request_timer_func(void) // call every: cfg_glo.request_period
522530
{
523-
if(sleep_after_errors_cnt) return;
531+
if(sleep_after_errors_cnt != 0) return;
524532
uint8 autosend = !uart_queue_len;
525533
if((uart_queue_len == 0 && pwmt_connect_status == PWMT_NOT_CONNECTED)
526534
|| (pwmt_last_response == 6 && pwmt_connect_status != PWMT_CONNECTING)) {
@@ -538,6 +546,7 @@ void ICACHE_FLASH_ATTR irda_init(void)
538546
pwmt_connect_status = PWMT_NOT_CONNECTED;
539547
pwmt_time_was_corrected_today = 0;
540548
pwmt_repeated_errors = 0;
549+
pwmt_repeat_on_error_cnt = cfg_glo.pwmt_on_error_repeat_cnt;
541550
uart_queue_len = 0;
542551
ets_timer_disarm(&uart_receive_timer);
543552
os_timer_setfn(&uart_receive_timer, (os_timer_func_t *)uart_receive_timer_func, NULL);

app/user/power_meter.c

+9-3
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,15 @@ void ICACHE_FLASH_ATTR update_cnt_timer_func(void) // repeat every 1 sec
125125
}
126126
}
127127
}
128-
if(sleep_after_errors_cnt) if(--sleep_after_errors_cnt == 0) {
129-
update_mux_uart0();
130-
pwmt_send_to_uart();
128+
if(sleep_after_errors_cnt != 0) {
129+
sleep_after_errors_cnt--;
130+
if(sleep_after_errors_cnt == 0) {
131+
dbg_printf("ErrWake\n");
132+
update_mux_uart0();
133+
if(pwmt_connect_status == PWMT_CONNECTED) uart_queue[0].flag = UART_DELETED;
134+
pwmt_repeat_on_error_cnt = cfg_glo.pwmt_on_error_repeat_cnt;
135+
pwmt_send_to_uart();
136+
}
131137
}
132138
if(pwmt_cur.Time == 0) return; else pwmt_cur.Time++;
133139
if(!(pwmt_cur.Time >= fram_store.ByMin.LastTime + TIME_STEP_SEC) || FRAM_Status) return; // dont passed 1 min

app/web/uart_tcp.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ void ICACHE_FLASH_ATTR update_rts0(void)
133133

134134
void ICACHE_FLASH_ATTR disable_mux_uart0(void)
135135
{
136-
MUX_TX_UART0 = (1<<GPIO_MUX_FUN_BIT0) | (1<<GPIO_MUX_FUN_BIT1) | (1<<GPIO_MUX_PULLDOWN_BIT); // VAL_MUX_TX_UART0_OFF;
137-
GPIO_OUT_W1TC = (1<<1); // GPIO1
136+
MUX_TX_UART0 = (1<<GPIO_MUX_FUN_BIT0) | (1<<GPIO_MUX_FUN_BIT1); // VAL_MUX_TX_UART0_OFF;
137+
GPIO_OUT_W1TC = (1<<1); // GPIO1 low
138+
GPIO_ENABLE_W1TS = (1<<1); // GPIO1 OUT
138139
MUX_RX_UART0 = VAL_MUX_RX_UART0_OFF;
139140
// MUX_RTS_UART0 = VAL_MUX_RTS_UART0_OFF;
140141
// MUX_CTS_UART0 = VAL_MUX_CTS_UART0_OFF;

bin/0x00000.bin

32 Bytes
Binary file not shown.

bin/0x07000.bin

96 Bytes
Binary file not shown.

bin/firmware.bin

96 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)