diff options
author | Dave Hodder <dave.hodder@focusrite.com> | 2016-02-12 18:06:50 +0000 |
---|---|---|
committer | Dave Hodder <dave.hodder@focusrite.com> | 2016-02-12 18:06:50 +0000 |
commit | 167a7dc6a753b5ba11c8c2ae2a365cec8656c171 (patch) | |
tree | ab89dcb74260171628ef12dce11f1ba6f8c64391 /src/app.c | |
parent | 6edc776b3d0a33c1b59ed29d66570cc8b5bc74e2 (diff) | |
download | launchpad-polymaker-167a7dc6a753b5ba11c8c2ae2a365cec8656c171.tar.gz launchpad-polymaker-167a7dc6a753b5ba11c8c2ae2a365cec8656c171.zip |
single-page flash storage
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 38 |
1 files changed, 30 insertions, 8 deletions
@@ -41,6 +41,15 @@ | |||
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 store all button states in an array, which we sometimes | ||
46 | // save to flash. | ||
47 | //______________________________________________________________________________ | ||
48 | |||
49 | #define BUTTON_COUNT 100 | ||
50 | |||
51 | u8 g_Buttons[BUTTON_COUNT] = {0}; | ||
52 | |||
44 | //______________________________________________________________________________ | 53 | //______________________________________________________________________________ |
45 | 54 | ||
46 | void app_surface_event(u8 type, u8 index, u8 value) | 55 | void app_surface_event(u8 type, u8 index, u8 value) |
@@ -49,16 +58,28 @@ void app_surface_event(u8 type, u8 index, u8 value) | |||
49 | { | 58 | { |
50 | case TYPEPAD: | 59 | case TYPEPAD: |
51 | { | 60 | { |
52 | // example - light / extinguish pad LEDs, send MIDI | 61 | // toggle it and store it off, so we can save to flash if we want to |
53 | hal_plot_led(TYPEPAD, index, value, value, value); | 62 | if (value) |
63 | { | ||
64 | g_Buttons[index] = MAXLED * !g_Buttons[index]; | ||
65 | } | ||
66 | |||
67 | // example - light / extinguish pad LEDs | ||
68 | hal_plot_led(TYPEPAD, index, 0, 0, g_Buttons[index]); | ||
69 | |||
70 | // example - send MIDI | ||
54 | hal_send_midi(DINMIDI, NOTEON | 0, index, value); | 71 | hal_send_midi(DINMIDI, NOTEON | 0, index, value); |
72 | |||
55 | } | 73 | } |
56 | break; | 74 | break; |
57 | 75 | ||
58 | case TYPESETUP: | 76 | case TYPESETUP: |
59 | { | 77 | { |
60 | // example - light the setup LED | 78 | if (value) |
61 | hal_plot_led(TYPESETUP, 0, value, value, value); | 79 | { |
80 | // save button states to flash (reload them by power cycling the hardware!) | ||
81 | hal_write_flash(0, g_Buttons, BUTTON_COUNT); | ||
82 | } | ||
62 | } | 83 | } |
63 | break; | 84 | break; |
64 | } | 85 | } |
@@ -137,16 +158,17 @@ void app_timer_event() | |||
137 | 158 | ||
138 | void app_init() | 159 | void app_init() |
139 | { | 160 | { |
161 | // example - load button states from flash | ||
162 | hal_read_flash(0, g_Buttons, BUTTON_COUNT); | ||
163 | |||
140 | // example - light the LEDs to say hello! | 164 | // example - light the LEDs to say hello! |
141 | for (int i=0; i < 10; ++i) | 165 | for (int i=0; i < 10; ++i) |
142 | { | 166 | { |
143 | for (int j=0; j < 10; ++j) | 167 | for (int j=0; j < 10; ++j) |
144 | { | 168 | { |
145 | u8 r = i < 5 ? (MAXLED * (5-i))/5 : 0; | 169 | u8 b = g_Buttons[j*10 + i]; |
146 | u8 g = i < 5 ? (MAXLED * i)/5 : (MAXLED * (10-i))/5; | ||
147 | u8 b = i < 5 ? 0 : (MAXLED * (i-5))/5; | ||
148 | 170 | ||
149 | hal_plot_led(TYPEPAD, j*10 + i, r, b, g); | 171 | hal_plot_led(TYPEPAD, j*10 + i, 0, 0, b); |
150 | } | 172 | } |
151 | } | 173 | } |
152 | } | 174 | } |