Skip to content

Commit 09faf2f

Browse files
committed
Add template for building new sensor functions
1 parent e6a4e28 commit 09faf2f

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

Logger.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2453,6 +2453,53 @@ void Logger::Barometer_BMP180(){
24532453
}
24542454
else Serial.println(F("BMP180 init fail"));
24552455
}
2456+
2457+
void Logger::_sensor_function_template(int pin, float param1, float param2,
2458+
bool flag){
2459+
/**
2460+
* @brief
2461+
* Function to help lay out a new sensor interface.
2462+
* This need not be "void": it may return a value as well.
2463+
*
2464+
* @details
2465+
* Details about sensor go here
2466+
*
2467+
* @param pin You often need to specify interface pins
2468+
*
2469+
* @param param1 A variable for the sensor or to interpret its value
2470+
*
2471+
* @param param2 A variable for the sensor or to interpret its value
2472+
*
2473+
* @param flag Something that helps to set an option
2474+
*
2475+
* Example (made up):
2476+
* ```
2477+
* logger.Example(A2, 1021.3, 15.2, True);
2478+
* ```
2479+
*
2480+
*/
2481+
2482+
float Vout_normalized_analog_example = analogReadOversample(xPin, \
2483+
ADC_resolution_nbits) / 1023.)
2484+
2485+
float Some_variable = Vout_normalized_analog_example * param1 / param2
2486+
if (flag){
2487+
Some_variable /= 2.
2488+
}
2489+
2490+
///////////////
2491+
// SAVE DATA //
2492+
///////////////
2493+
2494+
// SD write
2495+
datafile.print(Some_variable);
2496+
datafile.print(F(","));
2497+
2498+
// Echo to serial
2499+
Serial.print(Some_variable);
2500+
Serial.print(F(","));
2501+
2502+
}
24562503

24572504

24582505
void Logger::sleepNow_nap() // here we put the arduino to sleep between interrupt readings

Logger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ class Logger {
148148
void Pyranometer(int analogPin, float raw_mV_per_W_per_m2, \
149149
float gain, float V_ref, uint8_t ADC_resolution_nbits=14);
150150
void Barometer_BMP180();
151+
void _sensor_function_template(int pin, float param1, float param2, \
152+
bool flag=false);
151153

152154
// Sensors - triggered
153155
// Camera on/off function; decision made in end-user Arduino script

0 commit comments

Comments
 (0)