diff --git a/GpsTracker/Config.cpp b/GpsTracker/Config.cpp index 463a664..ff0db55 100644 --- a/GpsTracker/Config.cpp +++ b/GpsTracker/Config.cpp @@ -8,8 +8,10 @@ namespace config { Config value; void write() { - hardware::i2c::eeprom.writeBlock(CONFIG_ADDR, value); VERBOSE_FORMAT("writeConfig", "%s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry); + hardware::i2c::eepromPowerOn(); + int written = hardware::i2c::eeprom.writeBlock(CONFIG_ADDR, value); + hardware::i2c::eepromPowerOff(); } void reset() { @@ -23,12 +25,16 @@ namespace config { value = config; write(); + + VERBOSE_FORMAT("resetConfig", "value : %s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry); } void read() { + hardware::i2c::eepromPowerOn(); hardware::i2c::eeprom.readBlock(CONFIG_ADDR, value); if (!String(CONFIG_SEED).equals(value.seed)) reset(); VERBOSE_FORMAT("readConfig", "%s, %s, %d, %d", value.seed, value.version, value.firstEntry, value.lastEntry); + hardware::i2c::eepromPowerOff(); } } \ No newline at end of file diff --git a/GpsTracker/Config.h b/GpsTracker/Config.h index 9e438fa..f93cd34 100644 --- a/GpsTracker/Config.h +++ b/GpsTracker/Config.h @@ -15,7 +15,7 @@ struct Config { }; #define CONFIG_ADDR 0 -#define CONFIG_SEED "UIYB" +#define CONFIG_SEED "UIYA" #define VERSION "1.00" #define SLEEP_DEFAULT_TIME_SECONDS 1800 diff --git a/GpsTracker/Debug.cpp b/GpsTracker/Debug.cpp index c9c642b..3377cbc 100644 --- a/GpsTracker/Debug.cpp +++ b/GpsTracker/Debug.cpp @@ -96,6 +96,7 @@ namespace debug { void waitForSerial() { while (!Serial); + Serial.begin(DEBUG_SERIAL_SPEED); Serial.println("Starting !"); } @@ -142,6 +143,7 @@ namespace debug { void setFakeGpsPosition() { strncpy_P(gps::lastPosition, FAKE_GPS_ENTRY, GPS_POSITION_SIZE); + Log.notice(F("Last position set to : %s\n"), gps::lastPosition); } void getAndDisplayBattery() { @@ -160,9 +162,7 @@ namespace debug { } void getAndDisplayEepromConfig() { - hardware::i2c::eepromPowerOn(); config::read(); - hardware::i2c::eepromPowerOff(); } void getAndDisplayEepromPositions() { diff --git a/GpsTracker/GpsTracker.ino b/GpsTracker/GpsTracker.ino index b167dab..7f82d7d 100644 --- a/GpsTracker/GpsTracker.ino +++ b/GpsTracker/GpsTracker.ino @@ -18,6 +18,7 @@ void setup() { } void loop() { + debug::GPSTRACKER_DEBUG_COMMAND command = debug::GPSTRACKER_DEBUG_COMMAND::RUN; if(!bypassMenu) command = debug::menu(); diff --git a/GpsTracker/Hardware.cpp b/GpsTracker/Hardware.cpp index e249363..2e1b27b 100644 --- a/GpsTracker/Hardware.cpp +++ b/GpsTracker/Hardware.cpp @@ -1,5 +1,6 @@ #include "Hardware.h" #include "Pins.h" +#include "Debug.h" #include #include @@ -8,8 +9,11 @@ #include #include + namespace hardware { +#define LOGGER_NAME "Hardware::sim808" + namespace sim808 { SoftwareSerial simSerial = SoftwareSerial(SIM_TX, SIM_RX); SIM808 device = SIM808(SIM_RST, SIM_PWR, SIM_STATUS); @@ -66,6 +70,8 @@ namespace hardware { } } +#define LOGGER_NAME "Hardware::i2c" + namespace i2c { #define DEVICE_RTC 1 @@ -74,12 +80,12 @@ namespace hardware { E24 eeprom = E24(E24Size_t::E24_512K); uint8_t powered = 0; + uint8_t poweredCount = 0; //inline void powered() { digitalRead(I2C_PWR) == HIGH; } //TODO = replace enum with just reading the output pin ? void powerOn() { - if (powered > 0) return; - + VERBOSE("powerOn"); digitalWrite(I2C_PWR, HIGH); pinMode(I2C_PWR, OUTPUT); @@ -87,6 +93,7 @@ namespace hardware { } void powerOff() { + VERBOSE("powerOff"); pinMode(I2C_PWR, INPUT); digitalWrite(I2C_PWR, LOW); @@ -98,12 +105,19 @@ namespace hardware { digitalWrite(A5, LOW); } - inline void powerOffIfUnused() { - if (!powered) powerOff(); + void powerOnIfPoweredOff() { + if (!poweredCount) powerOn(); + poweredCount++; + } + + void powerOffIfUnused() { + if (!poweredCount) return; + poweredCount--; + if (!poweredCount) powerOff(); } void rtcPowerOn() { - powerOn(); + powerOnIfPoweredOff(); powered |= DEVICE_RTC; } @@ -113,7 +127,7 @@ namespace hardware { } void eepromPowerOn() { - powerOn(); + powerOnIfPoweredOff(); powered |= DEVICE_EEPROM; }