Skip to content

Commit 9f8be8d

Browse files
committed
use input framework to check for waiting input.
1 parent a4023bd commit 9f8be8d

File tree

1 file changed

+39
-47
lines changed

1 file changed

+39
-47
lines changed

esp32/main.c

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@
5151
#include "uart.h"
5252
#include "modmachine.h"
5353
#include "mpthreadport.h"
54+
#include "bpp_init.h"
5455
#include "badge_portexp.h"
5556
#include "badge_pins.h"
56-
#include "bpp_init.h"
57-
#include "driver/gpio.h"
5857
#include "badge_base.h"
5958
#include "badge_first_run.h"
59+
#include <badge_input.h>
60+
#include <badge.h>
6061

6162
// MicroPython runs as a task under FreeRTOS
6263
#define MP_TASK_PRIORITY (ESP_TASK_PRIO_MIN + 1)
@@ -128,60 +129,51 @@ void mp_task(void *pvParameter) {
128129
}
129130

130131
void do_bpp_bgnd() {
131-
//Kick off bpp
132-
bpp_init();
133-
printf("Bpp inited.\n");
134-
//immediately abort and reboot when touchpad detects something
135-
while(gpio_get_level(PIN_NUM_MPR121_INT)==1) {
136-
vTaskDelay(10);
137-
}
138-
printf("Touch detected. Exiting bpp, rebooting.\n");
132+
// Kick off bpp
133+
bpp_init();
134+
135+
printf("Bpp inited.\n");
136+
137+
// immediately abort and reboot when touchpad detects something
138+
while (badge_input_get_event(1000) == 0) { }
139+
140+
printf("Touch detected. Exiting bpp, rebooting.\n");
139141
esp_restart();
140142
}
141143

142144
void app_main(void) {
143-
badge_check_first_run();
144-
badge_base_init();
145+
badge_check_first_run();
146+
badge_base_init();
145147

146-
uint8_t magic = esp_rtcmem_read(0);
147-
uint8_t inv_magic = esp_rtcmem_read(1);
148+
uint8_t magic = esp_rtcmem_read(0);
149+
uint8_t inv_magic = esp_rtcmem_read(1);
148150

149-
#ifdef CONFIG_SHA_BPP_ENABLE
150-
//Grab level of int pin of touchpad. If high, this was a
151-
//scheduled wakeup because of a deep sleep timeout. If low,
152-
//the user used the touchpad.
153-
//yes, this is v1 specific. Please add v0.x support yourself.
154-
gpio_config_t io_conf = {
155-
.mode = GPIO_MODE_INPUT,
156-
.pin_bit_mask = 1LL << PIN_NUM_MPR121_INT,
157-
.pull_down_en = 0,
158-
.pull_up_en = 1,
159-
};
160-
gpio_config(&io_conf);
161-
#endif
151+
if (magic == (uint8_t)~inv_magic) {
152+
printf("Magic checked out!\n");
153+
switch (magic) {
154+
case 1:
155+
printf("Starting OTA\n");
156+
sha2017_ota_update();
157+
break;
162158

163-
if (magic == (uint8_t)~inv_magic) {
164-
printf("Magic checked out!\n");
165-
switch (magic) {
166-
case 1:
167-
printf("Starting OTA\n");
168-
sha2017_ota_update();
169-
break;
170159
#ifdef CONFIG_SHA_BPP_ENABLE
171-
case 2:
172-
if (gpio_get_level(PIN_NUM_MPR121_INT)==1) {
173-
printf("Touch int is high. Starting bpp.\n");
174-
do_bpp_bgnd();
175-
}
176-
break;
160+
case 2:
161+
badge_init();
162+
if (badge_input_button_state == 0) {
163+
printf("Starting bpp.\n");
164+
do_bpp_bgnd();
165+
}
166+
break;
177167
#endif
178-
case 3:
179-
badge_first_run();
180-
}
181-
} else {
182-
xTaskCreateStaticPinnedToCore(mp_task, "mp_task", MP_TASK_STACK_LEN, NULL, MP_TASK_PRIORITY,
183-
&mp_task_stack[0], &mp_task_tcb, 0);
184-
}
168+
169+
case 3:
170+
badge_first_run();
171+
}
172+
173+
} else {
174+
xTaskCreateStaticPinnedToCore(mp_task, "mp_task", MP_TASK_STACK_LEN, NULL, MP_TASK_PRIORITY,
175+
&mp_task_stack[0], &mp_task_tcb, 0);
176+
}
185177
}
186178

187179
void nlr_jump_fail(void *val) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy