mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-13 05:28:14 +08:00
fix:domoticz反馈数据导致的重复动作的问题
fix:优化全开全关是逻辑 add:增加mqtt连接状态判断函数
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "main.h"
|
||||
#include "user_gpio.h"
|
||||
#include "user_mqtt_client.h"
|
||||
#include "cJSON/cJSON.h"
|
||||
|
||||
mico_gpio_t relay[Relay_NUM] = { Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5 };
|
||||
|
||||
@@ -16,6 +17,18 @@ void user_led_set( char x )
|
||||
MicoGpioOutputLow( Led );
|
||||
}
|
||||
|
||||
bool relay_out( void )
|
||||
{
|
||||
char i;
|
||||
for ( i = 0; i < PLUG_NUM; i++ )
|
||||
{
|
||||
if ( user_config->plug[i].on != 0 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#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>
|
||||
@@ -25,8 +38,14 @@ void user_led_set( char x )
|
||||
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;
|
||||
|
||||
if ( relay_out( ) )
|
||||
user_led_set( 1 );
|
||||
else
|
||||
user_led_set( 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -36,27 +55,9 @@ void user_relay_set( char x, char y )
|
||||
*/
|
||||
void user_relay_set_all( char y )
|
||||
{
|
||||
char onoff = (y == 1 ? Relay_ON : Relay_OFF);
|
||||
char i, temp;
|
||||
|
||||
if ( y != 0 )
|
||||
{
|
||||
for ( i = 0; i < PLUG_NUM; i++ )
|
||||
temp |= user_config->plug[i].on;
|
||||
|
||||
if ( temp == 0 )
|
||||
{
|
||||
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 );
|
||||
}
|
||||
char i;
|
||||
for ( i = 0; i < PLUG_NUM; i++ )
|
||||
user_relay_set( i, y );
|
||||
}
|
||||
|
||||
static void key_long_press( void )
|
||||
@@ -68,9 +69,30 @@ static void key_long_press( void )
|
||||
}
|
||||
static void key_short_press( void )
|
||||
{
|
||||
//os_log("test");
|
||||
user_led_set( -1 );
|
||||
//user_relay_set(6,-1);
|
||||
char i;
|
||||
|
||||
cJSON *json_send = cJSON_CreateObject( );
|
||||
|
||||
cJSON_AddStringToObject( json_send, "mac", strMac );
|
||||
if ( user_config->idx >= 0 ) cJSON_AddNumberToObject( json_send, "idx", user_config->idx );
|
||||
|
||||
if ( relay_out( ) )
|
||||
{
|
||||
user_relay_set_all( 0 );
|
||||
cJSON_AddNumberToObject( json_send, "nvalue", 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
user_relay_set_all( 1 );
|
||||
cJSON_AddNumberToObject( json_send, "nvalue", 0 );
|
||||
}
|
||||
|
||||
char *json_str = cJSON_Print( json_send );
|
||||
if ( !user_mqtt_isconnect() )//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
user_udp_send( json_str );
|
||||
else
|
||||
user_mqtt_send( json_str );
|
||||
free( (void *) json_str );
|
||||
}
|
||||
|
||||
void key_init( void )
|
||||
|
||||
Reference in New Issue
Block a user