add:json数据解析处理(未测试)

fix:优化代码注释
This commit is contained in:
Zip
2019-03-14 12:25:26 +08:00
parent 575b666cab
commit 088ae209b8
5 changed files with 266 additions and 92 deletions

View File

@@ -16,44 +16,60 @@ void user_led_set( char x )
MicoGpioOutputLow( Led );
}
#define set_relay(a,b) if(((b) == 1) ? Relay_ON : Relay_OFF) MicoGpioOutputHigh( relay[(a)] );else MicoGpioOutputLow( relay[(a)] )
/*user_relay_set
* <20><><EFBFBD>ü̵<C3BC><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* x:<3A><><EFBFBD><EFBFBD> 0-5
* y:<3A><><EFBFBD><EFBFBD> 0:<3A><> 1:<3A><>
*/
void user_relay_set( char x, char y )
{
if ( x < 0 || x >= PLUG_NUM ) return;
set_relay( x, y );
user_config->plug[x].on = y;
}
/*
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>м̵<D0BC><CCB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* y:0:ȫ<><C8AB><EFBFBD><EFBFBD> 1:<3A><><EFBFBD>ݼ<EFBFBD>¼״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*
*/
void user_relay_set_all( char y )
{
char onoff = (y == 1 ? Relay_ON : Relay_OFF);
char i, temp;
OSStatus (* Gpiosetfunction)( mico_gpio_t );
if ( y == -1 )
Gpiosetfunction = MicoGpioOutputTrigger;
else if ( onoff )
Gpiosetfunction = MicoGpioOutputHigh;
else
Gpiosetfunction = MicoGpioOutputLow;
if ( x >= 0 && x < Relay_NUM )
if ( y != 0 )
{
(*Gpiosetfunction)( relay[x] );
os_log("set relay %d:%d",x,y);
} else if ( x == Relay_NUM )
{
for ( int i = 0; i < Relay_NUM; i++ )
for ( i = 0; i < PLUG_NUM; i++ )
temp |= user_config->plug[i].on;
if ( temp == 0 )
{
(*Gpiosetfunction)( relay[i] );
os_log("set relay %d:%d",i,y);
for ( i = 0; i < PLUG_NUM; i++ )
user_config->plug[i].on = 1;
}
for ( i = 0; i < PLUG_NUM; i++ )
set_relay( i, user_config->plug[i].on );
}
else
{
set_relay( i, 0 );
}
}
static void key_long_press( void )
{
os_log("key_long_press");
user_led_set(1);
user_led_set( 1 );
user_mqtt_send( "mqtt test" );
}
static void key_short_press( void )
{
//os_log("test");
user_led_set(-1);
user_led_set( -1 );
//user_relay_set(6,-1);
}