Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/Leds.c
mmi 3852a5e0d8 Added BiColour led behaviour to menu
git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@360 05563f52-14a8-4384-a975-3d1654cca0fa
2017-12-13 14:02:34 +00:00

194 lines
5.7 KiB
C

// -----------------------------------------------------------------------------
/// @file Leds.c
/// @brief Description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision$
/// $Author$
/// $Date$
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @file Leds.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "gpio.h"
#include "platform.h"
#include "IODevice.h"
#include "Leds.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
struct Led
{
bool initialized;
struct IODevice* ioDevice;
};
struct Leds
{
bool initialized;
struct Led leds[LED_NUMBER_OF_LEDS];
};
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
static struct Leds self = { .initialized = false };
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus Led_construct(struct Gpio* onboardGreen, struct Gpio* onboardOrange, struct Gpio* bicolourGreen, struct Gpio* bicolourRed)
{
ErrorStatus returnValue = SUCCESS;
if (!self.initialized)
{
self.initialized = true;
self.leds[LED_ONBOARD_GREEN].ioDevice = &onboardGreen->device;
self.leds[LED_ONBOARD_GREEN].initialized = true;
self.leds[LED_ONBOARD_ORANGE].ioDevice = &onboardOrange->device;
self.leds[LED_ONBOARD_ORANGE].initialized = true;
self.leds[LED_BICOLOR_GREEN].ioDevice = &bicolourGreen->device;
self.leds[LED_BICOLOR_GREEN].initialized = true;
self.leds[LED_BICOLOR_RED].ioDevice = &bicolourRed->device;
self.leds[LED_BICOLOR_RED].initialized = true;
}
else
{
returnValue = ERROR;
}
return returnValue;
}
extern void Led_on(Led led)
{
char bufferTrue = (char)true;
char bufferFalse = (char)false;
if (self.initialized)
{
if (self.leds[led].initialized)
{
// IN case of the BICOLOUR LED, actually the GREEN and RED LEDs must be switched
if (led == LED_BICOLOR_ORANGE)
{
IODevice_write(self.leds[LED_BICOLOR_GREEN].ioDevice, &bufferTrue, 1);
IODevice_write(self.leds[LED_BICOLOR_RED].ioDevice, &bufferTrue, 1);
}
else if (led == LED_BICOLOR_GREEN)
{
IODevice_write(self.leds[LED_BICOLOR_GREEN].ioDevice, &bufferTrue, 1);
IODevice_write(self.leds[LED_BICOLOR_RED].ioDevice, &bufferFalse, 1);
}
else if (led == LED_BICOLOR_RED)
{
IODevice_write(self.leds[LED_BICOLOR_GREEN].ioDevice, &bufferFalse, 1);
IODevice_write(self.leds[LED_BICOLOR_RED].ioDevice, &bufferTrue, 1);
}
else
{
IODevice_write(self.leds[led].ioDevice, &bufferTrue, 1);
}
}
}
}
extern void Led_off(Led led)
{
char bufferFalse = (char)false;
if (self.initialized)
{
if (self.leds[led].initialized)
{
// IN case of the BICOLOUR ORANGE LED, actually the GREEN and RED LEDs must be switched
if (led == LED_BICOLOR_ORANGE)
{
IODevice_write(self.leds[LED_BICOLOR_GREEN].ioDevice, &bufferFalse, 1);
IODevice_write(self.leds[LED_BICOLOR_RED].ioDevice, &bufferFalse, 1);
}
else
{
IODevice_write(self.leds[led].ioDevice, &bufferFalse, 1);
}
}
}
}
extern bool Led_getStatus(Led led)
{
bool returnValue = false;
if (self.initialized)
{
if (self.leds[led].initialized)
{
// IN case of the BICOLOUR ORANGE LED, actually the GREEN and RED LEDs must be read
if (led == LED_BICOLOR_ORANGE)
{
char valueRed;
char valueGreen;
size_t al;
IODevice_read(self.leds[LED_BICOLOR_RED].ioDevice, &valueRed, 1, &al);
IODevice_read(self.leds[LED_BICOLOR_GREEN].ioDevice, &valueGreen, 1, &al);
if ((valueRed != (char)false) && (valueGreen != (char)false))
{
returnValue = true;
}
}
else
{
char value;
size_t al;
IODevice_read(self.leds[led].ioDevice, &value, 1, &al);
if (value != (char)false)
{
returnValue = true;
}
}
}
}
return returnValue;
}