forked from kveilands/BlueSaab
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtons.cpp
More file actions
120 lines (113 loc) · 3.33 KB
/
Copy pathButtons.cpp
File metadata and controls
120 lines (113 loc) · 3.33 KB
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
/* C++ class for SAAB infotainment head unit and steering wheel button event handling
* Copyright (C) 2018 Girts Linde
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Buttons.h"
#include "Bluetooth.h"
#include "SidResource.h"
Buttons buttons;
Buttons::Buttons() {
}
void Buttons::initialize() {
saabCan.attach(CDC_CONTROL, callback(this, &Buttons::onFrame));
}
Buttons::Button decode(unsigned char data1, unsigned char data2) {
switch (data1) {
case 0x59: // NXT
return Buttons::NXT;
case 0x45: // SEEK+ button long press on IHU
return Buttons::SEEK_PLUS_LONG;
case 0x46: // SEEK- button long press on IHU
return Buttons::SEEK_MINUS_LONG;
case 0x84: // SEEK button (middle) long press on IHU
return Buttons::SEEK_MIDDLE_LONG;
case 0x88: // > 2 second long press of SEEK button (middle) on IHU
return Buttons::SEEK_MIDDLE_EXTRA_LONG;
case 0x76: // Random ON/OFF (Long press of CD/RDM button)
return Buttons::RANDOM;
case 0xB1: // Pause ON
return Buttons::PAUSE_ON;
case 0xB0: // Pause OFF
return Buttons::PAUSE_OFF;
case 0x35: // Track +
return Buttons::TRACK_PLUS;
case 0x36: // Track -
return Buttons::TRACK_MINUS;
case 0x68: // IHU buttons "1-6"
switch (data2) {
case 0x01:
return Buttons::IHU1;
case 0x02:
return Buttons::IHU2;
case 0x03:
return Buttons::IHU3;
case 0x04:
return Buttons::IHU4;
case 0x05:
return Buttons::IHU5;
case 0x06:
return Buttons::IHU6;
}
}
return Buttons::NONE;
}
void Buttons::onFrame(CANMessage& frame) {
if (frame.data[0] != 0x80)
return;
Buttons::Button button = decode(frame.data[1], frame.data[2]);
if (button != Buttons::NONE) {
#if SID_TEXT_CONTROL_ENABLED
// Driver breakthrough only for actual (recognized) button presses -
// not for every 0x80-flagged frame (mode changes, pause, unmapped
// codes), which needlessly escalated our display requests.
sidResource.requestDriverBreakthrough();
#endif
// getLog()->log("Buttons::onFrame button %d", button);
switch (button) {
case Buttons::NXT:
bluetooth.play();
break;
case Buttons::TRACK_PLUS:
bluetooth.next();
break;
case Buttons::TRACK_MINUS:
bluetooth.prev();
break;
case Buttons::IHU1:
case Buttons::SEEK_MIDDLE_EXTRA_LONG: // wheel-only pairing, pre-v6 muscle memory
bluetooth.discoverable();
#if SID_TEXT_CONTROL_ENABLED
sidResource.showTemporary("PAIRING", 10); // ~10 s, like STP,10 (actual discoverable window undocumented)
#endif
break;
case Buttons::IHU3:
bluetooth.reconnect();
break;
case Buttons::IHU4:
bluetooth.volumeDown();
break;
case Buttons::IHU5:
bluetooth.volumeUp();
break;
case Buttons::IHU6:
bluetooth.disconnect();
break;
default:
break;
}
} else {
// getLog()->log("Buttons::onFrame button unknown");
}
}