Answer the question
In order to leave comments, you need to log in
Why is type casting used like this?
Good day!
I'm trying to adapt the library from Arduino to Raspberry PI (c ++ WiringPI)
For example, there is such a function (Arduino):
int16_t ina219GetShuntVoltage(void)
{
uint16_t value;
ina219Read16(INA219_REG_SHUNTVOLTAGE, &value);
return value;
}
static void ina219Read16(uint8_t reg, uint16_t *value)
{
// Clear write buffers
uint32_t i;
for ( i = 0; i < I2C_BUFSIZE; i++ )
{
I2CMasterBuffer[i] = 0x00;
}
I2CWriteLength = 2;
I2CReadLength = 2;
I2CMasterBuffer[0] = INA219_ADDRESS; // I2C device address
I2CMasterBuffer[1] = reg; // Command register
// Append address w/read bit
I2CMasterBuffer[2] = INA219_ADDRESS | INA219_READ;
i2cEngine();
// Shift values to create properly formed integer
*value = ((I2CSlaveBuffer[0] << 8) | I2CSlaveBuffer[1]);
}
int16_t ina219GetShuntVoltage(void)
{
uint16_t value = wiringPiI2CReadReg16(node->fd, INA219_REG_SHUNTVOLTAGE);
return (int16_t)value;
}
int wiringPiI2CReadReg16 (int fd, int reg)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question