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

This commit is contained in:
Hans-Gert Dahmen 2011-10-28 18:53:38 +00:00
parent 31e21e170f
commit 2182e45c88
4 changed files with 160 additions and 30 deletions

78
animations/borg_time.c Normal file
View File

@ -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 Normal file
View File

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

View File

@ -13,6 +13,12 @@
can_addr myaddr;
extern jmp_buf newmode_jmpbuf;
#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();
@ -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
}
}

View File

@ -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"
@ -79,6 +80,11 @@ void display_loop(){
scrolltext(a);
}
#endif
#endif
#ifdef ANIMATION_TIME
time_anim();
#endif
#ifdef ANIMATION_TIME || ANIMATION_SCROLLTEXT
break;
#endif
@ -112,80 +118,92 @@ void display_loop(){
break;
#endif
#ifdef ANIMATION_MATRIX
#ifdef ANIMATION_TIME
case 7:
time_anim();
break;
#endif
#ifdef ANIMATION_MATRIX
case 8:
matrix();
break;
#endif
#ifdef ANIMATION_RANDOM_BRIGHT
case 8:
case 9:
random_bright(30);
break;
#endif
#ifdef ANIMATION_STONEFLY
case 9:
case 10:
stonefly();
break;
#endif
#ifdef ANIMATION_GAMEOFLIFE
case 10:
case 11:
gameoflife();
break;
#endif
#ifdef ANIMATION_FLYINGDOTS
case 11:
case 12:
flyingdots();
break;
#endif
#ifdef ANIMATION_BREAKOUT
case 12:
case 13:
breakout_demo();
break;
#endif
#ifdef ANIMATION_MHERWEG
case 13:
case 14:
mherweg();
break;
#endif
#ifdef ANIMATION_TIME
case 15:
time_anim();
break;
#endif
#ifdef ANIMATION_LTN_ANT
case 14:
case 16:
ltn_ant();
break;
#endif
#ifdef ANIMATION_LABORLOGO
case 15:
case 17:
laborlogo();
break;
#endif
#ifdef ANIMATION_AMPHIBIAN
case 16:
case 18:
amphibian();
break;
#endif
#ifdef ANIMATION_LOGO_OOS
case 17:
case 19:
logo_OutOfSpec();
break;
#endif
#ifdef ANIMATION_PLASMA
case 18:
case 20:
plasma();
break;
#endif
#ifdef ANIMATION_PSYCHEDELIC
case 19:
case 21:
psychedelic();
break;
#endif