Rover API Documentation
rover_display.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 FH Dortmund and others
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Description:
9  * Rover Display API - Interfaces for Rover display application development - Header file
10  *
11  * Usage Instructions:
12  * 1) One should set-up I2C on Raspberry Pi to run this script properly (taken from Adafruit):
13  * 1.1) Install necessary modules:
14  * sudo apt-get install -y python-smbus
15  * sudo apt-get install -y i2c-tools
16  * 1.2) In /etc/modules, add following lines:
17  * i2c-bcm2708
18  * i2c-dev
19  * 1.3) In /etc/modprobe.d/raspi-blacklist.conf, uncomment possible following lines:
20  * blacklist spi-bcm2708
21  * blacklist i2c-bcm2708
22  * 1.4) In /boot/config.txt, add following lines:
23  * dtparam=i2c1=on
24  * dtparam=i2c_arm=on
25  * 1.5) Then reboot
26  * sudo reboot
27  * 1.6) To test I2C and see the addresses,
28  * sudo i2cdetect -y 1
29  * 2) For cross-compilation using Eclipse IDE, make sure to follow the instructions located under readme.txt files
30  * in drivers/oled_drivers:
31  * Please note that in order to use OLED SSD1306 with I2C,
32  * one has to download bcm2835.c, bcm2835.h, and has access to current <linux/i2c-dev.h>.
33  * In case the compiler complains, please also download the newest i2c-dev.h and put it in drivers/oled_drivers folder.
34  * Download i2c-dev.h from: https://www.kernel.org/pub/linux/
35  * Download bcm2835.c and bcm2835.h from: https://github.com/hallard/ArduiPi_SSD1306
36  *
37  * Contributors:
38  * M.Ozcelikors <mozcelikors@gmail.com>, created API 17.11.2017
39  *
40  */
41 
42 #ifndef API_ROVER_DISPLAY_HPP_
43 #define API_ROVER_DISPLAY_HPP_
44 
45 #include <drivers/oled_drivers/Adafruit_SSD1306.h>
46 
47 #define NUMFLAKES 10
48 #define XPOS 0
49 #define YPOS 1
50 #define DELTAY 2
51 
52 namespace rover
53 {
58  {
59  private:
63  Adafruit_SSD1306 my_display;
64 
69 
70  public:
71 
75  static const int BLACK_COLOR = 0;
76 
80  static const int WHITE_COLOR = 1;
81 
85  RoverDisplay();
86 
91  void initialize (void);
92 
97  void display (void);
98 
103  Adafruit_SSD1306& getDisplay (void);
104 
109  void clearDisplay (void) ;
110 
121  void drawBitmap (int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color) ;
122 
129  void setCursor (int16_t x, int16_t y);
130 
136  void setTextSize (uint8_t s);
137 
143  void setTextColor (uint16_t c);
144 
151  void setTextColor (uint16_t c, uint16_t b);
152 
158  void print (const char * string);
159 
169  void drawRect (int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
170 
177  void drawPixel(int16_t x, int16_t y, uint16_t color);
178 
186  void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
187 
195  void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color);
196 
205  void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
206 
211  void fillScreen(uint16_t color);
212 
222  void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color);
223 
233  void drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color);
234 
245  void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
246 
257  void fillTriangle ( int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color);
258 
268  void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size);
269 
274  void setRotation(uint8_t x);
275 
279  void invertDisplay(boolean i);
280 
284  int16_t width(void);
285 
289  int16_t height(void);
290 
291 
292  };
293 }
294 
295 
296 
297 #endif /* API_ROVER_DISPLAY_HPP_ */
void initialize(void)
Initializes the OLED display of the rover.
Definition: rover_display.cpp:53
int16_t height(void)
Returns width of the display.
Definition: rover_display.cpp:400
void setTextSize(uint8_t s)
Sets the text size to one of the predefined sizes.
Definition: rover_display.cpp:142
Adafruit_SSD1306 & getDisplay(void)
Returns the display object.
Definition: rover_display.cpp:217
void drawPixel(int16_t x, int16_t y, uint16_t color)
Draws a pixel.
Definition: rover_display.cpp:230
void fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draws a filled circle.
Definition: rover_display.cpp:260
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
Draws a triangle.
Definition: rover_display.cpp:320
void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color)
Draws a filled rounded rectangle.
Definition: rover_display.cpp:305
void invertDisplay(boolean i)
Inverts the display.
Definition: rover_display.cpp:380
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
Draws a filled triangle.
Definition: rover_display.cpp:335
void drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color)
Draws a circle.
Definition: rover_display.cpp:245
void drawBitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color)
Draws a bitmap on the OLED display.
Definition: rover_display.cpp:112
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Draws a rectangle to OLED display.
Definition: rover_display.cpp:202
int16_t width(void)
Returns height of the display.
Definition: rover_display.cpp:395
static const int WHITE_COLOR
Static definition to indicate WHITE color.
Definition: rover_display.hpp:80
void drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color)
Draws a rounded rectangle.
void drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg, uint8_t size)
Used to draw a character.
Definition: rover_display.cpp:350
rover Namespace contains classes to manage Rover sensors, gpio, buzzer, buttons, driving, utilities, and cloud.
Definition: rover_api.hpp:293
int ROVER_DISPLAY_INIT_
Flag to hold if RoverDisplay is initialized.
Definition: rover_display.hpp:68
void print(const char *string)
Prints a string to OLED display starting from cursor location.
Definition: rover_display.cpp:187
Adafruit_SSD1306 my_display
Object to handle OLED operations.
Definition: rover_display.hpp:63
RoverDisplay()
(Default) Constructor for RoverDisplay class
Definition: rover_display.cpp:47
void fillScreen(uint16_t color)
Fills the entire screen.
Definition: rover_display.cpp:290
void clearDisplay(void)
Clears the display.
Definition: rover_display.cpp:96
void display(void)
Displays the buffer contents on the OLED display.
Definition: rover_display.cpp:80
Contains the member functions to control OLED display on the Rover. This class is a wrapper API for A...
Definition: rover_display.hpp:57
void setTextColor(uint16_t c)
Sets the text color to either white or black.
Definition: rover_display.cpp:157
void setCursor(int16_t x, int16_t y)
Sets the cursor to a position in order to start typing text.
Definition: rover_display.cpp:127
static const int BLACK_COLOR
Static definition to indicate BLACK color.
Definition: rover_display.hpp:75
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color)
Draws a line.
Definition: rover_display.cpp:275
void setRotation(uint8_t x)
Used to rotate the display. Can be 0,1,2, or 3.
Definition: rover_display.cpp:365