4
4
#include <p33EP512GP806.h>
5
5
#include <pic24_all.h>
6
6
#include <esos_f14ui.h>
7
-
7
+ #include <esos_comm.h>
8
8
#include <esos_sensor.h>
9
9
10
+
11
+
10
12
#include <stdio.h>
11
13
#include <stdlib.h>
12
14
13
15
#define LOOP_DELAY 1000
14
16
15
17
char buffer [30 ];
16
18
BOOL b_keepLooping = FALSE;
19
+
20
+ ESOS_CHILD_TASK (barGraph_child , uint16_t u16_num2graph ){ //visual display of data
21
+ static uint8_t u8_barGraph_value = 0 ;
22
+ static uint8_t i ;
23
+ static uint8_t j ;
24
+ ESOS_TASK_BEGIN ();
25
+ ESOS_TASK_WAIT_ON_SEND_STRING (" |" ); //draws a 20 '_' long line with a moving '|'
26
+ u8_barGraph_value = u16_num2graph / 50 ; //max output 2^10 ~= 1000; /50 gives increments of 20
27
+ for (i = 0 ; i < u8_barGraph_value ; i ++ ){
28
+ ESOS_TASK_WAIT_ON_SEND_STRING ("_" );
29
+ }
30
+ ESOS_TASK_WAIT_ON_SEND_STRING ("|" ); //after appropriate '_'s this is the values line
31
+ for (j = 0 ; j < (20 - u8_barGraph_value ); j ++ ){ //finish the 20 '_'s
32
+ ESOS_TASK_WAIT_ON_SEND_STRING ("_" );
33
+ }
34
+ ESOS_TASK_WAIT_ON_SEND_STRING ("|\n" );
35
+ ESOS_TASK_END ();
36
+ }
37
+
17
38
ESOS_USER_TASK (loop ) {
18
39
static uint16_t u16_data ;
19
-
40
+ static ESOS_TASK_HANDLE th_child ; //declare storage for handle to child task
20
41
ESOS_TASK_BEGIN ();{
21
42
for (;;) { //same as while(true)
22
43
23
- ESOS_TASK_WAIT_UNTIL (esos_uiF14_isSW1Pressed () || esos_uiF14_isSW2Pressed ()); /on either switch , start the DO loop
44
+ ESOS_TASK_WAIT_UNTIL (esos_uiF14_isSW1Pressed () || esos_uiF14_isSW2Pressed ()); // on either switch, start the DO loop
24
45
if (esos_uiF14_isSW2Pressed ()){
25
46
b_keepLooping = TRUE; //if sw2 then keep looping; checked at the bottom while statement
26
47
}
@@ -38,7 +59,12 @@ ESOS_USER_TASK(loop) {
38
59
//wait for UART availability to send output to Bully Bootloader
39
60
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM ();
40
61
41
- sprintf (buffer , "%d\n" , u16_data );
62
+ ESOS_TASK_WAIT_ON_SEND_UINT16_AS_HEX_STRING (u16_data ); //extra zeros but acceptable
63
+
64
+ ESOS_ALLOCATE_CHILD_TASK (th_child );
65
+ ESOS_TASK_SPAWN_AND_WAIT (th_child , barGraph_child , u16_data );
66
+
67
+ ESOS_TASK_WAIT_ON_SEND_STRING ("\n" );
42
68
ESOS_TASK_WAIT_ON_SEND_STRING (buffer ); //wait for data in buffer to be sent and release UART
43
69
ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM ();
44
70
ESOS_TASK_WAIT_TICKS (LOOP_DELAY /2 ); /*this is half of the 1 second delay between samples
@@ -63,11 +89,14 @@ ESOS_USER_TASK(loop) {
63
89
ESOS_TASK_END ();
64
90
}
65
91
92
+
66
93
void user_init (void ){
67
94
config_esos_uiF14 ();
68
95
69
96
// Config heartbeat
70
97
esos_uiF14_flashLED3 (500 );
71
98
72
99
esos_RegisterTask (loop );
100
+
101
+
73
102
}
0 commit comments