Skip to content

Commit a721c36

Browse files
author
Greg Smith
committed
- Implemented preset saving for the GP5 on LCD editor
- fixed unplugging/replugging of USB pedals. Can now swap between any pedal without needing a controller reboot
1 parent 6be8570 commit a721c36

File tree

8 files changed

+183
-7
lines changed

8 files changed

+183
-7
lines changed

source/main/control.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,19 @@ uint32_t control_get_current_preset_index(void)
12361236
return ControlData.ConfigData.PresetOrderMappingConfig.PresetOrder[ControlData.PresetIndex];
12371237
}
12381238

1239+
/****************************************************************************
1240+
* NAME:
1241+
* DESCRIPTION:
1242+
* PARAMETERS:
1243+
* RETURN:
1244+
* NOTES:
1245+
*****************************************************************************/
1246+
void control_get_current_preset_name(char* dest)
1247+
{
1248+
memcpy((void*)dest, (void*)ControlData.PresetNames[control_get_current_preset_index()], MAX_PRESET_NAME_LENGTH);
1249+
dest[MAX_PRESET_NAME_LENGTH - 1] = 0;
1250+
}
1251+
12391252
/****************************************************************************
12401253
* NAME:
12411254
* DESCRIPTION:

source/main/control.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ uint8_t* control_get_preset_order(void);
321321
void control_set_sync_complete(void);
322322
uint8_t control_get_sync_complete(void);
323323
uint32_t control_get_current_preset_index(void);
324+
void control_get_current_preset_name(char* dest);
324325

325326
// config API
326327
void control_set_default_config(void);

source/main/display.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ void action_amp_skin_next(lv_event_t * e)
480480
*****************************************************************************/
481481
void action_close_settings_page(lv_event_t * e)
482482
{
483+
// save preset
484+
usb_save_preset();
485+
486+
// close settings screen
483487
lv_scr_load_anim(objects.screen1, LV_SCR_LOAD_ANIM_FADE_IN, 0, 0, false);
484488
}
485489

source/main/usb_comms.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,34 @@ void usb_load_preset_to_slot_b(uint32_t preset)
516516
}
517517
}
518518

519+
/****************************************************************************
520+
* NAME:
521+
* DESCRIPTION:
522+
* PARAMETERS:
523+
* RETURN:
524+
* NOTES:
525+
*****************************************************************************/
526+
void usb_save_preset(void)
527+
{
528+
tUSBMessage message;
529+
530+
if (usb_input_queue == NULL)
531+
{
532+
ESP_LOGE(TAG, "usb_save_preset queue null");
533+
}
534+
else
535+
{
536+
message.Command = USB_COMMAND_SAVE_PRESET;
537+
message.Payload = 0;
538+
539+
// send to queue
540+
if (xQueueSend(usb_input_queue, (void*)&message, 0) != pdPASS)
541+
{
542+
ESP_LOGE(TAG, "usb_save_preset queue send failed!");
543+
}
544+
}
545+
}
546+
519547
/****************************************************************************
520548
* NAME:
521549
* DESCRIPTION:

source/main/usb_comms.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ enum USB_Commands
4545
USB_COMMAND_SET_PRESET,
4646
USB_COMMAND_MODIFY_PARAMETER,
4747
USB_COMMAND_LOAD_PRESET_TO_SLOT_A,
48-
USB_COMMAND_LOAD_PRESET_TO_SLOT_B
48+
USB_COMMAND_LOAD_PRESET_TO_SLOT_B,
49+
USB_COMMAND_SAVE_PRESET
4950
};
5051

5152
typedef struct
@@ -70,6 +71,7 @@ void usb_set_preset(uint32_t preset);
7071
void usb_modify_parameter(uint16_t index, float value);
7172
void usb_load_preset_to_slot_a(uint32_t preset);
7273
void usb_load_preset_to_slot_b(uint32_t preset);
74+
void usb_save_preset(void);
7375
uint8_t usb_get_max_presets_for_connected_modeller(void);
7476
uint8_t usb_get_first_preset_index_for_connected_modeller(void);
7577
uint8_t usb_get_connected_modeller_type(void);

source/main/usb_tonex.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,11 @@ void usb_tonex_handle(class_driver_t* driver_obj)
13021302
ESP_LOGW(TAG, "Attempt to modify unknown param %d", (int)message.Payload);
13031303
}
13041304
} break;
1305+
1306+
case USB_COMMAND_SAVE_PRESET:
1307+
{
1308+
// todo - need to send back the entire 32kb+ preset details
1309+
} break;
13051310
}
13061311
}
13071312
} break;
@@ -1539,6 +1544,29 @@ void usb_tonex_init(class_driver_t* driver_obj, QueueHandle_t comms_queue)
15391544
*****************************************************************************/
15401545
void usb_tonex_deinit(void)
15411546
{
1542-
//to do here: need to clean up properly if pedal disconnected
1543-
//cdc_acm_host_close();
1547+
// close USB
1548+
cdc_acm_host_close(cdc_dev);
1549+
vTaskDelay(200);
1550+
cdc_dev = NULL;
1551+
cdc_acm_host_uninstall();
1552+
1553+
// dealloc mem
1554+
free((void*)InputBuffers);
1555+
InputBuffers = NULL;
1556+
1557+
free((void*)TxBuffer);
1558+
TxBuffer = NULL;
1559+
1560+
free((void*)FramedBuffer);
1561+
FramedBuffer = NULL;
1562+
1563+
free((void*)TonexData);
1564+
TonexData = NULL;
1565+
1566+
boot_init_needed = 0;
1567+
boot_preset_request = 0;
1568+
boot_global_request = 0;
1569+
1570+
// preallocate big memory again, ready for freeing on reconnect
1571+
tonex_common_preallocate_memory();
15441572
}

source/main/usb_tonex_one.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,6 +1384,11 @@ void usb_tonex_one_handle(class_driver_t* driver_obj)
13841384
ESP_LOGW(TAG, "Attempt to modify unknown param %d", (int)message.Payload);
13851385
}
13861386
} break;
1387+
1388+
case USB_COMMAND_SAVE_PRESET:
1389+
{
1390+
// Tonex One uses auto save, nothing needed
1391+
} break;
13871392
}
13881393
}
13891394
} break;
@@ -1624,6 +1629,29 @@ void usb_tonex_one_init(class_driver_t* driver_obj, QueueHandle_t comms_queue)
16241629
*****************************************************************************/
16251630
void usb_tonex_one_deinit(void)
16261631
{
1627-
//to do here: need to clean up properly if pedal disconnected
1628-
//cdc_acm_host_close();
1632+
// close USB
1633+
cdc_acm_host_close(cdc_dev);
1634+
vTaskDelay(200);
1635+
cdc_dev = NULL;
1636+
cdc_acm_host_uninstall();
1637+
1638+
// dealloc mem
1639+
free((void*)InputBuffers);
1640+
InputBuffers = NULL;
1641+
1642+
free((void*)TxBuffer);
1643+
TxBuffer = NULL;
1644+
1645+
free((void*)FramedBuffer);
1646+
FramedBuffer = NULL;
1647+
1648+
free((void*)TonexData);
1649+
TonexData = NULL;
1650+
1651+
boot_init_needed = 0;
1652+
boot_global_request = 0;
1653+
boot_preset_request = 0;
1654+
1655+
// preallocate big memory again, ready for freeing on reconnect
1656+
tonex_common_preallocate_memory();
16291657
}

source/main/usb_valeton_gp5.c

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ static uint8_t usb_valeton_gp5_process_single_sysex(const uint8_t* buffer, uint3
423423
static void usb_valeton_gp5_request_ir(void);
424424
static void usb_valeton_gp5_request_nams(void);
425425
static void usb_valeton_gp5_request_globals(void);
426+
static void usb_valeton_gp5_save_preset(uint16_t preset_index, char* preset_name);
426427

427428
/****************************************************************************
428429
* NAME:
@@ -1593,6 +1594,48 @@ static void usb_valeton_gp5_set_effect_block_state(uint8_t block_index, uint8_t
15931594
usb_valeton_gp5_send_sysex((const uint8_t*)midi_tx, sizeof(midi_tx), 0x01);
15941595
}
15951596

1597+
/****************************************************************************
1598+
* NAME:
1599+
* DESCRIPTION:
1600+
* PARAMETERS:
1601+
* RETURN:
1602+
* NOTES:
1603+
*****************************************************************************/
1604+
static void usb_valeton_gp5_save_preset(uint16_t preset_index, char* preset_name)
1605+
{
1606+
uint8_t midi_tx[] = {0x04, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1607+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1608+
uint8_t preset_name_length;
1609+
uint8_t buffer_index;
1610+
1611+
// set preset index
1612+
midi_tx[2] = (uint8_t)(preset_index / 16);
1613+
midi_tx[3] = (uint8_t)(preset_index % 16);
1614+
1615+
// set preset name
1616+
preset_name_length = strlen(preset_name);
1617+
if (preset_name_length > 10)
1618+
{
1619+
preset_name_length = 10;
1620+
}
1621+
1622+
// name starts at offset 10, and is 10 characters/20 bytes long
1623+
buffer_index = 10;
1624+
for (uint32_t character = 0; character < preset_name_length; character++)
1625+
{
1626+
// break character into 2 x 4 bit nibbles e.g. 47 becomes 04 07
1627+
midi_tx[buffer_index++] = (preset_name[character] >> 4) & 0x0F;
1628+
midi_tx[buffer_index++] = preset_name[character] & 0x0F;
1629+
}
1630+
1631+
ESP_LOGI(TAG, "Save Preset");
1632+
1633+
// debug
1634+
//ESP_LOG_BUFFER_HEXDUMP(TAG, midi_tx, sizeof(midi_tx), ESP_LOG_INFO);
1635+
1636+
usb_valeton_gp5_send_sysex((const uint8_t*)midi_tx, sizeof(midi_tx), 0x01);
1637+
}
1638+
15961639
/****************************************************************************
15971640
* NAME:
15981641
* DESCRIPTION:
@@ -2148,6 +2191,14 @@ void usb_valeton_gp5_handle(class_driver_t* driver_obj)
21482191
ESP_LOGW(TAG, "Attempt to modify unknown param %d", (int)message.Payload);
21492192
}
21502193
} break;
2194+
2195+
case USB_COMMAND_SAVE_PRESET:
2196+
{
2197+
char preset_name[MAX_PRESET_NAME_LENGTH];
2198+
control_get_current_preset_name(preset_name);
2199+
2200+
usb_valeton_gp5_save_preset(control_get_current_preset_index(), preset_name);
2201+
} break;
21512202
}
21522203
}
21532204
} break;
@@ -2280,6 +2331,27 @@ void usb_valeton_gp5_init(class_driver_t* driver_obj, QueueHandle_t comms_queue)
22802331
*****************************************************************************/
22812332
void usb_valeton_gp5_deinit(void)
22822333
{
2283-
//to do here: need to clean up properly if pedal disconnected
2284-
//cdc_acm_host_close();
2334+
midi_host_close(midi_dev);
2335+
vTaskDelay(200);
2336+
midi_dev = NULL;
2337+
midi_host_uninstall();
2338+
2339+
// free mem
2340+
free((void*)InputBuffers);
2341+
InputBuffers = NULL;
2342+
2343+
free((void*)ProcessingBuffer);
2344+
ProcessingBuffer = NULL;
2345+
2346+
free((void*)TransmitBuffer);
2347+
TransmitBuffer = NULL;
2348+
2349+
free((void*)TxBuffer);
2350+
TxBuffer = NULL;
2351+
2352+
free((void*)ValetonGP5Data);
2353+
ValetonGP5Data = NULL;
2354+
2355+
// preallocate big memory again, ready for freeing on reconnect
2356+
tonex_common_preallocate_memory();
22852357
}

0 commit comments

Comments
 (0)