mirror of
https://github.com/usatiuk/cardboy.git
synced 2025-10-28 23:27:49 +01:00
120 lines
3.1 KiB
C++
120 lines
3.1 KiB
C++
/*
|
|
* SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD
|
|
*
|
|
* SPDX-License-Identifier: CC0-1.0
|
|
*/
|
|
|
|
#include <buttons.hpp>
|
|
#include <cstdint>
|
|
#include <disp_tools.hpp>
|
|
#include <disp_tty.hpp>
|
|
#include <esp_pm.h>
|
|
#include <inttypes.h>
|
|
#include <stdio.h>
|
|
#include "esp_chip_info.h"
|
|
#include "esp_flash.h"
|
|
#include "esp_system.h"
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "sdkconfig.h"
|
|
|
|
#include "display.hpp"
|
|
|
|
#include "bat_mon.hpp"
|
|
#include "driver/i2c_master.h"
|
|
#include "driver/spi_master.h"
|
|
#include "i2c_global.hpp"
|
|
|
|
#include <driver/gpio.h>
|
|
#include <esp_sleep.h>
|
|
#include <memory>
|
|
#include <power_helper.hpp>
|
|
#include <shutdowner.hpp>
|
|
#include <spi_global.hpp>
|
|
#include <string>
|
|
|
|
FbTty tty;
|
|
|
|
|
|
extern "C" void app_main() {
|
|
esp_pm_config_t pm_config = {
|
|
.max_freq_mhz = CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ, .min_freq_mhz = 16, .light_sleep_enable = true};
|
|
ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
|
|
printf("Hello world!\n");
|
|
// TODO: Where to put that?
|
|
ESP_ERROR_CHECK(esp_sleep_enable_gpio_wakeup());
|
|
// For some reason, calling it here hangs on startup, sometimes
|
|
// ESP_ERROR_CHECK(gpio_install_isr_service(0));
|
|
PowerHelper::get();
|
|
Shutdowner::get();
|
|
ESP_ERROR_CHECK(gpio_install_isr_service(0));
|
|
Shutdowner::get().install_isr();
|
|
PowerHelper::get().install_isr();
|
|
Buttons::get();
|
|
I2cGlobal::get();
|
|
BatMon::get();
|
|
SpiGlobal::get();
|
|
SMD::get();
|
|
SMD::get().clear();
|
|
DispTools::get().clear();
|
|
DispTools::get().draw_line(0, 0, 400, 240);
|
|
DispTools::get().draw_circle(100, 100, 20);
|
|
DispTools::get().draw_to_display();
|
|
tty.putstr("Hello\nworld!");
|
|
DispTools::get().draw_to_display();
|
|
|
|
int rx = 30, ry = 30;
|
|
|
|
int lastmove = 0;
|
|
|
|
while (true) {
|
|
// SMD::clear();
|
|
// printf("Voltage: %f\n", BatMon::get_voltage());
|
|
DispTools::get().clear();
|
|
tty.reset();
|
|
|
|
uint8_t pressed = Buttons::get().get_pressed();
|
|
if (pressed & L3)
|
|
rx -= 5;
|
|
if (pressed & L4)
|
|
ry += 5;
|
|
if (pressed & R3)
|
|
ry -= 5;
|
|
if (pressed & R4)
|
|
rx += 5;
|
|
|
|
if (pressed == 0 && !PowerHelper::get().is_slow())
|
|
lastmove++;
|
|
else if (pressed != 0) {
|
|
lastmove = 0;
|
|
PowerHelper::get().set_slow(false);
|
|
}
|
|
|
|
if (lastmove > 20) {
|
|
lastmove = 0;
|
|
PowerHelper::get().set_slow(true);
|
|
}
|
|
|
|
bool slow = PowerHelper::get().is_slow();
|
|
tty.fmt("{:.1f}mA {:.1f}V {:.1f}mAh {}", BatMon::get().get_current(), BatMon::get().get_voltage(),
|
|
BatMon::get().get_charge(), slow ? "S" : "");
|
|
|
|
if (rx < 30)
|
|
rx = 30;
|
|
if (rx > 370)
|
|
rx = 370;
|
|
if (ry < 30)
|
|
ry = 30;
|
|
if (ry > 210)
|
|
ry = 210;
|
|
// tty.fmt("Button: {}", pressed);
|
|
DispTools::get().draw_circle(rx, ry, 20);
|
|
// printf("Restarting in %d seconds...\n", i);
|
|
DispTools::get().draw_to_display();
|
|
PowerHelper::get().delay(10000, 30);
|
|
}
|
|
// printf("Restarting now.\n");
|
|
// fflush(stdout);
|
|
// esp_restart();
|
|
}
|