Added buzzer
Added powerloss detector Added buzzer behaviour to system. Added powerloss behaviour to system Added french translation to menu texts git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@359 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -24,6 +24,7 @@ ARFLAGS = rs
|
||||
|
||||
OBJECTS = \
|
||||
ADCDevice.o \
|
||||
Buzzer.o \
|
||||
CachedStorage.o \
|
||||
CoverSolenoid.o \
|
||||
crc32.o \
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
/// @file Buzzer.h
|
||||
/// @brief File 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) 2015 Micro-Key bv
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/// @defgroup {group_name} {group_description}
|
||||
/// Description
|
||||
|
||||
/// @file Buzzer.h
|
||||
/// @ingroup {group_name}
|
||||
|
||||
#ifndef INC_BUZZER_H_
|
||||
#define INC_BUZZER_H_
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#define BUZZER_MIN_PULSEWIDTH_MS (10)
|
||||
#define BUZZER_KEYPAD_PULSEWIDTH_MS (60)
|
||||
#define BUZZER_ERROR_PULSEWIDTH_MS (1000)
|
||||
#define BUZZER_WARNING_PULSEWIDTH_MS (500)
|
||||
|
||||
#define BUZZER_KEYPAD_ACKNOWLEDGE(self) \
|
||||
Buzzer_singleTone(self, BUZZER_KEYPAD_PULSEWIDTH_MS)
|
||||
|
||||
#define BUZZER_ERROR(self) \
|
||||
Buzzer_start(self, BUZZER_ERROR_PULSEWIDTH_MS)
|
||||
|
||||
#define BUZZER_WARNING(self) \
|
||||
Buzzer_start(self, BUZZER_WARNING_PULSEWIDTH_MS)
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions.
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
struct Buzzer
|
||||
{
|
||||
// General
|
||||
bool initialized;
|
||||
struct Gpio* gpio;
|
||||
// Functionary properties
|
||||
unsigned int pulseWidth;
|
||||
// Task properties
|
||||
bool runTask;
|
||||
bool runPeriodically;
|
||||
SemaphoreHandle_t semaphore;
|
||||
xTaskHandle taskHandle;
|
||||
int taskPriority;
|
||||
uint16_t stackSize;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Buzzer_construct
|
||||
* Description of function
|
||||
*
|
||||
* @param self
|
||||
* @param gpio
|
||||
* @param taskPriority
|
||||
* @param stackSize
|
||||
*
|
||||
* @return ErrorStatus
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern ErrorStatus Buzzer_construct(struct Buzzer* self, struct Gpio* gpio, int taskPriority, uint16_t stackSize);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Buzzer_destruct
|
||||
* Description of function
|
||||
*
|
||||
* @param self
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern void Buzzer_destruct(struct Buzzer* self);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Buzzer_start
|
||||
* Description of function
|
||||
*
|
||||
* @param self
|
||||
* @param pulseWidth
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern void Buzzer_start(struct Buzzer* self, unsigned int pulseWidth);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Buzzer_stop
|
||||
* Description of function
|
||||
*
|
||||
* @param self
|
||||
* @param
|
||||
* @return void
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern void Buzzer_stop(struct Buzzer* self);
|
||||
|
||||
|
||||
/** ----------------------------------------------------------------------------
|
||||
* Buzzer_singleTone
|
||||
* Description of function
|
||||
*
|
||||
* @param self
|
||||
* @param pulseWidth
|
||||
* @return void
|
||||
*
|
||||
* @todo
|
||||
* -----------------------------------------------------------------------------
|
||||
*/
|
||||
extern void Buzzer_singleTone(struct Buzzer* self, unsigned int pulseWidth);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* INC_BUZZER_H_ */
|
||||
@@ -0,0 +1,182 @@
|
||||
// -----------------------------------------------------------------------------
|
||||
/// @file Buzzer.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 Buzzer.c
|
||||
/// @ingroup {group_name}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Include files
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#include "Buzzer.h"
|
||||
#include "gpio.h"
|
||||
#include "IODevice.h"
|
||||
#include "Logger.h"
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Constant and macro definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Type definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// File-scope variables
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static void BuzzerTask(void* parameters);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
ErrorStatus Buzzer_construct(struct Buzzer* self, struct Gpio* gpio, int taskPriority, uint16_t stackSize)
|
||||
{
|
||||
ErrorStatus returnValue = SUCCESS;
|
||||
|
||||
if (!self->initialized)
|
||||
{
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
if (gpio != NULL)
|
||||
{
|
||||
self->gpio = gpio;
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
}
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
self->taskPriority = taskPriority;
|
||||
self->stackSize = stackSize;
|
||||
}
|
||||
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
vSemaphoreCreateBinary(self->semaphore);
|
||||
self->runPeriodically = false;
|
||||
}
|
||||
|
||||
|
||||
BaseType_t ctReturn = 0;
|
||||
if (returnValue == SUCCESS)
|
||||
{
|
||||
self->runTask = true;
|
||||
ctReturn = xTaskCreate(BuzzerTask, (const char*)"BuzzerTask", self->stackSize, self, self->taskPriority, &self->taskHandle);
|
||||
}
|
||||
if (ctReturn != pdPASS)
|
||||
{
|
||||
returnValue = ERROR;
|
||||
LOGGER_ERROR(mainLog, "Buzzer task failed to create with error %d", (int)ctReturn);
|
||||
}
|
||||
else
|
||||
{
|
||||
self->initialized = true;
|
||||
LOGGER_INFO(mainLog, "Buzzer task created successfully");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
returnValue = ERROR;
|
||||
}
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern void Buzzer_destruct(struct Buzzer* self)
|
||||
{
|
||||
self->runTask = false;
|
||||
self->initialized = false;
|
||||
}
|
||||
|
||||
|
||||
void Buzzer_start(struct Buzzer* self, unsigned int pulseWidth)
|
||||
{
|
||||
if (self->initialized)
|
||||
{
|
||||
if (pulseWidth >= BUZZER_MIN_PULSEWIDTH_MS)
|
||||
{
|
||||
self->pulseWidth = pulseWidth;
|
||||
xSemaphoreGive(self->semaphore);
|
||||
self->runPeriodically = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Buzzer_stop(struct Buzzer* self)
|
||||
{
|
||||
if (self->initialized)
|
||||
{
|
||||
self->runPeriodically = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Buzzer_singleTone(struct Buzzer* self, unsigned int pulseWidth)
|
||||
{
|
||||
if (self->initialized)
|
||||
{
|
||||
self->runPeriodically = false;
|
||||
self->pulseWidth = pulseWidth;
|
||||
xSemaphoreGive(self->semaphore);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void BuzzerTask(void* parameters)
|
||||
{
|
||||
char cTrue = (char)true;
|
||||
char cFalse = (char)false;
|
||||
struct Buzzer* self = (struct Buzzer*)parameters;
|
||||
|
||||
while (self->runTask)
|
||||
{
|
||||
xSemaphoreTake(self->semaphore, portMAX_DELAY);
|
||||
|
||||
IODevice_write(&self->gpio->device, &cTrue, 1);
|
||||
vTaskDelay(self->pulseWidth);
|
||||
IODevice_write(&self->gpio->device, &cFalse, 1);
|
||||
vTaskDelay(self->pulseWidth);
|
||||
|
||||
// For periodic use, give semaphore
|
||||
if (self->runPeriodically)
|
||||
{
|
||||
xSemaphoreGive(self->semaphore);
|
||||
}
|
||||
}
|
||||
LOGGER_INFO(mainLog, "Deleting task %s", pcTaskGetTaskName(self->taskHandle));
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
@@ -42,9 +42,9 @@
|
||||
|
||||
struct HighVoltageDetection
|
||||
{
|
||||
struct IODevice* hv0;
|
||||
struct IODevice* hv1;
|
||||
struct IODevice* hv2;
|
||||
struct Gpio* hv0;
|
||||
struct Gpio* hv1;
|
||||
struct Gpio* hv2;
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
@@ -71,9 +71,9 @@ ErrorStatus HighVoltageDetection_construct(struct Gpio* HV0_gpio, struct Gpio* H
|
||||
|
||||
if (!hvDetection->initialized)
|
||||
{
|
||||
hvDetection->hv0 = &HV0_gpio->device;
|
||||
hvDetection->hv1 = &HV1_gpio->device;
|
||||
hvDetection->hv2 = &HV2_gpio->device;
|
||||
hvDetection->hv0 = HV0_gpio;
|
||||
hvDetection->hv1 = HV1_gpio;
|
||||
hvDetection->hv2 = HV2_gpio;
|
||||
hvDetection->initialized = true;
|
||||
}
|
||||
else
|
||||
@@ -102,10 +102,11 @@ bool HighVoltageDetection_isVoltagePresent(void)
|
||||
char value0;
|
||||
char value1;
|
||||
char value2;
|
||||
size_t al;
|
||||
|
||||
IODevice_read(hvDetection->hv0, &value0, 1, NULL);
|
||||
IODevice_read(hvDetection->hv1, &value1, 1, NULL);
|
||||
IODevice_read(hvDetection->hv2, &value2, 1, NULL);
|
||||
IODevice_read((struct IODevice*)hvDetection->hv0, &value0, 1, &al);
|
||||
IODevice_read((struct IODevice*)hvDetection->hv1, &value1, 1, &al);
|
||||
IODevice_read((struct IODevice*)hvDetection->hv2, &value2, 1, &al);
|
||||
|
||||
if (PCBA_getInstance()->pcba == PCBA_Tesla)
|
||||
{
|
||||
@@ -127,5 +128,6 @@ bool HighVoltageDetection_isVoltagePresent(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
@@ -157,8 +157,9 @@ extern bool Led_getStatus(Led led)
|
||||
{
|
||||
char valueRed;
|
||||
char valueGreen;
|
||||
IODevice_read(self.leds[LED_BICOLOR_RED].ioDevice, &valueRed, 1, NULL);
|
||||
IODevice_read(self.leds[LED_BICOLOR_GREEN].ioDevice, &valueGreen, 1, NULL);
|
||||
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;
|
||||
@@ -167,7 +168,8 @@ extern bool Led_getStatus(Led led)
|
||||
else
|
||||
{
|
||||
char value;
|
||||
IODevice_read(self.leds[led].ioDevice, &value, 1, NULL);
|
||||
size_t al;
|
||||
IODevice_read(self.leds[led].ioDevice, &value, 1, &al);
|
||||
if (value != (char)false)
|
||||
{
|
||||
returnValue = true;
|
||||
|
||||
Reference in New Issue
Block a user