Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
fwatch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
fwatch
Commits
0190d7f8
Commit
0190d7f8
authored
Sep 24, 2014
by
Matthieu Cattin
Committed by
Projects
Sep 28, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sw: Working on a path drawing widget (for gps app).
parent
f4cd19ee
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
183 additions
and
8 deletions
+183
-8
Makefile
sw/ui-test/Makefile
+1
-1
digital_watch.c
sw/ui-test/digital_watch.c
+8
-4
path_widget.c
sw/ui-test/path_widget.c
+157
-0
path_widget.h
sw/ui-test/path_widget.h
+15
-0
plot_widget.c
sw/ui-test/plot_widget.c
+2
-3
No files found.
sw/ui-test/Makefile
View file @
0190d7f8
OBJS
=
plot_widget.o gfx.o ui.o ui_pc.o font_helv17.o font_luct38.o font_xm16x25b.o digital_watch.o font_helv38b.o font_helv29.o font_helv22b.o font_xm4x6.o font_xm5x8.o font_helv11.o
OBJS
=
plot_widget.o
path_widget.o
gfx.o ui.o ui_pc.o font_helv17.o font_luct38.o font_xm16x25b.o digital_watch.o font_helv38b.o font_helv29.o font_helv22b.o font_xm4x6.o font_xm5x8.o font_helv11.o
CFLAGS
=
`
sdl-config
--cflags
`
-I
.
-g
-O0
LDFLAGS
=
`
sdl-config
--libs
`
-g
-O0
...
...
sw/ui-test/digital_watch.c
View file @
0190d7f8
#include "ui.h"
#include "plot_widget.h"
#include "path_widget.h"
//#include "../bitmaps/bitmaps.h"
...
...
@@ -254,14 +255,17 @@ void home_screen_create()
ui_init_widget
(
&
digital_watch
);
//ui_init_widget (&pls_viewer);
ui_init_widget
(
&
hist_plot
);
ui_init_widget
(
&
path_widget
);
ui_add_widget
(
&
digital_watch
);
//
ui_add_widget(&digital_watch);
//ui_add_widget(&pls_viewer);
ui_add_widget
(
&
hist_plot
);
//ui_add_widget (&hist_plot);
ui_add_widget
(
&
path_widget
);
ui_add_child
(
&
home_screen
,
&
digital_watch
);
//
ui_add_child(&home_screen, &digital_watch);
//ui_add_child(&home_screen, &pls_viewer);
ui_add_child
(
&
home_screen
,
&
hist_plot
);
//ui_add_child (&home_screen, &hist_plot);
ui_add_child
(
&
home_screen
,
&
path_widget
);
ui_add_widget
(
&
home_screen
);
ui_init_widget
(
&
status_bar
);
...
...
sw/ui-test/path_widget.c
0 → 100644
View file @
0190d7f8
#include "path_widget.h"
void
find_path_min_max
(
int32_t
*
d
,
uint16_t
d_size
,
int32_t
*
min
,
int32_t
*
max
)
{
uint16_t
i
;
uint8_t
j
;
for
(
j
=
0
;
j
<
2
;
j
++
){
min
[
j
]
=
d
[
0
][
j
];
max
[
j
]
=
d
[
0
][
j
];
}
for
(
i
=
0
;
i
<
d_size
;
i
++
){
for
(
j
=
0
;
j
<
2
;
j
++
){
if
(
d
[
i
][
j
]
<
min
[
j
])
min
[
j
]
=
d
[
i
][
j
];
if
(
d
[
i
][
j
]
>
max
[
j
])
max
[
j
]
=
d
[
i
][
j
];
}
}
}
void
draw_path
(
struct
surface
*
surf
,
path
*
p
)
{
uint8_t
i
;
int32_t
min
[
2
];
int32_t
max
[
2
];
uint8_t
x_scale
,
y_scale
,
x_win
;
int8_t
y_pos
,
y_pos_next
;
char
buf
[
20
];
for
(
i
=
0
;
i
<
p
->
d_size
;
i
++
)
{
DBG
(
"data: %8d, %8d
\n
"
,
p
->
d
[
i
][
0
],
p
->
d
[
i
][
1
]);
}
// Find data min/max
find_min_max
(
p
->
d
,
p
->
d_size
,
&
min
[
0
],
&
max
[
0
]);
for
(
i
=
0
;
i
<
2
;
i
++
){
DBG
(
"%d: min: %d
\n
max: %d
\n
max-min: %d
\n
"
,
i
,
min
[
i
],
max
[
i
],(
max
[
i
]
-
min
[
i
]));
}
/*
// 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;
}
// Compute y scaling factor (rounded up by adding 1)
y_scale = (y_max - y_min) / p->y_size + 1;
DBG("x_scale: %d\ny_scale: %d\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]);
if(p->line)
gfx_line(surf, i, p->y_size-y_pos, i+1, p->y_size-y_pos_next, 1);
else
gfx_set_pixel(surf, i, 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);
// 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)
{
gfx_line(surf, 0, 0, p->x_size, 0, 1);
gfx_line(surf, p->x_size, 0, p->x_size, p->y_size, 1);
gfx_line(surf, p->x_size, p->y_size, 0, p->y_size, 1);
gfx_line(surf, 0, p->y_size, 0, 0, 1);
}
*/
}
static
void
path_event
(
struct
ui_widget
*
w
,
struct
ui_event
event
)
{
switch
(
event
.
type
)
{
case
EVT_NEXT_CYCLE
:
w
->
flags
|=
WF_DIRTY
;
break
;
default:
break
;
}
}
static
void
path_redraw
(
struct
ui_widget
*
w
)
{
#define D_SIZE 50
int32_t
data
[
D_SIZE
][
2
];
uint16_t
i
;
char
title
[
20
];
float
x
;
static
float
a
=
0
;
path
p
;
// Clear widget
gfx_clear
(
&
w
->
dc
,
0
);
// Generate test data
sprintf
(
title
,
"test path
\n
"
);
x
=
0
;
for
(
i
=
0
;
i
<
D_SIZE
;
i
++
)
{
x
+=
100
;
data
[
i
][
0
]
=
x
*
i
;
data
[
i
][
1
]
=
100
+
(
i
*
x
-
50
);
//DBG("data: %8d, %8d\n",data[i][0], data[i][1]);
}
a
+=
0
.
8
;
// Draw plot
p
.
d
=
&
data
[
0
][
0
];
p
.
d_size
=
D_SIZE
;
p
.
x_size
=
127
;
p
.
y_size
=
100
;
p
.
title
=
title
;
p
.
frame
=
1
;
p
.
line
=
1
;
draw_path
(
&
w
->
dc
,
&
p
);
}
struct
ui_widget
path_widget
=
{
path_redraw
,
path_event
,
{
0
,
16
,
127
,
127
},
0
,
WF_ACTIVE
|
WF_VISIBLE
};
sw/ui-test/path_widget.h
0 → 100644
View file @
0190d7f8
#include "ui.h"
#include "math.h"
extern
struct
ui_widget
path_widget
;
typedef
struct
path
{
int32_t
*
d
;
// pointer on data array
uint16_t
d_size
;
// data array size
uint8_t
x_size
;
// X plot size (pixel)
uint8_t
y_size
;
// Y plot size (pixel)
char
*
title
;
// pointer on plot title string
uint8_t
frame
;
// draw frame around plot
uint8_t
line
;
// draw lines between data points
}
path
;
sw/ui-test/plot_widget.c
View file @
0190d7f8
...
...
@@ -25,14 +25,13 @@ void draw_plot(struct surface* surf, plot* p)
uint8_t
x_scale
,
y_scale
,
x_win
;
int8_t
y_pos
,
y_pos_next
;
char
buf
[
20
];
float
t
;
// Find data min/max
find_min_max
(
p
->
d
,
p
->
d_size
,
&
y_min
,
&
y_max
);
DBG
(
"min: %d
\n
max: %d
\n
max-min: %d
\n
"
,
y_min
,
y_max
,(
y_max
-
y_min
));
// Compute x scaling factors
// If data size is smaller than the plot size, don't stretch
plot
// 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
;
...
...
@@ -124,7 +123,7 @@ static void hist_plot_redraw(struct ui_widget *w)
{
x
+=
0
.
03
;
data
[
i
]
=
(
int16_t
)((
200
+
a
*
100
)
*
sin
(
a
+
x
));
//data[i] = -
1
00 + i;
//data[i] = -
20
00 + i;
}
a
+=
0
.
8
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment