Reputation: 13
I am trying to write some program to display telemetry data on charts using Processing IDE. I use ControlP5 library to create chart. There will be many of them so I wanted to write some function that generates them, but there is some problem, I am not sure how to send chart name to the function. I tried using this but IDE throws some error:
The function create_chart(String, int, int, int, int, int, String) does not exist.
Here is code that I use:
ControlP5 gui;
Chart dane;
int i = 0, minimum, maximum;
int zero_point;
void setup()
{
size(1280, 720);
smooth();
gui= new ControlP5(this);
PFont pfont = createFont("TIMES", 20, true); // use true/false for smooth/no-smooth
ControlFont font = new ControlFont(pfont, 30);
gui.setFont(font);
dane.create_chart("Dane", 0, 450, 300, 415, 210, "world");
delay(100);
}
void draw()
{
textSize(15);
i=i+(int(random(-50, 50)));
background(45);/*
dane.push("zero", 0);
dane.push("world", i);
minimum = int(min(dane.getValuesFrom("world")));
maximum = int(max(dane.getValuesFrom("world")));
if (maximum<0) maximum = 0;
if (minimum>0) minimum = 0;
dane.setRange(minimum, maximum);
text(maximum, 390, 220);
text(minimum, 390, 510);
if (minimum<=0 && minimum!=maximum) {
zero_point = 220 + 290*maximum/(maximum-minimum);
text(0, 390, zero_point);
}
dane.getValueLabel();*/
}
class Dane {
Dane dane = new Dane();
}
public void create_chart(String name, int chart_number, int size_x, int size_y, int position_x, int position_y, String data)
{
gui.printPublicMethodsFor(Chart.class);
dane = gui.addChart(name)
.setPosition(position_x, position_y)
.setSize(size_x, size_y)
.setRange(-20, 20)
.setView(Chart.LINE)
;
this.getColor().setBackground(color(100, 100));
this.addDataSet("zero");
this.setData("zero", new float[500]);
this.addDataSet("world");
this.setColors("world", color(100, 100, 500));
this.setStrokeWeight(3);
}
Upvotes: 0
Views: 101
Reputation: 10972
As pointed out by @Andy the create_chart
method is not defined within the Dane
class in the above code example. This should be fixed first.
If you didn’t intend to add create_chart
to a separate class, you might want to change
dane.create_chart(…);
to simply
create_chart(…);
This however renders the Dane
class (even more) useless.
Otherwise in your code dane
in the setup()
method is an instance of Chart
from the ControlP5 library. The Chart
class doesn’t seem to have any create_chart
method and you probably intended to call the method from your Dane
class.
So you probably want to change the type of dane
from Chart
to Dane
.
The Dane
class itself seems to have some issues as well (what’s the purpose of the dane
member? And ControlP5.addChart
returns Chart
and not Dane
) but this is out-of-scope for this question.
All in all your code has several issues that make it difficult to guess what your expectations are and how to fix it.
Upvotes: 1