potion_party_leds/main/potion_party.c

101 lines
2.2 KiB
C

#include "leds.h"
#include "shared.h"
#include "network.h"
#include "server.h"
#include "rom/ets_sys.h"
#include <stdio.h>
#include <string.h>
// starts the basic subsystems we will be using
static
void init_esp(void) {
// start the networking interface
ESP_ERROR_CHECK(esp_netif_init());
// start the event loop
ESP_ERROR_CHECK(esp_event_loop_create_default());
}
static
void TEST_leds() {
// TEST: after a delay, set the leds to a gradient of red - black
sleep(1);
union led_t led = {
.components = {
.red = 0,
.green = 255,
.blue = 0,
.global = GLOBAL(10)
}
};
set_led_range(0, 120, led);
led.components.blue = 255;
set_led_range(60, 120, led);
send_leds();
sleep(1);
struct gradient_t gradient;
gradient.points_len = 4;
gradient.points[0].offset = 0;
gradient.points[0].movement = 0;
gradient.points[0].led.components = (struct led_components_t) {
.global = GLOBAL(0),
.red = 0,
.green = 0,
.blue = 0,
};
gradient.points[1].offset = 59;
gradient.points[1].movement = -1;
gradient.points[1].led.components = (struct led_components_t){
.global = GLOBAL(10),
.red = 40,
.green = 200,
.blue = 40,
};
gradient.points[2].offset = 61;
gradient.points[2].movement = 1;
gradient.points[2].led.components = (struct led_components_t){
.global = GLOBAL(10),
.red = 40,
.green = 200,
.blue = 40,
};
gradient.points[3].offset = 120;
gradient.points[3].movement = 0;
gradient.points[3].led.components = (struct led_components_t){
.global = GLOBAL(0),
.red = 0,
.green = 0,
.blue = 0,
};
leds_set_current_gradient(&gradient, 0);
}
void app_main(void) {
LOGLN("---- starting");
// start hardware subsystems
init_esp();
// startup leds and send initial state
leds_init();
send_leds();
// start wifi subsystem
wifi_init();
// configure wifi hardware to act as an access point
softap_init();
// start listening for HTTP signals
server_init();
TEST_leds();
LOGLN("---- finished setting up");
}