Ahhh okay that must be where the issue is! I have exclusively been using render etc so far so 'main' I kinda assumed to be same foolishly. I need to look into how to fox this then.
ill just attatch the main.cpp file its not much different honestly there is a little bit of trimming of other functions plus the new drawParams that has been added.
const unsigned int gI2cBus = 1;
#define DELAY_BUFFER_SIZE 44100
int remotePort = 7563;
unsigned int gActiveTarget = 0;
const int gLocalPort = 7562; //port for incoming OSC messages
Trill touchSensor;
int gInputPin = 0;
float gTouchPosition[2] = { 0.0 , 0.0 };
float gTouchSize = 0.0;
unsigned int gTaskSleepTime = 12000; // microseconds
float positionXsensor = 0;
float positionYsensor = 0;
float largeNumber;
void loop(void*)
{
while(!Bela_stopRequested())
{
// Read locations from Trill sensor
touchSensor.readI2C();
gTouchSize = touchSensor.compoundTouchSize();
gTouchPosition[0] = touchSensor.compoundTouchHorizontalLocation();
gTouchPosition[1] = touchSensor.compoundTouchLocation();
usleep(gTaskSleepTime);
}
}
bool setup(BelaContext *context, void *userData)
{
pinMode(context, 0, gInputPin, INPUT); //set input
if(touchSensor.setup(1, Trill::SQUARE) != 0) {
fprintf(stderr, "Unable to initialise Trill Square\n");
return false;
}
//touchSensor.printDetails();
// Set and schedule auxiliary task for reading sensor data from the I2C bus
Bela_runAuxiliaryTask(loop);
return true;
}
void drawSensorInputAsBar(U8G2 &u8g2, float xVal) {
u8g2.clearBuffer();
int displayWidth = u8g2.getDisplayWidth();
int displayHeight = u8g2.getHeight();
//u8g2.drawStr(0, 7, "| __ )| ____| | / \\");
int barWidth = 20; // Width of the bar to be drawn
int barHeight = displayHeight; // The bar spans the full height of the display
int barXPosition = (xVal * displayWidth);
// Draw the vertical bar according to the touch position
barXPosition = min(barXPosition, displayWidth);
u8g2.drawBox(barXPosition, 0, barWidth, barHeight); // Draw a vertical bar
u8g2.sendBuffer();
}
// #define I2C_MUX // allow I2C multiplexing to select different target displays
struct Display {U8G2 d; int mux;};
std::vector<Display> gDisplays = {
// use `-1` as the last value to indicate that the display is not behind a mux, or a number between 0 and 7 for its muxed channel number
{ U8G2LinuxI2C(U8G2_R0, gI2cBus, 0x3c, u8g2_Setup_ssd1306_i2c_128x64_noname_f), -1 },
// add more displays / addresses here
};
/// Determines how to select which display a message is targeted to:
typedef enum {
kTargetSingle, ///< Single target (one display).
kTargetEach, ///< The first argument to each message is an index corresponding to the target display
kTargetStateful, ///< Send a message to /target <float> to select which is the active display that all subsequent messages will be sent to
} TargetMode;
TargetMode gTargetMode = kTargetSingle; // can be changed with /targetMode
OscReceiver oscReceiver;
int gStop = 0;
// Handle Ctrl-C by requesting that the audio rendering stop
void interrupt_handler(int var)
{
gStop = true;
}
int parseMessage(oscpkt::Message msg, const char* address, void*)
{
oscpkt::Message::ArgReader args = msg.arg();
float xVal = gTouchPosition[0];
//printf("AAA PLEASE");
enum {
kOk = 0,
kUnmatchedPattern,
kWrongArguments,
kInvalidMode,
kOutOfRange,
} error = kOk;
printf("Message from %s\n", address);
bool stateMessage = false;
U8G2& u8g2 = gDisplays[gActiveTarget].d;
u8g2.clearBuffer();
//int displayWidth = u8g2.getDisplayWidth();
int displayHeight = u8g2.getDisplayHeight();
// code below MUST use msg.match() to check patterns and args.pop... or args.is ... to check message content.
// this way, anything popped above (if we are in kTargetEach mode), won't be re-used below
if(error || stateMessage) {
// nothing to do here, just avoid matching any of the others
} else if (msg.match("/osc-test"))
{
if(!args.isOkNoMoreArgs()){
error = kWrongArguments;
}
else {
printf("received /osc-test\n");
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.setFontRefHeightText();
u8g2.drawStr(0, displayHeight * 0.5, "OSC TEST SUCCESS!");
}
} else if (msg.match("/number"))
{
int number;
if(args.popNumber(number).isOkNoMoreArgs())
{
printf("received /number %d\n", number);
u8g2.setFont(u8g2_font_logisoso62_tn);
u8g2.drawUTF8(0, 0, std::to_string(number).c_str());
}
else
error = kWrongArguments;
}
else if (msg.match("/drawParams"))
{
//print(gTouchPosition[0]);
touchSensor.readI2C();
xVal = gTouchPosition[0];
touchSensor.printDetails();
drawSensorInputAsBar(u8g2,xVal);
//u8g2.sendBuffer(); // Update the display with the new buffer contents
}
else{
error = kUnmatchedPattern;
}
if(error)
{
std::string str;
switch(error){
case kUnmatchedPattern:
str = "no matching pattern available\n";
break;
case kWrongArguments:
str = "unexpected types and/or length\n";
break;
case kInvalidMode:
str = "invalid target mode\n";
break;
case kOutOfRange:
str = "argument(s) value(s) out of range\n";
break;
case kOk:
str = "";
break;
}
fprintf(stderr, "An error occurred with message to: %s: %s\n", msg.addressPattern().c_str(), str.c_str());
return 1;
} else
{
if(!stateMessage)
u8g2.sendBuffer();
}
return 0;
}
int main(int main_argc, char *main_argv[])
{
if(0 == gDisplays.size())
{
fprintf(stderr, "No displays in gDisplays\n");
return 1;
}
for(unsigned int n = 0; n < gDisplays.size(); ++n)
{
//switchTarget(n);
U8G2& u8g2 = gDisplays[gActiveTarget].d;
//drawSensorInputAsBar(u8g2, gTouchSize);
int mux = gDisplays[gActiveTarget].mux;
if(-1 != mux)
{
fprintf(stderr, "Display %u requires mux %d but I2C_MUX is disabled\n", n, mux);
return 1;
}
u8g2.initDisplay();
u8g2.setPowerSave(0);
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_4x6_tf);
u8g2.setFontRefHeightText();
u8g2.setFontPosTop();
u8g2.drawStr(0, 0, " ____ _____ _ _");
u8g2.drawStr(0, 7, "| __ )| ____| | / \\");
u8g2.drawStr(0, 14, "| _ \\| _| | | / _ \\");
u8g2.drawStr(0, 21, "| |_) | |___| |___ / ___ \\");
u8g2.sendBuffer();
oscReceiver.setup(gLocalPort, parseMessage);
while(!gStop)
{
u8g2.clearBuffer();
positionXsensor = gTouchPosition[0];
positionYsensor = gTouchPosition[1];
//drawSensorInputAsBar(u8g2, positionXsensor);
u8g2.drawBox(positionXsensor, 0, 15, 39);
u8g2.sendBuffer();
usleep(10000);
}
}
// Set up interrupt handler to catch Control-C and SIGTERM
signal(SIGINT, interrupt_handler);
signal(SIGTERM, interrupt_handler);
// OSC
return 0;
}
my apologies for the rough code