-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.h
151 lines (121 loc) · 3.12 KB
/
main.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
#ifndef _main_H_
#define _main_H_
//#define BREADBOARD
//#define TRAY_CALIBRATION
#include "Arduino.h"
// debug mode
#define DEBUG false
// display
#define SPI_UART1_DATA 11
#define SPI_UART1_CLOCK 12
#define NUM_LEDS 200
#define LEDS_PER_ROW 10
#define LED_TYPE SK9822
#define COLOR_ORDER BGR
#define LED_FPS 60
#define BRIGHTNESS 30
#include <FastLED.h>
// audio
#include "pmf_player.h"
#include "pmf_data.h"
// audio data
#include "audio_data.h"
// vibration data
#include "vibra_data.h"
// vibra-motor support
#include <Adafruit_DRV2605.h>
// tray control
#include "tray.h"
// non-volatile memory
#include <EEPROM.h>
// button and sensor debouncing
#include <Bounce2.h>
// catris
#include "catris.h"
// game engine
#include "tetris.h"
// random seed
#include "entropy.h"
// pin configuration
#define LBO 10
#define LED_LB 18
#define LED_SDI 11
#define LED_SCK 12
#ifdef BREADBOARD
#define BTN_PAUSE 27
#define BTN_SOUND 28
#define BTN_MUSIC 29
#define BTN_RESET 30
#define BTN_ROTATE_LEFT 31
#define BTN_ROTATE_RIGHT 20
#define BTN_LEFT 23
#define BTN_RIGHT 22
#define BTN_DOWN 21
#define BTN_HIGH_SCORE 19
#else
#define BTN_PAUSE 31
#define BTN_SOUND 19
#define BTN_MUSIC 20
#define BTN_RESET 28
#define BTN_ROTATE_LEFT 29
#define BTN_ROTATE_RIGHT 21
#define BTN_LEFT 30
#define BTN_RIGHT 22
#define BTN_DOWN 23
#define BTN_HIGH_SCORE 27
#endif
#define PI_CLSD 13
#define PI_OPEN 14
#define M_ENABLE 24
#define M_CTRL_1 25
#define M_CTRL_2 26
// button repeat
#define REPEAT_DELAY 400
#define REPEAT_INTERVAL 50
// memory address mapping
#define EE_ADDR_MUSIC 0
#define EE_ADDR_SOUND (EE_ADDR_MUSIC + sizeof(byte))
#define EE_ADDR_SURPRISE (EE_ADDR_SOUND + sizeof(bool))
#define EE_ADDR_HIGH_SCORE (EE_ADDR_SURPRISE + sizeof(bool))
// states
#define STATE_CATRIS_LOOP 0
#define STATE_CATRIS_ONCE 1
#define STATE_TETRIS 2
// score triggers
#define SCORES_SURPRISE_TEASER 1500
#define SCORES_SURPRISE_REVEAL 3000
// low battery detection
#define LOW_BAT_DETECTION_LIMIT 30
#define MILLIS_BATTERY_CHECK_INTERVAL 1000
// secret functions timing
#define MILLIS_SURPRISE_STATE 5000
#define MILLIS_SURPRISE_TOGGLE 10000
#define MILLIS_TRAY_TOGGLE 15000
// clear high score timing
#define MILLIS_CLEAR_HIGH_SCORE 5000
// tray
#define TRAY_CLOSING_DELAY 120
#define TRAY_OPENING_DELAY 80
// macros
#define canvasWidth() LEDS_PER_ROW
#define canvasHeight() (NUM_LEDS / LEDS_PER_ROW)
#define clrscr() clearCanvas(&setCanvas, 0, 0, canvasWidth(), canvasHeight())
// functions
void playMusic();
void playBeepUpSound();
void playBeepDownSound();
void playSuccessSound();
void playVibra(const uint8_t* pattern);
void tetrisEvent(TetrisEvent event, uint8_t data);
bool buttonRepeat(bool reset);
void showPauseSign();
void resetTetris();
bool isTetris();
void showTetris();
bool isCatris();
void showCatris(bool loop);
void setCanvas(int8_t x, int8_t y, uint8_t r, uint8_t g, uint8_t b);
uint8_t progMemRead(uint8_t* addr);
uint8_t directMemRead(uint8_t* addr);
const char* randomText(uint8_t count, ...);
#endif