PCB lives now in its own git repo https://git.la10cy.net/DeltaLima/CanGrow-12V-PCB
88 lines
2.5 KiB
C
88 lines
2.5 KiB
C
/*
|
|
*
|
|
* include/Sensor/09_Chirp.h - example sensor header I2C device
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
|
|
#include <I2CSoilMoistureSensor.h>
|
|
|
|
#define SENSOR_09_NAME "I2C-Chirp"
|
|
|
|
const byte Sensor_09_Chirp_Addr[] = { 0x20, 0x21, 0x22, 0x23 };
|
|
|
|
I2CSoilMoistureSensor Chirp[sizeof(Sensor_09_Chirp_Addr)];
|
|
|
|
/* Create main data array specifying max amount of readings */
|
|
float Sensor_09_Chirp[sizeof(Sensor_09_Chirp_Addr)][3];
|
|
|
|
void Sensor_09_Chirp_Update(const byte AddrId) {
|
|
const static char LogLoc[] PROGMEM = "[Sensor:09_Chirp:Update]";
|
|
|
|
#ifdef DEBUG
|
|
unsigned long mStart = millis();
|
|
unsigned long mStop;
|
|
Log.verbose(F("%s Start %u" CR), LogLoc, mStart);
|
|
#endif
|
|
|
|
/* keep the same order as in SensorIndex[].read[] !! */
|
|
|
|
#ifdef DEBUG
|
|
Log.verbose(F("%s capacitance (%u)" CR), LogLoc, millis());
|
|
#endif
|
|
Sensor_09_Chirp[AddrId][0] = Chirp[AddrId].getCapacitance();
|
|
|
|
#ifdef DEBUG
|
|
Log.verbose(F("%s temperature (%u)" CR), LogLoc, millis());
|
|
#endif
|
|
Sensor_09_Chirp[AddrId][1] = Chirp[AddrId].getTemperature()/(float)10;
|
|
|
|
/* light sensor is disabled, because it takes 3s to read, which is just too much */
|
|
//#ifndef DEBUG
|
|
//Log.verbose(F("%s light (%u)" CR), LogLoc, millis());
|
|
//#endif
|
|
//Sensor_09_Chirp[AddrId][2] = Chirp[AddrId].getLight(true);
|
|
|
|
Chirp[AddrId].sleep();
|
|
|
|
|
|
#ifdef DEBUG
|
|
mStop = millis();
|
|
Log.verbose(F("%s Stop %u (%u)" CR), LogLoc, mStop, mStop - mStart);
|
|
#endif
|
|
}
|
|
|
|
bool Sensor_09_Chirp_Init(const byte AddrId) {
|
|
/* Sensor Init function
|
|
*
|
|
* returns true (1) when Init was successful
|
|
* returns false (0) if not.
|
|
*/
|
|
const static char LogLoc[] PROGMEM = "[Sensor:09_Chirp:Init]";
|
|
bool returnCode;
|
|
|
|
/* manually check if I2C address answers on bus, i2c chirp lib does not return a value */
|
|
Wire.beginTransmission(Sensor_09_Chirp_Addr[AddrId]);
|
|
short i2cError = Wire.endTransmission();
|
|
|
|
/* when i2c sensor answered to our previous init request */
|
|
if(i2cError == 0) {
|
|
Log.notice(F("%s found at addr 0x%x" CR), LogLoc, Sensor_09_Chirp_Addr[AddrId]);
|
|
|
|
#ifdef ESP8266
|
|
/* maybe its not the best idea to place it here, but for the moment.. */
|
|
Wire.setClockStretchLimit(2500);
|
|
#endif
|
|
|
|
/* change chirp library I2C address, it will also trigger .begin() afterwards */
|
|
Chirp[AddrId].changeSensor(Sensor_09_Chirp_Addr[AddrId], false);
|
|
|
|
Sensor_09_Chirp_Update(AddrId);
|
|
returnCode = true;
|
|
} else {
|
|
Log.error(F("%s FAILED! Not found at addr 0x%x" CR), LogLoc, Sensor_09_Chirp_Addr[AddrId]);
|
|
returnCode = false;
|
|
}
|
|
return returnCode;
|
|
}
|