summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Hodder <dave.hodder@focusrite.com>2017-01-09 14:01:28 +0000
committerDave Hodder <dave.hodder@focusrite.com>2017-01-09 14:01:28 +0000
commit1fd765c53d36e6f4581e405263f8aa598ea98d8c (patch)
tree5dbdb37a4a19ab08fe64ac9ca8e52bc7e83b1449
parent167a7dc6a753b5ba11c8c2ae2a365cec8656c171 (diff)
downloadlaunchpad-polymaker-1fd765c53d36e6f4581e405263f8aa598ea98d8c.tar.gz
launchpad-polymaker-1fd765c53d36e6f4581e405263f8aa598ea98d8c.zip
experimenting with raw ADC api, moving 1kHz timer to main timer cb
-rw-r--r--include/app.h2
-rw-r--r--src/app.c79
2 files changed, 55 insertions, 26 deletions
diff --git a/include/app.h b/include/app.h
index c26c131..83ef48a 100644
--- a/include/app.h
+++ b/include/app.h
@@ -134,7 +134,7 @@ void hal_write_flash(u32 offset,const u8 *data, u32 length);
134/** 134/**
135 * Called on startup, this is a good place to do any initialisation. 135 * Called on startup, this is a good place to do any initialisation.
136 */ 136 */
137void app_init(); 137void app_init(const u16 *adc_buffer);
138 138
139/** 139/**
140 * 1kHz (1ms) timer. You can set LEDs and send MIDI out from this function, 140 * 1kHz (1ms) timer. You can set LEDs and send MIDI out from this function,
diff --git a/src/app.c b/src/app.c
index e250cd3..d4547dc 100644
--- a/src/app.c
+++ b/src/app.c
@@ -47,8 +47,11 @@
47//______________________________________________________________________________ 47//______________________________________________________________________________
48 48
49#define BUTTON_COUNT 100 49#define BUTTON_COUNT 100
50#define PAD_COUNT 64
50 51
51u8 g_Buttons[BUTTON_COUNT] = {0}; 52static u8 g_Buttons[BUTTON_COUNT] = {0};
53
54static const u16 *g_ADC = 0;
52 55
53//______________________________________________________________________________ 56//______________________________________________________________________________
54 57
@@ -58,17 +61,8 @@ void app_surface_event(u8 type, u8 index, u8 value)
58 { 61 {
59 case TYPEPAD: 62 case TYPEPAD:
60 { 63 {
61 // toggle it and store it off, so we can save to flash if we want to 64 return;
62 if (value)
63 {
64 g_Buttons[index] = MAXLED * !g_Buttons[index];
65 }
66 65
67 // example - light / extinguish pad LEDs
68 hal_plot_led(TYPEPAD, index, 0, 0, g_Buttons[index]);
69
70 // example - send MIDI
71 hal_send_midi(DINMIDI, NOTEON | 0, index, value);
72 66
73 } 67 }
74 break; 68 break;
@@ -113,6 +107,8 @@ void app_sysex_event(u8 port, u8 * data, u16 count)
113 107
114void app_aftertouch_event(u8 index, u8 value) 108void app_aftertouch_event(u8 index, u8 value)
115{ 109{
110 return;
111
116 // example - send poly aftertouch to MIDI ports 112 // example - send poly aftertouch to MIDI ports
117 hal_send_midi(USBMIDI, POLYAFTERTOUCH | 0, index, value); 113 hal_send_midi(USBMIDI, POLYAFTERTOUCH | 0, index, value);
118 114
@@ -137,6 +133,18 @@ void app_cable_event(u8 type, u8 value)
137 133
138//______________________________________________________________________________ 134//______________________________________________________________________________
139 135
136static const u8 ADC_MAP[] =
137{
138 11, 51, 12, 52, 13, 53, 14, 54,
139 15, 55, 16, 56, 17 ,57, 18, 58,
140 21, 61, 22, 62, 23, 63, 24, 64,
141 25, 65, 26, 66, 27, 67, 28, 68,
142 31, 71, 32, 72, 33, 73, 34, 74,
143 35, 75, 36, 76, 37, 77, 38, 78,
144 41, 81, 42, 82, 43, 83, 44, 84,
145 45, 85, 46, 86, 47, 87, 48, 88,
146};
147
140 148
141void app_timer_event() 149void app_timer_event()
142{ 150{
@@ -150,25 +158,46 @@ void app_timer_event()
150 ms = 0; 158 ms = 0;
151 159
152 // send a clock pulse up the USB 160 // send a clock pulse up the USB
153 hal_send_midi(USBSTANDALONE, MIDITIMINGCLOCK, 0, 0); 161 hal_send_midi(USBMIDI, MIDITIMINGCLOCK, 0, 0);
162 }
163
164 // example: render raw ADC data as LEDs
165 for (int i=0; i < PAD_COUNT; ++i)
166 {
167 // raw adc values are 12 bit, but LEDs are 6 bit.
168 // so saturate into r;g;b for a rainbow effect to show pressure
169 u16 r =0;
170 u16 g =0;
171 u16 b =0;
172
173 u16 x = g_ADC[i];
174
175 x = (3 * MAXLED * x) >> 12;
176
177 if (x < MAXLED)
178 {
179 r = x;
180 }
181 else if (x > MAXLED && x < (2*MAXLED))
182 {
183 r = MAXLED - x;
184 g = x - MAXLED;
185 }
186 else
187 {
188 g = MAXLED - x;
189 b = x - MAXLED;
190 }
191
192 hal_plot_led(TYPEPAD, ADC_MAP[i], r, g, b);
154 } 193 }
155} 194}
156 195
157//______________________________________________________________________________ 196//______________________________________________________________________________
158 197
159void app_init() 198void app_init(const u16 *adc_raw)
160{ 199{
161 // example - load button states from flash
162 hal_read_flash(0, g_Buttons, BUTTON_COUNT);
163 200
164 // example - light the LEDs to say hello! 201 // example - store off the raw ADC frame pointer for later use
165 for (int i=0; i < 10; ++i) 202 g_ADC = adc_raw;
166 {
167 for (int j=0; j < 10; ++j)
168 {
169 u8 b = g_Buttons[j*10 + i];
170
171 hal_plot_led(TYPEPAD, j*10 + i, 0, 0, b);
172 }
173 }
174} 203}