Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions firmware/powerboard1/code/app/housingMonitor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* housingMonitor.c
*
* Created on: Feb 14, 2020
* Author: Shuhang Tan
*/

#include "housingMonitor.h"
#include "ADC.h"


#define threshold 2048
static housingMonitor_housingStatus_E HStatus;

housingMonitor_housingStatus_E housingMonitor_getHousingStatus(const housingMonitor_housing_E housing)
{
housingMonitor_housingStatus_E HStatus_copy = HOUSINGMONITOR_HOUSINGSTATUS_NO_LEAK;
if (housing == HOUSINGMONITOR_HOUSING_MAIN)
{
HStatus_copy = HStatus;
}
return HStatus_copy;
}

//Actual detection of leakage
void housingMonitor_run(const housingMonitor_housing_E housing)
{
uint16_t sensorValue = 0;
if (housing == HOUSINGMONITOR_HOUSING_MAIN)
{
sensorValue = ADC_getChannelData(ADC_CHANNEL_WATER_SENSOR);
}
HStatus = HOUSINGMONITOR_HOUSINGSTATUS_NO_LEAK;
if (sensorValue >= threshold)
{
HStatus = HOUSINGMONITOR_HOUSINGSTATUS_LEAK;
}
/*//Testing code for leakage detection
housingMonitor_housing_E housing = HOUSINGMONITOR_HOUSING_MAIN;
if (housingMonitor_getHousingStatus(housing) == HOUSINGMONITOR_HOUSINGSTATUS_LEAK)
{
//Do something here.
//Testing: using GPIO, if leaking happened Pin PA2 output high, else is low
//GPIOA->ODR |= GPIO_PIN_2;

}
//else GPIOA->ODR &= ~GPIO_PIN_2;
*/
}
29 changes: 29 additions & 0 deletions firmware/powerboard1/code/app/housingMonitor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* housingMonitor.h
*
* Created on: Feb 14, 2020
* Author: me
*/

#ifndef POWERBOARD1_CODE_APP_HOUSINGMONITOR_H_
#define POWERBOARD1_CODE_APP_HOUSINGMONITOR_H_

typedef enum
{
HOUSINGMONITOR_HOUSINGSTATUS_NO_LEAK = 0,
HOUSINGMONITOR_HOUSINGSTATUS_LEAK = 1
} housingMonitor_housingStatus_E;


typedef enum
{
HOUSINGMONITOR_HOUSING_MAIN = 0
} housingMonitor_housing_E;

//void housingMonitor_init(void);
housingMonitor_housingStatus_E housingMonitor_getHousingStatus(const housingMonitor_housing_E housing);
void housingMonitor_run(const housingMonitor_housing_E housing);

#endif /* POWERBOARD1_CODE_APP_HOUSINGMONITOR_H_ */


Loading