Skip to content

Commit 07bdfcf

Browse files
committed
key: code refactoring
1 parent b4e1ced commit 07bdfcf

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

main/inc/core/os.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
typedef enum os_event_group_bits {
1515
WIFI_READY_BIT = BIT0,
1616
WIFI_CONFIG_BIT = BIT1,
17-
INPUT_READY_BIT = BIT2,
1817
} os_event_group_bits_t;
1918

2019
typedef enum user_event_group_bits {

main/src/user/http_app_ota.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ void http_app_ota_prepare_data(char *buf, int len)
117117
void http_app_check_for_updates(void)
118118
{
119119
#ifdef CONFIG_ENABLE_OTA
120-
xEventGroupClearBits(os_event_group, INPUT_READY_BIT);
121120
ESP_LOGI(TAG, "checking for firmware update...");
122121
EventBits_t uxBits = xEventGroupSync(
123122
user_event_group,
@@ -129,6 +128,5 @@ void http_app_check_for_updates(void)
129128
xEventGroupClearBits(user_event_group, HTTP_APP_OTA_RUN_BIT);
130129
}
131130
first_time = 1;
132-
xEventGroupSetBits(os_event_group, INPUT_READY_BIT);
133131
#endif
134132
}

main/src/user/http_app_token.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ void http_app_token_prepare_data(char *buf, int len)
8888

8989
void http_app_verify_token(char *token)
9090
{
91-
xEventGroupClearBits(os_event_group, INPUT_READY_BIT);
9291
data_ptr = token;
9392
EventBits_t uxBits = xEventGroupSync(
9493
user_event_group,
@@ -99,5 +98,4 @@ void http_app_verify_token(char *token)
9998
if ((uxBits & HTTP_APP_TOKEN_READY_BIT) == 0) {
10099
xEventGroupClearBits(user_event_group, HTTP_APP_TOKEN_RUN_BIT);
101100
}
102-
xEventGroupSetBits(os_event_group, INPUT_READY_BIT);
103101
}

main/src/user/key.c

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,37 @@
1616

1717
#define TAG "key"
1818

19-
static void key_task(void *pvParameter)
20-
{
2119
#ifdef CONFIG_ENABLE_SMARTCONFIG
22-
uint16_t count[] = {0};
23-
uint8_t gpio_pin[] = {CONFIG_SC_KEY_PIN};
24-
uint8_t gpio_val[] = {
20+
static uint8_t gpio_pin[] = {
21+
#ifdef CONFIG_ENABLE_SMARTCONFIG
22+
CONFIG_SC_KEY_PIN,
23+
#endif
24+
};
25+
26+
static uint8_t gpio_val[] = {
2527
#ifdef CONFIG_SC_KEY_ACTIVE_LOW
26-
0
28+
0,
2729
#else
28-
1
30+
1,
31+
#endif
32+
};
33+
34+
static uint16_t gpio_hold[] = {
35+
#ifdef CONFIG_ENABLE_SMARTCONFIG
36+
CONFIG_SC_KEY_HOLD_TIME,
37+
#endif
38+
};
39+
40+
static void (*key_handle[])(void) = {
41+
#ifdef CONFIG_ENABLE_SMARTCONFIG
42+
key_smartconfig_handle,
2943
#endif
30-
};
31-
uint16_t gpio_hold[] = {CONFIG_SC_KEY_HOLD_TIME};
32-
void (*key_handle[])(void) = {key_smartconfig_handle};
44+
};
3345

46+
static void key_task(void *pvParameter)
47+
{
3448
portTickType xLastWakeTime;
49+
uint16_t count[sizeof(gpio_pin)] = {0};
3550

3651
for (int i=0; i<sizeof(gpio_pin); i++) {
3752
gpio_set_direction(gpio_pin[i], GPIO_MODE_INPUT);
@@ -72,13 +87,12 @@ static void key_task(void *pvParameter)
7287

7388
vTaskDelayUntil(&xLastWakeTime, 10 / portTICK_RATE_MS);
7489
}
75-
#endif // CONFIG_ENABLE_SMARTCONFIG
7690
}
7791

7892
void key_init(void)
7993
{
80-
xEventGroupSetBits(os_event_group, INPUT_READY_BIT);
8194
xEventGroupSetBits(user_event_group, KEY_SCAN_RUN_BIT);
8295

8396
xTaskCreatePinnedToCore(key_task, "KeyT", 2048, NULL, 5, NULL, 1);
8497
}
98+
#endif

main/src/user/key_handle.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
#ifdef CONFIG_ENABLE_SMARTCONFIG
2525
void key_smartconfig_handle(void)
2626
{
27-
EventBits_t uxBits = xEventGroupGetBits(os_event_group);
28-
if (uxBits & INPUT_READY_BIT) {
29-
ESP_LOGI(SC_KEY_TAG, "enter smartconfig mode");
30-
xEventGroupClearBits(user_event_group, KEY_SCAN_RUN_BIT);
31-
} else {
32-
return;
33-
}
27+
xEventGroupClearBits(user_event_group, KEY_SCAN_RUN_BIT);
3428

29+
ESP_LOGI(SC_KEY_TAG, "start smartconfig");
3530
xEventGroupSetBits(os_event_group, WIFI_CONFIG_BIT);
3631

3732
nfc_app_set_mode(0);

main/src/user/ntp.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ static void ntp_task(void *pvParameter)
9393

9494
void ntp_sync_time(void)
9595
{
96-
xEventGroupClearBits(os_event_group, INPUT_READY_BIT);
9796
EventBits_t uxBits = xEventGroupGetBits(user_event_group);
9897
if ((uxBits & NTP_READY_BIT) == 0) {
9998
xEventGroupSync(
@@ -103,7 +102,6 @@ void ntp_sync_time(void)
103102
portMAX_DELAY
104103
);
105104
}
106-
xEventGroupSetBits(os_event_group, INPUT_READY_BIT);
107105
}
108106

109107
void ntp_init(void)

0 commit comments

Comments
 (0)