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