2023-09-18 20:41:46 +00:00
|
|
|
#include "leds.h"
|
2023-09-15 06:21:00 +00:00
|
|
|
#include "shared.h"
|
|
|
|
#include "network.h"
|
2023-09-18 20:41:46 +00:00
|
|
|
#include "server.h"
|
2023-09-15 06:21:00 +00:00
|
|
|
#include "rom/ets_sys.h"
|
2023-09-28 12:31:14 +00:00
|
|
|
#include "esp_system.h"
|
|
|
|
#include "esp_netif.h"
|
|
|
|
#include "esp_event.h"
|
2023-09-15 06:21:00 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2023-09-28 12:31:14 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
2023-09-15 06:21:00 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2023-09-19 08:34:06 +00:00
|
|
|
// starts the basic subsystems we will be using
|
2023-09-18 20:41:46 +00:00
|
|
|
static
|
|
|
|
void init_esp(void) {
|
2023-09-19 08:34:06 +00:00
|
|
|
// start the networking interface
|
2023-09-18 20:41:46 +00:00
|
|
|
ESP_ERROR_CHECK(esp_netif_init());
|
2023-09-19 08:34:06 +00:00
|
|
|
// start the event loop
|
2023-09-18 20:41:46 +00:00
|
|
|
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
|
|
|
}
|
|
|
|
|
2023-09-21 10:01:02 +00:00
|
|
|
static
|
|
|
|
void TEST_leds() {
|
|
|
|
// TEST: after a delay, set the leds to a gradient of red - black
|
|
|
|
sleep(1);
|
|
|
|
|
2023-09-28 12:43:07 +00:00
|
|
|
Led led = {
|
2023-09-21 10:01:02 +00:00
|
|
|
.components = {
|
|
|
|
.red = 0,
|
|
|
|
.green = 255,
|
|
|
|
.blue = 0,
|
|
|
|
.global = GLOBAL(10)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-09-27 12:59:03 +00:00
|
|
|
set_led_range(0, 120, led);
|
2023-09-21 10:01:02 +00:00
|
|
|
led.components.blue = 255;
|
2023-09-27 12:59:03 +00:00
|
|
|
set_led_range(60, 120, led);
|
2023-09-21 10:01:02 +00:00
|
|
|
send_leds();
|
|
|
|
|
|
|
|
sleep(1);
|
|
|
|
|
2023-09-28 12:43:07 +00:00
|
|
|
Gradient gradient;
|
2023-09-27 12:59:03 +00:00
|
|
|
gradient.points_len = 4;
|
|
|
|
|
|
|
|
gradient.points[0].offset = 0;
|
|
|
|
gradient.points[0].movement = 0;
|
2023-09-28 12:43:07 +00:00
|
|
|
gradient.points[0].led.components = (LedComponents) {
|
2023-09-27 12:59:03 +00:00
|
|
|
.global = GLOBAL(0),
|
|
|
|
.red = 0,
|
2023-09-21 10:01:02 +00:00
|
|
|
.green = 0,
|
2023-09-27 12:59:03 +00:00
|
|
|
.blue = 0,
|
2023-09-21 10:01:02 +00:00
|
|
|
};
|
|
|
|
|
2023-09-27 12:59:03 +00:00
|
|
|
gradient.points[1].offset = 59;
|
|
|
|
gradient.points[1].movement = -1;
|
2023-09-28 12:43:07 +00:00
|
|
|
gradient.points[1].led.components = (LedComponents){
|
2023-09-21 10:01:02 +00:00
|
|
|
.global = GLOBAL(10),
|
|
|
|
.red = 40,
|
2023-09-27 12:59:03 +00:00
|
|
|
.green = 200,
|
2023-09-21 10:01:02 +00:00
|
|
|
.blue = 40,
|
|
|
|
};
|
2023-09-27 12:59:03 +00:00
|
|
|
gradient.points[2].offset = 61;
|
|
|
|
gradient.points[2].movement = 1;
|
2023-09-28 12:43:07 +00:00
|
|
|
gradient.points[2].led.components = (LedComponents){
|
2023-09-21 10:01:02 +00:00
|
|
|
.global = GLOBAL(10),
|
2023-09-27 12:59:03 +00:00
|
|
|
.red = 40,
|
|
|
|
.green = 200,
|
|
|
|
.blue = 40,
|
|
|
|
};
|
|
|
|
gradient.points[3].offset = 120;
|
|
|
|
gradient.points[3].movement = 0;
|
2023-09-28 12:43:07 +00:00
|
|
|
gradient.points[3].led.components = (LedComponents){
|
2023-09-27 12:59:03 +00:00
|
|
|
.global = GLOBAL(0),
|
|
|
|
.red = 0,
|
|
|
|
.green = 0,
|
|
|
|
.blue = 0,
|
2023-09-21 10:01:02 +00:00
|
|
|
};
|
|
|
|
|
2023-09-27 12:59:03 +00:00
|
|
|
leds_set_current_gradient(&gradient, 0);
|
2023-09-21 10:01:02 +00:00
|
|
|
}
|
|
|
|
|
2023-09-18 20:41:46 +00:00
|
|
|
void app_main(void) {
|
|
|
|
LOGLN("---- starting");
|
2023-09-15 06:21:00 +00:00
|
|
|
|
2023-09-19 08:34:06 +00:00
|
|
|
// start hardware subsystems
|
2023-09-18 20:41:46 +00:00
|
|
|
init_esp();
|
2023-09-19 08:34:06 +00:00
|
|
|
// startup leds and send initial state
|
2023-09-18 20:41:46 +00:00
|
|
|
leds_init();
|
|
|
|
send_leds();
|
2023-09-19 08:34:06 +00:00
|
|
|
// start wifi subsystem
|
2023-09-15 06:21:00 +00:00
|
|
|
wifi_init();
|
2023-09-19 08:34:06 +00:00
|
|
|
// configure wifi hardware to act as an access point
|
2023-09-15 06:21:00 +00:00
|
|
|
softap_init();
|
2023-09-19 08:34:06 +00:00
|
|
|
// start listening for HTTP signals
|
2023-09-18 20:41:46 +00:00
|
|
|
server_init();
|
|
|
|
|
2023-09-21 10:01:02 +00:00
|
|
|
TEST_leds();
|
2023-09-19 08:34:06 +00:00
|
|
|
|
2023-09-15 06:21:00 +00:00
|
|
|
|
2023-09-18 20:41:46 +00:00
|
|
|
LOGLN("---- finished setting up");
|
2023-09-15 06:21:00 +00:00
|
|
|
}
|
|
|
|
|