]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/ulcdd/oledlib.cc
7d966d07f6be252dde993aee26ac5a91e30374ee
[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         printf("\n");   
31         return 0;
32 }
33
34 int oled_send_hw_status(uint8_t *buff, int buff_size, uint8_t *status)
35 {
36         if(buff_size < HW_STATUS_MSG_SIZE)
37                 return -1;
38         
39         buff[0] = MSG_START;
40         buff[1] = HW_STATUS_MSG;
41         buff[2] = status[0];
42         buff[3] = status[1];
43         buff[4] = status[2];
44         buff[5] = status[3];
45         buff[6] = status[4];
46         buff[7] = status[5];
47         buff[8] = MSG_TERM;
48         printf("\n");   
49         return 0;
50 }
51
52 int oled_set_color(uint8_t *buff, int buff_size, uint8_t color)
53 {
54         if(buff_size < COLOR_MSG_SIZE)
55                 return -1;
56         
57         buff[0] = MSG_START;
58         buff[1] = COLOR_MSG;
59         buff[2] = color;
60         buff[3] = MSG_TERM;
61         printf("\n");   
62         return 0;
63 }
64
65 int oled_switch_mode(uint8_t *buff, int buff_size, uint8_t mode, uint8_t status)
66 {
67         if(buff_size < SWITCH_MODE_MSG_SIZE)
68                 return -1;
69         
70         *buff = MSG_START;
71         *(buff+1) = CHANGE_MODE_REP;
72         *(buff+2) = status;
73         *(buff+3) = mode;
74         *(buff+4) = MSG_TERM;
75         
76         return 0;
77 }
78
79 int oled_send_voltage(uint8_t *buff, int buff_size, struct pwr_voltage_type *volt)
80 {
81
82         if(buff_size < VOLTAGE_MSG_SIZE)
83                 return -1;
84         
85         buff[0] = MSG_START;
86         
87         buff[1] = VOLTAGE_MSG;
88         
89         sprintf((char*)(buff+2),"%1.2f",volt->voltage33);
90         
91         sprintf((char*)(buff+6),"%1.2f",volt->voltage50);
92
93         sprintf((char*)(buff+10),"%1.2f",volt->voltage80);
94
95         sprintf((char*)(buff+14),"%2.2f",volt->voltageBAT);
96         
97         *(buff+19) = MSG_TERM;
98
99         return 0;
100 }
101
102 int oled_send_position(uint8_t *buff, int buff_size, struct est_pos_type *pos)
103 {
104         if(buff_size < POSITION_MSG_SIZE)
105                 return -1;
106         
107         buff[0] = MSG_START;
108         
109         buff[1] = POSITION_MSG;
110         
111         sprintf((char*)(buff+2),"%1.2f",pos->x);
112         
113         sprintf((char*)(buff+6),"%1.2f",pos->y);
114
115         *(buff+10) = MSG_TERM;
116
117         return 0;
118 }
119 int oled_send_fsm_state(uint8_t *buff, int buff_size, const char *name, int len)
120 {
121         int i;
122
123         if(buff_size > FSM_STATE_MSG_SIZE)
124                 return -1;
125         
126         buff[0] = MSG_START;
127         
128         buff[1] = FSM_STATE_MSG;
129         for(i=0; i<len; i++)
130                 buff[2+i] = name[i];
131         buff[2+i] = MSG_TERM;
132
133         return 0;
134 }
135