proton

Firmware for Ghostbusters proton pack
git clone https://git.woozle.org/neale/proton.git

commit
059eda4
parent
c3f635e
author
Neale Pickett
date
2016-09-25 22:43:31 -0600 MDT
Button more responsive, sorta
4 files changed,  +35, -13
M MusicPlayer.cpp
+6, -0
 1@@ -28,6 +28,12 @@ MusicPlayer::startPlayingFile(const char *trackname)
 2   return musicPlayer->startPlayingFile(trackname);
 3 }
 4 
 5+boolean
 6+MusicPlayer::isPlaying()
 7+{
 8+  return musicPlayer->playingMusic;
 9+}
10+
11 void
12 MusicPlayer::stopPlaying()
13 {
M MusicPlayer.h
+1, -0
1@@ -9,6 +9,7 @@ public:
2   MusicPlayer(int8_t cs, int8_t dcs, int8_t dreq, int8_t cardcs);
3   boolean startPlayingFile(const char *trackname);
4   void setVolume(uint8_t left, uint8_t right);
5+  boolean isPlaying();
6   void stopPlaying();
7   void poll(unsigned long jiffies);			// Call this once per loop()
8 };
M ProtonPack.ino
+25, -9
 1@@ -25,7 +25,7 @@ Synchrotron *sync1;
 2 #define DEBUG 13
 3 
 4 // Inputs
 5-#define TRIGGER 9
 6+#define TRIGGER 8
 7 
 8 // global time counter
 9 unsigned long jiffies = 0;
10@@ -63,18 +63,34 @@ void loop() {
11 
12   music->poll(jiffies);
13 
14-  if (state == 0) {
15-    if (new_jiffies > jiffies) {
16-      if (trigger) {
17+  switch (state) {
18+  case 0:
19+    if (trigger) {
20+      if (music->startPlayingFile("track001.mp3")) {
21 	state = 1;
22-	music->startPlayingFile("track001.mp3");
23 	sync1->charge();
24       }
25-
26-      jiffies = new_jiffies;
27-      sync1->tick(jiffies);
28-      flashDebug();
29     }
30+    break;
31+  case 1:
32+    if (! music->isPlaying()) {
33+      if (music->startPlayingFile("track002.mp3")) {
34+	state = 4;
35+	sync1->standby();
36+      }
37+    }
38+    break;
39+  case 4:
40+    if (! music->isPlaying()) {
41+      state = 0;
42+    }
43+    break;
44+  }
45+
46+  if (new_jiffies > jiffies) {
47+    jiffies = new_jiffies;
48+    sync1->tick(jiffies);
49+    flashDebug();
50   }
51 }
52 
M Synchrotron.cpp
+3, -4
 1@@ -37,10 +37,9 @@ Synchrotron::discharge() {
 2 }
 3 
 4 Synchrotron::tick(unsigned long jiffies) {
 5-  float adj = (float)ticks / (float)tickrate;
 6-  byte raa = r * adj;
 7-  byte gaa = g * adj;
 8-  byte baa = b * adj;
 9+  byte raa = r * ticks / tickrate;
10+  byte gaa = g * ticks / tickrate;
11+  byte baa = b * ticks / tickrate;
12   byte ra = r - raa;
13   byte ga = g - gaa;
14   byte ba = b - baa;