Subversion Repositories libOLED

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 mjames 1
#include "libOLED/displayXY.H"
2
 
3
const unsigned MARGIN = 1;
4
const unsigned BOTTOM_MARGIN = 17;
5
 
6
displayXY_t ::displayXY_t(display_t &disp,
7
                          int xmin, int xmax, int ymin, int ymax) : display(disp), x_min(xmin), x_max(xmax), y_min(ymin), y_max(ymax),
8
                                                                    left_margin(MARGIN), right_margin(display.width() - MARGIN), plot_width(right_margin - left_margin),
9
                                                                    top_margin(MARGIN), bottom_margin(display.height() - BOTTOM_MARGIN), plot_height(bottom_margin - top_margin), next_persist(0)
10
{
11
    for (uint8_t i = 0; i < PERSIST;  i++)
12
    {
13
        persist_x[i] = left_margin;
14
        persist_y[i] = bottom_margin;
15
    }
16
};
17
 
18
void displayXY_t ::drawAxes()
19
{
20
 
21
    display.drawLine(left_margin, bottom_margin, right_margin, bottom_margin,
22
                     WHITE, 0b10);
23
    display.drawLine(left_margin, bottom_margin, left_margin, top_margin, WHITE, 0b10);
24
}
25
 
26
void displayXY_t ::plotPoint(int x, int y, char *message,char * message_lower, char * message_upper)
27
{
28
    int y_coord = (plot_height * (y - y_min)) / (y_max - y_min);
29
    int x_coord = (plot_width * (x - x_min)) / (x_max - x_min);
30
    display.drawLine(left_margin, y_coord, right_margin, y_coord, WHITE, 0b111000);
31
    display.drawLine(x_coord, top_margin, x_coord, bottom_margin, WHITE, 0b111000);
32
    // imitate persistent plot
33
    persist_x[next_persist] = x_coord;
34
    persist_y[next_persist] = y_coord;
35
    next_persist++;
36
    if (next_persist > PERSIST)
37
        next_persist = 0;
38
 
39
    for (uint8_t i = 0; i < PERSIST; i++)
40
    {
41
        display.drawPixel(persist_x[i], persist_y[i], WHITE);
42
    }
43
 
44
    if(message)
45
    {
46
    display.gotoxy(0, 48);
47
    display.printString(large_font, message, 0, OVERLAY);
48
    }
49
    if (message_upper)
50
    {
51
    display.gotoxy(64,48);
52
    display.printString(small_font, message_upper, 0, OVERLAY);
53
    }
54
    if (message_lower)
55
    {
56
    display.gotoxy(64,56);
57
    display.printString(small_font, message_lower, 0, OVERLAY);
58
    }
59
 
60
}