stash
This commit is contained in:
parent
1d4613e0d4
commit
bce33fa836
3 changed files with 295 additions and 275 deletions
|
@ -11,25 +11,27 @@
|
|||
#include "esp/spi.h"
|
||||
#include "math.h"
|
||||
#include <time.h>
|
||||
#include <semphr.h>
|
||||
|
||||
#define DAYTIME(h, m, s) (h*3600+m*60+s)
|
||||
|
||||
extern SemaphoreHandle_t time_available_semaphore;
|
||||
|
||||
struct {
|
||||
time_t sunrise_start = DAYTIME(5,30,0);
|
||||
time_t sunrise_end = DAYTIME(6,0,0);
|
||||
time_t sunrise_start = DAYTIME(8, 30, 0);
|
||||
time_t sunrise_end = DAYTIME(9, 0, 0);
|
||||
time_t sunrise_shutdown = DAYTIME(7, 0, 0);
|
||||
time_t sunset_time = DAYTIME(22, 0, 0);
|
||||
} settings;
|
||||
|
||||
|
||||
|
||||
struct {
|
||||
uint8_t r = 255;
|
||||
uint8_t g = 160;
|
||||
uint8_t b = 80;
|
||||
} white;
|
||||
|
||||
time_t day_seconds() {
|
||||
extern "C" time_t day_seconds() {
|
||||
time_t t1, t2;
|
||||
struct tm tms;
|
||||
time(&t1);
|
||||
|
@ -87,17 +89,19 @@ void write_leds(){
|
|||
spi_transfer_32(1, 0xFFFFFFFF);
|
||||
}
|
||||
|
||||
enum state_t{ BOOT_S, SUNRISE_S, MORNING_S, DAY_S, NIGHT_S };
|
||||
enum state_t {
|
||||
BOOT_S, SUNRISE_S, MORNING_S, DAY_S, NIGHT_S
|
||||
};
|
||||
|
||||
state_t s = BOOT_S;
|
||||
volatile state_t s = BOOT_S;
|
||||
|
||||
bool maual_mode = false;
|
||||
volatile bool maual_mode = false;
|
||||
|
||||
extern "C" void manual_switch() {
|
||||
|
||||
maual_mode = !maual_mode;
|
||||
|
||||
printf("%d\n", (int)maual_mode);
|
||||
printf("int %d\n", (int) maual_mode);
|
||||
|
||||
if(maual_mode) {
|
||||
|
||||
|
@ -135,11 +139,28 @@ extern "C" void manual_switch(){
|
|||
}
|
||||
}
|
||||
|
||||
void loop(void *pvParameters)
|
||||
{
|
||||
[[noreturn]] void loop(void *pvParameters) {
|
||||
spi_init(1, SPI_MODE0, SPI_FREQ_DIV_1M, 1, SPI_LITTLE_ENDIAN, false);
|
||||
|
||||
while(1){
|
||||
while (!uxSemaphoreGetCount(time_available_semaphore))
|
||||
vTaskDelay(500 / portTICK_PERIOD_MS);
|
||||
|
||||
maual_mode = false;
|
||||
|
||||
for (int j = 0; j < 4; j++)
|
||||
for (int i = 0; i < 10; i++) {
|
||||
leds[j][i].global.mod = 0;
|
||||
leds[j][i].r = 0;
|
||||
leds[j][i].g = 0;
|
||||
leds[j][i].b = 0;
|
||||
}
|
||||
write_leds();
|
||||
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
|
||||
printf("START>\n");
|
||||
|
||||
while (true) {
|
||||
|
||||
time_t rt = day_seconds();
|
||||
|
||||
|
@ -178,6 +199,16 @@ void loop(void *pvParameters)
|
|||
s = MORNING_S;
|
||||
printf("MORNING_S\n");
|
||||
}
|
||||
if(rt >= settings.sunset_time || rt < settings.sunrise_start) {
|
||||
s = NIGHT_S;
|
||||
printf("NIGHT_S\n");
|
||||
}
|
||||
|
||||
printf("%lld | %lld %lld %lld %lld\n", rt,
|
||||
settings.sunrise_start,
|
||||
settings.sunrise_end,
|
||||
settings.sunset_time,
|
||||
settings.sunrise_shutdown);
|
||||
} else if(s == SUNRISE_S) {
|
||||
if(rt >= settings.sunrise_end) {
|
||||
s = MORNING_S;
|
||||
|
@ -187,13 +218,13 @@ void loop(void *pvParameters)
|
|||
int t = (rt - settings.sunrise_start) * (1000 / 50);
|
||||
for (; t < steps && !maual_mode; t++) {
|
||||
|
||||
for(int j = 0; j < 4; j++)
|
||||
for (auto &led: leds)
|
||||
for (int i = 0; i < 10; i++) {
|
||||
float val = (-i * 30. + t * 3. * (4. / 5.)) / (float) steps;
|
||||
leds[j][i].global.mod = 8 + fade(val,0.,0.5)*23;
|
||||
leds[j][i].r = fade(val,0.01,1.) * white.r;
|
||||
leds[j][i].g = fade(val,0.1,0.5) * white.g;
|
||||
leds[j][i].b = fade(val,0.6,0.7) * white.b;
|
||||
led[i].global.mod = 8 + fade(val, 0., 0.5) * 23;
|
||||
led[i].r = fade(val, 0.01, 1.) * white.r;
|
||||
led[i].g = fade(val, 0.1, 0.5) * white.g;
|
||||
led[i].b = fade(val, 0.6, 0.7) * white.b;
|
||||
}
|
||||
|
||||
write_leds();
|
||||
|
@ -254,8 +285,6 @@ void loop(void *pvParameters)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
extern "C" void register_app(void)
|
||||
{
|
||||
xTaskCreate(loop, "loop", 1024, NULL, 2, NULL);
|
||||
extern "C" void register_app(void) {
|
||||
xTaskCreate(loop, "loop", 512, nullptr, 2, NULL);
|
||||
}
|
||||
|
|
|
@ -39,18 +39,24 @@
|
|||
#define vTaskDelayMs(ms) vTaskDelay((ms)/portTICK_PERIOD_MS)
|
||||
#define UNUSED_ARG(x) (void)x
|
||||
|
||||
|
||||
const gpio_inttype_t int_type = GPIO_INTTYPE_EDGE_NEG;
|
||||
|
||||
|
||||
SemaphoreHandle_t time_available_semaphore;
|
||||
|
||||
|
||||
time_t day_seconds();
|
||||
|
||||
void sntp_tsk(void *pvParameters)
|
||||
{
|
||||
|
||||
void sntp_tsk(void *pvParameters) {
|
||||
const char *servers[] = {SNTP_SERVERS};
|
||||
UNUSED_ARG(pvParameters);
|
||||
|
||||
while (!uxSemaphoreGetCount(wifi_available_semaphore)) {
|
||||
vTaskDelay(2000 / portTICK_PERIOD_MS);
|
||||
printf("waitfi\n");
|
||||
}
|
||||
|
||||
/* Wait until we have joined AP and are assigned an IP */
|
||||
while (sdk_wifi_station_get_connect_status() != STATION_GOT_IP) {
|
||||
vTaskDelayMs(100);
|
||||
|
@ -66,14 +72,16 @@ void sntp_tsk(void *pvParameters)
|
|||
sntp_initialize(&tz);
|
||||
/* Servers must be configured right after initialization */
|
||||
sntp_set_servers(servers, sizeof(servers) / sizeof(char *));
|
||||
printf("DONE!\n");
|
||||
printf("SNTP DONE!\n");
|
||||
|
||||
xSemaphoreGive(time_available_semaphore);
|
||||
|
||||
/* Print date and time each 5 seconds */
|
||||
while (1) {
|
||||
vTaskDelayMs(5000);
|
||||
//time_t ts = time(NULL);
|
||||
//int t = ts;
|
||||
//printf("TIME: %d %d %s", t,(int) day_seconds(), ctime(&ts));
|
||||
time_t ts = time(NULL);
|
||||
int t = ts;
|
||||
printf("TIME: %d %d %s", t, (int) day_seconds(), ctime(&ts));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -111,41 +119,7 @@ void gpio_intr_handler(uint8_t gpio_num)
|
|||
|
||||
void register_app(void);
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||
|
||||
struct sdk_station_config config = {
|
||||
.ssid = WIFI_SSID,
|
||||
.password = WIFI_PASS,
|
||||
};
|
||||
|
||||
/* required to call wifi_set_opmode before station_set_config */
|
||||
sdk_wifi_set_opmode(STATION_MODE);
|
||||
sdk_wifi_station_set_config(&config);
|
||||
//netif_set_hostname(netif_default, "nachtlicht");
|
||||
sdk_wifi_station_connect();
|
||||
|
||||
/* turn off LED */
|
||||
gpio_enable(LED_PIN, GPIO_OUTPUT);
|
||||
gpio_write(LED_PIN, true);
|
||||
|
||||
|
||||
gpio_enable(SWITCH_PIN, GPIO_INPUT);
|
||||
|
||||
tsqueue = xQueueCreate(2, sizeof(uint32_t));
|
||||
//xTaskCreate(buttonIntTask, "buttonIntTask", 256, &tsqueue, 2, NULL);
|
||||
|
||||
/* initialize tasks */
|
||||
xTaskCreate(&httpd_task, "HTTP Daemon", 2048, NULL, 2, NULL);
|
||||
|
||||
xTaskCreate(&sntp_tsk, "SNTP", 512, NULL, 1, NULL);
|
||||
register_app();
|
||||
}
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
void user_init(void) {
|
||||
uart_set_baud(0, 115200);
|
||||
printf("SDK version: %s\n", sdk_system_get_sdk_version());
|
||||
|
||||
|
@ -154,13 +128,26 @@ void user_init(void)
|
|||
system_init_config();
|
||||
|
||||
wifi_available_semaphore = xSemaphoreCreateBinary();
|
||||
time_available_semaphore = xSemaphoreCreateBinary();
|
||||
|
||||
gpio_enable(SWITCH_PIN, GPIO_INPUT);
|
||||
|
||||
tsqueue = xQueueCreate(2, sizeof(uint32_t));
|
||||
|
||||
xTaskCreate(wifi_task, "wifi_task", 1024, NULL, 1, NULL);
|
||||
|
||||
xTaskCreate(&httpd_task, "httpd_task", 1024, NULL, 2, NULL);
|
||||
//xTaskCreate(&httpd_task, "httpd_task", 1024, NULL, 2, NULL);
|
||||
|
||||
xTaskCreate(&lux_task, "lux_task", 512, NULL, 1, NULL);
|
||||
//xTaskCreate(&lux_task, "lux_task", 512, NULL, 1, NULL);
|
||||
|
||||
xTaskCreate(&sntp_tsk, "SNTP", 512, NULL, 1, NULL);
|
||||
|
||||
//xTaskCreate(buttonIntTask, "buttonIntTask", 256, &tsqueue, 2, NULL);
|
||||
|
||||
register_app();
|
||||
|
||||
gpio_enable(LED_PIN, GPIO_OUTPUT);
|
||||
gpio_write(LED_PIN, true);
|
||||
rboot_config conf = rboot_get_config();
|
||||
printf("\r\n\r\nOTA Basic demo.\r\nCurrently running on flash slot %d / %d.\r\n\r\n",
|
||||
conf.current_rom, conf.count);
|
||||
|
|
|
@ -358,6 +358,10 @@ extern "C" void wifi_task(void *pvParameters) {
|
|||
if(wifi_ap_ssid) free(wifi_ap_ssid);
|
||||
if(wifi_ap_password) free(wifi_ap_password);
|
||||
|
||||
|
||||
//gpio_enable(LED_PIN, GPIO_OUTPUT);
|
||||
//gpio_write(LED_PIN, true);
|
||||
|
||||
xSemaphoreGive(wifi_available_semaphore);
|
||||
|
||||
//monitor loop connection here
|
||||
|
|
Loading…
Reference in a new issue