add support for I2C Ouput Module GP8403 (DFR Gravity)

This commit is contained in:
DeltaLima 2025-03-16 21:45:50 +01:00
parent 238dc34b95
commit a214aba81b
4 changed files with 82 additions and 16 deletions

View file

@ -62,6 +62,7 @@ case $1 in
"Adafruit TCS34725@1.4.4"
"Adafruit MLX90614 Library@2.1.5"
"I2CSoilMoistureSensor@1.1.4"
"DFRobot_GP8XXX@1.0.1"
)
echo ":: Setting up build environment for CanGrow Firmware."

View file

@ -8,6 +8,7 @@
#include "Output/Output_Common.h"
#include "Output/Output_I2C_01_MCP4725.h"
#include "Output/Output_I2C_02_GP8403.h"
/* OutputI2C index struct */
struct OutputI2C_Index {
@ -25,19 +26,19 @@ OutputI2C_Index OutputI2Cindex[] {
{
OUTPUT_I2C_01_NAME,
{
OUTPUT_TYPE_I2C_PORT_PERCENTAGE
OUTPUT_TYPE_I2C_PORT_BYTE
},
sizeof(Output_I2C_01_MCP4725_Addr),
},
/* 02 - dummy */
/* 02 - DFRobot Gravity (GP8403) */
{
"DFR Grafity DAC",
OUTPUT_I2C_02_NAME,
{
OUTPUT_TYPE_I2C_PORT_PERCENTAGE,
OUTPUT_TYPE_I2C_PORT_PERCENTAGE
OUTPUT_TYPE_I2C_PORT_BYTE,
OUTPUT_TYPE_I2C_PORT_BYTE
},
2
sizeof(Output_I2C_02_GP8403_Addr),
}
};
@ -55,7 +56,7 @@ byte Output_I2C_Addr_Init_Update(const byte OutputI2CindexId, const byte AddrId,
* 1 - init the output i2c module, returns true (1) if succeeded
* 2 - update i2 module data
*/
byte Dummy_Addr[] = { 0x42, 0x69 };
//byte Dummy_Addr[] = { 0x42, 0x69 };
/* invert Value if set, save it to Value_tmp */
byte Value_tmp = Value;
@ -80,22 +81,39 @@ byte Output_I2C_Addr_Init_Update(const byte OutputI2CindexId, const byte AddrId,
}
break;
/* 02 - dummy*/
/* I2C Output module 02 */
case 2:
switch(Mode) {
case 0:
return Dummy_Addr[AddrId];
case OUPUT_I2C_AIU_MODE_ADDR:
return Output_I2C_02_GP8403_Addr[AddrId];
break;
case 1:
return true;
case OUPUT_I2C_AIU_MODE_INIT:
return Output_I2C_02_GP8403_Init(AddrId, PortId);
break;
case 2:
true;
case OUPUT_I2C_AIU_MODE_UPDATE:
Output_I2C_02_GP8403_Update(AddrId, PortId, Value_tmp);
break;
}
break;
/* 02 - dummy*/
//case 2:
//switch(Mode) {
//case 0:
//return Dummy_Addr[AddrId];
//break;
//case 1:
//return true;
//break;
//case 2:
//true;
//break;
//}
//break;
/* unknown i2c output module id */
default:
Log.error(F("%s OutputI2Cindex ID %d not found" CR), LogLoc, OutputI2CindexId);

View file

@ -44,7 +44,7 @@ const byte OUTPUT_TYPE_I2C_MAX_PORTS = 2;
/* Total number of I2C PORT Types */
const byte OUTPUT_TYPE_I2C_PORT__TOTAL = 1;
/* port type for percentage. Those ports receive an int from 0 up to 100 to set their output value */
const byte OUTPUT_TYPE_I2C_PORT_PERCENTAGE = 1;
const byte OUTPUT_TYPE_I2C_PORT_BYTE = 1;
/* Output_I2C_Addr_Init_Update() modes */
const byte OUPUT_I2C_AIU_MODE_ADDR = 0;

View file

@ -0,0 +1,47 @@
/*
*
* include/Output/OutputI2C_01_MCP4725.h - sensor header for I2C Output MCP4725 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]";
//const short MaxRawValue = 4095;
//byte RawValue = map(); // (MaxRawValue * Value)/100;
/* 'Value' , which comes from outputState[], is byte, so 0-255. So we need to map this to the MCPs 0-4095 */
//MCP4725[AddrId].setVoltage(map(Value, 0, 255, 0, 4095), false);
#ifndef DEBUG
Log.verbose(F("%s 0x%x Port %d, Value %d, GP8403_Value %d" CR), LogLoc, Output_I2C_01_MCP4725_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;
//if(GP8403[AddrId].begin(Output_I2C_01_MCP4725_Addr[AddrId])) {
//Log.notice(F("%s found at addr 0x%x" CR), LogLoc, Output_I2C_02_GP8403_Addr[AddrId]);
//Output_I2C_01_MCP4725_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;
}