@@ -34,6 +34,7 @@ namespace core { | |||||
else increaseInARow = 0; | else increaseInARow = 0; | ||||
sleepTime = result; | sleepTime = result; | ||||
NOTICE_FORMAT("updateSleepTime", "%dkmh => %d seconds", velocity, sleepTime); | |||||
} | } | ||||
uint16_t computeSleepTime(uint8_t velocity) { | uint16_t computeSleepTime(uint8_t velocity) { | ||||
@@ -9,7 +9,7 @@ | |||||
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(HEADER, "-- Menu --"); | |||||
MENU_ENTRY(SEPARATOR, "----"); | MENU_ENTRY(SEPARATOR, "----"); | ||||
MENU_ENTRY(RUN, "[R] Run"); | MENU_ENTRY(RUN, "[R] Run"); | ||||
@@ -244,8 +244,8 @@ namespace debug { | |||||
uint16_t lastEntryIndex = config::main::value.lastEntry; | uint16_t lastEntryIndex = config::main::value.lastEntry; | ||||
PositionEntry lastEntry; | PositionEntry lastEntry; | ||||
positions::get(lastEntryIndex, lastEntry); | |||||
details::displayPosition(lastEntry); | |||||
if(positions::get(lastEntryIndex, lastEntry)) details::displayPosition(lastEntry); | |||||
else Log.notice(F("No position recorded\n")); | |||||
} | } | ||||
void addLastPositionToEeprom() { | void addLastPositionToEeprom() { | ||||
@@ -2,7 +2,7 @@ | |||||
#include <Arduino.h> | #include <Arduino.h> | ||||
#include "Config.h" | #include "Config.h" | ||||
#include "Log.h" | |||||
#include "Logging.h" | |||||
#include "Core.h" | #include "Core.h" | ||||
@@ -10,8 +10,6 @@ | |||||
#include "Gps.h" | #include "Gps.h" | ||||
#include "Rtc.h" | #include "Rtc.h" | ||||
#define DEBUG_SERIAL_SPEED 115200 | |||||
namespace debug { | namespace debug { | ||||
enum class GPSTRACKER_DEBUG_COMMAND : uint8_t { | enum class GPSTRACKER_DEBUG_COMMAND : uint8_t { | ||||
@@ -10,7 +10,7 @@ | |||||
bool bypassMenu = false; | bool bypassMenu = false; | ||||
void setup() { | void setup() { | ||||
log::setup(); | |||||
logging::setup(); | |||||
config::main::setup(); | config::main::setup(); | ||||
rtc::setup(); | rtc::setup(); | ||||
@@ -1,27 +0,0 @@ | |||||
#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("=============================")); | |||||
} | |||||
} |
@@ -0,0 +1,18 @@ | |||||
#include "Logging.h" | |||||
namespace logging { | |||||
void setup() { | |||||
#if _DEBUG | |||||
while (!Serial); | |||||
#endif | |||||
if (Serial) { | |||||
Serial.begin(LOG_SERIAL_SPEED); | |||||
Serial.println(F("=============================")); | |||||
Log.begin(LOG_LEVEL, &Serial); | |||||
} | |||||
} | |||||
} |
@@ -1,9 +1,15 @@ | |||||
#pragma once | #pragma once | ||||
#include "Config.h" | |||||
#define DISABLE_LOGGING 1 | |||||
//#define DISABLE_LOGGING 1 | |||||
#include <ArduinoLog.h> | #include <ArduinoLog.h> | ||||
#include "Config.h" | |||||
#define LOG_SERIAL_SPEED 115200 | |||||
#if _DEBUG | |||||
#define LOG_LEVEL LOG_LEVEL_VERBOSE | |||||
#else | |||||
#define LOG_LEVEL LOG_LEVEL_NOTICE | |||||
#endif | |||||
#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")) | ||||
@@ -24,6 +30,6 @@ | |||||
#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 { | |||||
namespace logging { | |||||
void setup(); | void setup(); | ||||
} | } |
@@ -36,7 +36,7 @@ namespace mainunit { | |||||
} | } | ||||
void sleep(period_t period) { | void sleep(period_t period) { | ||||
NOTICE_FORMAT("sleep", "Sleeping for period : %d", period); | |||||
NOTICE_FORMAT("sleep", "Period : %d", period); | |||||
details::prepareSleep(); | details::prepareSleep(); | ||||
LowPower.powerDown(period, ADC_OFF, BOD_OFF); | LowPower.powerDown(period, ADC_OFF, BOD_OFF); | ||||
details::wokeUp(); | details::wokeUp(); | ||||
@@ -44,7 +44,7 @@ namespace mainunit { | |||||
} | } | ||||
void deepSleep(uint16_t seconds) { | void deepSleep(uint16_t seconds) { | ||||
NOTICE_FORMAT("deepSleep", "Deep sleeping for %d seconds", seconds); | |||||
NOTICE_FORMAT("deepSleep", "%d seconds", seconds); | |||||
interruptIn(seconds); | interruptIn(seconds); | ||||
details::prepareSleep(); | details::prepareSleep(); | ||||
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); | LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF); | ||||
@@ -53,7 +53,7 @@ namespace positions { | |||||
} | } | ||||
bool acquire(PositionEntryMetadata &metadata) { | bool acquire(PositionEntryMetadata &metadata) { | ||||
VERBOSE("acquire"); | |||||
NOTICE("acquire"); | |||||
timestamp_t before; | timestamp_t before; | ||||
@@ -63,6 +63,8 @@ namespace positions { | |||||
SIM808ChargingStatus battery = hardware::sim808::device.getChargingState(); | SIM808ChargingStatus battery = hardware::sim808::device.getChargingState(); | ||||
gps::powerOff(); | gps::powerOff(); | ||||
NOTICE_FORMAT("acquire", "status : %d", gpsStatus); | |||||
if (gpsStatus < SIM808_GPS_STATUS::FIX) return false; | if (gpsStatus < SIM808_GPS_STATUS::FIX) return false; | ||||
uint16_t timeToFix = rtc::getTime() - before; | uint16_t timeToFix = rtc::getTime() - before; | ||||
@@ -98,7 +100,7 @@ namespace positions { | |||||
hardware::i2c::powerOn(); | hardware::i2c::powerOn(); | ||||
hardware::i2c::eeprom.writeBlock(entryAddress, entry); | hardware::i2c::eeprom.writeBlock(entryAddress, entry); | ||||
VERBOSE_FORMAT("appendLast", "Written to EEPROM @ %X : [%d%% @ %dmV] [%f°C] [TTF : %d, Status : %d, Position : %s]", entryAddress, entry.metadata.batteryLevel, entry.metadata.batteryVoltage, entry.metadata.temperature, entry.metadata.timeToFix, entry.metadata.status, entry.position); | |||||
NOTICE_FORMAT("appendLast", "Saved @ %X : [%d%% @ %dmV] [%f°C] [TTF : %d, Status : %d, Position : %s]", entryAddress, entry.metadata.batteryLevel, entry.metadata.batteryVoltage, entry.metadata.temperature, entry.metadata.timeToFix, entry.metadata.status, entry.position); | |||||
config->lastEntry++; | config->lastEntry++; | ||||
if (config->lastEntry > details::maxEntryIndex) config->lastEntry = 0; | if (config->lastEntry > details::maxEntryIndex) config->lastEntry = 0; | ||||
@@ -71,7 +71,7 @@ namespace rtc { | |||||
RTC.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 ON | RTC.control(DS3231_A1_INT_ENABLE, DS3231_ON); //Alarm 1 ON | ||||
RTC.control(DS3231_INT_ENABLE, DS3231_ON); //INTCN ON | RTC.control(DS3231_INT_ENABLE, DS3231_ON); //INTCN ON | ||||
NOTICE_FORMAT("setAlarm", "Next alarm : %d:%d:%d", time.Hour, time.Minute, time.Second); | |||||
VERBOSE_FORMAT("setAlarm", "Next alarm : %d:%d:%d", time.Hour, time.Minute, time.Second); | |||||
hardware::i2c::powerOff(); | hardware::i2c::powerOff(); | ||||
} | } | ||||