2025-11-28 18:26:32 -06:00
|
|
|
#include <driver/gptimer.h>
|
|
|
|
|
#include "pwm.h"
|
|
|
|
|
#include "defines.h"
|
|
|
|
|
#include "nvs_flash.h"
|
|
|
|
|
#include "NimBLEDevice.h"
|
|
|
|
|
#include "WiFi.hpp"
|
2025-11-29 16:24:56 -06:00
|
|
|
#include "setup.hpp"
|
2025-12-23 17:21:44 -06:00
|
|
|
#include "socketIO.hpp"
|
2025-12-28 12:46:09 -06:00
|
|
|
#include "encoder.hpp"
|
2025-11-28 18:26:32 -06:00
|
|
|
|
2025-12-28 12:46:10 -06:00
|
|
|
void mainApp() {
|
2025-12-23 17:21:44 -06:00
|
|
|
printf("Hello ");
|
2025-11-29 16:24:56 -06:00
|
|
|
esp_err_t ret = nvs_flash_init(); // change to secure init logic soon!!
|
2025-11-28 18:26:32 -06:00
|
|
|
// 2. If NVS is full or corrupt (common after flashing new code), erase and retry
|
|
|
|
|
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
|
2025-11-29 16:24:56 -06:00
|
|
|
ESP_ERROR_CHECK(nvs_flash_erase());
|
|
|
|
|
ret = nvs_flash_init();
|
2025-11-28 18:26:32 -06:00
|
|
|
}
|
|
|
|
|
ESP_ERROR_CHECK(ret);
|
|
|
|
|
|
2025-11-29 16:24:56 -06:00
|
|
|
bmWiFi.init();
|
2025-11-28 18:26:32 -06:00
|
|
|
|
2025-12-24 18:39:21 -06:00
|
|
|
setupLoop();
|
2025-12-23 17:21:44 -06:00
|
|
|
|
2025-12-24 18:39:21 -06:00
|
|
|
statusResolved = false;
|
2025-11-29 16:24:56 -06:00
|
|
|
|
|
|
|
|
// Main loop
|
2025-11-28 18:26:32 -06:00
|
|
|
while (1) {
|
2025-12-24 18:39:21 -06:00
|
|
|
if (statusResolved) {
|
|
|
|
|
if (!connected) {
|
|
|
|
|
printf("Disconnected! Beginning setup loop.\n");
|
|
|
|
|
stopSocketIO();
|
|
|
|
|
setupLoop();
|
|
|
|
|
}
|
|
|
|
|
else printf("Reconnected!\n");
|
|
|
|
|
statusResolved = false;
|
|
|
|
|
}
|
2025-11-29 16:24:56 -06:00
|
|
|
// Your main application logic here
|
2025-12-23 17:28:32 -06:00
|
|
|
vTaskDelay(pdMS_TO_TICKS(1000));
|
2025-12-24 18:39:21 -06:00
|
|
|
printf("loop\n");
|
2025-11-28 18:26:32 -06:00
|
|
|
}
|
2025-12-28 12:46:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void encoderTest() {
|
|
|
|
|
encoder_init();
|
|
|
|
|
|
|
|
|
|
int32_t prevCount = encoder_count;
|
|
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
|
if (encoder_count != prevCount) {
|
|
|
|
|
prevCount = encoder_count;
|
|
|
|
|
printf("Encoder Pos: %d\n", prevCount);
|
|
|
|
|
}
|
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(100));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" void app_main() {
|
|
|
|
|
// mainApp();
|
|
|
|
|
encoderTest();
|
2025-11-28 18:26:32 -06:00
|
|
|
}
|