voltage and current sensing
This commit is contained in:
@ -78,14 +78,46 @@ int main(void)
|
||||
rows,
|
||||
cfb_get_display_parameter(dev, CFB_DISPLAY_COLS));
|
||||
|
||||
cfb_framebuffer_invert(dev);
|
||||
|
||||
cfb_set_kerning(dev, 3);
|
||||
|
||||
const struct device *ina;
|
||||
|
||||
ina = DEVICE_DT_GET(DT_NODELABEL(ina231));
|
||||
if (!device_is_ready(dev))
|
||||
{
|
||||
printf("Device %s not ready\n", ina->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
while (1)
|
||||
{
|
||||
for (int i = 0; i < MIN(x_res, y_res); i++)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = sensor_sample_fetch(ina);
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Could not fetch sample (%d)", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct sensor_value voltage, current;
|
||||
ret = sensor_channel_get(ina, SENSOR_CHAN_VOLTAGE, &voltage);
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Could not get sample (%d)", ret);
|
||||
return 0;
|
||||
}
|
||||
ret = sensor_channel_get(ina, SENSOR_CHAN_CURRENT, ¤t);
|
||||
if (ret < 0)
|
||||
{
|
||||
LOG_ERR("Could not get sample (%d)", ret);
|
||||
return 0;
|
||||
}
|
||||
|
||||
printf("voltage: %d.%06d\tcurrent: %d.%06d\n", voltage.val1, voltage.val2, current.val1, current.val2);
|
||||
|
||||
cfb_framebuffer_clear(dev, false);
|
||||
if (cfb_print(dev,
|
||||
"0123456789mMgj!\"§$%&/()=",
|
||||
|
Reference in New Issue
Block a user