mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 01:10:22 +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;
|
int x = 0, y = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
// revert pixel
|
// revert pixel
|
||||||
short pixel = sensor.getPixel(x, y);
|
sensor.setPixel(x, y, sensor.getPixel(x, y));
|
||||||
pixel = (short) ((pixel == 0) ? 1 : 0);
|
|
||||||
sensor.setPixel(x, y, pixel);
|
|
||||||
|
|
||||||
if (++x == 13) {
|
if (++x == 13) {
|
||||||
x = 0;
|
x = 0;
|
||||||
|
@ -168,20 +168,22 @@ unsigned char* LoL::getFramebuffer() {
|
|||||||
return framebuffer;
|
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)
|
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;
|
framebuffer[x + LOL_X*y] = (pixel) ? 1 : 0;
|
||||||
return 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)
|
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
|
* Gets a pixel at specified coordinates
|
||||||
* @param x Coordinate x
|
* @param x Coordinate x
|
||||||
* @param y Coordinate y
|
* @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
|
* Sets a pixel at specified coordinates
|
||||||
* @param x Coordinate x
|
* @param x Coordinate x
|
||||||
* @param y Coordinate y
|
* @param y Coordinate y
|
||||||
* @param pixel 0 is off, 1 is on
|
* @param pixel false is off, true is on
|
||||||
* @return 0 if successful, -1 on error
|
* @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:
|
private:
|
||||||
mraa_gpio_context m_LoLCtx[14];
|
mraa_gpio_context m_LoLCtx[14];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user