From 2182e45c88482ce02027d6021d414a956efcae35 Mon Sep 17 00:00:00 2001 From: Hans-Gert Dahmen Date: Fri, 28 Oct 2011 18:53:38 +0000 Subject: [PATCH] added borg time stuff to source, but config doesnt enable it yet --- animations/borg_time.c | 78 ++++++++++++++++++++++++++++++++++++++++++ animations/borg_time.h | 19 ++++++++++ can/borg_can.c | 31 ++++++++++++----- display_loop.c | 62 +++++++++++++++++++++------------ 4 files changed, 160 insertions(+), 30 deletions(-) create mode 100644 animations/borg_time.c create mode 100644 animations/borg_time.h diff --git a/animations/borg_time.c b/animations/borg_time.c new file mode 100644 index 0000000..56726a3 --- /dev/null +++ b/animations/borg_time.c @@ -0,0 +1,78 @@ +/* + * Description: Request time strings from a can-master + * and show them in an animation + * Author: hansi + */ + +#include +#include +#include +#include "../config.h" +#include "../can.h" +#include "../lap.h" +#include "../util.h" +#include "../scrolltext.h" + +//address of the time master +#define TIME_MASTER_ADDR 0x00 + +//update timeout in ms +#define TIME_UPDATE_TIMEOUT 100 + +//hackhack +extern can_addr myaddr; + +//send a time request packet via can +void time_request(void) +{ + pdo_message msg; + + //source address + msg.addr_src = myaddr; + msg.port_src = PORT_MGT; + + //destination address + msg.addr_dst = TIME_MASTER_ADDR; + msg.port_dst = PORT_MGT; + + //time request command + msg.cmd = FKT_MGT_TIMEREQUEST; + + //set length and transmit + msg.dlc = 1; + can_transmit((can_message *)&msg); +} + +//update time via can, possibly blocking +uint8_t time_update(void) +{ + uint8_t timeout = TIME_UPDATE_TIMEOUT; + + //set "time-has-been-updated" to false + lap_time_update = 0; + + //send request + time_request(); + + //wait some time for a reply in 1ms steps + while((lap_time_update == 0) && (timeout-- > 0)) + wait(1); + + return lap_time_update; +} + +//display the time +void time_anim(void) +{ + char timestring[48]; + + //update time and return if we had no success + if(time_update() == 0) + return; + + //convert the time to a string + sprintf_P(timestring, PSTR(">+:p42d50/#%02hi#<;+p42d50/# %02hi#x49y8b255p42d50#:"), lap_time_h, lap_time_m); + + //show the time + scrolltext(timestring); +} diff --git a/animations/borg_time.h b/animations/borg_time.h new file mode 100644 index 0000000..d71c032 --- /dev/null +++ b/animations/borg_time.h @@ -0,0 +1,19 @@ +/* + * Description: Request time strings from a can-master + * and show them in an animation + * Author: hansi + */ + +#ifndef BORG_TIME_H_ +#define BORG_TIME_H_ + +//send a time request packet via can +void time_request(void); + +//update time via can, possibly blocking +uint8_t time_update(void); + +//display the time +void time_anim(void); + +#endif /* BORG_TIME_H_ */ diff --git a/can/borg_can.c b/can/borg_can.c index b407b40..c547d03 100644 --- a/can/borg_can.c +++ b/can/borg_can.c @@ -13,7 +13,13 @@ can_addr myaddr; extern jmp_buf newmode_jmpbuf; -void bcan_init() +#ifdef LAP_TIME_EXTENSION +//variables to save the last received hours and minutes +//(accessible via lap.h) +uint8_t lap_time_h, lap_time_m, lap_time_update = 0; +#endif + +void bcan_init() { spi_init(); can_init(); @@ -53,6 +59,15 @@ void process_mgt_msg(pdo_message *msg) rmsg->dlc = 1; can_transmit((can_message *)rmsg); break; + + #ifdef LAP_TIME_EXTENSION + //if we get a time reply, save it + case FKT_MGT_TIMEREPLY: + lap_time_h = msg->data[0]; + lap_time_m = msg->data[1]; + lap_time_update = 1; + break; + #endif } } @@ -85,27 +100,27 @@ void process_borg_msg(pdo_message *msg) #ifdef Hansi_hat_gelernt_Werte_vorher_zu_definieren //========== blinkenstuff - + //clear the blinkenbackbuffer to color case FKT_BLINK_CLEARBUF: blink_clearbuf(msg->data[0]); break; - + //set auto position increment flag case FKT_BLINK_SETAUTOPOS: blink_setautopos(msg->data[0]); break; - + //set the current blinkenbuffer offset position case FKT_BLINK_SETPOS: blink_setpos(msg->data[0]); break; - + //puts the current blinkenbuffer to the frontbuffer case FKT_BLINK_SHOW: blink_show(); break; - + //puts data into the blinkenbuffer case FKT_BLINK_DATA: blink_data(msg->data, msg->dlc - 1); @@ -122,10 +137,10 @@ void bcan_process_messages() if (!msg) return; - if(msg->addr_dst == myaddr && msg->port_dst == PORT_MGT) + if(msg->addr_dst == myaddr && msg->port_dst == PORT_MGT) process_mgt_msg(msg); - if(msg->addr_dst == myaddr && msg->port_dst == PORT_BORG) + if(msg->addr_dst == myaddr && msg->port_dst == PORT_BORG) process_borg_msg(msg); msg = (pdo_message*) can_get_nb(); diff --git a/display_loop.c b/display_loop.c index 32b4368..bd4a509 100644 --- a/display_loop.c +++ b/display_loop.c @@ -8,7 +8,7 @@ #include "animations/programm.h" #include "animations/matrix.h" #include "animations/gameoflife.h" -#include "animations/stonefly.h" +#include "animations/stonefly.h" #include "animations/flyingdots.h" #include "animations/breakout_demo.h" #include "animations/ltn_ant.h" @@ -17,6 +17,7 @@ #include "animations/outofspec.h" #include "animations/fpmath_patterns.h" #include "animations/mherweg.h" +#include "animations/borg_time.h" #include "borg_hw/borg_hw.h" #include "can/borg_can.h" #include "random/prng.h" @@ -72,13 +73,18 @@ void display_loop(){ case 1: scrolltext(scrolltext_text); -# ifdef RANDOM_SUPPORT + #ifdef RANDOM_SUPPORT { char a[28]; sprintf(a,"