Skip to content
Permalink
Browse files

implement configuration variations instead of "define spaghetti"

  • Loading branch information
ayavilevich committed Oct 24, 2017
1 parent 690b6f8 commit a96034fb009365f2f33c5534286becb69b90e540
@@ -1,4 +1,5 @@
## fochica specific files
ConfigPrivateVariation-*.h
main-flags-override-*.h

## IDE project files
@@ -0,0 +1,61 @@
/*
Fochica™ - Forgotten Child in Car Alert - http://fochica.com/
Copyright (c) 2017, AY Garage Ltd. All rights reserved.
Please see DISCLAIMER.md for important legal terms.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _CONFIGVARIATION_h
#define _CONFIGVARIATION_h

// Configuration variations for the Basic build
// https://github.com/fochica/fochica-wiki/wiki/Basic-build
// 1 BLE modules, 1 seat, 2 sensors
class ConfigVariation : public ConfigVariationBase
{
public:
ConfigVariation();

virtual void registerSensors(SensorManager & sm);

protected:

private:
// capacitive touch sensor
const int CAPACITIVE_TOUCH_SENSOR_READ_ANALOG_PIN = 2; // analog pin#
const int CAPACITIVE_TOUCH_SENSOR_AUX_ANALOG_PIN = 3; // analog pin#

// chest buckle sensor
const int REED_SWITCH_SENSOR_PIN = 6;

};

ConfigVariation::ConfigVariation()
{

}

void ConfigVariation::registerSensors(SensorManager & sm)
{
SensorQtouch * capSense=new SensorQtouch("CapSense", CAPACITIVE_TOUCH_SENSOR_READ_ANALOG_PIN, CAPACITIVE_TOUCH_SENSOR_AUX_ANALOG_PIN);
SensorDigital * digitalReed=new SensorDigital("Reed", REED_SWITCH_SENSOR_PIN, INPUT_PULLUP);

sm.setSeatCount(1);
sm.setSensorCount(2);

capSense->begin();
sm.addSensor(0, SensorLocation::UnderSeat, capSense);
digitalReed->begin();
sm.addSensor(0, SensorLocation::Chest, digitalReed);

}

#else
#error Only one ConfigVariation can be included
#endif
@@ -0,0 +1,94 @@
/*
Fochica™ - Forgotten Child in Car Alert - http://fochica.com/
Copyright (c) 2017, AY Garage Ltd. All rights reserved.
Please see DISCLAIMER.md for important legal terms.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _CONFIGVARIATION_h
#define _CONFIGVARIATION_h

#ifndef ARDUINO_AVR_NANO
#error This configuration is for Nano build settings
#endif

// Configuration variations for the Nano V1 build
// https://hackaday.io/project/20902/log/68057-finals-submission-and-the-nano-build
// 2 BLE modules, 2 seats, 2 sensors
class ConfigVariation : public ConfigVariationBase
{
public:
ConfigVariation();

virtual Nullable<uint8_t> getAliveLedPin() { return Nullable<uint8_t>(LED_BUILTIN); } // "alive" led, flashes during operation. use built-in LED typically on pin 13.

virtual void registerClientDevices(ClientManager & cm);
virtual void registerSensors(SensorManager & sm);

protected:

private:
// module #2
const int BLE2_RX_PIN = 2;
const int BLE2_TX_PIN = 3;
const int BLE2_STATE_PIN = 5;

// pressure sensors
const int CAPACITIVE_PRESSURE_SENSOR_PIN = A2;
const int CAPACITIVE_PRESSURE_SENSOR2_PIN = A3;

};

ConfigVariation::ConfigVariation()
{

}

void ConfigVariation::registerClientDevices(ClientManager & cm)
{
// communication devices
#ifdef HAVE_HWSERIAL1
GenericBLEModuleClient * ble = new GenericBLEModuleClient(Serial1, BLE_STATE_PIN);
#else
SoftwareSerial * bleSerial = new SoftwareSerial(BLE_RX_PIN, BLE_TX_PIN);
GenericBLEModuleClient * ble = new GenericBLEModuleClient(*bleSerial, BLE_STATE_PIN);
#endif

#ifdef HAVE_HWSERIAL2
GenericBLEModuleClient * ble2=new GenericBLEModuleClient(Serial2, BLE2_STATE_PIN);
#else
SoftwareSerial * bleSerial2=new SoftwareSerial(BLE2_RX_PIN, BLE2_TX_PIN);
GenericBLEModuleClient * ble2=new GenericBLEModuleClient(*bleSerial2, BLE2_STATE_PIN);
#endif

cm.setDeviceCount(2);
ble->begin();
cm.addDevice(ble);
ble2->begin();
cm.addDevice(ble2);
// this call is only done at init, the modules are never deallocated
}

void ConfigVariation::registerSensors(SensorManager & sm)
{
SensorCapacitivePressure1Pin * capPressure = new SensorCapacitivePressure1Pin("CapPressure", CAPACITIVE_PRESSURE_SENSOR_PIN);
SensorCapacitivePressure1Pin * capPressure2 = new SensorCapacitivePressure1Pin("CapPressure2", CAPACITIVE_PRESSURE_SENSOR2_PIN);

sm.setSeatCount(2);
sm.setSensorCount(2);

capPressure->begin();
sm.addSensor(0, SensorLocation::UnderSeat, capPressure);
capPressure->begin();
sm.addSensor(1, SensorLocation::UnderSeat, capPressure2);
}

#else
#error Only one ConfigVariation can be included
#endif
@@ -0,0 +1,113 @@
/*
Fochica™ - Forgotten Child in Car Alert - http://fochica.com/
Copyright (c) 2017, AY Garage Ltd. All rights reserved.
Please see DISCLAIMER.md for important legal terms.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _CONFIGVARIATION_h
#define _CONFIGVARIATION_h

#ifndef ARDUINO_AVR_MEGA2560
#error This configuration is assuming Mega build settings
#endif

// Configuration variations for the Mega prototype
// 1 BLEm 4 sensors and 2 seats
// Uses a SD card for persistent log
class ConfigVariation : public ConfigVariationBase
{
public:
ConfigVariation();

virtual IRTC * getRTC() { return new RTCImpl_DS1307; }
virtual IPersistentLog * getPersistentLog(IRTC * rtc) {
//return new PersistentLogImpl_Serial(Serial, *rtc); // log "persistent data" to serial
//return new PersistentLogImpl_Null(); // log "persistent data" to null, to reduce verbosity
return new PersistentLogImpl_SD(*rtc, SD_CS_PIN, SD_MOSI_PIN, SD_MISO_PIN, SD_SCK_PIN); // log "persistent data" to SD card.
}

virtual uint8_t getBuzzerOffState() { return HIGH; } // this prototype uses PNP transistor for the buzzer
virtual void registerSensors(SensorManager & sm);

protected:

private:
// capacitive touch sensor
const int CAPACITIVE_TOUCH_SENSOR_READ_ANALOG_PIN = 2; // analog pin#
const int CAPACITIVE_TOUCH_SENSOR_AUX_ANALOG_PIN = 3; // analog pin#

// chest buckle sensor
const int REED_SWITCH_SENSOR_PIN = 6;

// capacitive touch sensor
const int CAPACITIVE_TOUCH_SENSOR2_READ_ANALOG_PIN = 3; // analog pin#
const int CAPACITIVE_TOUCH_SENSOR2_AUX_ANALOG_PIN = 2; // analog pin#

// chest buckle sensor
const int REED_SWITCH_SENSOR2_PIN = A0;

/// pressure sensors
const int FSR_SENSOR_ANALOG_PIN = 8; // analog pin#
const int CAPACITIVE_PRESSURE_SENSOR_PIN = A10;
const int FSR_SENSOR2_ANALOG_PIN = 9; // analog pin#
const int CAPACITIVE_PRESSURE_SENSOR2_PIN = A11;

// Uno SD shield, an old type that doesn't support Mega naturally
const int SD_CS_PIN = 10; // depends on SD shield module, probably pin 10. need to free it from being used by other component and allocate here.
// if you shield doesn't support Arduino Mega hardware SPI pins, you might need to override the defaults here
const int SD_MOSI_PIN = 11; // 51 native on Mega
const int SD_MISO_PIN = 12; // 50 native on Mega
const int SD_SCK_PIN = 13; // 52 native on Mega
//const int SD_MOSI_PIN = -1; // use default
//const int SD_MISO_PIN = -1; // use default
//const int SD_SCK_PIN = -1; // use default
};

ConfigVariation::ConfigVariation()
{

}

void ConfigVariation::registerSensors(SensorManager & sm)
{
SensorQtouch * capSense = new SensorQtouch("CapSense", CAPACITIVE_TOUCH_SENSOR_READ_ANALOG_PIN, CAPACITIVE_TOUCH_SENSOR_AUX_ANALOG_PIN);
SensorDigital * digitalReed = new SensorDigital("Reed", REED_SWITCH_SENSOR_PIN, INPUT_PULLUP);
SensorAnalog * fsr = new SensorAnalog("FSR", FSR_SENSOR_ANALOG_PIN, SensorType::FSR);
SensorCapacitivePressure1Pin * capPressure = new SensorCapacitivePressure1Pin("CapPressure", CAPACITIVE_PRESSURE_SENSOR_PIN);
SensorQtouch * capSense2 = new SensorQtouch("CapSense2", CAPACITIVE_TOUCH_SENSOR2_READ_ANALOG_PIN, CAPACITIVE_TOUCH_SENSOR2_AUX_ANALOG_PIN);
SensorDigital * digitalReed2 = new SensorDigital("Reed2", REED_SWITCH_SENSOR2_PIN, INPUT_PULLUP);
SensorAnalog * fsr2 = new SensorAnalog("FSR2", FSR_SENSOR2_ANALOG_PIN, SensorType::FSR);
SensorCapacitivePressure1Pin * capPressure2 = new SensorCapacitivePressure1Pin("CapPressure2", CAPACITIVE_PRESSURE_SENSOR2_PIN);

sm.setSeatCount(2);
sm.setSensorCount(8);

capSense->begin();
sm.addSensor(0, SensorLocation::UnderSeat, capSense);
digitalReed->begin();
sm.addSensor(0, SensorLocation::Chest, digitalReed);
fsr->begin();
sm.addSensor(0, SensorLocation::UnderSeat, fsr);
capPressure->begin();
sm.addSensor(0, SensorLocation::UnderSeat, capPressure);

capSense2->begin();
sm.addSensor(1, SensorLocation::UnderSeat, capSense2);
digitalReed2->begin();
sm.addSensor(1, SensorLocation::Chest, digitalReed2);
fsr->begin();
sm.addSensor(1, SensorLocation::UnderSeat, fsr2);
capPressure->begin();
sm.addSensor(1, SensorLocation::UnderSeat, capPressure2);
}

#else
#error Only one ConfigVariation can be included
#endif
@@ -0,0 +1,118 @@
/*
Fochica™ - Forgotten Child in Car Alert - http://fochica.com/
Copyright (c) 2017, AY Garage Ltd. All rights reserved.
Please see DISCLAIMER.md for important legal terms.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _CONFIGVARIATION_h
#define _CONFIGVARIATION_h

// Configuration variations for the Uno Shield V1 build
// https://hackaday.io/project/20902/log/60964-goodbye-breadboard
// 2 BLE modules, 2 seats, 4 sensors, discharge protection and "alive" LED
class ConfigVariation : public ConfigVariationBase
{
public:
ConfigVariation();

virtual Nullable<uint8_t> getAliveLedPin() { return Nullable<uint8_t>(LED_BUILTIN); } // "alive" led, flashes during operation. use built-in LED typically on pin 13.
virtual DischargeProtectionManager * getDischargeProtectionManager(ISensor * batterySensor);

virtual void registerClientDevices(ClientManager & cm);
virtual void registerSensors(SensorManager & sm);

protected:

private:
// module #2
const int BLE2_RX_PIN = 2;
const int BLE2_TX_PIN = 3;
const int BLE2_STATE_PIN = 5;

// capacitive touch sensor
const int CAPACITIVE_TOUCH_SENSOR_READ_ANALOG_PIN = 2; // analog pin#
const int CAPACITIVE_TOUCH_SENSOR_AUX_ANALOG_PIN = 3; // analog pin#

// chest buckle sensor
const int REED_SWITCH_SENSOR_PIN = 6;

// capacitive touch sensor
const int CAPACITIVE_TOUCH_SENSOR2_READ_ANALOG_PIN = 3; // analog pin#
const int CAPACITIVE_TOUCH_SENSOR2_AUX_ANALOG_PIN = 2; // analog pin#

// chest buckle sensor
const int REED_SWITCH_SENSOR2_PIN = A0;

// Discharge protection parameters
const int DISCHARGE_PROTECTION_KEEPALIVE_PIN = 10;
};

ConfigVariation::ConfigVariation()
{

}

DischargeProtectionManager * ConfigVariation::getDischargeProtectionManager(ISensor * batterySensor)
{
if (batterySensor == NULL) // must have data about battery charge to perform protection
return NULL;
CalibratedSensor * lowBatCharge=new CalibratedSensor(batterySensor, DISCHARGE_PROTECTION_ALPHA, DISCHARGE_PROTECTION_LOW_CHARGE_TH, DISCHARGE_PROTECTION_HIGH_CHARGE_TH, CalibratedSensorState::B, DISCHARGE_PROTECTION_HIGH_CHARGE_TH); // set to start in state=B="high charge"
return new DischargeProtectionManager(*lowBatCharge, DISCHARGE_PROTECTION_KEEPALIVE_PIN);
}

void ConfigVariation::registerClientDevices(ClientManager & cm)
{
// communication devices (also supports mega with additional hardware serials)
#ifdef HAVE_HWSERIAL1
GenericBLEModuleClient * ble = new GenericBLEModuleClient(Serial1, BLE_STATE_PIN);
#else
SoftwareSerial * bleSerial = new SoftwareSerial(BLE_RX_PIN, BLE_TX_PIN);
GenericBLEModuleClient * ble = new GenericBLEModuleClient(*bleSerial, BLE_STATE_PIN);
#endif

#ifdef HAVE_HWSERIAL2
GenericBLEModuleClient * ble2 = new GenericBLEModuleClient(Serial2, BLE2_STATE_PIN);
#else
SoftwareSerial * bleSerial2 = new SoftwareSerial(BLE2_RX_PIN, BLE2_TX_PIN);
GenericBLEModuleClient * ble2 = new GenericBLEModuleClient(*bleSerial2, BLE2_STATE_PIN);
#endif

cm.setDeviceCount(2);
ble->begin();
cm.addDevice(ble);
ble2->begin();
cm.addDevice(ble2);
// this call is only done at init, the modules are never deallocated
}

void ConfigVariation::registerSensors(SensorManager & sm)
{
SensorQtouch * capSense = new SensorQtouch("CapSense", CAPACITIVE_TOUCH_SENSOR_READ_ANALOG_PIN, CAPACITIVE_TOUCH_SENSOR_AUX_ANALOG_PIN);
SensorDigital * digitalReed = new SensorDigital("Reed", REED_SWITCH_SENSOR_PIN, INPUT_PULLUP);
SensorQtouch * capSense2 = new SensorQtouch("CapSense2", CAPACITIVE_TOUCH_SENSOR2_READ_ANALOG_PIN, CAPACITIVE_TOUCH_SENSOR2_AUX_ANALOG_PIN);
SensorDigital * digitalReed2 = new SensorDigital("Reed2", REED_SWITCH_SENSOR2_PIN, INPUT_PULLUP);

sm.setSeatCount(2);
sm.setSensorCount(4);

capSense->begin();
sm.addSensor(0, SensorLocation::UnderSeat, capSense);
digitalReed->begin();
sm.addSensor(0, SensorLocation::Chest, digitalReed);

capSense2->begin();
sm.addSensor(1, SensorLocation::UnderSeat, capSense2);
digitalReed2->begin();
sm.addSensor(1, SensorLocation::Chest, digitalReed2);
}

#else
#error Only one ConfigVariation can be included
#endif

0 comments on commit a96034f

Please sign in to comment.
You can’t perform that action at this time.