some changes in MLX90640, add scripts

This commit is contained in:
Edward Emelianov 2023-02-04 12:05:21 +03:00
parent 8a0277171a
commit b8b845c2f5
8 changed files with 57 additions and 15 deletions

Binary file not shown.

View File

@ -1,11 +1,11 @@
# run `make DEF=...` to add extra defines
PROGRAM := mlx
LDFLAGS := -fdata-sections -ffunction-sections -Wl,--gc-sections -Wl,--discard-all
LDFLAGS += -lwiringPi -lusefull_macros -L/usr/local/lib -lm -lcrypt
LDFLAGS += -lwiringPi -lusefull_macros -L/usr/local/lib -lm -lcrypt -flto
SRCS := $(wildcard *.c)
DEFINES := $(DEF) -D_GNU_SOURCE -D_XOPEN_SOURCE=1111
OBJDIR := mk
CFLAGS += -O2 -Wall -Wextra -Wno-trampolines -std=gnu99
CFLAGS += -O2 -Wall -Wextra -Wno-trampolines -std=gnu99 -flto
OBJS := $(addprefix $(OBJDIR)/, $(SRCS:%.c=%.o))
DEPS := $(OBJS:.o=.d)
TARGFILE := $(OBJDIR)/TARGET

View File

@ -45,6 +45,7 @@ static glob_pars const Gdefault = {
.addr = DEFAULT_ADDR,
.device = DEFAULT_I2C,
.pidfile = DEFAULT_PIDFILE,
.simple = 2,
.logfile = NULL // don't save logs
};
@ -59,6 +60,7 @@ static myoption cmdlnopts[] = {
{"pidfile", NEED_ARG, NULL, 'P', arg_string, APTR(&G.pidfile), _("pidfile (default: " DEFAULT_PIDFILE ")")},
{"device", NEED_ARG, NULL, 'd', arg_string, APTR(&G.device), _("I2C device path (default: " DEFAULT_I2C ")")},
{"address", NEED_ARG, NULL, 'a', arg_int, APTR(&G.addr), _("slave address (default:" STR(DEFAULT_ADDR) ")")},
{"simple", NEED_ARG, NULL, 's', arg_int, APTR(&G.simple), _("simple= (0..2, default: 2)")},
end_option
};

View File

@ -23,6 +23,7 @@
*/
typedef struct{
int addr; // slave address
int simple; // 'simple'
char *device; // I2C device
char *pidfile; // name of PID file
char *logfile; // logging to this file

23
MLX90640/get_pic.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
ctr=1
function getx() {
~/MLX90640_OrangePi/mlx -s ${2} -a ${1} | head -n 36 | tail -n 24 > data.dat && ~/MLX90640_OrangePi/plotimage
mv sensor.jpg sensor_${1}_${2}_${TIMEST}.jpg
mv data.dat ${TIMEST}_${1}_${2}.dat
}
while true; do
h=$(date +"%H")
[ $h -gt 7 -a $h -lt 17 ] && exit 0
TIMEST=$(date +%d-%H:%M)
wget http://zarch.sao.ru/lastMONO.jpg?0.$((ctr++)) -O allsky_${TIMEST}.jpg
for a in 0x33 0x37; do for i in 0 1 2; do
getx $a $i
done; done
sleep 60
done

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <math.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
@ -41,7 +42,7 @@ static double image[MLX_PIXNO];
static double image2[MLX_PIXNO];
static void pushima(const double *img){
for(int i = 0; i < MLX_PIXNO; ++i){
double val = *img++;
register double val = *img++;
image[i] += val;
image2[i] += val*val;
}
@ -55,29 +56,30 @@ int main (int argc, char **argv){
FREE(self);
if(GP->addr < 0 || GP->addr > 0xff) ERRX("Wrong I2C address");
if(GP->logfile) OPENLOG(GP->logfile, LOGLEVEL_ANY, 1);
if(GP->simple < 0 || GP->simple > 2) ERRX("simple = 0..2");
if(!mlx90640_init(GP->device, (uint8_t)GP->addr)) ERR("Can't open device");
//mlx90640_dump_parameters();
#define N 5
double *ima = NULL;
if(!mlx90640_take_image(GP->simple, &ima) || !ima) ERRX("Can't take image"); // take trash image
#define N 10
double T0 = dtime();
uint8_t simple = 2;
//for(uint8_t simple = 0; simple < 3; ++simple){
memset(image, 0, sizeof(image));
memset(image2, 0, sizeof(image));
for(int i = 0; i < N; ++i){
double *ima = NULL;
if(!mlx90640_take_image(simple, &ima) || !ima) ERRX("Can't take image");
if(!mlx90640_take_image(GP->simple, &ima) || !ima) ERRX("Can't take image");
printf("Got image %d, T=%g; val[0]=%g, val[1]=%g\n", i, dtime() - T0, ima[0], ima[1]);
pushima(ima);
printf("Got image %d, T=%g\n", i, dtime() - T0);
T0 = dtime();
}
double *im = image, *im2 = image2;
green("\nImage (simple=%d):\n", simple);
green("\nImage (simple=%d):\n", GP->simple);
for(int row = 0; row < MLX_H; ++row){
for(int col = 0; col < MLX_W; ++col){
double v = *im++, v2 = *im2;
v /= N; v2 /= N;
printf("%5.1f ", v);
*im2++ = v2 - v*v;
printf("%6.1f ", v);
*im2++ = v2 - v*v; // now it is std
}
printf("\n");
}
@ -86,7 +88,7 @@ int main (int argc, char **argv){
im2 = image2;
for(int row = 0; row < MLX_H; ++row){
for(int col = 0; col < MLX_W; ++col){
printf("%5.1f ", *im2++);
printf("%6.2f ", sqrt(*im2++));
}
printf("\n");
}

View File

@ -52,7 +52,7 @@ static int errctr = 0;
static double Tlast = 0.;
#define chstate() do{errctr = 0; Tlast = dtime(); DBG("chstate()");}while(0)
#define chkerr() do{DBG("chkerr(), T=%g", dtime()-Tlast); if(++errctr > MLX_MAXERR_COUNT){ DBG("-> M_ERROR"); return FALSE;}else continue;}while(0)
#define chktmout() do{DBG("chktmout, T=%g", dtime()-Tlast); if(dtime() - Tlast > MLX_TIMEOUT){ DBG("Timeout! -> M_ERROR"); return FALSE;}else continue;}while(0)
#define chktmout() do{/*DBG("chktmout, T=%g", dtime()-Tlast);*/ if(dtime() - Tlast > MLX_TIMEOUT){ DBG("Timeout! -> M_ERROR"); return FALSE;}else continue;}while(0)
// read register value
@ -90,6 +90,7 @@ static int read_regN(uint16_t regaddr, uint16_t *data, uint16_t N){
m[0].buf = a; m[1].buf = d;
if(ioctl(I2Cfd, I2C_RDWR, &x) < 0) return FALSE;
if(data) for(int i = 0; i < N; ++i){
// DBG("Read 0x%04x from reg 0x%04x", (uint16_t)((d[2*i] << 8) | (d[2*i+1])), regaddr+i);
*data++ = (uint16_t)((d[2*i] << 8) | (d[2*i + 1]));
}
return TRUE;

13
MLX90640/plotimage Executable file
View File

@ -0,0 +1,13 @@
#!/usr/bin/gnuplot
set terminal jpeg enhanced size 640,480
#set size square
set size ratio -1
#set xrange [0:32]
#set yrange [0:24]
set autoscale xfix
set autoscale yfix
set autoscale cbfix
set output 'sensor.jpg'
#set pm3d map
plot 'data.dat' matrix with image notitle