@@ -5,7 +5,14 @@ Serial port;
55final int [] COLORS = {#00FF00,#FF0000 ,#0000FF}; // int color codes
66final char OUTER_KEY = ' #' ;
77final String INNER_KEY = " @" ;
8- final double AXIS_COVERAGE = 0.75 ;
8+ final float AXIS_COVERAGE = 0.75 ;
9+ final int LABEL_SZ = 16 ; // text sizes
10+ final int TITLE_SZ = 20 ;
11+ final int NUM_SZ = 12 ;
12+ final int BG_COL = 75 ;
13+ final int PLOT_COL = 115 ;
14+ final int TICK_LEN = 6 ;
15+ final int NUM_TICKS = 4 ;
916
1017// Setup and config Globals
1118int h;
@@ -36,21 +43,21 @@ String[] labels;
3643
3744
3845void setup () {
46+ fullScreen();
3947 h = displayHeight;
4048 w = displayWidth;
41- fullScreen();
4249 String portID = Serial . list()[0 ];
4350 port = new Serial (this , portID, 115200 );
4451 port. bufferUntil(' #' );
4552 frameRate (100 );
4653 textSize (16 );
47- background (75 );
54+ background (BG_COL );
4855}
4956
5057void draw () {
5158 // PLOT ALL
5259 if (configured) {
53- background (75 );
60+ background (BG_COL );
5461 for (int i = 0 ; i < num_graphs; i++ ) {
5562 if (xvy[i]) {
5663 plot_xy(i);
@@ -74,10 +81,28 @@ void plot_xy(int graph_index) {
7481 double y_offset = y_scale* extremes_graphs[g][3 ] + 0.5 * (1.0 - AXIS_COVERAGE )* sub_height;
7582
7683 // Drawing setup
77- fill (115 );
84+ fill (PLOT_COL );
7885 stroke (255 );
7986 rect (pos_graphs[g][0 ],pos_graphs[g][1 ],sub_width,sub_height);
8087
88+ // Label graph
89+ stroke (255 );
90+ fill (255 );
91+ textSize (NUM_SZ );
92+ float temp_x = pos_graphs[g][0 ] - TICK_LEN / 2 ;
93+ float tick_offset = 0.5 * (1.0 - AXIS_COVERAGE )* sub_height;
94+ float val = (float )extremes_graphs[g][3 ];
95+ float val_interval = (float )(extremes_graphs[g][3 ] - extremes_graphs[g][2 ]) / (NUM_TICKS - 1 );
96+ for (float temp_y = pos_graphs[g][1 ] + tick_offset;
97+ temp_y <= pos_graphs[g][1 ] + sub_height - tick_offset;
98+ temp_y += AXIS_COVERAGE * sub_height / (NUM_TICKS - 1 )) {
99+ line (temp_x, temp_y, temp_x + TICK_LEN , temp_y);
100+ text (Float . toString(val), temp_x + TICK_LEN + 1 , temp_y + NUM_SZ / 2 );
101+ val -= val_interval;
102+ }
103+ // float temp_y = pos_graphs[g][1] + sub_height + TICK_LEN/2;
104+
105+ // line(temp_x, temp_x + TICK_LEN, pos_graphs[g][1] + y_offset, pos_graphs[g][1] + y_offset
81106 // ** add support for multiple paths in x-y here **
82107 stroke (COLORS [0 ]);
83108 for (int j = 0 ; j < num_points[g]; j++ ) {
@@ -157,12 +182,14 @@ void serialEvent(Serial ser) {
157182 for (int i = 0 ; i < num_high; i++ ) {
158183 for (int j = 0 ; j < num_wide; j++ ) {
159184 if (k < num_graphs) {
160- pos_graphs[k][0 ] = j* sub_width;
185+ pos_graphs[k][0 ] = j* sub_width + LABEL_SZ ;
161186 pos_graphs[k][1 ] = i* sub_height;
162187 }
163188 k++ ;
164189 }
165190 }
191+ sub_width -= LABEL_SZ ;
192+ sub_height -= LABEL_SZ ;
166193
167194 // Reset data storage arrays
168195 total_vars = Integer . parseInt(array_sub[1 ]);
0 commit comments