100 lines
2.4 KiB
C++
Raw Normal View History

#include <esp_log.h>
2018-12-21 09:20:30 -08:00
#include <string.h>
#include <u8g2.h>
2018-12-21 09:20:30 -08:00
#include "U8g2lib.hh"
2019-01-17 22:34:34 -08:00
#include "ugv_comms.hh"
2019-01-03 12:27:17 -07:00
#include "ugv_config.h"
#include "ugv_io.hh"
namespace ugv {
2019-01-17 22:34:34 -08:00
using ugv::comms::Comms;
2019-01-17 23:15:07 -08:00
using ugv::io::IO;
2018-12-16 18:12:21 -08:00
2019-01-03 12:27:17 -07:00
static const char *TAG = "ugv_main";
2018-12-16 18:12:21 -08:00
2019-01-15 18:04:16 -08:00
U8G2 *oled;
2018-12-16 18:12:21 -08:00
void setup_oled(void) {
2019-01-15 18:04:16 -08:00
oled = new U8G2_SSD1306_128X64_NONAME_F_HW_I2C(U8G2_R0, 16, 15, 4);
oled->initDisplay();
oled->clearDisplay();
oled->setPowerSave(false);
2018-12-21 09:20:30 -08:00
}
2018-12-20 19:26:59 -08:00
void setup(void) {
2018-12-20 19:26:59 -08:00
ESP_LOGI(TAG, "setup");
2018-12-21 09:20:30 -08:00
setup_oled();
2019-01-17 22:34:34 -08:00
Comms.Init();
IO.Init();
2018-12-20 19:26:59 -08:00
}
2019-01-03 17:50:12 -07:00
#define BUF_SZ 32
void loop(void) {
2019-01-03 17:50:12 -07:00
static int32_t lora_rssi;
static uint8_t lora_lna_gain;
static TickType_t last_packet_tick;
static int32_t last_packet_rssi;
static int8_t last_packet_snr;
2019-01-17 23:15:07 -08:00
static char buf[BUF_SZ];
static io::Inputs inputs;
IO.ReadInputs(inputs);
// ESP_LOGI(TAG, "inputs %s", inputs.ToString());
2019-01-03 17:50:12 -07:00
2019-01-15 18:04:16 -08:00
oled->firstPage();
2019-01-17 23:15:07 -08:00
lora_rssi = Comms.ReadRssi();
2019-01-17 22:34:34 -08:00
lora_lna_gain = Comms.ReadLnaGain();
2019-01-03 17:50:12 -07:00
2019-01-17 22:34:34 -08:00
Comms.Lock();
last_packet_tick = Comms.last_packet_tick;
last_packet_rssi = Comms.last_packet_rssi;
last_packet_snr = Comms.last_packet_snr;
Comms.Unlock();
do {
2019-01-15 18:04:16 -08:00
oled->drawRFrame(0, 0, OLED_W, OLED_H, 4);
2018-12-20 19:26:59 -08:00
2018-12-30 23:56:51 -07:00
multi_heap_info_t heap_info;
heap_caps_get_info(&heap_info, MALLOC_CAP_DEFAULT);
2019-01-15 18:04:16 -08:00
oled->setFont(u8g2_font_4x6_mr);
oled->drawStr(4, 8, "=====UAS UGV=====");
2019-01-03 17:50:12 -07:00
snprintf(buf, BUF_SZ, "heap allc/free %d/%d",
heap_info.total_allocated_bytes, heap_info.total_free_bytes);
2019-01-15 18:04:16 -08:00
oled->drawStr(4, 2 * 8, buf);
2018-12-20 19:26:59 -08:00
2019-01-03 17:50:12 -07:00
snprintf(buf, BUF_SZ, "rssi: %d lna gain: %d", lora_rssi, lora_lna_gain);
2019-01-15 18:04:16 -08:00
oled->drawStr(4, 3 * 8, buf);
2019-01-03 17:50:12 -07:00
if (last_packet_tick > 0) {
double time_since_last_packet =
1000.0f /
((xTaskGetTickCount() - last_packet_tick) * portTICK_RATE_MS);
snprintf(buf, BUF_SZ, "last pkt rx %f s ago", time_since_last_packet);
2019-01-15 18:04:16 -08:00
oled->drawStr(4, 4 * 8, buf);
2019-01-03 17:50:12 -07:00
snprintf(buf, BUF_SZ, "pkt rssi: %d, snr: %f", last_packet_rssi,
last_packet_snr * 0.25f);
2019-01-15 18:04:16 -08:00
oled->drawStr(4, 5 * 8, buf);
2019-01-03 17:50:12 -07:00
} else {
2019-01-15 18:04:16 -08:00
oled->drawStr(4, 4 * 8, "no pkt rx");
2018-12-20 19:26:59 -08:00
}
2019-01-15 18:04:16 -08:00
} while (oled->nextPage());
2018-12-21 09:20:30 -08:00
vTaskDelay(pdMS_TO_TICKS(1000));
}
void loopTask(void *pvUser) {
2018-12-21 09:20:30 -08:00
setup();
while (1) {
2018-12-21 09:20:30 -08:00
loop();
}
}
2018-12-20 19:26:59 -08:00
} // namespace ugv
2019-01-15 18:04:16 -08:00
extern "C" void app_main() {
xTaskCreatePinnedToCore(ugv::loopTask, "loopTask", 8192, NULL, 1, NULL, 1);
2018-12-31 01:40:41 -07:00
}