yes, it was a process, many many prompts. took about an hour and a half altogether.
i started by pasting in the original .cpp file and asked it to analyse and provide a summary.
it came back with:
This C++ code is an implementation of an OSC (Open Sound Control) message receiver that controls multiple I2C OLED displays using the U8g2 library. The code supports optional I2C multiplexing, allowing multiple displays to be controlled through a single I2C bus by using a TCA9548A I2C multiplexer.
Here's a summary of the key features:
Includes necessary libraries, such as signal.h, OscReceiver.h, U8g2LinuxI2C.h, vector, and algorithm.
A global vector, gDisplays, stores display configurations, including the U8G2 object and an optional I2C multiplexer channel number.
A global variable, gActiveTarget, is used to store the currently active display.
If I2C multiplexing is enabled, the code includes the TCA9548A.h library and initializes a TCA9548A object, gTca.
TargetMode enumeration is used to define different targeting modes for the OSC messages.
interrupt_handler function is used to handle the termination of the program when a SIGINT or SIGTERM signal is received (e.g., Ctrl-C).
switchTarget function is used to switch the active display target, handling the I2C multiplexer channel selection if required.
parseMessage function is the core function for processing received OSC messages, updating the display content based on the message received.
main function initializes the I2C multiplexer (if enabled), initializes the displays, sets up the interrupt handlers, and starts the OSC receiver. The program continues to run until a termination signal is received.
The code listens for specific OSC messages, and based on the messages received, it updates the content on the active display. The supported OSC messages are:
/target - Select the active display (only valid in stateful target mode).
/targetMode - Change the target mode (single, each, or stateful).
/osc-test - Display "OSC TEST SUCCESS!" on the active display.
/number - Display a large number on the active display.
/display-text - Display up to three lines of text on the active display.
/parameters - Display three horizontal bars, each representing a float parameter value.
/lfos - Display three ellipses, each representing a float parameter value.
/waveform - Display a waveform based on a series of float values.
Next prompt: Please can you use the above code as a guideline to create new display functionality that listens for the OSC message '/drawXY'
Please write the code that will be added to the 'parseMessage' function for processing received OSC messages.
The OSC message will be two numbers representing X and Y values. These X and Y values should be able to update the OLED display in real-time, based on the data being sent via OSC.
Please represent the X and Y values inside of a square frame.
Response:
To add the new display functionality for the OSC message '/drawXY', you can add a new case inside the parseMessage function to handle this specific message pattern. Here is the code to process the '/drawXY' OSC message:
cpp
Copy code
// ...
} else if (msg.match("/drawXY")) {
float xValue, yValue;
if(args.popFloat(xValue).popFloat(yValue).isOkNoMoreArgs()) {
printf("received /drawXY float %f float %f\n", xValue, yValue);
// Normalize the X and Y values to fit within the display dimensions
int xPos = static_cast<int>(xValue * (displayWidth - 1));
int yPos = static_cast<int>(yValue * (displayHeight - 1));
// Draw a square frame on the display
u8g2.drawFrame(0, 0, displayWidth, displayHeight);
// Draw a point at the specified X and Y values
u8g2.drawPixel(xPos, yPos);
} else {
error = kWrongArguments;
}
// ...
This code snippet first checks if the message matches the '/drawXY' pattern. It then tries to pop two float values from the message as the X and Y values. If successful, the X and Y values are normalized to fit within the display dimensions. A square frame is drawn around the entire display, and a point is drawn at the specified X and Y values. If the arguments are not as expected, an error is set.
Make sure to add this case within the parseMessage function, in the section where you check for other message patterns using msg.match().
This generated a rectangle frame, but it worked!
Then there was a lot of back and forth to get it to correctly produce a square and align it to the right hand side.




