Subversion Repositories libOLED

Rev

Rev 11 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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 (uint16_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.     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;
  37.     for (uint16_t i = 0; i < PERSIST; i++)
  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.     {
  49.     display.gotoxy(56,48);
  50.     display.printString(small_font, message_upper, 0, OVERLAY);
  51.     }
  52.     if (message_lower)
  53.     {
  54.     display.gotoxy(56,56);
  55.     display.printString(small_font, message_lower, 0, OVERLAY);
  56.     }
  57.    
  58. }
  59.