]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/ulcdd/oledlib.cc
uoled: removed ghost newlines
[eurobot/public.git] / src / ulcdd / oledlib.cc
1 #include <sys/types.h>
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <fcntl.h> 
6 #include <unistd.h>
7 #include <string.h>
8
9 #include <robottype.h>
10 #include <robottype_eb2008.h>
11 #include <robot_eb2008.h>
12
13 #include "oledlib.h"
14
15 int oled_set_balls(uint8_t *buff, int buff_size, uint8_t *carousel)
16 {
17         if(buff_size < BALLS_MSG_SIZE)
18                 return -1;
19         
20         buff[0] = MSG_START;
21         buff[1] = BALLS_MSG;
22         buff[2] = carousel[0];
23         buff[3] = carousel[1];
24         buff[4] = carousel[2];
25         buff[5] = carousel[3];
26         buff[6] = carousel[4];
27         buff[7] = 0;//FIXME
28         buff[8] = 0;//FIXME
29         buff[9] = MSG_TERM;
30         return 0;
31 }
32
33 int oled_send_hw_status(uint8_t *buff, int buff_size, uint8_t *status)
34 {
35         if(buff_size < HW_STATUS_MSG_SIZE)
36                 return -1;
37         
38         buff[0] = MSG_START;
39         buff[1] = HW_STATUS_MSG;
40         buff[2] = status[0];
41         buff[3] = status[1];
42         buff[4] = status[2];
43         buff[5] = status[3];
44         buff[6] = status[4];
45         buff[7] = status[5];
46         buff[8] = MSG_TERM;
47         return 0;
48 }
49
50 int oled_set_color(uint8_t *buff, int buff_size, uint8_t color)
51 {
52         if(buff_size < COLOR_MSG_SIZE)
53                 return -1;
54         
55         buff[0] = MSG_START;
56         buff[1] = COLOR_MSG;
57         buff[2] = color;
58         buff[3] = MSG_TERM;
59         return 0;
60 }
61
62 int oled_switch_mode(uint8_t *buff, int buff_size, uint8_t mode, uint8_t status)
63 {
64         if(buff_size < SWITCH_MODE_MSG_SIZE)
65                 return -1;
66         
67         *buff = MSG_START;
68         *(buff+1) = CHANGE_MODE_REP;
69         *(buff+2) = status;
70         *(buff+3) = mode;
71         *(buff+4) = MSG_TERM;
72         
73         return 0;
74 }
75
76 int oled_send_voltage(uint8_t *buff, int buff_size, struct pwr_voltage_type *volt)
77 {
78
79         if(buff_size < VOLTAGE_MSG_SIZE)
80                 return -1;
81         
82         buff[0] = MSG_START;
83         
84         buff[1] = VOLTAGE_MSG;
85         
86         sprintf((char*)(buff+2),"%1.2f",volt->voltage33);
87         
88         sprintf((char*)(buff+6),"%1.2f",volt->voltage50);
89
90         sprintf((char*)(buff+10),"%1.2f",volt->voltage80);
91
92         sprintf((char*)(buff+14),"%2.2f",volt->voltageBAT);
93         
94         *(buff+19) = MSG_TERM;
95
96         return 0;
97 }
98
99 int oled_send_position(uint8_t *buff, int buff_size, struct est_pos_type *pos)
100 {
101         if(buff_size < POSITION_MSG_SIZE)
102                 return -1;
103         
104         buff[0] = MSG_START;
105         
106         buff[1] = POSITION_MSG;
107         
108         sprintf((char*)(buff+2),"%1.2f",pos->x);
109         
110         sprintf((char*)(buff+6),"%1.2f",pos->y);
111
112         *(buff+10) = MSG_TERM;
113
114         return 0;
115 }
116 int oled_send_fsm_state(uint8_t *buff, int buff_size, const char *name, int len)
117 {
118         int i;
119
120         if(buff_size > FSM_STATE_MSG_SIZE)
121                 return -1;
122         
123         buff[0] = MSG_START;
124         
125         buff[1] = FSM_STATE_MSG;
126         for(i=0; i<len; i++)
127                 buff[2+i] = name[i];
128         buff[2+i] = MSG_TERM;
129
130         return 0;
131 }
132