]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
fsm: changes on display fsm
authorMartin Zidek <martin@martinzidek.com>
Fri, 11 Apr 2008 06:29:56 +0000 (08:29 +0200)
committerMartin Zidek <martin@martinzidek.com>
Fri, 11 Apr 2008 06:29:56 +0000 (08:29 +0200)
uoledlib: added message for sending of voltage readings

src/robofsm/Makefile.omk
src/robofsm/fsmdisplay.cc [changed mode: 0755->0644]
src/robofsm/roboevent.py
src/ulcdd/Makefile.omk
src/ulcdd/oledlib.cc
src/ulcdd/oledlib.h
src/ulcdd/uoled.c
src/ulcdd/uoled.h

index 272f45144d20614fd6b83c64343c0e538fc9b748..6f960e818ea19fe349e7058ab9573194b57e266d 100644 (file)
@@ -46,7 +46,7 @@ goto_SOURCES = robot_goto.cc
 lib_LIBRARIES += robot
 robot_SOURCES = serva.c robot.c roboorte.c fsmmove.cc \
                fsmpickup.c fsmdet.c fsmjoy.c \
-               movehelper.cc roboevent.c
+               movehelper.cc roboevent.c fsmdisplay.cc
 include_HEADERS = robotdim.h
 
 bin_PROGRAMS += test_timer
old mode 100755 (executable)
new mode 100644 (file)
index 7b7567f..8a11660
@@ -10,6 +10,7 @@
 #include <signal.h>
 #include <pthread.h>
 #include <unistd.h>
+#include <uoled.h>
 
 /**
  * A thread for serial line communication.
@@ -27,6 +28,10 @@ static void *serial_comm(void *arg)
        
 }
 
+int init_display() {
+       uoled_init();
+}
+
 FSM_STATE_DECL(console);
 FSM_STATE_DECL(status);
 FSM_STATE_DECL(map);
@@ -49,6 +54,12 @@ FSM_STATE(console) {
 
 FSM_STATE(status) {
        switch (FSM_EVENT) {
+               case EV_STATE_ENTERED:
+                       FSM_TIMER(1000);
+                       break;
+               case EV_TIMER:
+                       uoled_send_voltage(NULL);
+                       break;
                case EV_SWITCH_TO_CONS:
                        break;
                case EV_SWITCH_TO_STATUS:
index 1691c2adc557d04fb7a7b5ac637b98a1cea63187..ee1e7dd3ae9fad7c3e0f06b11b5ebd674f2a2f73 100644 (file)
@@ -54,5 +54,11 @@ events = {
        "EV_LOC_LOST" : "Localization can't estimate the position of the robot.",
     },
     "joystick" : {
+    },
+    "display" : {
+       "EV_SWITCH_TO_CONS" : "Switch display mode to CONSOLE",
+       "EV_SWITCH_TO_STATUS" : "Switch display mode to STATUS",
+       "EV_SWITCH_TO_MAP" : "Switch display mode to MAP",
+       "EV_SWITCH_TO_MISC" : "Switch display mode to MISC",
     }
 }
index 0e04b30ca73cfe72c739e6a7ca30e6066ee673b3..90bb1424b4af26522fa54d645ab726506b996d2f 100644 (file)
@@ -1,12 +1,12 @@
 # -*- makefile -*-
 
-lib_LIBRARIES = lcdlib
-lcdlib_SOURCES = lcdlib.c
+lib_LIBRARIES = oledlib
+oledlib_SOURCES = oledlib.cc
 
-include_HEADERS = lcdlib.h
+include_HEADERS = uoled.h
 
-bin_PROGRAMS  = ulcdd
+#bin_PROGRAMS  = ulcdd
 
-ulcdd_SOURCES = ulcdd.c
+#ulcdd_SOURCES = ulcdd.c
 
-ulcdd_LIBS = sercom lcdlib m
+#ulcdd_LIBS = sercom lcdlib m
index 497e83ccca81cb808a513dca759b481a3db37fec..fd9451e5b32974bcd10c1a47b0f0100c39fce737 100644 (file)
@@ -4,6 +4,9 @@
 #include <stdlib.h>
 #include <fcntl.h> 
 #include <unistd.h>
+#include <string.h>
+
+#include <RobotType.h>
 
 #include "oledlib.h"
 
@@ -18,4 +21,34 @@ int oled_switch_mode(u_int8_t *buff, int buff_size, struct mode_info *info) {
        *(buff+4) = MSG_TERM;
        
        return 5;
-}
\ No newline at end of file
+}
+
+int oled_send_voltage(u_int8_t *buff, int buff_size, struct pwr_act_volts_type *volt) {
+       char tmp[5];
+       u_int8_t *ptr;
+
+       ptr=buff;
+
+       if(buff_size < VOLTAGE_MSG_SIZE)
+               return -1;
+       
+       *buff = MSG_START;
+       
+       *(buff+1) = VOLTAGE_MSG;
+       
+       sprintf(tmp,"%2.2f",volt->voltage33);
+       memcpy(buff+2,tmp,5);
+       
+       sprintf(tmp,"%2.2f",volt->voltage50);
+       memcpy(buff+7,tmp,5);
+
+       sprintf(tmp,"%2.2f",volt->voltage80);
+       memcpy(buff+12,tmp,5);
+
+       sprintf(tmp,"%2.2f",volt->voltageBAT);
+       memcpy(buff+17,tmp,5);
+       
+       *(buff+22) = MSG_TERM;
+
+       return 0;
+}
index a5b3afa632f7bb19cd604c0948f89d79d7fdc3a6..adf728e0e9cadff252ddbb51e85915a033feec62 100644 (file)
@@ -1,8 +1,9 @@
 #define SWITCH_MODE_MSG_SIZE 4
-
+#define VOLTAGE_MSG_SIZE 23 //FIXME
 #define MSG_START 150
 
 #define CHANGE_MODE_REP 200
+#define VOLTAGE_MSG 160
 #define CHANGE_MODE_OK 201
 
 #define MSG_TERM 254
 struct mode_info {
        u_int8_t mode;
        u_int8_t status;        
-};
\ No newline at end of file
+};
+
+struct voltages {
+       double voltage33;
+       double voltage50;
+       double voltage80;
+       double voltageBAT;
+};
index b773999ff86b61746c99c3911b5f7e316228ee4a..63d33a3d574235884e808236c38399c2e54acd58 100644 (file)
@@ -8,9 +8,24 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <RobotType.h>
 
 struct sercom_data sercom;
 
+int uoled_init() {
+       strcpy((char *)&sercom.devname, "/dev/ttyUSB0");
+       sercom.baudrate = 2400;
+       sercom.parity = SERCOM_PARNONE;
+       sercom.databits = 8;
+       sercom.stopbits = 1;
+       sercom.mode = 0;
+       
+//     sercom.saio.sa_handler = lcd_receive;
+       
+       sercom_open(&sercom);
+       return 0;
+}
+
 int uoled_write_cmd(u_int8_t *buff, int size) {
        int ret, i;
        u_int8_t rep;
@@ -49,4 +64,17 @@ int uoled_switch_mode_rep() {
        
        return 0;
 
-}
\ No newline at end of file
+}
+
+int uoled_send_voltage(struct pwr_act_volts *volt) {
+       int ret;
+       u_int8_t msg[MSG_VOLTAGE_SIZE];
+
+       oled_send_voltage(msg, VOLTAGE_MSG_SIZE, volt);
+
+       ret = uoled_write_cmd(msg, VOLTAGE_MSG_SIZE);
+       if(ret)
+               return -1;
+
+       return 0;
+}
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..2eb039ad93b3e067c962c545627b8d221cbdf797 100644 (file)
@@ -0,0 +1,6 @@
+#ifndef _UOLED_H
+#define _UOLED_H
+
+int uoled_init();
+int uoled_send_voltage(struct pwr_act_volts_type *volt);
+#endif