-
Notifications
You must be signed in to change notification settings - Fork 0
/
RadioProject.ino
115 lines (93 loc) · 3.19 KB
/
RadioProject.ino
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
/*
To upload code when the serial port is busy and the port is flip-flopping between being available and not:
1. Connect the board via the USB cable (no need to disconnect and reconnect)
2. Press and hold the BOOT button (white, left of the USB port),
3. While still pressing the BOOT button, press RST (side, black button)
4. Release the RST
5. Release the BOOT button - this boots the board into an idle state, but you can't upload, so...
6. Press and release the BOOT button again
7. Upload your sketch
Also bought a cable directly from Arduino
Also installed new drivers on my Mac per the instructions here https://mim-armand.medium.com/esp32-upload-problem-on-mac-os-ae5318358ad6 and used
/dev/cu/wchusbserial56570278231 as my port instead of the non-"wch" port
Reference: https://github.com/Xinyuan-LilyGO/T-Display-S3/issues/111
Upload speed seems to have to be 115200 or slower
*/
#include "MomentaryButton.h"
#include "Logger.h"
#include "Receiver.h"
#include "FMRadio.h"
#include "BluetoothReceiver.h"
#include "Screen.h"
#include "AlbumImage.h"
#include <RotaryEncoder.h>
Receiver* receiver;
FMRadio fmRadio;
BluetoothReceiver bluetoothReceiver;
Print* logger = &Serial;
Screen screen = Screen();
RotaryEncoder encoder(2, 15, RotaryEncoder::LatchMode::TWO03);
int albumDelay = 1000; //1 second
long int albumGoTime;
int buttonDelay = 100;
long int buttonGoTime;
int scrollDelay = 10;
long int scrollTime;
void avrc_metadata_callback(uint8_t attributeId, const uint8_t* buffer) {
logger->printf("AVRC metadata rsp: attribute id 0x%x, %s\n", attributeId, buffer);
String str = (char*)buffer;
if(attributeId == ESP_AVRC_MD_ATTR_TITLE) {
screen.setTitle((String)str);
}
if(attributeId == ESP_AVRC_MD_ATTR_ARTIST) {
screen.setArtist((String)str);
}
}
void setup() {
Serial.begin(9600); // initialize serial communication at 9600 bits per second:
albumGoTime = millis();
buttonGoTime = millis();
MomentaryButton button1(16, &callTheCallback, logger);
MomentaryButton button2(16, &callTheCallback, logger);
MomentaryButton button3(16, &callTheCallback, logger);
screen.begin();
fmRadio = FMRadio(button1, button2, button3, logger);
bluetoothReceiver = BluetoothReceiver(button1, button2, button3, logger, avrc_metadata_callback);
receiver = &bluetoothReceiver;
}
void loop() {
if(millis() >= albumGoTime) {
screen.drawJpeg(AlbumImage, sizeof(AlbumImage), 0, 0);
albumGoTime = millis() + albumDelay;
}
if(millis() >= buttonGoTime) {
receiver->checkButtons();
buttonGoTime = millis() + buttonDelay;
}
if(millis() >= scrollTime) {
screen.scrollTitle();
screen.scrollArtist();
scrollTime = millis() + scrollDelay;
}
static int pos = 0;
encoder.tick();
int newPos = encoder.getPosition();
if (pos != newPos) {
logger->print("pos:");
logger->print(newPos);
logger->print(" dir:");
int newDir = (int)(encoder.getDirection());
logger->println(newDir);
if(newDir > 0) {
logger->println("Up");
receiver->volumeUp(newPos - pos);
} else {
logger->println("Down");
receiver->volumeDown(pos - newPos);
}
pos = newPos;
}
}
void callTheCallback() {
logger->println("Button called back!");
}