forked from techwillsaveus/Gamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProGamer.h
189 lines (158 loc) · 3.4 KB
/
ProGamer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#pragma once
#include "Arduino.h"
#include <avr/interrupt.h>
#include <avr/io.h>
class ProGamer {
private:
#define DEFAULT_REFRESH_RATE 50
#define FLASH_LOOP_TIME 20
#define DARK_TICKS_ON 1
#define DARK_TICKS_OFF 3
#define LIGHT_TICKS_ON 3
#define LIGHT_TICKS_OFF 2
enum RenderMode {
RM_NONE,
RM_SCORE,
RM_STRING,
};
public:
#define UP 0
#define LEFT 1
#define RIGHT 2
#define DOWN 3
#define START 4
//Note: Gamer v1.9 is Capacitive touch instead of LDR.
#define LDR 5
#define CAPTOUCH 6
#define TRACK_SIZE(_TRACK_) (sizeof(_TRACK_) / sizeof(_TRACK_[0]))
enum PixelColour {
CLR4_ZERO = 0b00,
CLR4_DARK = 0b01,
CLR4_LIGHT = 0b10,
CLR4_ONE = 0b11
};
struct Note {
enum Pitch {
E3 = 53,
DSHARP3 = 57,
D3 = 64,
CSHARP3 = 68,
C3 = 78,
B3 = 83,
ASHARP3 = 88,
A3 = 94,
GSHARP2 = 99,
G2 = 115,
FSHARP2 = 122,
F2 = 129,
E2 = 137,
DSHARP2 = 145,
D2 = 169,
CSHARP2 = 179,
C2 = 190,
B2 = 201,
ASHARP2 = 213,
A2 = 226,
GSHARP1 = 240,
G1 = 254
};
byte value;
byte duration;
};
ProGamer();
void irEnd();
void irBegin();
void begin();
void update();
void setFramelength(long value);
long getFramelength();
bool isRenderingSpecial();
int ldrValue();
void setldrThreshold(uint16_t threshold);
void setRefreshRate(uint16_t refreshRate);
// Inputs
bool isPressed(uint8_t input);
bool isHeld(uint8_t input);
// Outputs
void allOn();
void clear();
void setPixel(int x, int y, byte colour);
byte getPixel(int x, int y);
inline void printImage(byte* img) { printImage(img, 0, 0); }
void printImage(byte* img, int x, int y);
void printString(char *string);
void printChar(char chr);
void showScore(int n);
void appendColumn(uint16_t col);
void appendColumn(byte col);
void setLED(bool value);
void toggleLED();
// Music and sound
void playTrack(int trackSize, Note track[], int beatLength, int pitchModifier = 0);
void playSFX(int trackSize, byte track[], int beatLength);
void setSoundOn(bool value);
bool isSoundOn();
void isrRoutine();
private:
// Keywords
#define CLK1 6
#define DAT 8
#define LAT 9
#define CLK2 7
#define DAT 8
#define LAT 9
#define OE 10
#define LED 13
#define BUZZER 2
#define RX 5
#define TX 4
#define DEBOUNCETIME 50
uint16_t _refreshRate;
uint16_t ldrThreshold;
uint16_t image[8];
long frameLength = FLASH_LOOP_TIME;
long tick;
byte pressedInputs = 0;
byte currentInputState = 0;
byte lastInputState = 0;
int lastLDRValue;
bool capTouchFlag;
//byte renderMode = RM_NONE;
void (ProGamer::*renderFunction)() = nullptr;
int renderVar;
int renderVar2;
char *currentString;
Note *currentTrack = nullptr;
int trackIdx;
int trackEndIdx;
int beatLength;
int pitchModifier;
int noteTime;
bool soundOn = true;
byte *currentSFX = nullptr;
byte currentNote;
int sfxTick;
int sfxEndIdx;
int sfxBeatLength;
byte pulseCount;
byte currentRow;
byte counter;
byte colourCounter;
bool colourToBinaryDigit(byte colour);
void renderScore();
void renderString();
void printDigit(int digit, int x);
int charToLetterIndex(char c);
bool capTouch();
void updateAudio();
void playTone(int note);
void stopTone();
void writeToDriver();
void writeToRegister(byte dataOut);
void checkInputs();
void updateRow();
// Numbers and letters for printString
#define LETEND B10101010
const static uint8_t allLetters[85][8];
const static uint8_t allNumbers[10][8];
};