Compare commits
6 Commits
main
...
def4197c0b
| Author | SHA1 | Date | |
|---|---|---|---|
| def4197c0b | |||
| 95b1f4f019 | |||
| 8954979aa1 | |||
| 244cfa02c4 | |||
| e13f608b58 | |||
| 364c711a04 |
12
src/custom_types.h
Normal file
12
src/custom_types.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#include <inttypes.h>
|
||||||
|
typedef struct vehicle_config{
|
||||||
|
uint16_t config_lock;
|
||||||
|
bool auto_detect_track;
|
||||||
|
uint8_t num_tracks;
|
||||||
|
uint8_t selected_track;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct track_data {
|
||||||
|
char name[64];
|
||||||
|
|
||||||
|
};
|
||||||
4
src/flags.h
Normal file
4
src/flags.h
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#define INFO
|
||||||
|
#define WARN
|
||||||
|
#define ERROR
|
||||||
|
#define DEBUG
|
||||||
38
src/main.cpp
38
src/main.cpp
@@ -1,18 +1,34 @@
|
|||||||
#include <Arduino.h>
|
#include "flags.h"
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "modules/lcd/lcd.h"
|
||||||
|
#include "modules/gps/gps.h"
|
||||||
|
#include "modules/logger/system_logger.h"
|
||||||
|
|
||||||
|
|
||||||
|
system_logger *logger_output = new system_logger(&Serial);
|
||||||
|
|
||||||
|
lcd *driver_display = new lcd();
|
||||||
|
gps *gps_module = new gps(&Serial2, logger_output);
|
||||||
|
|
||||||
// put function declarations here:
|
|
||||||
int myFunction(int, int);
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
// put your setup code here, to run once:
|
driver_display->init();
|
||||||
int result = myFunction(2, 3);
|
driver_display->print_message("Starting Initialization");
|
||||||
|
delay(1000);
|
||||||
|
|
||||||
|
driver_display->print_message("Serial Init...");
|
||||||
|
Serial.begin(115200);
|
||||||
|
delay(500);
|
||||||
|
driver_display->print_message("Serial Init Complete");
|
||||||
|
delay(500);
|
||||||
|
|
||||||
|
driver_display->print_message("GPS Init...");
|
||||||
|
gps_module->init();
|
||||||
|
delay(500);
|
||||||
|
driver_display->print_message("GPS Init Complete");
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// put your main code here, to run repeatedly:
|
gps_module->parse_task(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
// put function definitions here:
|
|
||||||
int myFunction(int x, int y) {
|
|
||||||
return x + y;
|
|
||||||
}
|
|
||||||
60
src/modules/gps/gps.h
Normal file
60
src/modules/gps/gps.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "TinyGPSPlus.h"
|
||||||
|
#include "modules/logger/system_logger.h"
|
||||||
|
#include "flags.h"
|
||||||
|
|
||||||
|
class gps
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
TinyGPSPlus *_gps;
|
||||||
|
HardwareSerial *_data_stream;
|
||||||
|
system_logger *_logger = nullptr;
|
||||||
|
bool _lock_valid = false;
|
||||||
|
unsigned long _last_lock = 0;
|
||||||
|
public:
|
||||||
|
gps(HardwareSerial *data_stream);
|
||||||
|
gps(HardwareSerial *data_stream, system_logger *logger);
|
||||||
|
~gps();
|
||||||
|
int parse_task(unsigned long timeout_ms = 500);
|
||||||
|
int init();
|
||||||
|
};
|
||||||
|
|
||||||
|
gps::gps(HardwareSerial *data_stream) {
|
||||||
|
_data_stream = data_stream;
|
||||||
|
_gps = new TinyGPSPlus();
|
||||||
|
}
|
||||||
|
|
||||||
|
gps::gps(HardwareSerial *data_stream, system_logger *logger) {
|
||||||
|
_data_stream = data_stream;
|
||||||
|
_gps = new TinyGPSPlus();
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
gps::~gps() {
|
||||||
|
_data_stream = nullptr;
|
||||||
|
delete _gps;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gps::init() {
|
||||||
|
_data_stream->begin(9600);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int gps::parse_task(unsigned long timeout_ms) {
|
||||||
|
unsigned long timeout = millis() + timeout_ms;
|
||||||
|
while (_data_stream->available() > 0) {
|
||||||
|
if (_gps->encode(_data_stream->read())) {
|
||||||
|
_lock_valid = true;
|
||||||
|
_last_lock = millis();
|
||||||
|
}
|
||||||
|
if (millis() > timeout) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (_logger != nullptr) {
|
||||||
|
_logger->debug("GPS Parser timed out, exiting task");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
45
src/modules/lcd/lcd.h
Normal file
45
src/modules/lcd/lcd.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "flags.h"
|
||||||
|
#include "modules/logger/system_logger.h"
|
||||||
|
#include <LiquidCrystal_I2C.h>
|
||||||
|
class lcd {
|
||||||
|
private:
|
||||||
|
LiquidCrystal_I2C *_display;
|
||||||
|
system_logger *_logger = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
lcd();
|
||||||
|
lcd(system_logger *logger);
|
||||||
|
~lcd();
|
||||||
|
int init();
|
||||||
|
int print_message(String message);
|
||||||
|
};
|
||||||
|
|
||||||
|
lcd::lcd() { _display = new LiquidCrystal_I2C(0x27, 20, 4); }
|
||||||
|
|
||||||
|
lcd::lcd(system_logger *logger) {
|
||||||
|
_display = new LiquidCrystal_I2C(0x27, 20, 4);
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
lcd::~lcd() {}
|
||||||
|
|
||||||
|
int lcd::init() {
|
||||||
|
_display->init();
|
||||||
|
_display->backlight();
|
||||||
|
_display->clear();
|
||||||
|
_display->setCursor(0, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int lcd::print_message(String message) {
|
||||||
|
_display->clear();
|
||||||
|
_display->setCursor(0, 0);
|
||||||
|
_display->print(message);
|
||||||
|
#ifdef INFO
|
||||||
|
if (_logger != nullptr) {
|
||||||
|
_logger->info(message);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
71
src/modules/logger/system_logger.h
Normal file
71
src/modules/logger/system_logger.h
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "flags.h"
|
||||||
|
|
||||||
|
class system_logger
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
HardwareSerial *_output;
|
||||||
|
int print_message(String pre, String message);
|
||||||
|
public:
|
||||||
|
system_logger(HardwareSerial *output);
|
||||||
|
~system_logger();
|
||||||
|
#ifdef INFO
|
||||||
|
int info(String message);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WARN
|
||||||
|
int warn(String message);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ERROR
|
||||||
|
int error(String message);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
int debug(String message);
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
system_logger::system_logger(HardwareSerial *output)
|
||||||
|
{
|
||||||
|
_output = output;
|
||||||
|
}
|
||||||
|
|
||||||
|
system_logger::~system_logger()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int system_logger::print_message(String pre, String message) {
|
||||||
|
if (_output->availableForWrite()) {
|
||||||
|
_output->print(millis());
|
||||||
|
_output->print(pre);
|
||||||
|
_output->println(message);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef INFO
|
||||||
|
int system_logger::info(String message) {
|
||||||
|
return this->print_message(" [INFO] ", message);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WARN
|
||||||
|
int system_logger::warn(String message) {
|
||||||
|
return this->print_message(" [WARNING] ", message);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef ERROR
|
||||||
|
int system_logger::error(String message) {
|
||||||
|
return this->print_message(" [ERROR] ", message);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
int system_logger::debug(String message) {
|
||||||
|
return this->print_message(" [DEBUG] ", message);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user