Commit 16d82f58 authored by Matthieu Cattin's avatar Matthieu Cattin

sw: First working prototype of the path widget.

parent dc1a284e
#include "path_widget.h"
void find_path_min_max(struct coord *d, uint16_t d_size, struct coord *min, struct coord *max)
{
uint16_t i;
uint8_t j;
min->lat = d[0].lat;
max->lat = d[0].lat;
min->lon = d[0].lon;
max->lon = d[0].lon;
min->alt = d[0].alt;
max->alt = d_size;
for(i=0; i<d_size; i++){
if(d[i].lat < min->lat)
min->lat = d[i].lat;
if(d[i].lat > max->lat)
max->lat = d[i].lat;
}
DBG("find_min_max: d_size=%d\n",d_size);
}
#include <stdlib.h>
#include <stdio.h>
void draw_path(struct surface *surf, path *p)
{
uint8_t i;
struct coord min;
struct coord max;
struct coord *p_min;
struct coord *p_max;
uint8_t x_scale, y_scale, x_win;
coord min;
coord max;
double x_scale, y_scale;
int8_t y_pos, y_pos_next;
int8_t x_pos, x_pos_next;
char buf[20];
p_min = &min;
p_max = &max;
min.lat = p->d[0].lat;
max.lat = p->d[0].lat;
min.lon = p->d[0].lon;
max.lon = p->d[0].lon;
min.alt = p->d[0].alt;
max.alt = p->d[0].alt;
for(i=0; i<p->d_size; i++)
{
DBG("data: %8d, %8d, %8d\n",p->d[i].lat, p->d[i].lon, p->d[i].alt);
DBG("data: %f, %f, %f\n",p->d[i].lat, p->d[i].lon, p->d[i].alt);
}
DBG("draw_path: d_size=%d, i=%d\n",p->d_size, i);
// Find data min/max
find_min_max(p->d, p->d_size, p_min, p_max);
DBG("lat: min: %8d, max: %8d, max-min: %8d\n", min.lat, max.lat, (max.lat - min.lat));
DBG("lon: min: %8d, max: %8d, max-min: %8d\n", min.lon, max.lon, (max.lon - min.lon));
DBG("alt: min: %8d, max: %8d, max-min: %8d\n", min.alt, max.alt, (max.alt - min.alt));
/*
// Compute x scaling factors
// If data size is smaller than the plot size, don't stretch data
if(p->d_size < p->x_size){
x_scale = 1;
x_win = p->d_size;
}
else{
x_scale = p->d_size / p->x_size;
x_win = p->x_size;
for(i=0; i<p->d_size; i++){
if(p->d[i].lat < min.lat)
min.lat = p->d[i].lat;
if(p->d[i].lat > max.lat)
max.lat = p->d[i].lat;
if(p->d[i].lon < min.lon)
min.lon = p->d[i].lon;
if(p->d[i].lon > max.lon)
max.lon = p->d[i].lon;
if(p->d[i].alt < min.alt)
min.alt = p->d[i].alt;
if(p->d[i].alt > max.alt)
max.alt = p->d[i].alt;
}
//find_min_max(p->d, p->d_size, p_min, p_max);
DBG("lat: min: %f, max: %f, max-min: %f\n", min.lat, max.lat, (max.lat - min.lat));
DBG("lon: min: %f, max: %f, max-min: %f\n", min.lon, max.lon, (max.lon - min.lon));
DBG("alt: min: %f, max: %f, max-min: %f\n", min.alt, max.alt, (max.alt - min.alt));
// Compute x scaling factor (rounded up by adding 1)
x_scale = (max.lat - min.lat) / p->x_size + 1;
// Compute y scaling factor (rounded up by adding 1)
y_scale = (y_max - y_min) / p->y_size + 1;
y_scale = (max.lon - min.lon) / p->y_size + 1;
DBG("x_scale: %d\ny_scale: %d\n",x_scale, y_scale);
DBG("x_scale: %f\ny_scale: %f\n",x_scale, y_scale);
// Rescale and plot data
for(i=0; i<x_win-1; i++){
//y_pos = (d[i*x_scale])/y_scale + y_size/2;
//y_pos_next = (d[(i+1)*x_scale])/y_scale + y_size/2;
y_pos = (p->d[i*x_scale] - y_min)/y_scale;
y_pos_next = (p->d[(i+1)*x_scale] - y_min)/y_scale;
//DBG("x=%3d, y=%3d (%d)\n", i, y_pos, d[i*x_scale]);
for(i=0; i<p->d_size-1; i++){
x_pos = (p->d[i].lat - min.lat)/x_scale;
x_pos_next = (p->d[i+1].lat - min.lat)/x_scale;
y_pos = (p->d[i].lon - min.lon)/y_scale;
y_pos_next = (p->d[i+1].lon - min.lon)/y_scale;
DBG("x=%4d, y=%4d\n", x_pos, y_pos);
if(p->line)
gfx_line(surf, i, p->y_size-y_pos, i+1, p->y_size-y_pos_next, 1);
gfx_line(surf, x_pos, p->y_size-y_pos, x_pos_next, p->y_size-y_pos_next, 1);
else
gfx_set_pixel(surf, i, p->y_size-y_pos, 1);
gfx_set_pixel(surf, x_pos, p->y_size-y_pos, 1);
}
// Print plot title
DBG("title: %s",p->title);
//gfx_text(surf, &font_xm5x8, 0, 0, p->title);
//gfx_centered_text(surf, &font_helv11, 0, p->title);
gfx_centered_text(surf, &font_xm4x6, p->y_size+1, p->title);
gfx_centered_text(surf, &font_xm4x6, p->y_size+1, p->title);
/*
// Print min max
sprintf(buf,"min:%d",y_min);
gfx_text(surf, &font_xm4x6, 1, p->y_size+1, buf);
sprintf(buf,"max:%d",y_max);
gfx_text(surf, &font_xm4x6, p->x_size-gfx_text_width(&font_xm4x6,buf), p->y_size+1, buf);
*/
// Print frame, if enabled
if(p->frame)
{
......@@ -105,7 +96,7 @@ void draw_path(struct surface *surf, path *p)
gfx_line(surf, p->x_size, p->y_size, 0, p->y_size, 1);
gfx_line(surf, 0, p->y_size, 0, 0, 1);
}
*/
}
......@@ -127,9 +118,11 @@ static void path_redraw(struct ui_widget *w)
coord data[D_SIZE];
uint16_t i;
char title[20];
float x;
static float a=0;
path p;
int sign;
#define DIV 1000000.0
// Clear widget
gfx_clear(&w->dc, 0);
......@@ -137,13 +130,23 @@ static void path_redraw(struct ui_widget *w)
// Generate test data
sprintf(title, "test path\n");
x = 0;
for(i=0; i<D_SIZE; i++)
data[0].lat = rand()/DIV;
data[0].lon = rand()/DIV;
data[0].alt = rand() % 1000;
for(i=1; i<D_SIZE; i++)
{
x+=100;
data[i].lat = x*i;
data[i].lon = 100+(i*x-50);
data[i].alt = 10+i;
sign = rand() % 2;
if(sign)
data[i].lat = data[i-1].lat + rand()/(DIV);
else
data[i].lat = data[i-1].lat - rand()/(DIV);
sign = rand() % 2;
if(sign)
data[i].lon = data[i-1].lon + rand()/(DIV);
else
data[i].lon = data[i-1].lon - rand()/(DIV);
data[i].alt = rand() % 1000;
//DBG("data: %8d, %8d, %8d\n",data[i].lat, data[i].lon, data[i].alt);
}
......
......@@ -5,9 +5,9 @@
extern struct ui_widget path_widget;
typedef struct coord{
int32_t lat;
int32_t lon;
int32_t alt;
double lat;
double lon;
double alt;
}coord;
typedef struct path{
......@@ -19,3 +19,4 @@ typedef struct path{
uint8_t frame; // draw frame around plot
uint8_t line; // draw lines between data points
}path;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment