Subversion Repositories libOLED

Rev

Rev 11 | Details | Compare with Previous | 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
{
19 mjames 11
    for (uint16_t i = 0; i < PERSIST;  i++)
11 mjames 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
    persist_x[next_persist] = x_coord;
33
    persist_y[next_persist] = y_coord;
34
    next_persist++;
35
    if (next_persist > PERSIST)
36
        next_persist = 0;
19 mjames 37
    for (uint16_t i = 0; i < PERSIST; i++)
11 mjames 38
    {
39
        display.drawPixel(persist_x[i], persist_y[i], WHITE);
40
    }
41
 
42
    if(message)
43
    {
44
    display.gotoxy(0, 48);
45
    display.printString(large_font, message, 0, OVERLAY);
46
    }
47
    if (message_upper)
48
    {
19 mjames 49
    display.gotoxy(56,48);
11 mjames 50
    display.printString(small_font, message_upper, 0, OVERLAY);
51
    }
52
    if (message_lower)
53
    {
19 mjames 54
    display.gotoxy(56,56);
11 mjames 55
    display.printString(small_font, message_lower, 0, OVERLAY);
56
    }
57
 
58
}