fix bmp288 and stub in hdc1080
Some checks failed
Documentation / build (push) Successful in 4s
Build / build (ubuntu-22.04) (push) Failing after 18s
Build / build (macos-12) (push) Has been cancelled
Build / build (windows-2022) (push) Has been cancelled
Build / build (macos-14) (push) Has been cancelled

This commit is contained in:
2024-04-24 00:25:40 -06:00
parent a02a1c2641
commit a004d2526a
2 changed files with 60 additions and 15 deletions

View File

@ -30,7 +30,7 @@ int main(void)
dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display)); dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
if (!device_is_ready(dev)) if (!device_is_ready(dev))
{ {
printf("Device %s not ready\n", dev->name); LOG_ERR("Device %s not ready\n", dev->name);
return 0; return 0;
} }
@ -38,7 +38,7 @@ int main(void)
{ {
if (display_set_pixel_format(dev, PIXEL_FORMAT_MONO01) != 0) if (display_set_pixel_format(dev, PIXEL_FORMAT_MONO01) != 0)
{ {
printf("Failed to set required pixel format"); LOG_ERR("Failed to set required pixel format");
return 0; return 0;
} }
} }
@ -47,7 +47,7 @@ int main(void)
if (cfb_framebuffer_init(dev)) if (cfb_framebuffer_init(dev))
{ {
printf("Framebuffer initialization failed!\n"); LOG_ERR("Framebuffer initialization failed!\n");
return 0; return 0;
} }
@ -81,29 +81,38 @@ int main(void)
cfb_set_kerning(dev, 3); cfb_set_kerning(dev, 3);
const struct device *ina, *bmp; const struct device *ina, *bmp, *hdc;
ina = DEVICE_DT_GET(DT_NODELABEL(ina231)); ina = DEVICE_DT_GET(DT_NODELABEL(ina231));
if (!device_is_ready(dev)) if (!device_is_ready(dev))
{ {
printf("Device %s not ready\n", ina->name); LOG_ERR("Device %s not ready\n", ina->name);
return 0; return 0;
} }
bmp = DEVICE_DT_GET(DT_NODELABEL(bmp388)); bmp = DEVICE_DT_GET(DT_NODELABEL(bmp388));
if (!device_is_ready(dev)) if (!device_is_ready(dev))
{ {
printf("Device %s not ready\n", bmp->name); LOG_ERR("Device %s not ready\n", bmp->name);
return 0; return 0;
} }
// hdc = DEVICE_DT_GET(DT_NODELABEL(hdc1080));
// if (!device_is_ready(dev))
// {
// printf("Device %s not ready\n", hdc->name);
// return 0;
// }
while (1) while (1)
{ {
int ret; int ret;
struct sensor_value voltage, current, pressure; struct sensor_value voltage, current, pressure, temperature, humidity;
char str_v[15] = {0}; char str_v[15] = {0};
char str_i[15] = {0}; char str_i[15] = {0};
char str_p[15] = {0}; char str_p[16] = {0};
char str_t[16] = {0};
char str_h[16] = {0};
ret = sensor_sample_fetch(ina); ret = sensor_sample_fetch(ina);
if (ret < 0) if (ret < 0)
@ -111,17 +120,16 @@ int main(void)
LOG_ERR("Could not fetch sample (%d)", ret); LOG_ERR("Could not fetch sample (%d)", ret);
return 0; return 0;
} }
ret = sensor_channel_get(ina, SENSOR_CHAN_VOLTAGE, &voltage); ret = sensor_channel_get(ina, SENSOR_CHAN_VOLTAGE, &voltage);
if (ret < 0) if (ret < 0)
{ {
LOG_ERR("Could not get sample (%d)", ret); LOG_ERR("Could not get voltage (%d)", ret);
return 0; return 0;
} }
ret = sensor_channel_get(ina, SENSOR_CHAN_CURRENT, &current); ret = sensor_channel_get(ina, SENSOR_CHAN_CURRENT, &current);
if (ret < 0) if (ret < 0)
{ {
LOG_ERR("Could not get sample (%d)", ret); LOG_ERR("Could not get current (%d)", ret);
return 0; return 0;
} }
@ -131,12 +139,39 @@ int main(void)
LOG_ERR("Could not fetch sample (%d)", ret); LOG_ERR("Could not fetch sample (%d)", ret);
return 0; return 0;
} }
ret = sensor_channel_get(bmp, SENSOR_CHAN_PRESS, &pressure);
if (ret < 0)
{
LOG_ERR("Could not get pressure (%d)", ret);
return 0;
}
ret = sensor_channel_get(bmp, SENSOR_CHAN_AMBIENT_TEMP, &temperature);
if (ret < 0)
{
LOG_ERR("Could not get temperature (%d)", ret);
return 0;
}
// ret = sensor_sample_fetch(hdc);
// if (ret < 0)
// {
// LOG_ERR("Could not fetch sample (%d)", ret);
// return 0;
// }
// ret = sensor_channel_get(ina, SENSOR_CHAN_HUMIDITY, &humidity);
// if (ret < 0)
// {
// LOG_ERR("Could not get sample (%d)", ret);
// return 0;
// }
sprintf(str_v, "V:%01d.%06d", voltage.val1, voltage.val2); sprintf(str_v, "V:%01d.%06d", voltage.val1, voltage.val2);
sprintf(str_i, "I:%01d.%06d", current.val1, current.val2); sprintf(str_i, "I:%01d.%06d", current.val1, current.val2);
sprintf(str_p, "P:%05d.%02d", pressure.val1, pressure.val2 / 10000); sprintf(str_p, "P:%03d.%04d", pressure.val1, pressure.val2 / 100);
sprintf(str_t, "T:%03d.%04d", temperature.val1, temperature.val2 / 100);
sprintf(str_h, "H:%05d.%06d", humidity.val1, humidity.val2);
printf("%s\t%s\t%s\n", str_v, str_i, str_p); printf("%s\t%s\t%s\t%s\n", str_v, str_i, str_p, str_t);
cfb_framebuffer_clear(dev, false); cfb_framebuffer_clear(dev, false);
if (cfb_print(dev, str_v, 0, 0)) if (cfb_print(dev, str_v, 0, 0))
@ -149,7 +184,12 @@ int main(void)
printf("Failed to print a string\n"); printf("Failed to print a string\n");
continue; continue;
} }
if (cfb_print(dev, str_p, 0, 32)) if (cfb_print(dev, str_p, 0, 16 * 2))
{
printf("Failed to print a string\n");
continue;
}
if (cfb_print(dev, str_t, 0, 16 * 3))
{ {
printf("Failed to print a string\n"); printf("Failed to print a string\n");
continue; continue;

View File

@ -160,9 +160,14 @@
compatible = "bosch,bmp388"; compatible = "bosch,bmp388";
reg = <0x76>; reg = <0x76>;
int-gpios = <&gpio0 27 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; int-gpios = <&gpio0 27 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
odr = "1.563"; // odr = "1.563";
osr-press = <1>; osr-press = <1>;
}; };
hdc1080: hdc1080@40 {
compatible = "ti,hdc20xx"; // FIXME: add proper support for this part. Hopefully these parts are close enough
reg = <0x40>;
};
}; };
&spi1 { &spi1 {