Ver a proveniência

Code cleanup etc

tags/v1.2.0
Bertrand Lemasle há 7 anos
ascendente
cometimento
d66789faed
5 ficheiros alterados com 81 adições e 56 eliminações
  1. +12
    -20
      GpsTracker/Debug.cpp
  2. +26
    -25
      GpsTracker/Debug.h
  3. +9
    -11
      GpsTracker/GpsTracker.ino
  4. +27
    -0
      GpsTracker/Log.cpp
  5. +7
    -0
      GpsTracker/Log.h

+ 12
- 20
GpsTracker/Debug.cpp Ver ficheiro

@@ -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,,";

MENU_ENTRY(HEADER, "-- Debug Menu --");
MENU_ENTRY(SEPARATOR, "----");
MENU_ENTRY(HEADER, "-- Debug Menu --");
MENU_ENTRY(SEPARATOR, "----");

MENU_ENTRY(RUN, "[R] Run");
MENU_ENTRY(RUN_ONCE, "[r] Run once");
@@ -116,11 +116,6 @@ namespace debug {
}
}

void waitForSerial() {
while (!Serial);
Serial.begin(DEBUG_SERIAL_SPEED);
}

int freeRam() {
return freeRam2();
}
@@ -141,13 +136,10 @@ namespace debug {
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;
size_t menuSize = flash::getArraySize(MENU_ENTRIES);
int16_t timeout = MENU_TIMEOUT;
uint8_t intermediate_timeout = 50;

do {
for (uint8_t i = 0; i < menuSize; i++) {
@@ -155,17 +147,17 @@ namespace debug {
}

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());
while (Serial.available()) Serial.read();
while (Serial.available()) Serial.read(); //flushing input
} while (command == GPSTRACKER_DEBUG_COMMAND::NONE);
return command;


+ 26
- 25
GpsTracker/Debug.h Ver ficheiro

@@ -1,9 +1,11 @@
#pragma once

#include <Arduino.h>

#include "Log.h"
#include "Config.h"
#include "Log.h"

#include "Core.h"

#include "Hardware.h"
#include "Gps.h"
#include "Rtc.h"
@@ -13,34 +15,33 @@
namespace debug {

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();
void displayFreeRam();

GPSTRACKER_DEBUG_COMMAND menu();
GPSTRACKER_DEBUG_COMMAND menu(uint16_t timeout);

void getAndDisplayBattery();
void getAndDisplayGpsPosition();


+ 9
- 11
GpsTracker/GpsTracker.ino Ver ficheiro

@@ -1,30 +1,28 @@
#include "GpsTracker.h"
#include "Positions.h"

bool bypassMenu = false;

void setup() {
#if _DEBUG
debug::waitForSerial();
Log.begin(LOG_LEVEL_VERBOSE, &Serial);
#define MENU_TIMEOUT 0
#else
if (Serial) {
Serial.begin(DEBUG_SERIAL_SPEED);
Log.begin(LOG_LEVEL_NOTICE, &Serial);
}
#define MENU_TIMEOUT 10000

#endif
bool bypassMenu = false;

void setup() {
log::setup();

if (Serial) Serial.println(F("============================="));
config::main::setup();
rtc::setup();
hardware::sim808::setup();

positions::setup();
}

void loop() {

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;



+ 27
- 0
GpsTracker/Log.cpp Ver ficheiro

@@ -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("============================="));
}

}

+ 7
- 0
GpsTracker/Log.h Ver ficheiro

@@ -3,6 +3,8 @@
#define DISABLE_LOGGING 1
#include <ArduinoLog.h>

#include "Config.h"

#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_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_MSG(f, msg) LOG_MSG(notice, f, msg)
#define NOTICE_FORMAT(f, msg, ...) LOG_FORMAT(notice, f, msg, __VA_ARGS__)


namespace log {
void setup();
}

Carregando…
Cancelar
Guardar