diff options
author | Dave Hodder <dave.hodder@focusrite.com> | 2017-01-09 14:22:58 +0000 |
---|---|---|
committer | Dave Hodder <dave.hodder@focusrite.com> | 2017-01-09 14:22:58 +0000 |
commit | 50778f7bbb9ba2135df5e699521a61a83dcddbc6 (patch) | |
tree | 7c1efbaf890c19ee8d9e2363bbbd66e5ed5a44d4 /src/app.c | |
parent | 9b3521954b5a06ba46be099b6d4757669f517a9d (diff) | |
download | launchpad-polymaker-50778f7bbb9ba2135df5e699521a61a83dcddbc6.tar.gz launchpad-polymaker-50778f7bbb9ba2135df5e699521a61a83dcddbc6.zip |
minimal example for ADC processing
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 68 |
1 files changed, 2 insertions, 66 deletions
@@ -42,58 +42,23 @@ | |||
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 store all button states in an array, which we sometimes | 45 | // In this example, we render the raw ADC data as LED rainbows. |
46 | // save to flash. | ||
47 | //______________________________________________________________________________ | 46 | //______________________________________________________________________________ |
48 | 47 | ||
49 | #define BUTTON_COUNT 100 | ||
50 | #define PAD_COUNT 64 | 48 | #define PAD_COUNT 64 |
51 | 49 | ||
52 | static u8 g_Buttons[BUTTON_COUNT] = {0}; | ||
53 | |||
54 | static const u16 *g_ADC = 0; | 50 | static const u16 *g_ADC = 0; |
55 | 51 | ||
56 | //______________________________________________________________________________ | 52 | //______________________________________________________________________________ |
57 | 53 | ||
58 | void app_surface_event(u8 type, u8 index, u8 value) | 54 | void app_surface_event(u8 type, u8 index, u8 value) |
59 | { | 55 | { |
60 | switch (type) | ||
61 | { | ||
62 | case TYPEPAD: | ||
63 | { | ||
64 | return; | ||
65 | |||
66 | |||
67 | } | ||
68 | break; | ||
69 | |||
70 | case TYPESETUP: | ||
71 | { | ||
72 | if (value) | ||
73 | { | ||
74 | // save button states to flash (reload them by power cycling the hardware!) | ||
75 | hal_write_flash(0, g_Buttons, BUTTON_COUNT); | ||
76 | } | ||
77 | } | ||
78 | break; | ||
79 | } | ||
80 | } | 56 | } |
81 | 57 | ||
82 | //______________________________________________________________________________ | 58 | //______________________________________________________________________________ |
83 | 59 | ||
84 | void app_midi_event(u8 port, u8 status, u8 d1, u8 d2) | 60 | void app_midi_event(u8 port, u8 status, u8 d1, u8 d2) |
85 | { | 61 | { |
86 | // example - MIDI interface functionality for USB "MIDI" port -> DIN port | ||
87 | if (port == USBMIDI) | ||
88 | { | ||
89 | hal_send_midi(DINMIDI, status, d1, d2); | ||
90 | } | ||
91 | |||
92 | // // example -MIDI interface functionality for DIN -> USB "MIDI" port port | ||
93 | if (port == DINMIDI) | ||
94 | { | ||
95 | hal_send_midi(USBMIDI, status, d1, d2); | ||
96 | } | ||
97 | } | 62 | } |
98 | 63 | ||
99 | //______________________________________________________________________________ | 64 | //______________________________________________________________________________ |
@@ -107,33 +72,17 @@ void app_sysex_event(u8 port, u8 * data, u16 count) | |||
107 | 72 | ||
108 | void app_aftertouch_event(u8 index, u8 value) | 73 | void app_aftertouch_event(u8 index, u8 value) |
109 | { | 74 | { |
110 | return; | ||
111 | |||
112 | // example - send poly aftertouch to MIDI ports | ||
113 | hal_send_midi(USBMIDI, POLYAFTERTOUCH | 0, index, value); | ||
114 | |||
115 | // example - set LED to white, brightness in proportion to pressure | ||
116 | hal_plot_led(TYPEPAD, index, value/2, value/2, value/2); | ||
117 | } | 75 | } |
118 | 76 | ||
119 | //______________________________________________________________________________ | 77 | //______________________________________________________________________________ |
120 | 78 | ||
121 | void app_cable_event(u8 type, u8 value) | 79 | void app_cable_event(u8 type, u8 value) |
122 | { | 80 | { |
123 | // example - light the Setup LED to indicate cable connections | ||
124 | if (type == MIDI_IN_CABLE) | ||
125 | { | ||
126 | hal_plot_led(TYPESETUP, 0, 0, value, 0); // green | ||
127 | } | ||
128 | else if (type == MIDI_OUT_CABLE) | ||
129 | { | ||
130 | hal_plot_led(TYPESETUP, 0, value, 0, 0); // red | ||
131 | } | ||
132 | } | 81 | } |
133 | 82 | ||
134 | //______________________________________________________________________________ | 83 | //______________________________________________________________________________ |
135 | 84 | ||
136 | static const u8 ADC_MAP[] = | 85 | static const u8 ADC_MAP[PAD_COUNT] = |
137 | { | 86 | { |
138 | 11, 51, 12, 52, 13, 53, 14, 54, | 87 | 11, 51, 12, 52, 13, 53, 14, 54, |
139 | 15, 55, 16, 56, 17 ,57, 18, 58, | 88 | 15, 55, 16, 56, 17 ,57, 18, 58, |
@@ -148,19 +97,6 @@ static const u8 ADC_MAP[] = | |||
148 | 97 | ||
149 | void app_timer_event() | 98 | void app_timer_event() |
150 | { | 99 | { |
151 | // example - send MIDI clock at 125bpm | ||
152 | #define TICK_MS 20 | ||
153 | |||
154 | static u8 ms = TICK_MS; | ||
155 | |||
156 | if (++ms >= TICK_MS) | ||
157 | { | ||
158 | ms = 0; | ||
159 | |||
160 | // send a clock pulse up the USB | ||
161 | hal_send_midi(USBMIDI, MIDITIMINGCLOCK, 0, 0); | ||
162 | } | ||
163 | |||
164 | // example: render raw ADC data as LEDs | 100 | // example: render raw ADC data as LEDs |
165 | for (int i=0; i < PAD_COUNT; ++i) | 101 | for (int i=0; i < PAD_COUNT; ++i) |
166 | { | 102 | { |