I"m trying to test FIFO to transfer sensor values from one function/thread to other.
This is my current code:
K_FIFO_DEFINE(temp_fifo);
struct data_item_t {
void *fifo_reserved; /* 1st word reserved for use by FIFO */
struct sensor_value temp;
struct sensor_value hum;
};
struct data_item_t *rx_buf;
struct data_item_t tx_buf;
void print_data(void){
rx_buf = k_fifo_get(&temp_fifo, K_FOREVER);
printf("HTS221: Temperature: %.1f C\n", sensor_value_to_double(rx_buf->temp));
printf("HTS221: Relative Humidity: %.1f%%\n", sensor_value_to_double(rx_buf->hum));
printf("\n");
}
void work_sample(struct k_work *work) {
if (sensor_sample_fetch(hts221) < 0) {
printf("HTS221 Sensor sample update error\n");
return;
}
sensor_channel_get(hts221, SENSOR_CHAN_AMBIENT_TEMP, &tx_buf.temp);
sensor_channel_get(hts221, SENSOR_CHAN_HUMIDITY, &tx_buf.hum);
k_fifo_put(&temp_fifo, &tx_buf);
print_data();
}
K_WORK_DEFINE(my_work, work_sample);
void timer_handler(struct k_timer *timer_id){
k_work_submit(&my_work);
}
K_TIMER_DEFINE(my_timer, timer_handler, NULL);
I'm getting the following error:
../src/main.c: In function 'print_data':
c:\Work\zephyr-course\sensor_fifo\src\main.c:36:71: error: incompatible type for argument 1 of 'sensor_value_to_double'
36 | printf("HTS221: Temperature: %.1f C\n", sensor_value_to_double(rx_buf->temp));
| ~~~~~~^~~~~~
| |
| struct sensor_value
In file included from c:\Work\zephyr-course\sensor_fifo\src\main.c:10:
C:\Work\nrf-tm\v1.9.1\zephyr\include\drivers\sensor.h:659:72: note: expected 'const struct sensor_value *' but argument is of type 'struct sensor_value'
659 | static inline double sensor_value_to_double(const struct sensor_value *val)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
c:\Work\zephyr-course\sensor_fifo\src\main.c:37:77: error: incompatible type for argument 1 of 'sensor_value_to_double'
37 | printf("HTS221: Relative Humidity: %.1f%%\n", sensor_value_to_double(rx_buf->hum));
| ~~~~~~^~~~~
| |
| struct sensor_value
In file included from c:\Work\zephyr-course\sensor_fifo\src\main.c:10:
C:\Work\nrf-tm\v1.9.1\zephyr\include\drivers\sensor.h:659:72: note: expected 'const struct sensor_value *' but argument is of type 'struct sensor_value'
659 | static inline double sensor_value_to_double(const struct sensor_value *val)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
At top level:
c:\Work\zephyr-course\sensor_fifo\src\main.c:17:34: warning: 'hum' defined but not used [-Wunused-variable]
17 | static struct sensor_value temp, hum;
| ^~~
c:\Work\zephyr-course\sensor_fifo\src\main.c:17:28: warning: 'temp' defined but not used [-Wunused-variable]
17 | static struct sensor_value temp, hum;
| ^~~~
ninja: build stopped: subcommand failed.
It appears that my FIFO is being completely optimized out...
Any light on this?