mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
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>
This commit is contained in:
parent
fcb36276b7
commit
500e14663b
@ -41,9 +41,7 @@ public class LoL_exampleSample {
|
||||
int x = 0, y = 0;
|
||||
while (true) {
|
||||
// revert pixel
|
||||
short pixel = sensor.getPixel(x, y);
|
||||
pixel = (short) ((pixel == 0) ? 1 : 0);
|
||||
sensor.setPixel(x, y, pixel);
|
||||
sensor.setPixel(x, y, sensor.getPixel(x, y));
|
||||
|
||||
if (++x == 13) {
|
||||
x = 0;
|
||||
|
@ -168,20 +168,22 @@ unsigned char* LoL::getFramebuffer() {
|
||||
return framebuffer;
|
||||
}
|
||||
|
||||
unsigned char LoL::setPixel(int x, int y, unsigned char pixel)
|
||||
void LoL::setPixel(int x, int y, bool pixel)
|
||||
{
|
||||
if (x < 0 || y < 0 || x >= LOL_X || y >= LOL_Y)
|
||||
return -1;
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": pixel coordinates out of bounds");
|
||||
|
||||
framebuffer[x + LOL_X*y] = (pixel == 0) ? 0 : 1;
|
||||
return 0;
|
||||
framebuffer[x + LOL_X*y] = (pixel) ? 1 : 0;
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned char LoL::getPixel(int x, int y)
|
||||
bool LoL::getPixel(int x, int y)
|
||||
{
|
||||
if (x < 0 || y < 0 || x >= LOL_X || y >= LOL_Y)
|
||||
return -1;
|
||||
throw std::invalid_argument(std::string(__FUNCTION__) +
|
||||
": pixel coordinates out of bounds");
|
||||
|
||||
return (framebuffer[x + LOL_X*y] == 0) ? 0 : 1;
|
||||
return (framebuffer[x + LOL_X*y] == 0) ? false : true;
|
||||
}
|
||||
|
||||
|
@ -77,18 +77,19 @@ class LoL {
|
||||
* Gets a pixel at specified coordinates
|
||||
* @param x Coordinate x
|
||||
* @param y Coordinate y
|
||||
* @return 1 if the pixel is on, 0 if off, -1 on error
|
||||
* @return true if the pixel is on, false if off
|
||||
* @throws std::invalid_argument if pixel is out of bounds
|
||||
*/
|
||||
unsigned char getPixel(int x, int y);
|
||||
bool getPixel(int x, int y);
|
||||
|
||||
/**
|
||||
* Sets a pixel at specified coordinates
|
||||
* @param x Coordinate x
|
||||
* @param y Coordinate y
|
||||
* @param pixel 0 is off, 1 is on
|
||||
* @return 0 if successful, -1 on error
|
||||
* @param pixel false is off, true is on
|
||||
* @throws std::invalid_argument if pixel is out of bounds
|
||||
*/
|
||||
unsigned char setPixel(int x, int y, unsigned char pixel);
|
||||
void setPixel(int x, int y, bool pixel);
|
||||
|
||||
private:
|
||||
mraa_gpio_context m_LoLCtx[14];
|
||||
|
Loading…
x
Reference in New Issue
Block a user