aboutsummaryrefslogtreecommitdiff
path: root/laser-tag software
diff options
context:
space:
mode:
authorDavid Barksdale <amatus@amatus.name>2016-01-06 21:26:25 -0600
committerDavid Barksdale <amatus@amatus.name>2016-01-06 21:26:39 -0600
commitc12d27033f2191f48c391c9caedd21c461af62df (patch)
tree2c89f183b15872ebf7d3e96a829ecceafd609e08 /laser-tag software
parente9374a99727e08b75af5f4d3da9c007b6503b5de (diff)
Laser tag demo code
You can select what data to send the other badge using the up/down/left/right keys. Then use the trigger to fire the laser! Up: Light LED red Left: Light LED green Right: Light LED blue Down: Start playing music (press any key to stop)
Diffstat (limited to 'laser-tag software')
-rwxr-xr-xlaser-tag software/main.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/laser-tag software/main.c b/laser-tag software/main.c
index a5ac1ba..53a381e 100755
--- a/laser-tag software/main.c
+++ b/laser-tag software/main.c
@@ -243,6 +243,7 @@ static dma_channel_t g_dacChan, g_fioChan;
static lpuart_state_t g_lpuartState;
static uint8_t rxBuff[1];
static uint32_t shift0_buf[3];
+static uint32_t blank_led;
static void led(uint8_t red, uint8_t green, uint8_t blue)
{
@@ -279,6 +280,13 @@ static void lptmr_call_back(void)
CMP_DRV_ConfigDacChn(0, &g_cmpDacConf);
}
}
+ // countdown to turn off LED
+ if (blank_led) {
+ if (blank_led == 1) {
+ led(0, 0, 0);
+ }
+ blank_led--;
+ }
}
/* Play music using the PIT timer */
@@ -335,7 +343,7 @@ void PIT_IRQHandler(void)
}
}
-uint8_t g_txBuff[] = { '$' };
+uint8_t g_txBuff[] = { 'R' };
void PORTA_IRQHandler(void)
{
@@ -355,6 +363,19 @@ void PORTA_IRQHandler(void)
} else {
LPUART_DRV_SendData(1, g_txBuff, 1);
}
+
+ if (!GPIO_DRV_ReadPinInput(g_switchUp.pinName)) {
+ g_txBuff[0] = 'R';
+ }
+ if (!GPIO_DRV_ReadPinInput(g_switchLeft.pinName)) {
+ g_txBuff[0] = 'G';
+ }
+ if (!GPIO_DRV_ReadPinInput(g_switchRight.pinName)) {
+ g_txBuff[0] = 'B';
+ }
+ if (!GPIO_DRV_ReadPinInput(g_switchDown.pinName)) {
+ g_txBuff[0] = '!';
+ }
}
static void lpuartTxCallback(uint32_t instance, void *lpuartState)
@@ -371,10 +392,27 @@ static void lpuartRxCallback(uint32_t instance, void *lpuartState)
bool parity_error = stat & LPUART_STAT_PF_MASK;
LPUART_WR_STAT(base, (stat & 0x3e000000) |
LPUART_STAT_NF_MASK | LPUART_STAT_FE_MASK | LPUART_STAT_PF_MASK);
- if (rxBuff[0] == '$') {
+ if (rxBuff[0] == 'R') {
+ led(0xff, 0x00, 0x00);
+ blank_led = 30;
+ return;
+ }
+ if (rxBuff[0] == 'G') {
led(0x00, 0xff, 0x00);
+ blank_led = 30;
return;
}
+ if (rxBuff[0] == 'B') {
+ led(0x00, 0x00, 0xff);
+ blank_led = 30;
+ return;
+ }
+ if (rxBuff[0] == '!') {
+ position = 0;
+ PIT_DRV_StartTimer(0, 0);
+ return;
+ }
+ return;
if (noise) {
led(0xff, 0xff, 0x00);
return;
@@ -480,6 +518,9 @@ int main (void)
TPM_DRV_Init(0, &tmpConfig);
TPM_DRV_SetClock(0, kTpmClockSourceModuleMCGIRCLK, kTpmDividedBy1);
+ /* Blank LED just in case, saves power */
+ led(0x00, 0x00, 0x00);
+
/* We're done, everything else is triggered through interrupts */
for(;;) {
#ifndef DEBUG