]> rtime.felk.cvut.cz Git - eurobot/public.git/blob - src/ulcdd/oledlib.cc
fsm: changes on display fsm
[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
11 #include "oledlib.h"
12
13 int oled_switch_mode(u_int8_t *buff, int buff_size, struct mode_info *info) {
14         if(buff_size < SWITCH_MODE_MSG_SIZE)
15                 return -1;
16         
17         *buff = MSG_START;
18         *(buff+1) = CHANGE_MODE_REP;
19         *(buff+2) = info->status;
20         *(buff+3) = info->mode;
21         *(buff+4) = MSG_TERM;
22         
23         return 5;
24 }
25
26 int oled_send_voltage(u_int8_t *buff, int buff_size, struct pwr_act_volts_type *volt) {
27         char tmp[5];
28         u_int8_t *ptr;
29
30         ptr=buff;
31
32         if(buff_size < VOLTAGE_MSG_SIZE)
33                 return -1;
34         
35         *buff = MSG_START;
36         
37         *(buff+1) = VOLTAGE_MSG;
38         
39         sprintf(tmp,"%2.2f",volt->voltage33);
40         memcpy(buff+2,tmp,5);
41         
42         sprintf(tmp,"%2.2f",volt->voltage50);
43         memcpy(buff+7,tmp,5);
44
45         sprintf(tmp,"%2.2f",volt->voltage80);
46         memcpy(buff+12,tmp,5);
47
48         sprintf(tmp,"%2.2f",volt->voltageBAT);
49         memcpy(buff+17,tmp,5);
50         
51         *(buff+22) = MSG_TERM;
52
53         return 0;
54 }