@@ -9,8 +9,8 @@ | |||||
const char FAKE_GPS_ENTRY[] PROGMEM = "1,1,20170924184842.000,49.454862,1.144537,71.900,67.99,172.6,1,,1.3,2.2,1.8,,11,7,,,37,,"; | const char FAKE_GPS_ENTRY[] PROGMEM = "1,1,20170924184842.000,49.454862,1.144537,71.900,67.99,172.6,1,,1.3,2.2,1.8,,11,7,,,37,,"; | ||||
MENU_ENTRY(HEADER, "-- Debug Menu --"); | |||||
MENU_ENTRY(SEPARATOR, "----"); | |||||
MENU_ENTRY(HEADER, "-- Debug Menu --"); | |||||
MENU_ENTRY(SEPARATOR, "----"); | |||||
MENU_ENTRY(RUN, "[R] Run"); | MENU_ENTRY(RUN, "[R] Run"); | ||||
MENU_ENTRY(RUN_ONCE, "[r] Run once"); | MENU_ENTRY(RUN_ONCE, "[r] Run once"); | ||||
@@ -116,11 +116,6 @@ namespace debug { | |||||
} | } | ||||
} | } | ||||
void waitForSerial() { | |||||
while (!Serial); | |||||
Serial.begin(DEBUG_SERIAL_SPEED); | |||||
} | |||||
int freeRam() { | int freeRam() { | ||||
return freeRam2(); | return freeRam2(); | ||||
} | } | ||||
@@ -141,13 +136,10 @@ namespace debug { | |||||
return GPSTRACKER_DEBUG_COMMAND::NONE; | return GPSTRACKER_DEBUG_COMMAND::NONE; | ||||
} | } | ||||
GPSTRACKER_DEBUG_COMMAND menu() { | |||||
if (!Serial) return GPSTRACKER_DEBUG_COMMAND::RUN; | |||||
GPSTRACKER_DEBUG_COMMAND menu(uint16_t timeout) { | |||||
GPSTRACKER_DEBUG_COMMAND command; | GPSTRACKER_DEBUG_COMMAND command; | ||||
size_t menuSize = flash::getArraySize(MENU_ENTRIES); | size_t menuSize = flash::getArraySize(MENU_ENTRIES); | ||||
int16_t timeout = MENU_TIMEOUT; | |||||
uint8_t intermediate_timeout = 50; | |||||
do { | do { | ||||
for (uint8_t i = 0; i < menuSize; i++) { | for (uint8_t i = 0; i < menuSize; i++) { | ||||
@@ -155,17 +147,17 @@ namespace debug { | |||||
} | } | ||||
while (!Serial.available()) { | while (!Serial.available()) { | ||||
#ifndef _DEBUG | |||||
delay(50); | |||||
timeout -= 50; | |||||
if (timeout < 0) { | |||||
NOTICE_MSG("menu", "Timeout expired."); | |||||
return GPSTRACKER_DEBUG_COMMAND::RUN; | |||||
if (timeout > 0) { | |||||
delay(intermediate_timeout); | |||||
timeout -= intermediate_timeout; | |||||
if (timeout <= 0) { | |||||
NOTICE_MSG("menu", "Timeout expired."); | |||||
return GPSTRACKER_DEBUG_COMMAND::RUN; | |||||
} | |||||
} | } | ||||
#endif | |||||
} | } | ||||
command = parseCommand(Serial.read()); | command = parseCommand(Serial.read()); | ||||
while (Serial.available()) Serial.read(); | |||||
while (Serial.available()) Serial.read(); //flushing input | |||||
} while (command == GPSTRACKER_DEBUG_COMMAND::NONE); | } while (command == GPSTRACKER_DEBUG_COMMAND::NONE); | ||||
return command; | return command; | ||||
@@ -1,9 +1,11 @@ | |||||
#pragma once | #pragma once | ||||
#include <Arduino.h> | #include <Arduino.h> | ||||
#include "Log.h" | |||||
#include "Config.h" | #include "Config.h" | ||||
#include "Log.h" | |||||
#include "Core.h" | |||||
#include "Hardware.h" | #include "Hardware.h" | ||||
#include "Gps.h" | #include "Gps.h" | ||||
#include "Rtc.h" | #include "Rtc.h" | ||||
@@ -13,34 +15,33 @@ | |||||
namespace debug { | namespace debug { | ||||
enum class GPSTRACKER_DEBUG_COMMAND : uint8_t { | enum class GPSTRACKER_DEBUG_COMMAND : uint8_t { | ||||
NONE = 0, | |||||
RUN = 1, | |||||
ONCE = 2, | |||||
RAM = 3, | |||||
BATTERY = 4, | |||||
GPS_ON = 5, | |||||
GPS_OFF = 6, | |||||
GPS_GET = 7, | |||||
GPS_SET = 8, | |||||
RTC_GET = 11, | |||||
RTC_SET = 12, | |||||
SD_WRITE_TEST = 13, | |||||
EEPROM_GET_CONFIG = 14, | |||||
EEPROM_RESET_CONFIG = 15, | |||||
EEPROM_GET_CONTENT = 16, | |||||
EEPROM_GET_LAST_ENTRY = 17, | |||||
EEPROM_GET_ENTRIES = 18, | |||||
EEPROM_ADD_ENTRY = 19, | |||||
EEPROM_BACKUP_ENTRIES = 20, | |||||
SLEEP = 21, | |||||
SLEEP_DEEP = 22 | |||||
NONE, | |||||
RUN, | |||||
ONCE, | |||||
RAM, | |||||
BATTERY, | |||||
GPS_ON, | |||||
GPS_OFF, | |||||
GPS_GET, | |||||
GPS_SET, | |||||
RTC_GET, | |||||
RTC_SET, | |||||
SD_WRITE_TEST, | |||||
EEPROM_GET_CONFIG, | |||||
EEPROM_RESET_CONFIG, | |||||
EEPROM_GET_CONTENT, | |||||
EEPROM_GET_LAST_ENTRY, | |||||
EEPROM_GET_ENTRIES, | |||||
EEPROM_ADD_ENTRY, | |||||
EEPROM_BACKUP_ENTRIES, | |||||
SLEEP, | |||||
SLEEP_DEEP | |||||
}; | }; | ||||
void waitForSerial(); | |||||
int freeRam(); | int freeRam(); | ||||
void displayFreeRam(); | void displayFreeRam(); | ||||
GPSTRACKER_DEBUG_COMMAND menu(); | |||||
GPSTRACKER_DEBUG_COMMAND menu(uint16_t timeout); | |||||
void getAndDisplayBattery(); | void getAndDisplayBattery(); | ||||
void getAndDisplayGpsPosition(); | void getAndDisplayGpsPosition(); | ||||
@@ -1,30 +1,28 @@ | |||||
#include "GpsTracker.h" | #include "GpsTracker.h" | ||||
#include "Positions.h" | #include "Positions.h" | ||||
bool bypassMenu = false; | |||||
void setup() { | |||||
#if _DEBUG | #if _DEBUG | ||||
debug::waitForSerial(); | |||||
Log.begin(LOG_LEVEL_VERBOSE, &Serial); | |||||
#define MENU_TIMEOUT 0 | |||||
#else | #else | ||||
if (Serial) { | |||||
Serial.begin(DEBUG_SERIAL_SPEED); | |||||
Log.begin(LOG_LEVEL_NOTICE, &Serial); | |||||
} | |||||
#define MENU_TIMEOUT 10000 | |||||
#endif | #endif | ||||
bool bypassMenu = false; | |||||
void setup() { | |||||
log::setup(); | |||||
if (Serial) Serial.println(F("=============================")); | |||||
config::main::setup(); | config::main::setup(); | ||||
rtc::setup(); | rtc::setup(); | ||||
hardware::sim808::setup(); | hardware::sim808::setup(); | ||||
positions::setup(); | positions::setup(); | ||||
} | } | ||||
void loop() { | void loop() { | ||||
debug::GPSTRACKER_DEBUG_COMMAND command = debug::GPSTRACKER_DEBUG_COMMAND::RUN; | debug::GPSTRACKER_DEBUG_COMMAND command = debug::GPSTRACKER_DEBUG_COMMAND::RUN; | ||||
if(!bypassMenu) command = debug::menu(); | |||||
if (Serial && !bypassMenu) command = debug::menu(MENU_TIMEOUT); | |||||
bypassMenu = command == debug::GPSTRACKER_DEBUG_COMMAND::RUN; | bypassMenu = command == debug::GPSTRACKER_DEBUG_COMMAND::RUN; | ||||
@@ -0,0 +1,27 @@ | |||||
#include "Log.h" | |||||
namespace log { | |||||
namespace details { | |||||
void waitForSerial() { | |||||
while (!Serial); | |||||
Serial.begin(DEBUG_SERIAL_SPEED); | |||||
} | |||||
} | |||||
void setup() { | |||||
#if _DEBUG | |||||
details::waitForSerial(); | |||||
Log.begin(LOG_LEVEL_VERBOSE, &Serial); | |||||
#else | |||||
if (Serial) { | |||||
Serial.begin(DEBUG_SERIAL_SPEED); | |||||
Log.begin(LOG_LEVEL_NOTICE, &Serial); | |||||
} | |||||
#endif | |||||
if (Serial) Serial.println(F("=============================")); | |||||
} | |||||
} |
@@ -3,6 +3,8 @@ | |||||
#define DISABLE_LOGGING 1 | #define DISABLE_LOGGING 1 | ||||
#include <ArduinoLog.h> | #include <ArduinoLog.h> | ||||
#include "Config.h" | |||||
#define LOG(level, f) Log.level(F("[" LOGGER_NAME "::" f "]\n")) | #define LOG(level, f) Log.level(F("[" LOGGER_NAME "::" f "]\n")) | ||||
#define LOG_MSG(level, f, msg) Log.level(F("[" LOGGER_NAME "::" f "] " msg "\n")) | #define LOG_MSG(level, f, msg) Log.level(F("[" LOGGER_NAME "::" f "] " msg "\n")) | ||||
#define LOG_FORMAT(level, f, msg, ...) Log.level(F("[" LOGGER_NAME "::" f "] " msg "\n"), __VA_ARGS__) | #define LOG_FORMAT(level, f, msg, ...) Log.level(F("[" LOGGER_NAME "::" f "] " msg "\n"), __VA_ARGS__) | ||||
@@ -20,3 +22,8 @@ | |||||
#define NOTICE(f) LOG(notice, f) | #define NOTICE(f) LOG(notice, f) | ||||
#define NOTICE_MSG(f, msg) LOG_MSG(notice, f, msg) | #define NOTICE_MSG(f, msg) LOG_MSG(notice, f, msg) | ||||
#define NOTICE_FORMAT(f, msg, ...) LOG_FORMAT(notice, f, msg, __VA_ARGS__) | #define NOTICE_FORMAT(f, msg, ...) LOG_FORMAT(notice, f, msg, __VA_ARGS__) | ||||
namespace log { | |||||
void setup(); | |||||
} |