From 58eec84eec26bba09f40df7e4948af0ee2860c8d Mon Sep 17 00:00:00 2001 From: zogodo <742782908@qq.com> Date: Wed, 9 Oct 2019 18:12:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=90=8D=E9=A9=BC=E5=B3=B0?= =?UTF-8?q?=E5=BC=8F-2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TC1/http_server/app_httpd.c | 6 ++-- TC1/main.c | 4 +-- TC1/user_function.c | 2 +- TC1/user_gpio.c | 64 ++++++++++++++++++------------------- TC1/user_gpio.h | 14 ++++---- TC1/user_mqtt_client.c | 4 +-- TC1/user_rtc.c | 2 +- TC1/user_wifi.c | 12 +++---- 8 files changed, 54 insertions(+), 54 deletions(-) diff --git a/TC1/http_server/app_httpd.c b/TC1/http_server/app_httpd.c index aa31946..e720ab8 100644 --- a/TC1/http_server/app_httpd.c +++ b/TC1/http_server/app_httpd.c @@ -62,7 +62,7 @@ exit: static int HttpGetTc1Status(httpd_request_t *req) { - const unsigned char* sockets = get_socket_status(); + const unsigned char* sockets = GetSocketStatus(); char* ap_name = "TC1-AP"; char* ap_pwd = "12345678"; char* ip = "192.168.33.222"; @@ -91,7 +91,7 @@ static int HttpSetSocketStatus(httpd_request_t *req) err = httpd_get_data(req, buf, buf_size); require_noerr(err, exit); - set_socket_status(buf); + SetSocketStatus(buf); send_http("OK", 2, exit, &err); @@ -103,7 +103,7 @@ exit: static int HttpGetWifiConfig(httpd_request_t *req) { OSStatus err = kNoErr; - const unsigned char* status = get_socket_status(); + const unsigned char* status = GetSocketStatus(); send_http(status, strlen(status), exit, &err); exit: return err; diff --git a/TC1/main.c b/TC1/main.c index e657ad6..4243321 100644 --- a/TC1/main.c +++ b/TC1/main.c @@ -100,7 +100,7 @@ int application_start(void) for (i = 0; i < Relay_NUM; i++) { MicoGpioInitialize(Relay[i], OUTPUT_PUSH_PULL); - user_relay_set(i, user_config->plug[i].on); + UserRelaySet(i, user_config->plug[i].on); } MicoSysLed(0); @@ -156,7 +156,7 @@ int application_start(void) WifiConnect(sys_config->micoSystemConfig.ssid, sys_config->micoSystemConfig.user_key); } user_udp_init(); - key_init(); + KeyInit(); err = user_mqtt_init(); require_noerr(err, exit); err = user_rtc_init(); diff --git a/TC1/user_function.c b/TC1/user_function.c index 1a65e31..8442f3d 100644 --- a/TC1/user_function.c +++ b/TC1/user_function.c @@ -236,7 +236,7 @@ bool json_plug_analysis(int udp_flag, unsigned char x, cJSON * pJsonRoot, cJSON { if (cJSON_IsNumber(p_plug_on)) { - user_relay_set(x, p_plug_on->valueint); + UserRelaySet(x, p_plug_on->valueint); return_flag = true; } user_mqtt_send_plug_state(x); diff --git a/TC1/user_gpio.c b/TC1/user_gpio.c index 8f15046..b9fbf70 100644 --- a/TC1/user_gpio.c +++ b/TC1/user_gpio.c @@ -8,7 +8,7 @@ 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 UserLedSet(char x) { if (x == -1) MicoGpioOutputTrigger(Led); @@ -18,7 +18,7 @@ void user_led_set(char x) MicoGpioOutputLow(Led); } -bool relay_out(void) +bool RelayOut(void) { int i; for (i = 0; i < PLUG_NUM; i++) @@ -31,7 +31,7 @@ bool relay_out(void) return false; } -const unsigned char* get_socket_status() +const unsigned char* GetSocketStatus() { sprintf(socket_status, "%d,%d,%d,%d,%d,%d", user_config->plug[0].on, @@ -43,7 +43,7 @@ const unsigned char* get_socket_status() return (const unsigned char*)socket_status; } -void set_socket_status(char* socket_status) +void SetSocketStatus(char* socket_status) { int ons[6] = { 0 }; sscanf(socket_status, "%d,%d,%d,%d,%d,%d,", @@ -51,16 +51,16 @@ void set_socket_status(char* socket_status) int i = 0; for (i = 0; i < PLUG_NUM; i++) { - user_relay_set(i, ons[i]); + UserRelaySet(i, ons[i]); } } -/*user_relay_set +/*UserRelaySet * 设置继电器开关 * i:编号 0-5 * on:开关 0:关 1:开 */ -void user_relay_set(unsigned char i, unsigned char on) +void UserRelaySet(unsigned char i, unsigned char on) { if (i >= PLUG_NUM) return; @@ -75,13 +75,13 @@ void user_relay_set(unsigned char i, unsigned char on) user_config->plug[i].on = on; - if (relay_out()) + if (RelayOut()) { - user_led_set(1); + UserLedSet(1); } else { - user_led_set(0); + UserLedSet(0); } } @@ -90,46 +90,46 @@ void user_relay_set(unsigned char i, unsigned char on) * y: 0:全部关 1:全部开 * */ -void user_relay_set_all(char y) +void UserRelaySetAll(char y) { int i; for (i = 0; i < PLUG_NUM; i++) - user_relay_set(i, y); + UserRelaySet(i, y); } -static void key_long_press(void) +static void KeyLongPress(void) { -// os_log("key_long_press"); -// user_led_set(1); +// os_log("KeyLongPress"); +// UserLedSet(1); // user_mqtt_send("mqtt test"); } -static void key_long_10s_press(void) +static void KeyLong10sPress(void) { os_log("WARNGIN: user params restored!"); // char i = 0; // for (i = 0; i < 3; i++) // { -// user_led_set(1); +// UserLedSet(1); // mico_rtos_thread_msleep(100); -// user_led_set(0); +// UserLedSet(0); // } // appRestoreDefault_callback(user_config, sizeof(user_config_t)); sys_config->micoSystemConfig.ssid[0] = 0; mico_system_context_update(mico_system_context_get()); } -static void key_short_press(void) +static void KeyShortPress(void) { char i; - if (relay_out()) + if (RelayOut()) { - user_relay_set_all(0); + UserRelaySetAll(0); } else { - user_relay_set_all(1); + UserRelaySetAll(1); } for (i = 0; i < PLUG_NUM; i++) @@ -141,7 +141,7 @@ 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 KeyTimeoutHandler(void* arg) { static char key_trigger, key_continue; //按键扫描程序 @@ -160,19 +160,19 @@ static void key_timeout_handler(void* arg) if (key_time == 30) { - key_long_press(); + KeyLongPress(); } else if (key_time == 100) { - key_long_10s_press(); + KeyLong10sPress(); } else if (key_time == 102) { - user_led_set(1); + UserLedSet(1); } else if (key_time == 103) { - user_led_set(0); + UserLedSet(0); key_time = 101; } } @@ -184,7 +184,7 @@ static void key_timeout_handler(void* arg) { //100ms*10=1s 大于1s为长按 key_time = 0; os_log("button short pressed:%d",key_time); - key_short_press(); + KeyShortPress(); } else if (key_time > 100) { MicoSystemReboot(); @@ -193,16 +193,16 @@ static void key_timeout_handler(void* arg) } } -static void key_falling_irq_handler(void* arg) +static void KeyFallingIrqHandler(void* arg) { mico_rtos_start_timer(&user_key_timer); } -void key_init(void) +void KeyInit(void) { MicoGpioInitialize(Button, INPUT_PULL_UP); - mico_rtos_init_timer(&user_key_timer, 100, key_timeout_handler, NULL); + mico_rtos_init_timer(&user_key_timer, 100, KeyTimeoutHandler, NULL); - MicoGpioEnableIRQ(Button, IRQ_TRIGGER_FALLING_EDGE, key_falling_irq_handler, NULL); + MicoGpioEnableIRQ(Button, IRQ_TRIGGER_FALLING_EDGE, KeyFallingIrqHandler, NULL); } diff --git a/TC1/user_gpio.h b/TC1/user_gpio.h index 906d306..a5b5771 100644 --- a/TC1/user_gpio.h +++ b/TC1/user_gpio.h @@ -6,12 +6,12 @@ #include "mico.h" #include "micokit_ext.h" -void user_led_set(char x); -void key_init(void); -void user_relay_set(unsigned char x,unsigned char y); -void user_relay_set_all(char y); -bool relay_out(void); -const unsigned char* get_socket_status(); -void set_socket_status(char* socket_status); +void UserLedSet(char x); +void KeyInit(void); +void UserRelaySet(unsigned char x,unsigned char y); +void UserRelaySetAll(char y); +bool RelayOut(void); +const unsigned char* GetSocketStatus(); +void SetSocketStatus(char* socket_status); #endif diff --git a/TC1/user_mqtt_client.c b/TC1/user_mqtt_client.c index fa3934f..922e38c 100644 --- a/TC1/user_mqtt_client.c +++ b/TC1/user_mqtt_client.c @@ -406,9 +406,9 @@ void mqtt_client_thread(mico_thread_arg_t arg) mqtt_client_release(&c, &n); isconnect = false; - user_led_set(-1); + UserLedSet(-1); mico_rtos_thread_msleep(100); - user_led_set(-1); + UserLedSet(-1); mico_rtos_thread_sleep(5); goto MQTT_start; diff --git a/TC1/user_rtc.c b/TC1/user_rtc.c index d1d7c13..9633865 100644 --- a/TC1/user_rtc.c +++ b/TC1/user_rtc.c @@ -192,7 +192,7 @@ void rtc_thread(mico_thread_arg_t arg) { if (user_config->plug[i].on != user_config->plug[i].task[j].action) { - user_relay_set(i, user_config->plug[i].task[j].action); + UserRelaySet(i, user_config->plug[i].task[j].action); update_user_config_flag = 1; user_mqtt_send_plug_state(i); } diff --git a/TC1/user_wifi.c b/TC1/user_wifi.c index 8a56f86..9c8a636 100644 --- a/TC1/user_wifi.c +++ b/TC1/user_wifi.c @@ -97,7 +97,7 @@ static void WifiLedTimerCallback(void* arg) { case WIFI_STATE_FAIL: os_log("wifi connect fail"); - user_led_set(0); + UserLedSet(0); mico_rtos_stop_timer(&wifi_led_timer); break; case WIFI_STATE_NOCONNECT: @@ -105,15 +105,15 @@ static void WifiLedTimerCallback(void* arg) break; case WIFI_STATE_CONNECTING: num = 0; - user_led_set(-1); + UserLedSet(-1); break; case WIFI_STATE_CONNECTED: - user_led_set(0); + UserLedSet(0); mico_rtos_stop_timer(&wifi_led_timer); - if (relay_out()) - user_led_set(1); + if (RelayOut()) + UserLedSet(1); else - user_led_set(0); + UserLedSet(0); break; } }