Craig Evans / N5110

Dependents:   LV7_LCDtest LV7_Grupa5_Tim003_Zadatak1 lv7_Grupa5_Tim008_zad1 LV7_PAI_Grupa5_tim10_Zadatak1 ... more

Files at this revision

API Documentation at this revision

Comitter:
valavanisalex
Date:
Thu Feb 16 15:58:48 2017 +0000
Parent:
32:c9643726edca
Child:
35:2d5931a66fba
Commit message:
Use enumerations to make fill-types more self-explanatory

Changed in this revision

N5110.cpp Show annotated file Show diff for this revision Revisions of this file
N5110.h Show annotated file Show diff for this revision Revisions of this file
--- a/N5110.cpp	Thu Feb 16 15:41:00 2017 +0000
+++ b/N5110.cpp	Thu Feb 16 15:58:48 2017 +0000
@@ -322,7 +322,7 @@
 void N5110:: drawCircle(unsigned int const x0,
                         unsigned int const y0,
                         unsigned int const radius,
-                        unsigned int const fill)
+                        FillType const     fill)
 {
     // from http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
     int x = radius;
@@ -332,7 +332,7 @@
     while(x >= y) {
 
         // if transparent, just draw outline
-        if (fill == 0) {
+        if (fill == FILL_TRANSPARENT) {
             setPixel( x + x0,  y + y0);
             setPixel(-x + x0,  y + y0);
             setPixel( y + x0,  x + y0);
@@ -343,7 +343,7 @@
             setPixel(-x + x0, -y + y0);
         } else {  // drawing filled circle, so draw lines between points at same y value
 
-            int type = (fill==1) ? 1:0;  // black or white fill
+            int type = (fill==FILL_BLACK) ? 1:0;  // black or white fill
 
             drawLine(x+x0,y+y0,-x+x0,y+y0,type);
             drawLine(y+x0,x+y0,-y+x0,x+y0,type);
@@ -418,15 +418,15 @@
                      unsigned int const y0,
                      unsigned int const width,
                      unsigned int const height,
-                     unsigned int const fill)
+                     FillType const     fill)
 {
-    if (fill == 0) { // transparent, just outline
+    if (fill == FILL_TRANSPARENT) { // transparent, just outline
         drawLine(x0,y0,x0+(width-1),y0,1);  // top
         drawLine(x0,y0+(height-1),x0+(width-1),y0+(height-1),1);  // bottom
         drawLine(x0,y0,x0,y0+(height-1),1);  // left
         drawLine(x0+(width-1),y0,x0+(width-1),y0+(height-1),1);  // right
     } else { // filled rectangle
-        int type = (fill==1) ? 1:0;  // black or white fill
+        int type = (fill==FILL_BLACK) ? 1:0;  // black or white fill
         for (int y = y0; y<y0+height; y++) {  // loop through rows of rectangle
             drawLine(x0,y,x0+(width-1),y,type);  // draw line across screen
         }
--- a/N5110.h	Thu Feb 16 15:41:00 2017 +0000
+++ b/N5110.h	Thu Feb 16 15:58:48 2017 +0000
@@ -32,6 +32,13 @@
 #define HEIGHT 48
 #define BANKS 6
 
+/// Fill types for 2D shapes
+enum FillType {
+    FILL_TRANSPARENT, ///< Transparent with outline
+    FILL_BLACK,       ///< Filled black
+    FILL_WHITE,       ///< Filled white (no outline)
+};
+
 /** N5110 Class
 @brief Library for interfacing with Nokia 5110 LCD display (https://www.sparkfun.com/products/10168) using the hardware SPI on the mbed.
 @brief The display is powered from a GPIO pin meaning it can be controlled via software.  The LED backlight is also software-controllable (via PWM pin).
@@ -151,21 +158,20 @@
 
         lcd.clear();
         // example of how to draw circles
-        lcd.drawCircle(WIDTH/2,HEIGHT/2,20,1);  // x,y,radius,black fill
-        lcd.drawCircle(WIDTH/2,HEIGHT/2,10,2);  // x,y,radius,white fill
-        lcd.drawCircle(WIDTH/2,HEIGHT/2,30,0);  // x,y,radius,transparent with outline
+        lcd.drawCircle(WIDTH/2,HEIGHT/2,20,FILL_BLACK);  // x,y,radius,black fill
+        lcd.drawCircle(WIDTH/2,HEIGHT/2,10,FILL_WHITE);  // x,y,radius,white fill
+        lcd.drawCircle(WIDTH/2,HEIGHT/2,30,FILL_TRANSPARENT);  // x,y,radius,transparent with outline
         lcd.refresh();  // refresh after drawing shapes
         wait(5.0);
 
         lcd.clear();
         // example of how to draw rectangles
         //          origin x,y,width,height,type
-        lcd.drawRect(10,10,50,30,1);  // filled black rectangle
-        lcd.drawRect(15,15,20,10,2);  // filled white rectange (no outline)
-        lcd.drawRect(2,2,70,40,0);    // transparent, just outline
+        lcd.drawRect(10,10,50,30,FILL_BLACK);  // filled black rectangle
+        lcd.drawRect(15,15,20,10,FILL_WHITE);  // filled white rectange (no outline)
+        lcd.drawRect(2,2,70,40,  FILL_TRANSPARENT);    // transparent, just outline
         lcd.refresh();  // refresh after drawing shapes
         wait(5.0);
-
     }
 }
 
@@ -342,15 +348,15 @@
     *   This function draws a circle at the specified origin with specified radius in the screen buffer
     *   Uses the midpoint circle algorithm.
     *   @see http://en.wikipedia.org/wiki/Midpoint_circle_algorithm
-    *   @param  x0 - x-coordinate of centre
-    *   @param  y0 - y-coordinate of centre
+    *   @param  x0     - x-coordinate of centre
+    *   @param  y0     - y-coordinate of centre
     *   @param  radius - radius of circle in pixels
-    *   @param  fill - 0 transparent (w/outline), 1 filled black, 2 filled white (wo/outline)
+    *   @param  fill   - fill-type for the shape
     */
     void drawCircle(unsigned int const x0,
                     unsigned int const y0,
                     unsigned int const radius,
-                    unsigned int const fill);
+                    FillType const     fill);
 
     /** Draw Line
     *
@@ -374,13 +380,13 @@
     *   @param  y0 - y-coordinate of origin (top-left)
     *   @param  width - width of rectangle
     *   @param  height - height of rectangle
-    *   @param  fill - 0 transparent (w/outline), 1 filled black, 2 filled white (wo/outline)
+    *   @param  fill   - fill-type for the shape
     */
     void drawRect(unsigned int const x0,
                   unsigned int const y0,
                   unsigned int const width,
                   unsigned int const height,
-                  unsigned int const fill);
+                  FillType const     fill);
 
 private:
 // methods