From 167a7dc6a753b5ba11c8c2ae2a365cec8656c171 Mon Sep 17 00:00:00 2001 From: Dave Hodder Date: Fri, 12 Feb 2016 18:06:50 +0000 Subject: single-page flash storage --- src/app.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index f0edec8..e250cd3 100644 --- a/src/app.c +++ b/src/app.c @@ -41,6 +41,15 @@ // // This is where the fun is! Add your code to the callbacks below to define how // your app behaves. +// +// In this example, we store all button states in an array, which we sometimes +// save to flash. +//______________________________________________________________________________ + +#define BUTTON_COUNT 100 + +u8 g_Buttons[BUTTON_COUNT] = {0}; + //______________________________________________________________________________ void app_surface_event(u8 type, u8 index, u8 value) @@ -49,16 +58,28 @@ void app_surface_event(u8 type, u8 index, u8 value) { case TYPEPAD: { - // example - light / extinguish pad LEDs, send MIDI - hal_plot_led(TYPEPAD, index, value, value, value); + // toggle it and store it off, so we can save to flash if we want to + if (value) + { + g_Buttons[index] = MAXLED * !g_Buttons[index]; + } + + // example - light / extinguish pad LEDs + hal_plot_led(TYPEPAD, index, 0, 0, g_Buttons[index]); + + // example - send MIDI hal_send_midi(DINMIDI, NOTEON | 0, index, value); + } break; case TYPESETUP: { - // example - light the setup LED - hal_plot_led(TYPESETUP, 0, value, value, value); + if (value) + { + // save button states to flash (reload them by power cycling the hardware!) + hal_write_flash(0, g_Buttons, BUTTON_COUNT); + } } break; } @@ -137,16 +158,17 @@ void app_timer_event() void app_init() { + // example - load button states from flash + hal_read_flash(0, g_Buttons, BUTTON_COUNT); + // example - light the LEDs to say hello! for (int i=0; i < 10; ++i) { for (int j=0; j < 10; ++j) { - u8 r = i < 5 ? (MAXLED * (5-i))/5 : 0; - u8 g = i < 5 ? (MAXLED * i)/5 : (MAXLED * (10-i))/5; - u8 b = i < 5 ? 0 : (MAXLED * (i-5))/5; + u8 b = g_Buttons[j*10 + i]; - hal_plot_led(TYPEPAD, j*10 + i, r, b, g); + hal_plot_led(TYPEPAD, j*10 + i, 0, 0, b); } } } -- cgit v1.2.1 From 1fd765c53d36e6f4581e405263f8aa598ea98d8c Mon Sep 17 00:00:00 2001 From: Dave Hodder Date: Mon, 9 Jan 2017 14:01:28 +0000 Subject: experimenting with raw ADC api, moving 1kHz timer to main timer cb --- src/app.c | 79 +++++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 25 deletions(-) (limited to 'src') 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 @@ //______________________________________________________________________________ #define BUTTON_COUNT 100 +#define PAD_COUNT 64 -u8 g_Buttons[BUTTON_COUNT] = {0}; +static u8 g_Buttons[BUTTON_COUNT] = {0}; + +static const u16 *g_ADC = 0; //______________________________________________________________________________ @@ -58,17 +61,8 @@ void app_surface_event(u8 type, u8 index, u8 value) { case TYPEPAD: { - // toggle it and store it off, so we can save to flash if we want to - if (value) - { - g_Buttons[index] = MAXLED * !g_Buttons[index]; - } + return; - // example - light / extinguish pad LEDs - hal_plot_led(TYPEPAD, index, 0, 0, g_Buttons[index]); - - // example - send MIDI - hal_send_midi(DINMIDI, NOTEON | 0, index, value); } break; @@ -113,6 +107,8 @@ void app_sysex_event(u8 port, u8 * data, u16 count) void app_aftertouch_event(u8 index, u8 value) { + return; + // example - send poly aftertouch to MIDI ports hal_send_midi(USBMIDI, POLYAFTERTOUCH | 0, index, value); @@ -137,6 +133,18 @@ void app_cable_event(u8 type, u8 value) //______________________________________________________________________________ +static const u8 ADC_MAP[] = +{ + 11, 51, 12, 52, 13, 53, 14, 54, + 15, 55, 16, 56, 17 ,57, 18, 58, + 21, 61, 22, 62, 23, 63, 24, 64, + 25, 65, 26, 66, 27, 67, 28, 68, + 31, 71, 32, 72, 33, 73, 34, 74, + 35, 75, 36, 76, 37, 77, 38, 78, + 41, 81, 42, 82, 43, 83, 44, 84, + 45, 85, 46, 86, 47, 87, 48, 88, +}; + void app_timer_event() { @@ -150,25 +158,46 @@ void app_timer_event() ms = 0; // send a clock pulse up the USB - hal_send_midi(USBSTANDALONE, MIDITIMINGCLOCK, 0, 0); + hal_send_midi(USBMIDI, MIDITIMINGCLOCK, 0, 0); + } + + // example: render raw ADC data as LEDs + for (int i=0; i < PAD_COUNT; ++i) + { + // raw adc values are 12 bit, but LEDs are 6 bit. + // so saturate into r;g;b for a rainbow effect to show pressure + u16 r =0; + u16 g =0; + u16 b =0; + + u16 x = g_ADC[i]; + + x = (3 * MAXLED * x) >> 12; + + if (x < MAXLED) + { + r = x; + } + else if (x > MAXLED && x < (2*MAXLED)) + { + r = MAXLED - x; + g = x - MAXLED; + } + else + { + g = MAXLED - x; + b = x - MAXLED; + } + + hal_plot_led(TYPEPAD, ADC_MAP[i], r, g, b); } } //______________________________________________________________________________ -void app_init() +void app_init(const u16 *adc_raw) { - // example - load button states from flash - hal_read_flash(0, g_Buttons, BUTTON_COUNT); - // example - light the LEDs to say hello! - for (int i=0; i < 10; ++i) - { - for (int j=0; j < 10; ++j) - { - u8 b = g_Buttons[j*10 + i]; - - hal_plot_led(TYPEPAD, j*10 + i, 0, 0, b); - } - } + // example - store off the raw ADC frame pointer for later use + g_ADC = adc_raw; } -- cgit v1.2.1 From 50778f7bbb9ba2135df5e699521a61a83dcddbc6 Mon Sep 17 00:00:00 2001 From: Dave Hodder Date: Mon, 9 Jan 2017 14:22:58 +0000 Subject: minimal example for ADC processing --- src/app.c | 68 ++------------------------------------------------------------- 1 file changed, 2 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index d4547dc..3499d58 100644 --- a/src/app.c +++ b/src/app.c @@ -42,58 +42,23 @@ // This is where the fun is! Add your code to the callbacks below to define how // your app behaves. // -// In this example, we store all button states in an array, which we sometimes -// save to flash. +// In this example, we render the raw ADC data as LED rainbows. //______________________________________________________________________________ -#define BUTTON_COUNT 100 #define PAD_COUNT 64 -static u8 g_Buttons[BUTTON_COUNT] = {0}; - static const u16 *g_ADC = 0; //______________________________________________________________________________ void app_surface_event(u8 type, u8 index, u8 value) { - switch (type) - { - case TYPEPAD: - { - return; - - - } - break; - - case TYPESETUP: - { - if (value) - { - // save button states to flash (reload them by power cycling the hardware!) - hal_write_flash(0, g_Buttons, BUTTON_COUNT); - } - } - break; - } } //______________________________________________________________________________ void app_midi_event(u8 port, u8 status, u8 d1, u8 d2) { - // example - MIDI interface functionality for USB "MIDI" port -> DIN port - if (port == USBMIDI) - { - hal_send_midi(DINMIDI, status, d1, d2); - } - - // // example -MIDI interface functionality for DIN -> USB "MIDI" port port - if (port == DINMIDI) - { - hal_send_midi(USBMIDI, status, d1, d2); - } } //______________________________________________________________________________ @@ -107,33 +72,17 @@ void app_sysex_event(u8 port, u8 * data, u16 count) void app_aftertouch_event(u8 index, u8 value) { - return; - - // example - send poly aftertouch to MIDI ports - hal_send_midi(USBMIDI, POLYAFTERTOUCH | 0, index, value); - - // example - set LED to white, brightness in proportion to pressure - hal_plot_led(TYPEPAD, index, value/2, value/2, value/2); } //______________________________________________________________________________ void app_cable_event(u8 type, u8 value) { - // example - light the Setup LED to indicate cable connections - if (type == MIDI_IN_CABLE) - { - hal_plot_led(TYPESETUP, 0, 0, value, 0); // green - } - else if (type == MIDI_OUT_CABLE) - { - hal_plot_led(TYPESETUP, 0, value, 0, 0); // red - } } //______________________________________________________________________________ -static const u8 ADC_MAP[] = +static const u8 ADC_MAP[PAD_COUNT] = { 11, 51, 12, 52, 13, 53, 14, 54, 15, 55, 16, 56, 17 ,57, 18, 58, @@ -148,19 +97,6 @@ static const u8 ADC_MAP[] = void app_timer_event() { - // example - send MIDI clock at 125bpm -#define TICK_MS 20 - - static u8 ms = TICK_MS; - - if (++ms >= TICK_MS) - { - ms = 0; - - // send a clock pulse up the USB - hal_send_midi(USBMIDI, MIDITIMINGCLOCK, 0, 0); - } - // example: render raw ADC data as LEDs for (int i=0; i < PAD_COUNT; ++i) { -- cgit v1.2.1 From 59d4f28fe214601d323b2e0fb8a272040ba02a37 Mon Sep 17 00:00:00 2001 From: Dave Hodder Date: Mon, 9 Jan 2017 14:30:20 +0000 Subject: tidying up ADC api --- src/app.c | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index 3499d58..d4db1f9 100644 --- a/src/app.c +++ b/src/app.c @@ -45,8 +45,6 @@ // In this example, we render the raw ADC data as LED rainbows. //______________________________________________________________________________ -#define PAD_COUNT 64 - static const u16 *g_ADC = 0; //______________________________________________________________________________ @@ -82,33 +80,18 @@ void app_cable_event(u8 type, u8 value) //______________________________________________________________________________ -static const u8 ADC_MAP[PAD_COUNT] = -{ - 11, 51, 12, 52, 13, 53, 14, 54, - 15, 55, 16, 56, 17 ,57, 18, 58, - 21, 61, 22, 62, 23, 63, 24, 64, - 25, 65, 26, 66, 27, 67, 28, 68, - 31, 71, 32, 72, 33, 73, 34, 74, - 35, 75, 36, 76, 37, 77, 38, 78, - 41, 81, 42, 82, 43, 83, 44, 84, - 45, 85, 46, 86, 47, 87, 48, 88, -}; - - void app_timer_event() { - // example: render raw ADC data as LEDs + // render raw ADC data as LEDs for (int i=0; i < PAD_COUNT; ++i) { // raw adc values are 12 bit, but LEDs are 6 bit. - // so saturate into r;g;b for a rainbow effect to show pressure - u16 r =0; - u16 g =0; - u16 b =0; - - u16 x = g_ADC[i]; + // Let's saturate into r;g;b for a rainbow effect to show pressure + u16 r = 0; + u16 g = 0; + u16 b = 0; - x = (3 * MAXLED * x) >> 12; + u16 x = (3 * MAXLED * g_ADC[i]) >> 12; if (x < MAXLED) { @@ -134,6 +117,6 @@ void app_timer_event() void app_init(const u16 *adc_raw) { - // example - store off the raw ADC frame pointer for later use + // store off the raw ADC frame pointer for later use g_ADC = adc_raw; } -- cgit v1.2.1 From db91c3e329815c2988a4e32fea582ca7f29a594e Mon Sep 17 00:00:00 2001 From: Dave Hodder Date: Tue, 10 Jan 2017 12:59:05 +0000 Subject: tidying up timers --- src/app.c | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index d4db1f9..9ffa7d7 100644 --- a/src/app.c +++ b/src/app.c @@ -63,7 +63,6 @@ void app_midi_event(u8 port, u8 status, u8 d1, u8 d2) void app_sysex_event(u8 port, u8 * data, u16 count) { - // example - respond to UDI messages? } //______________________________________________________________________________ -- cgit v1.2.1 From d64ad7c106dccf8258c9ea36e311d2ec70fb3c2d Mon Sep 17 00:00:00 2001 From: Dave Hodder Date: Tue, 10 Jan 2017 17:21:00 +0000 Subject: closed a gap in the rainbow --- src/app.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/app.c b/src/app.c index 9ffa7d7..fed9127 100644 --- a/src/app.c +++ b/src/app.c @@ -96,7 +96,7 @@ void app_timer_event() { r = x; } - else if (x > MAXLED && x < (2*MAXLED)) + else if (x >= MAXLED && x < (2*MAXLED)) { r = MAXLED - x; g = x - MAXLED; -- cgit v1.2.1