115 lines
No EOL
3 KiB
C
115 lines
No EOL
3 KiB
C
/*
|
|
* Copyright (c) 2024 PM
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <string.h>
|
|
|
|
#include <app_version.h>
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <lvgl.h>
|
|
#include <lvgl_input_device.h>
|
|
|
|
#include <zephyr/drivers/display.h>
|
|
#include <zephyr/drivers/sensor.h>
|
|
#include <zephyr/input/input.h>
|
|
#include <zephyr/random/random.h>
|
|
|
|
#include <zephyr/logging/log.h>
|
|
|
|
#include "../../drivers/sensor/mlx90640/mlx90640.h"
|
|
|
|
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
|
|
|
|
int main(void)
|
|
{
|
|
int ret;
|
|
printk("IRCAM %s\n", APP_VERSION_STRING);
|
|
|
|
char count_str[11] = {0};
|
|
const struct device *display_dev;
|
|
const struct device *ir_dev;
|
|
|
|
display_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
|
|
if (!device_is_ready(display_dev))
|
|
{
|
|
printf("Device %s not ready\n", display_dev->name);
|
|
return 0;
|
|
}
|
|
|
|
if (display_set_pixel_format(display_dev, PIXEL_FORMAT_RGB_888) != 0)
|
|
{
|
|
printk("display pixel 888 not ok\n");
|
|
printf("Failed to set required pixel format");
|
|
return 0;
|
|
}
|
|
|
|
printf("Initialized %s\n", display_dev->name);
|
|
static lv_color_t cbuf[32 * 24];
|
|
|
|
lv_obj_t *ir_image = lv_canvas_create(lv_scr_act());
|
|
lv_canvas_set_buffer(ir_image, cbuf, 32, 24, LV_IMG_CF_TRUE_COLOR);
|
|
|
|
lv_canvas_fill_bg(ir_image, lv_color_make(0x40, 0x40, 0x40), LV_OPA_COVER);
|
|
|
|
lv_obj_set_size(ir_image, 32, 24);
|
|
lv_obj_align(ir_image, LV_ALIGN_TOP_LEFT, 4, 4);
|
|
lv_img_set_pivot(ir_image, 0, 0);
|
|
// lv_img_set_zoom(ir_image, 256 * 2);
|
|
lv_img_set_zoom(ir_image, 256 * 12);
|
|
lv_img_set_antialias(ir_image, false);
|
|
|
|
lv_timer_handler();
|
|
display_blanking_off(display_dev);
|
|
|
|
ir_dev = DEVICE_DT_GET(DT_NODELABEL(mlx90640_mlx90640_elecrow_i2c));
|
|
if (!device_is_ready(ir_dev))
|
|
{
|
|
printf("Device %s not ready\n", ir_dev->name);
|
|
return 0;
|
|
}
|
|
|
|
lv_color32_t color;
|
|
float *temps = ((struct mlx90640_data *)ir_dev->data)->temps;
|
|
int64_t reftime = k_uptime_get();
|
|
while (1)
|
|
{
|
|
sensor_sample_fetch(ir_dev);
|
|
mlx90640_calculate_to(ir_dev, 0.8, ((struct mlx90640_data *)ir_dev->data)->ta - 8.0f); // Tr = Ta - 8.0 from PDF
|
|
|
|
for (int y = 0; y < 24; y++)
|
|
{
|
|
for (int x = 0; x < 32; x++)
|
|
{
|
|
if (temps[y * 32 + x] < 0)
|
|
{
|
|
color = lv_color_black();
|
|
}
|
|
else if (temps[y * 32 + x] > 64)
|
|
{
|
|
color = lv_color_white();
|
|
}
|
|
else
|
|
{
|
|
color.ch.red = (uint8_t)(temps[y * 32 + x] * 4);
|
|
color.ch.green = color.ch.red;
|
|
color.ch.blue = color.ch.red;
|
|
}
|
|
lv_canvas_set_px_color(ir_image, x, y, color);
|
|
}
|
|
}
|
|
|
|
lv_timer_handler();
|
|
|
|
int64_t elapsed = k_uptime_delta(&reftime);
|
|
printf("took %d ms", (uint32_t)elapsed);
|
|
|
|
if (elapsed < 100)
|
|
{
|
|
k_msleep(100 - elapsed);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
} |