1 | // plow_main.c |
2 | // Main logic controller for the snow plow |
3 | // Copyright (c) Joshua 'joshuas3' Stockin 2019 |
4 |
|
5 | #include "plow_main.h" |
6 | #include "pulseIn.h" |
7 | #include "util.h" |
8 |
|
9 | #include <stdio.h> |
10 |
|
11 | #include "esp_system.h" |
12 | #include "esp_task_wdt.h" |
13 | #include "freertos/FreeRTOS.h" |
14 | #include "freertos/task.h" |
15 | #include "driver/gpio.h" |
16 |
|
17 | static void pingTask(void * pingOK) { |
18 | configASSERT(((bool)pingOK) == true); |
19 | static int beeps; |
20 | for (;;) { |
21 | delay(2400); |
22 | printf("ping x%d - %i ticks\n", ++beeps, xTaskGetTickCount()); |
23 | gpio_set_level(STATUS_YELLOW, HIGH); |
24 | delay(0200); |
25 | gpio_set_level(STATUS_YELLOW, LOW); |
26 | delay(0200); |
27 | gpio_set_level(STATUS_YELLOW, HIGH); |
28 | delay(0200); |
29 | gpio_set_level(STATUS_YELLOW, LOW); |
30 | } |
31 | } |
32 |
|
33 | static void radioTask(void * arg) { |
34 | configASSERT(((bool)arg) == true); |
35 | int R1; |
36 | int R2; |
37 | int R3; |
38 | int R4; |
39 | int R5; |
40 | int R6; |
41 | for (;;) { |
42 | R1 = pulseIn(RADIO_1, true); |
43 | R2 = pulseIn(RADIO_2, true); |
44 | R3 = pulseIn(RADIO_3, true); |
45 | R4 = pulseIn(RADIO_4, true); |
46 | R5 = pulseIn(RADIO_5, true); |
47 | R6 = pulseIn(RADIO_6, true); |
48 | printf("%i\t%i\t%i\t%i\t%i\t%i\n", R1, R2, R3, R4, R5, R6); |
49 | esp_task_wdt_reset(); |
50 | delay(10); |
51 | } |
52 | } |
53 |
|
54 | void app_main(void) |
55 | { |
56 | printf("entering app_main\n"); |
57 |
|
58 | printf("configuring STATUS_[GREEN|YELLOW|RED] GPIO output\n"); |
59 | gpio_config_t io_conf; |
60 | io_conf.pin_bit_mask = (1ULL<<STATUS_GREEN) | (1ULL<<STATUS_YELLOW) | (1ULL<<STATUS_RED); |
61 | io_conf.mode = GPIO_MODE_OUTPUT; |
62 | io_conf.pull_up_en = 0; |
63 | io_conf.pull_down_en = 1; |
64 | io_conf.intr_type = GPIO_INTR_DISABLE; |
65 | gpio_config(&io_conf); |
66 |
|
67 | printf("configuring RADIO_[1-6] GPIO input\n"); |
68 | io_conf.pin_bit_mask = (1ULL<<RADIO_1) | (1ULL<<RADIO_2) | (1ULL<<RADIO_3) | (1ULL<<RADIO_4) | (1ULL<<RADIO_5) | (1ULL<<RADIO_6); |
69 | io_conf.mode = GPIO_MODE_INPUT; |
70 | io_conf.pull_up_en = 0; |
71 | io_conf.pull_down_en = 0; |
72 | io_conf.intr_type = GPIO_INTR_DISABLE; |
73 | gpio_config(&io_conf); |
74 |
|
75 | printf("creating ping task\n"); |
76 | TaskHandle_t pingTaskHandle = NULL; |
77 | xTaskCreate(pingTask, "pingTask", 2000, (void *)true, tskIDLE_PRIORITY, &pingTaskHandle); |
78 |
|
79 | printf("creating radio task\n"); |
80 | TaskHandle_t radioTaskHandle = NULL; |
81 | xTaskCreate(radioTask, "radioTask", 10000, (void *)true, 1, &radioTaskHandle); |
82 |
|
83 | printf("setting STATUS_GREEN HIGH\n"); |
84 | gpio_set_level(STATUS_GREEN, HIGH); |
85 | } |
86 |
|