Hardware mirror in the ST7789 (rotation 3 <-> rotation 1); the 35-px window offset is the same both ways. Stored in settings v3.
68 lines
2.0 KiB
C
68 lines
2.0 KiB
C
#include "battery.h"
|
|
#include "board.h"
|
|
#include "display.h"
|
|
#include "input.h"
|
|
#include "jpegdec.h"
|
|
#include "leds.h"
|
|
#include "net.h"
|
|
#include "power.h"
|
|
#include "settings.h"
|
|
#include "slideshow.h"
|
|
#include "ui.h"
|
|
#include "sdkconfig.h"
|
|
#include "driver/gpio.h"
|
|
#include "esp_log.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
|
|
static const char *TAG = "main";
|
|
|
|
static void run_portal(void)
|
|
{
|
|
net_start_portal();
|
|
leds_set_mode(LED_BREATHE, 0x8030ff);
|
|
ui_status("Wi-Fi setup",
|
|
"Join the Wi-Fi network\n\"" CONFIG_WIDGET_AP_SSID "\" with your phone.\n"
|
|
"The setup page opens by itself\n(or browse to http://192.168.4.1)");
|
|
net_wait_connected(-1);
|
|
}
|
|
|
|
void app_main(void)
|
|
{
|
|
board_init();
|
|
power_report_wakeup();
|
|
settings_init();
|
|
leds_init();
|
|
leds_set_brightness(settings.led_brightness);
|
|
power_confirm_wake(); // may go back to sleep instead of returning
|
|
leds_set_mode(LED_BREATHE, 0x404040);
|
|
|
|
display_init();
|
|
display_set_flipped(settings.flip);
|
|
ui_init();
|
|
ui_set_theme(settings.theme);
|
|
ui_status("insecam widget", "starting");
|
|
display_set_backlight(settings.lcd_brightness);
|
|
|
|
ESP_ERROR_CHECK(jpegdec_init());
|
|
battery_init();
|
|
net_init();
|
|
|
|
// Holding the knob after power-up forces the setup hotspot.
|
|
gpio_config_t btn = {.pin_bit_mask = 1ULL << board->enc_btn, .mode = GPIO_MODE_INPUT, .pull_up_en = 1};
|
|
gpio_config(&btn);
|
|
bool force_setup = !gpio_get_level(board->enc_btn) || settings_take_portal_request();
|
|
input_init();
|
|
|
|
if (force_setup || !net_has_credentials()) {
|
|
run_portal();
|
|
} else {
|
|
ui_status("insecam widget", "connecting to Wi-Fi");
|
|
if (!net_wait_connected(20000)) run_portal();
|
|
}
|
|
ESP_LOGI(TAG, "online at %s", net_ip_str());
|
|
ui_status("insecam widget", "online - finding cameras\n\nturn: next / previous\nclick: pause\nhold: menu");
|
|
leds_set_mode(LED_SPIN, 0x2060ff);
|
|
slideshow_start();
|
|
}
|