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
847e5f43
Commit
847e5f43
authored
Aug 26, 2014
by
Matthieu Cattin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sw: work on pressure graph display (still buggy).
parent
721320d0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
126 additions
and
8 deletions
+126
-8
main.c
sw/alti_test/main.c
+126
-8
No files found.
sw/alti_test/main.c
View file @
847e5f43
...
...
@@ -36,6 +36,112 @@
#include <drivers/altimeter.h>
#define HIST_SIZE 127
typedef
struct
hist_buf
{
//uint16_t *buffer; // data buffer
uint16_t
buffer
[
HIST_SIZE
];
// data buffer
uint16_t
*
end
;
// end of data buffer
bool
wrap
;
// indicates buffer wrap
uint16_t
*
head
;
// pointer to head
uint16_t
*
tail
;
// pointer to tail
}
hist_buf
;
void
buf_init
(
hist_buf
*
buf
,
uint16_t
size
)
{
uint16_t
*
scan
;
//buf->buffer = malloc(size);
//buf->end = buf->buffer + size;
buf
->
end
=
&
buf
->
buffer
[
HIST_SIZE
];
buf
->
wrap
=
false
;
buf
->
head
=
buf
->
buffer
;
buf
->
tail
=
buf
->
buffer
;
scan
=
buf
->
buffer
;
while
(
scan
<=
buf
->
end
)
{
*
scan
=
0
;
scan
++
;
}
}
void
buf_write
(
hist_buf
*
buf
,
uint16_t
data
)
{
*
buf
->
head
++
=
data
;
if
(
buf
->
head
>=
buf
->
end
)
{
buf
->
head
=
buf
->
buffer
;
buf
->
wrap
=
true
;
}
if
(
buf
->
wrap
)
{
buf
->
tail
++
;
if
(
buf
->
tail
>=
buf
->
end
)
{
buf
->
tail
=
buf
->
buffer
;
}
}
}
void
buf_get_last
(
hist_buf
*
buf
,
uint16_t
*
last
)
{
if
(
buf
->
head
==
buf
->
buffer
)
{
last
=
buf
->
end
;
}
else
{
last
=
buf
->
head
--
;
}
}
void
plot_hist
(
hist_buf
*
buf
,
uint8_t
y_org
,
uint8_t
y_size
)
{
uint8_t
x
;
uint16_t
y_min
,
y_max
;
uint16_t
*
scan
;
uint16_t
y_val
;
buf_get_last
(
buf
,
scan
);
y_min
=
*
scan
;
y_max
=
*
scan
;
while
(
scan
!=
buf
->
tail
)
{
scan
++
;
if
(
scan
>=
buf
->
end
)
{
scan
=
buf
->
buffer
;
}
if
(
*
scan
>
y_max
)
y_max
=
*
scan
;
if
(
*
scan
<
y_min
)
y_min
=
*
scan
;
}
buf_get_last
(
buf
,
scan
);
// scan x axis (entire screen)
for
(
x
=
0
;
x
<
127
;
x
++
)
{
while
(
scan
!=
buf
->
tail
)
{
if
(
*
scan
!=
0
)
{
y_val
=
(
*
scan
-
960
)
*
(
10
)
/
y_size
;
//y_val = (*scan-y_min) * (y_max-y_min)/y_size;
lcd_set_pixel
(
x
,
y_val
+
y_org
,
1
);
}
scan
++
;
}
}
}
/**
* @brief Main function
...
...
@@ -52,6 +158,7 @@ int main(void)
double
altitude
=
0
;
double
pressure_calc
;
double
pressure_comp
;
hist_buf
*
pressure_hist
;
/* Setup SysTick Timer for 1 msec interrupts */
if
(
SysTick_Config
(
CMU_ClockFreqGet
(
cmuClock_CORE
)
/
1000
))
while
(
1
);
...
...
@@ -67,6 +174,9 @@ int main(void)
I2CDRV_Init
(
&
i2cInit
);
//ui_init();
//alti_screen_create();
err
=
alti_init
();
sprintf
(
str
,
"init: 0x%02x"
,
err
);
text
(
&
font_helv11
,
5
,
10
,
str
);
...
...
@@ -76,29 +186,36 @@ int main(void)
err
=
alti_altitude2mbar
(
&
pressure_calc
,
440
);
pressure_comp
=
pressure
-
pressure_calc
;
buf_init
(
pressure_hist
,
HIST_SIZE
);
while
(
1
)
{
//ui_update();
err
=
alti_get_temp_pressure
(
&
temp
,
&
pressure
,
true
);
sprintf
(
str
,
"temp: %f C"
,
temp
);
text
(
&
font_helv11
,
5
,
2
0
,
str
);
sprintf
(
str
,
"temp: %
3.2
f C"
,
temp
);
text
(
&
font_helv11
,
5
,
1
0
,
str
);
sprintf
(
str
,
"pressure: %5.2f mbar"
,
pressure
);
text
(
&
font_helv11
,
5
,
30
,
str
);
text
(
&
font_helv11
,
5
,
20
,
str
);
buf_write
(
pressure_hist
,
(
uint16_t
)(
pressure
));
err
=
alti_mbar2altitude
(
pressure
,
&
altitude
);
sprintf
(
str
,
"altitude: %4.2f m"
,
altitude
);
text
(
&
font_helv11
,
5
,
40
,
str
);
text
(
&
font_helv11
,
5
,
30
,
str
);
sprintf
(
str
,
"p calc: %5.2f mbar"
,
pressure_calc
);
text
(
&
font_helv11
,
5
,
6
0
,
str
);
text
(
&
font_helv11
,
5
,
5
0
,
str
);
sprintf
(
str
,
"p comp: %5.2f mbar"
,
pressure_comp
);
text
(
&
font_helv11
,
5
,
7
0
,
str
);
text
(
&
font_helv11
,
5
,
6
0
,
str
);
err
=
alti_mbar2altitude
(
pressure
-
pressure_comp
,
&
altitude
);
sprintf
(
str
,
"alti comp: %4.2f m"
,
altitude
);
text
(
&
font_helv11
,
5
,
50
,
str
);
text
(
&
font_helv11
,
5
,
40
,
str
);
//plot_hist(pressure_hist, 120, 60);
//sprintf(str, "err: 0x%02x", err);
//text(&font_helv11, 5, 50, str);
...
...
@@ -106,6 +223,7 @@ int main(void)
//Delay(1000);
//box(5, 10, 128, 50, 0);
lcd_clear
();
}
...
...
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