Selaa lähdekoodia

Improved logging and removed eepromPowerOff/On && rtcPowerOff/On

tags/v1.2.0
Bertrand Lemasle 7 vuotta sitten
vanhempi
commit
6fc4e7b451
6 muutettua tiedostoa jossa 38 lisäystä ja 63 poistoa
  1. +4
    -4
      GpsTracker/Debug.cpp
  2. +26
    -46
      GpsTracker/Hardware.cpp
  3. +1
    -7
      GpsTracker/Hardware.h
  4. +3
    -2
      GpsTracker/Rtc.cpp
  5. +2
    -2
      GpsTracker/Rtc.h
  6. +2
    -2
      GpsTracker/Storage.h

+ 4
- 4
GpsTracker/Debug.cpp Näytä tiedosto

@@ -173,7 +173,7 @@ namespace debug {


void getAndDisplayEepromContent() { void getAndDisplayEepromContent() {
char buffer[128]; char buffer[128];
hardware::i2c::eepromPowerOn();
hardware::i2c::powerOn();


for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
hardware::i2c::eeprom.read(128 * i, buffer, 128); hardware::i2c::eeprom.read(128 * i, buffer, 128);
@@ -182,7 +182,7 @@ namespace debug {
} }
} }
Serial.println(); Serial.println();
hardware::i2c::eepromPowerOff();
hardware::i2c::powerOff();
Log.notice(F("Done\n")); Log.notice(F("Done\n"));
} }


@@ -190,12 +190,12 @@ namespace debug {
uint16_t currentEntryIndex = config::get().firstEntry; uint16_t currentEntryIndex = config::get().firstEntry;
PositionEntry currentEntry; PositionEntry currentEntry;


hardware::i2c::eepromPowerOn();
hardware::i2c::powerOn();
do { do {
if (!positions::get(currentEntryIndex, currentEntry)) break; if (!positions::get(currentEntryIndex, currentEntry)) break;
details::displayPosition(currentEntry); details::displayPosition(currentEntry);
} while (positions::moveNext(currentEntryIndex)); } while (positions::moveNext(currentEntryIndex));
hardware::i2c::eepromPowerOff();
hardware::i2c::powerOff();
} }


void getAndDisplayEepromLastPosition() { void getAndDisplayEepromLastPosition() {


+ 26
- 46
GpsTracker/Hardware.cpp Näytä tiedosto

@@ -19,6 +19,7 @@ namespace hardware {
SIM808 device = SIM808(SIM_RST, SIM_PWR, SIM_STATUS); SIM808 device = SIM808(SIM_RST, SIM_PWR, SIM_STATUS);


void powerOn() { void powerOn() {
VERBOSE("powerOn");
bool poweredOn = device.powerOnOff(true); bool poweredOn = device.powerOnOff(true);
if (!poweredOn) return; if (!poweredOn) return;


@@ -26,6 +27,7 @@ namespace hardware {
} }


void powerOff() { void powerOff() {
VERBOSE("powerOff");
device.powerOnOff(false); device.powerOnOff(false);
} }


@@ -39,6 +41,7 @@ namespace hardware {
} }


void setup() { void setup() {
VERBOSE("setup");
device.powerOnOff(true); device.powerOnOff(true);
simSerial.begin(4800); simSerial.begin(4800);


@@ -47,22 +50,26 @@ namespace hardware {
} }


void gpsPowerOn() { void gpsPowerOn() {
VERBOSE("gpsPowerOn");
powerOn(); powerOn();
device.enableGps(); device.enableGps();
} }


void gpsPowerOff() { void gpsPowerOff() {
VERBOSE("gpsPowerOff");
device.disableGps(); device.disableGps();
powerOffIfUnused(); powerOffIfUnused();
} }


void networkPowerOn() { void networkPowerOn() {
VERBOSE("networkPowerOn");
powerOn(); powerOn();
device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::FULL); device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::FULL);
device.enableGprs("Free"); //TODO : configure
device.enableGprs(config::get().apn);
} }


void networkPowerOff() { void networkPowerOff() {
VERBOSE("networkPowerOff");
device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::MINIMUM); device.setPhoneFunctionality(SIM808_PHONE_FUNCTIONALITY::MINIMUM);
device.disableGprs(); device.disableGprs();


@@ -74,66 +81,39 @@ namespace hardware {


namespace i2c { namespace i2c {


#define DEVICE_RTC 1
#define DEVICE_EEPROM 2

E24 eeprom = E24(E24Size_t::E24_512K); E24 eeprom = E24(E24Size_t::E24_512K);


uint8_t powered = 0;
uint8_t poweredCount = 0; uint8_t poweredCount = 0;


//inline void powered() { digitalRead(I2C_PWR) == HIGH; } //TODO = replace enum with just reading the output pin ? //inline void powered() { digitalRead(I2C_PWR) == HIGH; } //TODO = replace enum with just reading the output pin ?


void powerOn() { void powerOn() {
VERBOSE("powerOn");
digitalWrite(I2C_PWR, HIGH);
pinMode(I2C_PWR, OUTPUT);

Wire.begin();
}
if (!poweredCount) {
VERBOSE("powerOn");
digitalWrite(I2C_PWR, HIGH);
pinMode(I2C_PWR, OUTPUT);


void powerOff() {
VERBOSE("powerOff");
pinMode(I2C_PWR, INPUT);
digitalWrite(I2C_PWR, LOW);

//turn off i2c
TWCR &= ~(bit(TWEN) | bit(TWIE) | bit(TWEA));

//disable i2c internal pull ups
digitalWrite(A4, LOW);
digitalWrite(A5, LOW);
}
Wire.begin();
}


void powerOnIfPoweredOff() {
if (!poweredCount) powerOn();
poweredCount++; poweredCount++;
} }


void powerOffIfUnused() {
if (!poweredCount) return;
poweredCount--;
if (!poweredCount) powerOff();
}
void powerOff(bool forced = false) {
if (poweredCount == 1 || forced) {
VERBOSE("powerOff");
pinMode(I2C_PWR, INPUT);
digitalWrite(I2C_PWR, LOW);


void rtcPowerOn() {
powerOnIfPoweredOff();
powered |= DEVICE_RTC;
}
//turn off i2c
TWCR &= ~(bit(TWEN) | bit(TWIE) | bit(TWEA));


void rtcPowerOff() {
powered &= ~DEVICE_RTC;
powerOffIfUnused();
}

void eepromPowerOn() {
powerOnIfPoweredOff();
powered |= DEVICE_EEPROM;
}
//disable i2c internal pull ups
digitalWrite(A4, LOW);
digitalWrite(A5, LOW);
}


void eepromPowerOff() {
powered &= ~DEVICE_EEPROM;
powerOffIfUnused();
poweredCount--;
} }
} }
} }

+ 1
- 7
GpsTracker/Hardware.h Näytä tiedosto

@@ -24,12 +24,6 @@ namespace hardware {
extern E24 eeprom; extern E24 eeprom;


void powerOn(); void powerOn();
void powerOff();

void rtcPowerOn();
void rtcPowerOff();

void eepromPowerOn();
void eepromPowerOff();
void powerOff(bool forced = false);
} }
} }

+ 3
- 2
GpsTracker/Rtc.cpp Näytä tiedosto

@@ -35,6 +35,7 @@ namespace rtc {
} }
void setup() { void setup() {
VERBOSE("setup");
powerOn(); powerOn();
RTC.control(DS3231_12H, DS3231_OFF); //24 hours clock RTC.control(DS3231_12H, DS3231_OFF); //24 hours clock
RTC.control(DS3231_INT_ENABLE, DS3231_OFF); //INTCN OFF RTC.control(DS3231_INT_ENABLE, DS3231_OFF); //INTCN OFF
@@ -72,13 +73,13 @@ namespace rtc {
void setAlarm(tmElements_t &time) { void setAlarm(tmElements_t &time) {
details::writeTimeToRegisters(time); details::writeTimeToRegisters(time);


hardware::i2c::rtcPowerOn();
powerOn();
RTC.writeAlarm1(DS3231_ALM_DTHMS); RTC.writeAlarm1(DS3231_ALM_DTHMS);


RTC.control(DS3231_A1_FLAG, DS3231_OFF); //reset Alarm 1 flag RTC.control(DS3231_A1_FLAG, DS3231_OFF); //reset Alarm 1 flag
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
hardware::i2c::rtcPowerOff();
powerOff();


Log.notice(F("Set alarm to : %d/%d/%d %d:%d:%d\n"), tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second); Log.notice(F("Set alarm to : %d/%d/%d %d:%d:%d\n"), tmYearToCalendar(time.Year), time.Month, time.Day, time.Hour, time.Minute, time.Second);




+ 2
- 2
GpsTracker/Rtc.h Näytä tiedosto

@@ -5,11 +5,11 @@


namespace rtc { namespace rtc {
inline void powerOn() { inline void powerOn() {
hardware::i2c::rtcPowerOn();
hardware::i2c::powerOn();
} }


inline void powerOff() { inline void powerOff() {
hardware::i2c::rtcPowerOff();
hardware::i2c::powerOff();
} }


void setup(); void setup();


+ 2
- 2
GpsTracker/Storage.h Näytä tiedosto

@@ -4,11 +4,11 @@


namespace storage { namespace storage {
inline void powerOn() { inline void powerOn() {
hardware::i2c::eepromPowerOn();
hardware::i2c::powerOn();
} }


inline void powerOff() { inline void powerOff() {
hardware::i2c::eepromPowerOff();
hardware::i2c::powerOff();
} }





Ladataan…
Peruuta
Tallenna