mirror of
https://github.com/oopuuu/zTC1.git
synced 2025-12-12 21:18:13 +08:00
fix:优化按键按下发送逻辑
已知issue:按键导致复位
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "user_gpio.h"
|
#include "user_gpio.h"
|
||||||
#include "user_mqtt_client.h"
|
#include "user_mqtt_client.h"
|
||||||
|
#include "user_udp.h"
|
||||||
#include "cJSON/cJSON.h"
|
#include "cJSON/cJSON.h"
|
||||||
|
|
||||||
mico_gpio_t relay[Relay_NUM] = { Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5 };
|
mico_gpio_t relay[Relay_NUM] = { Relay_0, Relay_1, Relay_2, Relay_3, Relay_4, Relay_5 };
|
||||||
@@ -70,29 +71,35 @@ static void key_long_press( void )
|
|||||||
static void key_short_press( void )
|
static void key_short_press( void )
|
||||||
{
|
{
|
||||||
char i;
|
char i;
|
||||||
|
OSStatus err;
|
||||||
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( ) )
|
if ( relay_out( ) )
|
||||||
{
|
{
|
||||||
user_relay_set_all( 0 );
|
user_relay_set_all( 0 );
|
||||||
cJSON_AddNumberToObject( json_send, "nvalue", 1 );
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
user_relay_set_all( 1 );
|
user_relay_set_all( 1 );
|
||||||
cJSON_AddNumberToObject( json_send, "nvalue", 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char *json_str = cJSON_Print( json_send );
|
uint8_t *buf = NULL;
|
||||||
|
if ( user_config->idx >= 0 )
|
||||||
|
{
|
||||||
|
|
||||||
|
buf = malloc( 1024 );
|
||||||
|
require_action( buf, exit, err = kNoMemoryErr );
|
||||||
|
|
||||||
|
sprintf( buf, "{\"idx\" : %d,\"mac\" : \"%s\",\"nvalue\" : %d}", user_config->idx,strMac, relay_out() );
|
||||||
if ( !user_mqtt_isconnect( ) ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
if ( !user_mqtt_isconnect( ) ) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
user_udp_send( json_str );
|
user_udp_send( buf );
|
||||||
else
|
else
|
||||||
user_mqtt_send( json_str );
|
user_mqtt_send( buf );
|
||||||
free( (void *) json_str );
|
}
|
||||||
|
exit:
|
||||||
|
if ( err != kNoErr )
|
||||||
|
os_log("key_short_press Send data with err: %d", err);
|
||||||
|
if ( buf != NULL ) free( buf );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_init( void )
|
void key_init( void )
|
||||||
|
|||||||
Reference in New Issue
Block a user