]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/uoled/oledlib.cc
Fix angle sign on display
[eurobot/public.git] / src / uoled / 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.h>
11 #include <robot.h>
12 #include <robomath.h>
13
14 #include "oledlib.h"
15
16 int oled_send_hw_status(uint8_t *buff, int buff_size, uint8_t *status)
17 {
18         if(buff_size < HW_STATUS_MSG_SIZE)
19                 return -1;
20         
21         buff[0] = HW_STATUS_MSG;
22         buff[1] = status[0];
23         buff[2] = status[1];
24         buff[3] = status[2];
25         buff[4] = status[3];
26         buff[5] = status[4];
27         buff[6] = status[5];
28         buff[7] = status[6];
29         buff[8] = status[7];
30         buff[9] = MSG_TERM;
31         return HW_STATUS_MSG_SIZE;
32 }
33
34 int oled_set_color(uint8_t *buff, int buff_size, uint8_t color)
35 {
36         if(buff_size < COLOR_MSG_SIZE)
37                 return -1;
38         
39         buff[0] = COLOR_MSG;
40         buff[1] = color;
41         buff[2] = MSG_TERM;
42         return COLOR_MSG_SIZE;
43 }
44
45 int oled_send_game_conf(uint8_t *buff, int buff_size, uint8_t conf)
46 {
47         if(buff_size < CONF_MSG_SIZE)
48                 return -1;
49         
50         buff[0] = GAME_CONF_MSG;
51         sprintf((char*)buff+1, "%1d", conf);
52         sprintf((char*)buff+2, "%1d", conf);
53         buff[3] = MSG_TERM;
54         return CONF_MSG_SIZE;
55 }
56
57 int oled_switch_mode(uint8_t *buff, int buff_size, uint8_t mode, uint8_t status)
58 {
59         if(buff_size < SWITCH_MODE_MSG_SIZE)
60                 return -1;
61         
62         *(buff+0) = CHANGE_MODE_REP;
63         *(buff+1) = status;
64         *(buff+2) = mode;
65         *(buff+3) = MSG_TERM;
66         
67         return SWITCH_MODE_MSG_SIZE;
68 }
69
70 int oled_send_voltage(uint8_t *buff, int buff_size, struct pwr_voltage_type *volt)
71 {
72
73         if(buff_size < VOLTAGE_MSG_SIZE)
74                 return -1;
75         
76         buff[0] = VOLTAGE_MSG;
77         
78         sprintf((char*)(buff+1),"%1.2f",volt->voltage33);
79         
80         sprintf((char*)(buff+5),"%1.2f",volt->voltage50);
81
82         sprintf((char*)(buff+9),"%1.2f",volt->voltage80);
83
84         sprintf((char*)(buff+13),"%2.2f",volt->voltageBAT);
85         
86         *(buff+18) = MSG_TERM;
87
88         return VOLTAGE_MSG_SIZE;
89 }
90
91 int oled_send_position(uint8_t *buff, int buff_size, struct est_pos_type *pos)
92 {
93         if(buff_size < POSITION_MSG_SIZE)
94                 return -1;
95         
96         buff[0] = POSITION_MSG;
97         
98         sprintf((char*)(buff+1),"%1.2f",pos->x);
99         
100         sprintf((char*)(buff+5),"%1.2f",pos->y);
101
102         sprintf((char*)(buff+9),"%3.0f ",RAD2DEG(pos->phi));
103
104         *(buff+13) = MSG_TERM;
105
106         return POSITION_MSG_SIZE;
107 }
108
109 int oled_send_fsm_state(uint8_t *buff, int buff_size, const char *name, int len, uint8_t type)
110 {
111         memset(buff, ' ', FSM_STATE_MSG_SIZE);
112         buff[0] = type;
113         strncpy((char*)buff+1, name, (len > 20) ? 20 : len);
114         buff[FSM_STATE_MSG_SIZE-1] = MSG_TERM;
115
116         return FSM_STATE_MSG_SIZE;
117 }
118
119 int oled_send_pucks_nr(uint8_t *buff, int buff_size, char nr)
120 {
121         if(buff_size < PUCKS_MSG_SIZE)
122                 return -1;
123
124         buff[0] = PUCKS_MSG;
125         sprintf((char*)buff+1, "%1d", nr);
126         buff[2] = MSG_TERM;
127
128         return PUCKS_MSG_SIZE;
129 }
130
131 int oled_send_lift_pos(uint8_t *buff, int buff_size, uint16_t pos)
132 {
133         if(buff_size < LIFT_MSG_SIZE)
134                 return -1;
135
136         buff[0] = LIFT_MSG;
137         sprintf((char*)buff+1, "%4d", pos);
138         buff[5] = MSG_TERM;
139
140         return LIFT_MSG_SIZE;
141 }
142