瀏覽代碼

lol: Added exception when invalid argument is passed to method

Signed-off-by: Stefan Andritoiu <stefan.andritoiu@intel.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Andrei Vasiliu 9 年之前
父節點
當前提交
500e14663b
共有 3 個文件被更改,包括 16 次插入15 次删除
  1. 1
    3
      examples/java/LoL_exampleSample.java
  2. 9
    7
      src/lol/lol.cxx
  3. 6
    5
      src/lol/lol.h

+ 1
- 3
examples/java/LoL_exampleSample.java 查看文件

@@ -41,9 +41,7 @@ public class LoL_exampleSample {
41 41
 		int x = 0, y = 0;
42 42
 		while (true) {
43 43
 			// revert pixel
44
-			short pixel = sensor.getPixel(x, y);
45
-			pixel = (short) ((pixel == 0) ? 1 : 0);
46
-			sensor.setPixel(x, y, pixel);
44
+			sensor.setPixel(x, y, sensor.getPixel(x, y));
47 45
 
48 46
 			if (++x == 13) {
49 47
 				x = 0;

+ 9
- 7
src/lol/lol.cxx 查看文件

@@ -168,20 +168,22 @@ unsigned char* LoL::getFramebuffer() {
168 168
     return framebuffer;
169 169
 }
170 170
 
171
-unsigned char LoL::setPixel(int x, int y, unsigned char pixel)
171
+void LoL::setPixel(int x, int y, bool pixel)
172 172
 {
173 173
     if (x < 0 || y < 0 || x >= LOL_X || y >= LOL_Y)
174
-        return -1;
174
+        throw std::invalid_argument(std::string(__FUNCTION__) +
175
+                ": pixel coordinates out of bounds");
175 176
 
176
-    framebuffer[x + LOL_X*y] = (pixel == 0) ? 0 : 1;
177
-    return 0;
177
+    framebuffer[x + LOL_X*y] = (pixel) ? 1 : 0;
178
+    return;
178 179
 }
179 180
 
180
-unsigned char LoL::getPixel(int x, int y)
181
+bool LoL::getPixel(int x, int y)
181 182
 {
182 183
     if (x < 0 || y < 0 || x >= LOL_X || y >= LOL_Y)
183
-        return -1;
184
+        throw std::invalid_argument(std::string(__FUNCTION__) +
185
+                ": pixel coordinates out of bounds");
184 186
 
185
-    return (framebuffer[x + LOL_X*y] == 0) ? 0 : 1;
187
+    return (framebuffer[x + LOL_X*y] == 0) ? false : true;
186 188
 }
187 189
 

+ 6
- 5
src/lol/lol.h 查看文件

@@ -77,18 +77,19 @@ class LoL {
77 77
          * Gets a pixel at specified coordinates
78 78
          * @param x Coordinate x
79 79
          * @param y Coordinate y
80
-         * @return 1 if the pixel is on, 0 if off, -1 on error
80
+         * @return true if the pixel is on, false if off
81
+         * @throws std::invalid_argument if pixel is out of bounds
81 82
          */
82
-        unsigned char getPixel(int x, int y);
83
+        bool getPixel(int x, int y);
83 84
 
84 85
         /**
85 86
          * Sets a pixel at specified coordinates
86 87
          * @param x Coordinate x
87 88
          * @param y Coordinate y
88
-         * @param pixel 0 is off, 1 is on
89
-         * @return 0 if successful, -1 on error
89
+         * @param pixel false is off, true is on
90
+         * @throws std::invalid_argument if pixel is out of bounds
90 91
          */
91
-        unsigned char setPixel(int x, int y, unsigned char pixel);
92
+        void setPixel(int x, int y, bool pixel);
92 93
 
93 94
     private:
94 95
         mraa_gpio_context m_LoLCtx[14];