summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Hodder <dave.hodder@focusrite.com>2017-11-20 13:54:16 +0000
committerDave Hodder <dave.hodder@focusrite.com>2017-11-20 13:54:16 +0000
commitd910a607b308c5ed02e476a5051fac184f61c86f (patch)
treeda05174d3c8c6846359e4d16f0cee06bb4703aba /src
parentaf0c758cceb310b69c9192d7cdc8133ba63a3f98 (diff)
parent7ff741e4206b75e941aa982360402bc8f8e58198 (diff)
downloadlaunchpad-polymaker-d910a607b308c5ed02e476a5051fac184f61c86f.tar.gz
launchpad-polymaker-d910a607b308c5ed02e476a5051fac184f61c86f.zip
Merge branch 'raw-adc' (bringing in ADC and flash access)
Diffstat (limited to 'src')
-rw-r--r--src/app.c153
1 files changed, 90 insertions, 63 deletions
diff --git a/src/app.c b/src/app.c
index f0edec8..5b83182 100644
--- a/src/app.c
+++ b/src/app.c
@@ -41,51 +41,57 @@
41// 41//
42// This is where the fun is! Add your code to the callbacks below to define how 42// This is where the fun is! Add your code to the callbacks below to define how
43// your app behaves. 43// your app behaves.
44//
45// In this example, we render the raw ADC data as LED rainbows.
46//______________________________________________________________________________
47
48static const u16 *g_ADC = 0;
49
44//______________________________________________________________________________ 50//______________________________________________________________________________
45 51
46void app_surface_event(u8 type, u8 index, u8 value) 52void app_surface_event(u8 type, u8 index, u8 value)
47{ 53{
48 switch (type) 54 switch (type)
49 { 55 {
50 case TYPEPAD: 56 case TYPEPAD:
51 { 57 {
52 // example - light / extinguish pad LEDs, send MIDI 58 // example - light / extinguish pad LEDs, send MIDI
53 hal_plot_led(TYPEPAD, index, value, value, value); 59 hal_plot_led(TYPEPAD, index, value, value, value);
54 hal_send_midi(DINMIDI, NOTEON | 0, index, value); 60 hal_send_midi(DINMIDI, NOTEON | 0, index, value);
55 } 61 }
56 break; 62 break;
57 63
58 case TYPESETUP: 64 case TYPESETUP:
59 { 65 {
60 // example - light the setup LED 66 // example - light the setup LED
61 hal_plot_led(TYPESETUP, 0, value, value, value); 67 hal_plot_led(TYPESETUP, 0, value, value, value);
62 } 68 }
63 break; 69 break;
64 } 70 }
65} 71}
66 72
67//______________________________________________________________________________ 73//______________________________________________________________________________
68 74
69void app_midi_event(u8 port, u8 status, u8 d1, u8 d2) 75void app_midi_event(u8 port, u8 status, u8 d1, u8 d2)
70{ 76{
71 // example - MIDI interface functionality for USB "MIDI" port -> DIN port 77 // example - MIDI interface functionality for USB "MIDI" port -> DIN port
72 if (port == USBMIDI) 78 if (port == USBMIDI)
73 { 79 {
74 hal_send_midi(DINMIDI, status, d1, d2); 80 hal_send_midi(DINMIDI, status, d1, d2);
75 } 81 }
76 82
77 // // example -MIDI interface functionality for DIN -> USB "MIDI" port port 83 // // example -MIDI interface functionality for DIN -> USB "MIDI" port port
78 if (port == DINMIDI) 84 if (port == DINMIDI)
79 { 85 {
80 hal_send_midi(USBMIDI, status, d1, d2); 86 hal_send_midi(USBMIDI, status, d1, d2);
81 } 87 }
82} 88}
83 89
84//______________________________________________________________________________ 90//______________________________________________________________________________
85 91
86void app_sysex_event(u8 port, u8 * data, u16 count) 92void app_sysex_event(u8 port, u8 * data, u16 count)
87{ 93{
88 // example - respond to UDI messages? 94 // example - respond to UDI messages?
89} 95}
90 96
91//______________________________________________________________________________ 97//______________________________________________________________________________
@@ -93,60 +99,81 @@ void app_sysex_event(u8 port, u8 * data, u16 count)
93void app_aftertouch_event(u8 index, u8 value) 99void app_aftertouch_event(u8 index, u8 value)
94{ 100{
95 // example - send poly aftertouch to MIDI ports 101 // example - send poly aftertouch to MIDI ports
96 hal_send_midi(USBMIDI, POLYAFTERTOUCH | 0, index, value); 102 hal_send_midi(USBMIDI, POLYAFTERTOUCH | 0, index, value);
97 103
98 // example - set LED to white, brightness in proportion to pressure 104 // example - set LED to white, brightness in proportion to pressure
99 hal_plot_led(TYPEPAD, index, value/2, value/2, value/2); 105 hal_plot_led(TYPEPAD, index, value/2, value/2, value/2);
100} 106}
101 107
102//______________________________________________________________________________ 108//______________________________________________________________________________
103 109
104void app_cable_event(u8 type, u8 value) 110void app_cable_event(u8 type, u8 value)
105{ 111{
106 // example - light the Setup LED to indicate cable connections 112 // example - light the Setup LED to indicate cable connections
107 if (type == MIDI_IN_CABLE) 113 if (type == MIDI_IN_CABLE)
108 { 114 {
109 hal_plot_led(TYPESETUP, 0, 0, value, 0); // green 115 hal_plot_led(TYPESETUP, 0, 0, value, 0); // green
110 } 116 }
111 else if (type == MIDI_OUT_CABLE) 117 else if (type == MIDI_OUT_CABLE)
112 { 118 {
113 hal_plot_led(TYPESETUP, 0, value, 0, 0); // red 119 hal_plot_led(TYPESETUP, 0, value, 0, 0); // red
114 } 120 }
115} 121}
116 122
117//______________________________________________________________________________ 123//______________________________________________________________________________
118 124
119
120void app_timer_event() 125void app_timer_event()
121{ 126{
122 // example - send MIDI clock at 125bpm 127 // example - send MIDI clock at 125bpm
123#define TICK_MS 20 128#define TICK_MS 20
124 129
125 static u8 ms = TICK_MS; 130 static u8 ms = TICK_MS;
126 131
127 if (++ms >= TICK_MS) 132 if (++ms >= TICK_MS)
133 {
134 ms = 0;
135
136 // send a clock pulse up the USB
137 hal_send_midi(USBSTANDALONE, MIDITIMINGCLOCK, 0, 0);
138 }
139
140/*
141 // alternative example - show raw ADC data as LEDs
142 for (int i=0; i < PAD_COUNT; ++i)
128 { 143 {
129 ms = 0; 144 // raw adc values are 12 bit, but LEDs are 6 bit.
145 // Let's saturate into r;g;b for a rainbow effect to show pressure
146 u16 r = 0;
147 u16 g = 0;
148 u16 b = 0;
149
150 u16 x = (3 * MAXLED * g_ADC[i]) >> 12;
151
152 if (x < MAXLED)
153 {
154 r = x;
155 }
156 else if (x >= MAXLED && x < (2*MAXLED))
157 {
158 r = MAXLED - x;
159 g = x - MAXLED;
160 }
161 else
162 {
163 g = MAXLED - x;
164 b = x - MAXLED;
165 }
130 166
131 // send a clock pulse up the USB 167 hal_plot_led(TYPEPAD, ADC_MAP[i], r, g, b);
132 hal_send_midi(USBSTANDALONE, MIDITIMINGCLOCK, 0, 0);
133 } 168 }
169 */
134} 170}
135 171
136//______________________________________________________________________________ 172//______________________________________________________________________________
137 173
138void app_init() 174void app_init(const u16 *adc_raw)
139{ 175{
140 // example - light the LEDs to say hello! 176
141 for (int i=0; i < 10; ++i) 177 // store off the raw ADC frame pointer for later use
142 { 178 g_ADC = adc_raw;
143 for (int j=0; j < 10; ++j)
144 {
145 u8 r = i < 5 ? (MAXLED * (5-i))/5 : 0;
146 u8 g = i < 5 ? (MAXLED * i)/5 : (MAXLED * (10-i))/5;
147 u8 b = i < 5 ? 0 : (MAXLED * (i-5))/5;
148
149 hal_plot_led(TYPEPAD, j*10 + i, r, b, g);
150 }
151 }
152} 179}