I'm relatively new to Arduino and C++.... So please play nice, I'll try to be as thorough and helpful about my issue as I can.
To rough out my project I have a guitar amp connected via USB into a USB Sheild on the Arduino. The arduino is part of a controller board with footswitches and the board read/writes to the amp over USB to make changes.
=====
The amp has lots of parameters it can manipulate such as Volume. Each of these has it's own address inside the amp.
Inside my Arduino code I have this class:
class Parameter
{
public:
const unsigned long address;
int16_t index = 0;
Parameter(unsigned long a)
:
address(a)
{
}
Instantiated like:
Parameter paramVolume(0x6000043E);
This is so that the arduino board and the amp have the same list of parameters with the same addresses, so they can both talk back and forth in order to read/write the changes and keep in sync on both sides.
When something is changed on the amp it essentially spits out a memory address relating to a parameter on the amp, plus some data. So using the above example maybe '0x6000043E, 100' (the address for Volume on the amp, and telling us the volume is set to 100/100)
Inside my arduino code I have a function that deals with incoming data with the arguments 'unsigned long address' and 'byte data'. I'm hoping it can set a pointer:
Parameter *paramPTR;
to point to a Parameter if the address matches, and then sets the associated index to the incoming data.
Inside I have/want a switch statement that compares the incoming address to the 'Parameter::address' so that we can set the Parameter::index as the data.
My problem is two fold... I cannot use member variables in a switch statement (apparently even if they are marked as const)... Secondly the list of Parameters I need to compare the incoming address to is huge, as in 500+ addresses.
Here's a non-working example of what I was trying to achieve.
void parseData(unsigned long address, byte data)
{
switch (address)
{
case paramVolume.address:
paramPTR = ¶mVolume;
break;
case paramExample1.address:
paramPTR = ¶mExample1;
break;
case paramExample2.address:
paramPTR = ¶mExample2;
break;
case paramExample3.address:
paramPTR = ¶mExample3;
break;
// This goes on forever... 500+ addresses to check
case paramExample499.address:
paramPTR = ¶mExample499;
break;
case paramExample500.address:
paramPTR = ¶mExample500;
break;
}
paramPTR->index = data;
}
I've had this working previously before I implemented the Parameter class because all of the addresses I had been comparing to had been global variables marked as const very big, very messy.
Since moving everything inside the class, and using pointers to objects, the switch statement firstly doesn't work against member variables... and secondly is so massive I can't help but wonder if there's something better (maybe even faster) I can use to compare the incoming address to the massive list, in order to set data effectively.
Any thoughts?
Many thanks!
Steve.