From: Martin Zidek Date: Fri, 11 Apr 2008 06:29:56 +0000 (+0200) Subject: fsm: changes on display fsm X-Git-Tag: eb2008~296 X-Git-Url: http://rtime.felk.cvut.cz/gitweb/eurobot/public.git/commitdiff_plain/679fc2708f14af8c9d4d53b9ea05fbb6a388e31e fsm: changes on display fsm uoledlib: added message for sending of voltage readings --- diff --git a/src/robofsm/Makefile.omk b/src/robofsm/Makefile.omk index 272f4514..6f960e81 100644 --- a/src/robofsm/Makefile.omk +++ b/src/robofsm/Makefile.omk @@ -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 diff --git a/src/robofsm/fsmdisplay.cc b/src/robofsm/fsmdisplay.cc old mode 100755 new mode 100644 index 7b7567f7..8a11660c --- a/src/robofsm/fsmdisplay.cc +++ b/src/robofsm/fsmdisplay.cc @@ -10,6 +10,7 @@ #include #include #include +#include /** * 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: diff --git a/src/robofsm/roboevent.py b/src/robofsm/roboevent.py index 1691c2ad..ee1e7dd3 100644 --- a/src/robofsm/roboevent.py +++ b/src/robofsm/roboevent.py @@ -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", } } diff --git a/src/ulcdd/Makefile.omk b/src/ulcdd/Makefile.omk index 0e04b30c..90bb1424 100644 --- a/src/ulcdd/Makefile.omk +++ b/src/ulcdd/Makefile.omk @@ -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 diff --git a/src/ulcdd/oledlib.cc b/src/ulcdd/oledlib.cc index 497e83cc..fd9451e5 100644 --- a/src/ulcdd/oledlib.cc +++ b/src/ulcdd/oledlib.cc @@ -4,6 +4,9 @@ #include #include #include +#include + +#include #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; +} diff --git a/src/ulcdd/oledlib.h b/src/ulcdd/oledlib.h index a5b3afa6..adf728e0 100644 --- a/src/ulcdd/oledlib.h +++ b/src/ulcdd/oledlib.h @@ -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 @@ -10,4 +11,11 @@ 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; +}; diff --git a/src/ulcdd/uoled.c b/src/ulcdd/uoled.c index b773999f..63d33a3d 100644 --- a/src/ulcdd/uoled.c +++ b/src/ulcdd/uoled.c @@ -8,9 +8,24 @@ #include #include #include +#include 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; +} diff --git a/src/ulcdd/uoled.h b/src/ulcdd/uoled.h index e69de29b..2eb039ad 100644 --- a/src/ulcdd/uoled.h +++ b/src/ulcdd/uoled.h @@ -0,0 +1,6 @@ +#ifndef _UOLED_H +#define _UOLED_H + +int uoled_init(); +int uoled_send_voltage(struct pwr_act_volts_type *volt); +#endif