Browse Source

added borg time stuff to source, but config doesnt enable it yet

feature/2015
Hans-Gert Dahmen 13 years ago
parent
commit
2182e45c88
  1. 78
      animations/borg_time.c
  2. 19
      animations/borg_time.h
  3. 31
      can/borg_can.c
  4. 62
      display_loop.c

78
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 <stdio.h>
#include <stdlib.h>
#include <avr/pgmspace.h>
#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);
}

19
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_ */

31
can/borg_can.c

@ -13,7 +13,13 @@
can_addr myaddr; can_addr myaddr;
extern jmp_buf newmode_jmpbuf; 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(); spi_init();
can_init(); can_init();
@ -53,6 +59,15 @@ void process_mgt_msg(pdo_message *msg)
rmsg->dlc = 1; rmsg->dlc = 1;
can_transmit((can_message *)rmsg); can_transmit((can_message *)rmsg);
break; 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 #ifdef Hansi_hat_gelernt_Werte_vorher_zu_definieren
//========== blinkenstuff //========== blinkenstuff
//clear the blinkenbackbuffer to color //clear the blinkenbackbuffer to color
case FKT_BLINK_CLEARBUF: case FKT_BLINK_CLEARBUF:
blink_clearbuf(msg->data[0]); blink_clearbuf(msg->data[0]);
break; break;
//set auto position increment flag //set auto position increment flag
case FKT_BLINK_SETAUTOPOS: case FKT_BLINK_SETAUTOPOS:
blink_setautopos(msg->data[0]); blink_setautopos(msg->data[0]);
break; break;
//set the current blinkenbuffer offset position //set the current blinkenbuffer offset position
case FKT_BLINK_SETPOS: case FKT_BLINK_SETPOS:
blink_setpos(msg->data[0]); blink_setpos(msg->data[0]);
break; break;
//puts the current blinkenbuffer to the frontbuffer //puts the current blinkenbuffer to the frontbuffer
case FKT_BLINK_SHOW: case FKT_BLINK_SHOW:
blink_show(); blink_show();
break; break;
//puts data into the blinkenbuffer //puts data into the blinkenbuffer
case FKT_BLINK_DATA: case FKT_BLINK_DATA:
blink_data(msg->data, msg->dlc - 1); blink_data(msg->data, msg->dlc - 1);
@ -122,10 +137,10 @@ void bcan_process_messages()
if (!msg) if (!msg)
return; 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); 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); process_borg_msg(msg);
msg = (pdo_message*) can_get_nb(); msg = (pdo_message*) can_get_nb();

62
display_loop.c

@ -8,7 +8,7 @@
#include "animations/programm.h" #include "animations/programm.h"
#include "animations/matrix.h" #include "animations/matrix.h"
#include "animations/gameoflife.h" #include "animations/gameoflife.h"
#include "animations/stonefly.h" #include "animations/stonefly.h"
#include "animations/flyingdots.h" #include "animations/flyingdots.h"
#include "animations/breakout_demo.h" #include "animations/breakout_demo.h"
#include "animations/ltn_ant.h" #include "animations/ltn_ant.h"
@ -17,6 +17,7 @@
#include "animations/outofspec.h" #include "animations/outofspec.h"
#include "animations/fpmath_patterns.h" #include "animations/fpmath_patterns.h"
#include "animations/mherweg.h" #include "animations/mherweg.h"
#include "animations/borg_time.h"
#include "borg_hw/borg_hw.h" #include "borg_hw/borg_hw.h"
#include "can/borg_can.h" #include "can/borg_can.h"
#include "random/prng.h" #include "random/prng.h"
@ -72,13 +73,18 @@ void display_loop(){
case 1: case 1:
scrolltext(scrolltext_text); scrolltext(scrolltext_text);
# ifdef RANDOM_SUPPORT #ifdef RANDOM_SUPPORT
{ {
char a[28]; char a[28];
sprintf(a,"</# counter == %lu ", (unsigned long) percnt_get()); sprintf(a,"</# counter == %lu ", (unsigned long) percnt_get());
scrolltext(a); scrolltext(a);
} }
# endif #endif
#endif
#ifdef ANIMATION_TIME
time_anim();
#endif
#ifdef ANIMATION_TIME || ANIMATION_SCROLLTEXT
break; break;
#endif #endif
@ -112,80 +118,92 @@ void display_loop(){
break; break;
#endif #endif
#ifdef ANIMATION_MATRIX #ifdef ANIMATION_TIME
case 7: case 7:
time_anim();
break;
#endif
#ifdef ANIMATION_MATRIX
case 8:
matrix(); matrix();
break; break;
#endif #endif
#ifdef ANIMATION_RANDOM_BRIGHT #ifdef ANIMATION_RANDOM_BRIGHT
case 8: case 9:
random_bright(30); random_bright(30);
break; break;
#endif #endif
#ifdef ANIMATION_STONEFLY #ifdef ANIMATION_STONEFLY
case 9:
stonefly();
break;
#endif
#ifdef ANIMATION_GAMEOFLIFE
case 10: case 10:
stonefly();
break;
#endif
#ifdef ANIMATION_GAMEOFLIFE
case 11:
gameoflife(); gameoflife();
break; break;
#endif #endif
#ifdef ANIMATION_FLYINGDOTS #ifdef ANIMATION_FLYINGDOTS
case 11: case 12:
flyingdots(); flyingdots();
break; break;
#endif #endif
#ifdef ANIMATION_BREAKOUT #ifdef ANIMATION_BREAKOUT
case 12: case 13:
breakout_demo(); breakout_demo();
break; break;
#endif #endif
#ifdef ANIMATION_MHERWEG #ifdef ANIMATION_MHERWEG
case 13: case 14:
mherweg(); mherweg();
break; break;
#endif #endif
#ifdef ANIMATION_TIME
case 15:
time_anim();
break;
#endif
#ifdef ANIMATION_LTN_ANT #ifdef ANIMATION_LTN_ANT
case 14: case 16:
ltn_ant(); ltn_ant();
break; break;
#endif #endif
#ifdef ANIMATION_LABORLOGO #ifdef ANIMATION_LABORLOGO
case 15: case 17:
laborlogo(); laborlogo();
break; break;
#endif #endif
#ifdef ANIMATION_AMPHIBIAN #ifdef ANIMATION_AMPHIBIAN
case 16: case 18:
amphibian(); amphibian();
break; break;
#endif #endif
#ifdef ANIMATION_LOGO_OOS #ifdef ANIMATION_LOGO_OOS
case 17: case 19:
logo_OutOfSpec(); logo_OutOfSpec();
break; break;
#endif #endif
#ifdef ANIMATION_PLASMA #ifdef ANIMATION_PLASMA
case 18: case 20:
plasma(); plasma();
break; break;
#endif #endif
#ifdef ANIMATION_PSYCHEDELIC #ifdef ANIMATION_PSYCHEDELIC
case 19: case 21:
psychedelic(); psychedelic();
break; break;
#endif #endif
@ -233,7 +251,7 @@ void display_loop(){
#endif #endif
#ifdef MENU_SUPPORT #ifdef MENU_SUPPORT
case 42: case 42:
mode = 1; mode = 1;
break; break;

Loading…
Cancel
Save