Files
hsb/S - Software/0 - HSB MRTS Kathode-MCP/3 - Implementation/0 - Code/HAL/src/storm700.c
2017-10-17 07:40:31 +00:00

133 lines
3.8 KiB
C

// -----------------------------------------------------------------------------
/// @file storm700.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 storm700.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "storm700.h"
#include "keypadMatrix.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
static char keyLookupTable[STORM700_NUMBER_OF_ROWS][STORM700_NUMBER_OF_COLUMNS] =
{
{ '1', '2', '3', 'X' },
{ '4', '5', '6', 'U' },
{ '7', '8', '9', 'D' },
{ 'L', '0', 'R', 'E' }
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
static ErrorStatus read(const struct KeyboardDevice* self, char* buffer, Keypad_KeyState* keyState);
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus Storm700_construct(struct Storm700* self, const struct IODevice* device)
{
ErrorStatus returnValue = SUCCESS;
if (!self->initialized)
{
if (device != NULL)
{
self->device = device;
struct KeyboardDeviceParameters kbParameters;
kbParameters.numberOfKeys = STORM700_NUMBER_OF_ROWS * STORM700_NUMBER_OF_COLUMNS;
KeyboardDevice_construct(&self->keyboardDevice, &kbParameters, read);
self->initialized = true;
}
}
return returnValue;
}
void Storm700_destruct(struct Storm700* self)
{
self->initialized= false;
self->device = NULL;
}
ErrorStatus Storm700_readKey(const struct Storm700* self, char* key, Keypad_KeyState* keyState)
{
ErrorStatus returnValue = SUCCESS;
if (self->initialized)
{
size_t actualLength;
char buffer[sizeof(struct KeypadQueueItem) / sizeof(char)];
returnValue = IODevice_read(self->device, buffer, sizeof(struct KeypadQueueItem) / sizeof(char), &actualLength);
if (returnValue == SUCCESS)
{
struct KeypadQueueItem* rxQueueItem = (struct KeypadQueueItem*)buffer;
*key = keyLookupTable[rxQueueItem->rowCoordinate][rxQueueItem->columnCoordinate];
*keyState = rxQueueItem->keyEvent;
}
else
{
returnValue = ERROR;
}
}
else
{
returnValue = ERROR;
}
return returnValue;
}
static ErrorStatus read(const struct KeyboardDevice* self, char* buffer, Keypad_KeyState* keyState)
{
return Storm700_readKey((const struct Storm700*)self, buffer, keyState);
}