gpio input

2-sided-pcb
Eggert Jung 6 years ago
parent e760559fcf
commit 0a02f17a5f

@ -8,24 +8,23 @@
#include "esp_log.h"
#include "nvs_flash.h"
#include <esp_http_server.h>
#include "driver/gpio.h"
#define WIFI_SSID "AndroidAP"
#define WIFI_PASS "uyts6533"
#define ESP_INTR_FLAG_DEFAULT 0
uint8_t led_state = 0;
// Event group
static EventGroupHandle_t wifi_event_group;
const int CONNECTED_BIT = BIT0;
static xQueueHandle gpio_evt_queue = NULL;
static char* resp_str ="\
<input type=\"submit\" name=\"lamp_state\" onclick=\"sendState(this.value)\" value=\"ON\"> \
<input type=\"submit\" name=\"lamp_state\" onclick=\"sendState(this.value)\" value=\"OFF\"> \
<label class=\"switch\">\
<input type=\"checkbox\">\
<span class=\"slider\"></span>\
</label>\
</form> \
\
<input type=\"range\" min=\"0\" max=\"100\" value=\"0\" oninput=\"sendSlider(this.value)\" class=\"slider\" id=\"myRange\"> \
<script> \
function sendSlider(data) { \
@ -53,6 +52,32 @@ static const httpd_uri_t default_uri = {
.handler = &default_get_handler
};
static void IRAM_ATTR gpio_isr_handler(void* arg)
{
uint32_t gpio_num = (uint32_t) arg;
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
}
static void gpio_task(void* arg)
{
printf("GPIO task started\n");
uint32_t io_num;
for(;;) {
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
printf("GPIO[%d] intr, val: %d\n", io_num, gpio_get_level(io_num));
}
}
led_state^=1;
if(led_state){
ledc_set_duty(ledc_channel.speed_mode, ledc_channel.channel, 1<<11);
ledc_update_duty(ledc_channel.speed_mode, ledc_channel.channel);
}
else{
ledc_set_duty(ledc_channel.speed_mode, ledc_channel.channel, 0);
ledc_update_duty(ledc_channel.speed_mode, ledc_channel.channel);
}
}
// Wifi event handler
static esp_err_t event_handler(void *ctx, system_event_t *event)
{
@ -81,6 +106,19 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
// Main application
void app_main()
{
gpio_config_t io_conf;
io_conf.intr_type = GPIO_PIN_INTR_NEGEDGE;
io_conf.pin_bit_mask = (1ULL<<17);
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 1;
gpio_config(&io_conf);
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
xTaskCreate(&gpio_task, "gpio_task", 2048, NULL, 10, NULL);
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
gpio_isr_handler_add(17, gpio_isr_handler, (void*) 17);
// disable the default wifi logging
esp_log_level_set("wifi", ESP_LOG_NONE);

Loading…
Cancel
Save