Files
zTC1/TC1/user_gpio.c
Zip 882b4bb0a8 fix:优化rtc及sntp逻辑
fix:优化部分函数名
add:增加relay直接控制函数(未测试)
2019-01-29 16:33:04 +08:00

69 lines
1.5 KiB
C

#define os_log(format, ...) custom_log("KEY", format, ##__VA_ARGS__)
#include "main.h"
#include "user_gpio.h"
#include "user_mqtt_client.h"
mico_gpio_t relay[Relay_NUM] = { Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5 };
void user_led_set( char x )
{
if ( x == -1 )
MicoGpioOutputTrigger( Led );
else if ( x )
MicoGpioOutputHigh( Led );
else
MicoGpioOutputLow( Led );
}
void user_relay_set( char x, char y )
{
char onoff = (y == 1 ? Relay_ON : Relay_OFF);
OSStatus (* Gpiosetfunction)( mico_gpio_t );
if ( y == -1 )
Gpiosetfunction = MicoGpioOutputTrigger;
else if ( onoff )
Gpiosetfunction = MicoGpioOutputHigh;
else
Gpiosetfunction = MicoGpioOutputLow;
if ( x >= 0 && x < Relay_NUM )
{
(*Gpiosetfunction)( relay[x] );
} else if ( x == Relay_NUM )
{
OSStatus *setgpiofunction = MicoGpioOutputTrigger;
for ( int i = 0; i < Relay_NUM; i++ )
{
(*Gpiosetfunction)( relay[i] );
}
}
}
static void key_long_press( void )
{
os_log("key_long_press");
user_led_set(1);
user_mqtt_send( "mqtt test" );
}
static void key_short_press( void )
{
//os_log("test");
user_led_set(-1);
}
void key_init( void )
{
button_init_t button_config = {
.gpio = Button,
.long_pressed_func = key_long_press,
.pressed_func = key_short_press,
.long_pressed_timeout = 800,
};
button_init( IOBUTTON_USER_1, button_config );
}