(*) -> ()

This commit is contained in:
zogodo
2019-09-24 21:44:51 +08:00
parent e7009528aa
commit 2a328b9225
19 changed files with 824 additions and 824 deletions

View File

@@ -8,22 +8,22 @@
mico_gpio_t relay[Relay_NUM] = { Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5 };
void user_led_set( char x )
void user_led_set(char x)
{
if ( x == -1 )
MicoGpioOutputTrigger( Led );
else if ( x )
MicoGpioOutputHigh( Led );
if (x == -1)
MicoGpioOutputTrigger(Led);
else if (x)
MicoGpioOutputHigh(Led);
else
MicoGpioOutputLow( Led );
MicoGpioOutputLow(Led);
}
bool relay_out( void )
bool relay_out(void)
{
unsigned char i;
for ( i = 0; i < PLUG_NUM; i++ )
for (i = 0; i < PLUG_NUM; i++)
{
if ( user_config->plug[i].on != 0 )
if (user_config->plug[i].on != 0)
{
return true;
}
@@ -90,51 +90,51 @@ void user_relay_set(unsigned char i, unsigned char on)
* y: 0:ȫ<><C8AB><EFBFBD><EFBFBD> 1:ȫ<><C8AB><EFBFBD><EFBFBD>
*
*/
void user_relay_set_all( char y )
void user_relay_set_all(char y)
{
int i;
for (i = 0; i < PLUG_NUM; i++)
user_relay_set(i, y);
}
static void key_long_press( void )
static void key_long_press(void)
{
// os_log("key_long_press");
// user_led_set( 1 );
// user_mqtt_send( "mqtt test" );
// user_led_set(1);
// user_mqtt_send("mqtt test");
}
static void key_long_10s_press( void )
static void key_long_10s_press(void)
{
OSStatus err;
char i = 0;
os_log( "WARNGIN: user params restored!" );
// for ( i = 0; i < 3; i++ )
os_log("WARNGIN: user params restored!");
// for (i = 0; i < 3; i++)
// {
// user_led_set( 1 );
// mico_rtos_thread_msleep( 100 );
// user_led_set( 0 );
// user_led_set(1);
// mico_rtos_thread_msleep(100);
// user_led_set(0);
// }
//
appRestoreDefault_callback( user_config, sizeof(user_config_t) );
appRestoreDefault_callback(user_config, sizeof(user_config_t));
sys_config->micoSystemConfig.ssid[0] = 0;
mico_system_context_update( mico_system_context_get( ) );
mico_system_context_update(mico_system_context_get());
}
static void key_short_press( void )
static void key_short_press(void)
{
char i;
OSStatus err;
if ( relay_out() )
if (relay_out())
{
user_relay_set_all( 0 );
user_relay_set_all(0);
}
else
{
user_relay_set_all( 1 );
user_relay_set_all(1);
}
for ( i = 0; i < PLUG_NUM; i++ )
for (i = 0; i < PLUG_NUM; i++)
{
user_mqtt_send_plug_state(i);
}
@@ -146,42 +146,42 @@ mico_timer_t user_key_timer;
uint16_t key_time = 0;
#define BUTTON_LONG_PRESS_TIME 10 //100ms*10=1s
static void key_timeout_handler( void* arg )
static void key_timeout_handler(void* arg)
{
static uint8_t key_trigger, key_continue;
static uint8_t key_last;
//<2F><><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
uint8_t tmp = ~(0xfe | MicoGpioInputGet( Button ));
uint8_t tmp = ~(0xfe | MicoGpioInputGet(Button));
key_trigger = tmp & (tmp ^ key_continue);
key_continue = tmp;
// os_log("button scan:%02x %02x",key_trigger,key_continue);
if ( key_trigger != 0 ) key_time = 0; //<2F>°<EFBFBD><C2B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ,<2C><><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ
if ( key_continue != 0 )
if (key_trigger != 0) key_time = 0; //<2F>°<EFBFBD><C2B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ,<2C><><EFBFBD>¿<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ
if (key_continue != 0)
{
//any button pressed
key_time++;
if ( key_time < BUTTON_LONG_PRESS_TIME )
if (key_time < BUTTON_LONG_PRESS_TIME)
key_last = key_continue;
else
{
os_log("button long pressed:%d",key_time);
if ( key_time == 30 )
if (key_time == 30)
{
key_long_press( );
key_long_press();
}
else if ( key_time == 100 )
else if (key_time == 100)
{
key_long_10s_press( );
key_long_10s_press();
}
else if ( key_time == 102 )
else if (key_time == 102)
{
user_led_set( 1 );
user_led_set(1);
}
else if ( key_time == 103 )
else if (key_time == 103)
{
user_led_set( 0 );
user_led_set(0);
key_time = 101;
}
}
@@ -189,30 +189,30 @@ static void key_timeout_handler( void* arg )
} else
{
//button released
if ( key_time < BUTTON_LONG_PRESS_TIME )
if (key_time < BUTTON_LONG_PRESS_TIME)
{ //100ms*10=1s <20><><EFBFBD><EFBFBD>1sΪ<73><CEAA><EFBFBD><EFBFBD>
key_time = 0;
os_log("button short pressed:%d",key_time);
key_short_press( );
} else if ( key_time > 100 )
key_short_press();
} else if (key_time > 100)
{
MicoSystemReboot( );
MicoSystemReboot();
}
key_last = 0;
mico_rtos_stop_timer( &user_key_timer );
mico_rtos_stop_timer(&user_key_timer);
}
}
static void key_falling_irq_handler( void* arg )
static void key_falling_irq_handler(void* arg)
{
mico_rtos_start_timer( &user_key_timer );
mico_rtos_start_timer(&user_key_timer);
}
void key_init( void )
void key_init(void)
{
MicoGpioInitialize( Button, INPUT_PULL_UP );
mico_rtos_init_timer( &user_key_timer, 100, key_timeout_handler, NULL );
MicoGpioInitialize(Button, INPUT_PULL_UP);
mico_rtos_init_timer(&user_key_timer, 100, key_timeout_handler, NULL);
MicoGpioEnableIRQ( Button, IRQ_TRIGGER_FALLING_EDGE, key_falling_irq_handler, NULL );
MicoGpioEnableIRQ(Button, IRQ_TRIGGER_FALLING_EDGE, key_falling_irq_handler, NULL);
}