it takes pictures, it uses timers, its great

This commit is contained in:
Morgan 'ARR\!' Allen 2019-09-14 18:40:37 -07:00
parent 8bc2fbc65e
commit 996a8b687f

View file

@ -11,8 +11,8 @@
#include <math.h> #include <math.h>
#include "freertos/FreeRTOS.h" #include "freertos/FreeRTOS.h"
#include "freertos/task.h" #include "freertos/task.h"
#include "freertos/timers.h"
#include "freertos/event_groups.h" #include "freertos/event_groups.h"
#include "driver/spi_master.h"
#include "esp_system.h" #include "esp_system.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_console.h" #include "esp_console.h"
@ -25,20 +25,28 @@
#include "soc/mcpwm_struct.h" #include "soc/mcpwm_struct.h"
#include "linenoise/linenoise.h" #include "linenoise/linenoise.h"
#include "argtable3/argtable3.h" #include "argtable3/argtable3.h"
#include "driver/gpio.h"
#include "esp32-wifi-manager.h" #include "esp32-wifi-manager.h"
#define TAG "CACO" #define TAG "CACO"
#define GPIO_INPUT_IO_0 33
#define GPIO_INPUT_PIN_SEL ((1ULL<<GPIO_INPUT_IO_0))
#define ESP_INTR_FLAG_DEFAULT 0
#define BASE_URL "http://192.168.0.1/" #define BASE_URL "http://192.168.0.1/"
#define CMD_BEEP "cmd=audio resplay 0 1 3\n" #define CMD_BEEP "cmd=audio resplay 0 1 3\n"
#define CONFIG_SERVO_ENABLE (0) #define CONFIG_SERVO_ENABLE (0)
#define CONFIG_SHOOT_DELAY_MS (30000) #define CONFIG_SHOOT_DELAY_MS (30000)
#define CONFIG_TIMEOUT_SHOOT (100 / portTICK_PERIOD_MS)
static uint8_t id; static uint8_t id;
EventGroupHandle_t wm_event_group; static EventGroupHandle_t wm_event_group;
static xQueueHandle gpio_evt_queue = NULL;
static xTimerHandle button_timer;
static struct { static struct {
struct arg_int *value; // how fast it will move in uS struct arg_int *value; // how fast it will move in uS
@ -145,7 +153,7 @@ void loop() {
vTaskDelay(1000 / portTICK_PERIOD_MS); vTaskDelay(1000 / portTICK_PERIOD_MS);
while(true) { while(true) {
shoot(); //shoot();
if(CONFIG_SERVO_ENABLE) { if(CONFIG_SERVO_ENABLE) {
vTaskDelay(3000 / portTICK_PERIOD_MS); vTaskDelay(3000 / portTICK_PERIOD_MS);
@ -270,6 +278,63 @@ static void initialize_console() {
linenoiseHistorySetMaxLen(100); linenoiseHistorySetMaxLen(100);
} }
static void IRAM_ATTR gpio_isr_handler(void* arg)
{
uint32_t gpio_num = (uint32_t) arg;
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
}
void gpio_loop() {
int8_t state = -1;
uint32_t io_num;
for(;;) {
if(xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
uint8_t level = gpio_get_level(io_num);
printf("GPIO[%d] intr, val: %d\n", io_num, level);
// don't act on state level twice
if(level == state) continue;
// track level for duplicate
state = level;
if(level == 0) {
xTimerChangePeriod(button_timer, CONFIG_TIMEOUT_SHOOT, portMAX_DELAY);
xTimerStart(button_timer, portMAX_DELAY);
} else {
xTimerStop(button_timer, portMAX_DELAY);
}
}
}
}
void handle_button_timer() {
shoot();
}
void gpio_init() {
gpio_config_t io_conf;
io_conf.intr_type = GPIO_PIN_INTR_ANYEDGE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 1;
gpio_config(&io_conf);
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
gpio_isr_handler_add(GPIO_INPUT_IO_0, gpio_isr_handler, (void*) GPIO_INPUT_IO_0);
//create a queue to handle gpio event from isr
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
//start gpio task
button_timer = xTimerCreate("gpio_timer", 1000, pdFALSE, (void*)NULL, handle_button_timer);
xTaskCreate(gpio_loop, "gpio_loop", 2048, NULL, 10, NULL);
}
void app_main() { void app_main() {
esp_err_t ret; esp_err_t ret;
@ -300,6 +365,8 @@ void app_main() {
} }
} }
wifi_manager_scan();
//initialize_console(); //initialize_console();
//esp_console_register_help_command(); //esp_console_register_help_command();
//register_servo_cmd(); //register_servo_cmd();
@ -310,6 +377,8 @@ void app_main() {
const char* prompt = LOG_COLOR_I "grii> " LOG_RESET_COLOR; const char* prompt = LOG_COLOR_I "grii> " LOG_RESET_COLOR;
gpio_init();
return; return;
while(true) { while(true) {
char* line = linenoise(prompt); char* line = linenoise(prompt);