summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Hodder <dave.hodder@focusrite.com>2017-11-20 14:00:28 +0000
committerDave Hodder <dave.hodder@focusrite.com>2017-11-20 14:00:28 +0000
commit74474ab0c25b9efa52b2e27861d28a1ccf5f6c45 (patch)
tree0806f1f2cefc25f6e2251fa5aca4160e582ca29e
parentd910a607b308c5ed02e476a5051fac184f61c86f (diff)
downloadlaunchpad-polymaker-74474ab0c25b9efa52b2e27861d28a1ccf5f6c45.tar.gz
launchpad-polymaker-74474ab0c25b9efa52b2e27861d28a1ccf5f6c45.zip
updated example code to include flash api usage
-rw-r--r--src/app.c49
1 files changed, 40 insertions, 9 deletions
diff --git a/src/app.c b/src/app.c
index 5b83182..8117a18 100644
--- a/src/app.c
+++ b/src/app.c
@@ -42,11 +42,18 @@
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// 44//
45// In this example, we render the raw ADC data as LED rainbows. 45// In this example, we either render the raw ADC data as LED rainbows or store
46// and recall the pad state from flash.
46//______________________________________________________________________________ 47//______________________________________________________________________________
47 48
49// store ADC frame pointer
48static const u16 *g_ADC = 0; 50static const u16 *g_ADC = 0;
49 51
52// buffer to store pad states for flash save
53#define BUTTON_COUNT 100
54
55u8 g_Buttons[BUTTON_COUNT] = {0};
56
50//______________________________________________________________________________ 57//______________________________________________________________________________
51 58
52void app_surface_event(u8 type, u8 index, u8 value) 59void app_surface_event(u8 type, u8 index, u8 value)
@@ -55,18 +62,30 @@ void app_surface_event(u8 type, u8 index, u8 value)
55 { 62 {
56 case TYPEPAD: 63 case TYPEPAD:
57 { 64 {
58 // example - light / extinguish pad LEDs, send MIDI 65 // toggle it and store it off, so we can save to flash if we want to
59 hal_plot_led(TYPEPAD, index, value, value, value); 66 if (value)
67 {
68 g_Buttons[index] = MAXLED * !g_Buttons[index];
69 }
70
71 // example - light / extinguish pad LEDs
72 hal_plot_led(TYPEPAD, index, 0, 0, g_Buttons[index]);
73
74 // example - send MIDI
60 hal_send_midi(DINMIDI, NOTEON | 0, index, value); 75 hal_send_midi(DINMIDI, NOTEON | 0, index, value);
76
61 } 77 }
62 break; 78 break;
63 79
64 case TYPESETUP: 80 case TYPESETUP:
65 { 81 {
66 // example - light the setup LED 82 if (value)
67 hal_plot_led(TYPESETUP, 0, value, value, value); 83 {
84 // save button states to flash (reload them by power cycling the hardware!)
85 hal_write_flash(0, g_Buttons, BUTTON_COUNT);
86 }
68 } 87 }
69 break; 88 break;
70 } 89 }
71} 90}
72 91
@@ -101,8 +120,7 @@ void app_aftertouch_event(u8 index, u8 value)
101 // example - send poly aftertouch to MIDI ports 120 // example - send poly aftertouch to MIDI ports
102 hal_send_midi(USBMIDI, POLYAFTERTOUCH | 0, index, value); 121 hal_send_midi(USBMIDI, POLYAFTERTOUCH | 0, index, value);
103 122
104 // example - set LED to white, brightness in proportion to pressure 123
105 hal_plot_led(TYPEPAD, index, value/2, value/2, value/2);
106} 124}
107 125
108//______________________________________________________________________________ 126//______________________________________________________________________________
@@ -173,6 +191,19 @@ void app_timer_event()
173 191
174void app_init(const u16 *adc_raw) 192void app_init(const u16 *adc_raw)
175{ 193{
194 // example - load button states from flash
195 hal_read_flash(0, g_Buttons, BUTTON_COUNT);
196
197 // example - light the LEDs to say hello!
198 for (int i=0; i < 10; ++i)
199 {
200 for (int j=0; j < 10; ++j)
201 {
202 u8 b = g_Buttons[j*10 + i];
203
204 hal_plot_led(TYPEPAD, j*10 + i, 0, 0, b);
205 }
206 }
176 207
177 // store off the raw ADC frame pointer for later use 208 // store off the raw ADC frame pointer for later use
178 g_ADC = adc_raw; 209 g_ADC = adc_raw;