I'm trying to learn how these c++/arduino class structures work. (I'm a js/perl/php developer). It's been about 2 decades since I had a c/c++ class, and thus have haven't worked a lot with OOP in them.
I want to set up a class with a property that is a 2 element integer array to store a binary representation of two characters on a 7 element display as a user-friendly id. I figured out last week how to pass an array into a function and think I've even figured out how to use strcpy or memcpy to assign the local property, but I'm stuck on how to get it back out again.
Do I have to pass a 2 element array pointer into the accessor and have the class transfer the property contents into it or is there a better way to read out the id array?
I know I can store the characters as two separate values and return them one at a time, but I'm never going to use them just one at a time, so that seems silly. Is there a better way to do this?
I would prefer to be able to assign the result of an accessor to a local array such as:
uint8_t deviceId[2] = MyDevice.getId();
data[0] = display.encodeDigit(i+1);
data[1] = deviceId[0];
data[2] = deviceId[1];
data[3] = MyDevice.getStatusDigit();
... or even access the elements directly somehow, such as:
data = { display.encodeDigit(i+1), MyDevice.id[0], MyDevice.id[1], MyDevice.getStatusDigit() };
Extra detail on the project (only if needed for reference):
The class I'm trying to build will be used as a companion to a relay sketch to turn power on and off to devices using an ESP8266 over wifi. But I also picked up a TM1637 to display info locally. One of my goals is to reduce the number of pins needed for local control (my initial working version had 4 relays and 4 buttons, one for each relay. I would like to add more relays but the nodemcu I am using is limited on pins. I figured a single, multi-function button [short/long press sorta thing] could allow me to do simple local on/off and status display with just a 4 digit 7-segment display.
Thus I figured it might be easier to store all relevant information for any device/relay combination in a pre-defined class. I would like to set one class object for each device/relay combination I connect. One property will be the pin the relay is connected to, another is a two-byte array for the characters to display on digits 2 & 3 of the led. I've also added the Relay code I'm using right in there to handle things like switching and reading back the status, and a 8 element character array to store a friendly name for use over the wifi or serial feedback.
I ultimately need to get the two characters out and assign them to the 2nd and 3rd elements of another array as I will be creating an array of these objects to define stuff connected via relays, and using the array index + 1 as the first digit on the led. In the last position I'm going to symbolize a dip switch by drawing a small circle either in the on or off position.
As an example, a device with id of 'id' (yes, I actually have one of those snicker) would translate to an array of { 0b00000100, 0b01011110 } for the id array/property such that when if it was the first defined device in the MyDevice[0] position, the display would show it as "1ido" when off. (just imagine the last 'o' higher for on grins)