![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Modularizando o src
Dependencies: EALib EthernetInterface_vz mbed-rtos mbed
Fork of header_main_colinas_V0-20-09-14 by
Diff: main_app_functions.cpp
- Revision:
- 128:3ae1c74773a8
- Parent:
- 127:e7160a463b6c
- Child:
- 129:d73538fbc017
diff -r e7160a463b6c -r 3ae1c74773a8 main_app_functions.cpp --- a/main_app_functions.cpp Sun May 24 16:07:14 2015 +0000 +++ b/main_app_functions.cpp Mon May 25 13:11:00 2015 +0000 @@ -56,6 +56,8 @@ if ( debug_app_init ) send_msg ( "init_bl() :: %s", ( init_bl() == 0 ) ? "Ok" : "Failure" ); if ( debug_app_init ) send_msg ( "init_clock () :: %s", ( init_clock () == 0 ) ? "Ok" : "Failure" ); + + if ( debug_app_init ) send_msg ( "init_pwr_src () :: %s", ( init_pwr_src () == 0 ) ? "Ok" : "Failure" ); } sync_timer.start(); @@ -145,6 +147,8 @@ test_ts_timer.start (); + pwr_src_timer.start (); + send_msg ( "" ); return ( 0 ); @@ -173,6 +177,8 @@ if ( debug_app_init ) send_msg ( "init_bl() :: %s", ( init_bl() == 0 ) ? "Ok" : "Failure" ); if ( debug_app_init ) send_msg ( "init_clock() :: %s", ( init_clock() == 0 ) ? "Ok" : "Failure" ); + + if ( debug_app_init ) send_msg ( "init_pwr_src () :: %s", ( init_pwr_src () == 0 ) ? "Ok" : "Failure" ); } return eth_status; @@ -2125,4 +2131,43 @@ } send_msg ( "%s", str ); +} + +/* Funcao para leitura da fonte de alimentacao e aviso ao servidor */ +void check_power_source ( void ) +{ + static uint8_t samples = 0, warn_back = 0, wait_to_warn = 0; + //static uint16_t wait_to_warn = 0; + + pwr_src_timer.stop(); + pwr_src_timer.reset(); + + if (pwr_src_in) { + if (samples < 8) samples++; + } else { + if (samples > 0) samples--; + } + + if (wait_to_warn) wait_to_warn--; + + if (samples >= 8) { + pwr_src_status = 1; + if (!wait_to_warn) { + wait_to_warn = 255; + warn_back = 1; + pwr_src_client.sendTo( pwr_src_server, "mainpowerisdown", strlen( "mainpowerisdown" ) ); + debug_msg( "Main power is DOWN!" ); + } else { + wait_to_warn--; + } + } + if ((samples == 0) and (warn_back)) { + pwr_src_status = 0; + warn_back = 0; + wait_to_warn = 0; + pwr_src_client.sendTo( pwr_src_server, "mainpowerisback", strlen( "mainpowerisback" ) ); + debug_msg( "Main power is BACK!" ); + } + + pwr_src_timer.start(); } \ No newline at end of file