PCB lives now in its own git repo https://git.la10cy.net/DeltaLima/CanGrow-12V-PCB
52 lines
1.8 KiB
C
52 lines
1.8 KiB
C
/*
|
|
*
|
|
* include/Output/OutputI2C_Output_I2C_02_GP8403.h - sensor header for I2C Output GP8403 (DFR Gravity) sensor
|
|
*
|
|
*
|
|
*
|
|
*/
|
|
|
|
#include <DFRobot_GP8XXX.h>
|
|
|
|
#define OUTPUT_I2C_02_NAME "GP8403"
|
|
|
|
const byte Output_I2C_02_GP8403_Addr[] = { 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F };
|
|
|
|
DFRobot_GP8403 GP8403[sizeof(Output_I2C_02_GP8403_Addr)];
|
|
|
|
const byte Output_I2C_02_GP8403_Ports = 2;
|
|
|
|
|
|
void Output_I2C_02_GP8403_Update(const byte AddrId, const byte PortId, const byte Value) {
|
|
/* Update Output Port of I2C Module */
|
|
const static char LogLoc[] PROGMEM = "[Output:I2C:02_GP8403:Update]";
|
|
|
|
/* 'Value' , which comes from outputState[], is byte, so 0-255. So we need to map this to the GP8403 0-4095 */
|
|
GP8403[AddrId].setDACOutVoltage(map(Value, 0, 255, 0, 4095), PortId);
|
|
|
|
#ifdef DEBUG
|
|
Log.verbose(F("%s 0x%x Port %d, Value %d, GP8403_Value %d" CR), LogLoc, Output_I2C_02_GP8403_Addr[AddrId], PortId, Value, map(Value, 0, 255, 0, 4095));
|
|
#endif
|
|
|
|
}
|
|
|
|
bool Output_I2C_02_GP8403_Init(const byte AddrId, const byte PortId) {
|
|
/* Initialize I2C Module, return true when successful */
|
|
const static char LogLoc[] PROGMEM = "[Output:I2C:02_GP8403:Init]";
|
|
bool returnCode;
|
|
|
|
/* Overwrite the default address of the library 0x58 with configured one */
|
|
GP8403[AddrId] = DFRobot_GP8403(Output_I2C_02_GP8403_Addr[AddrId]);
|
|
|
|
if(GP8403[AddrId].begin() == 0) {
|
|
/* Set output to 0-10V - this is what most grow devices are using as control standard */
|
|
GP8403[AddrId].setDACOutRange(GP8403[AddrId].eOutputRange10V);
|
|
Log.notice(F("%s found at addr 0x%x" CR), LogLoc, Output_I2C_02_GP8403_Addr[AddrId]);
|
|
Output_I2C_02_GP8403_Update(AddrId, PortId, 0);
|
|
returnCode = true;
|
|
} else {
|
|
Log.error(F("%s FAILED! Not found at addr 0x%x" CR), LogLoc, Output_I2C_02_GP8403_Addr[AddrId]);
|
|
returnCode = false;
|
|
}
|
|
return returnCode;
|
|
}
|