Baby Monitoring System
Loading...
Searching...
No Matches
ParentSide.c File Reference

Defines the parent side of a baby monitoring system. More...

#include <esp_now.h>
#include <WiFi.h>
#include <LiquidCrystal_I2C.h>
#include <string.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/queue.h>
#include <freertos/semphr.h>

Data Structures

struct  SensorInfo
 Stores information associated with a sensor. More...
 

Macros

#define NUM_SENSORS   6 /**> Number of sensors in the system */
 
#define BUZZER_PIN   9 /**> Buzzer pin number */
 
#define X_PIN   13
 
#define Y_PIN   14
 
#define SW_PIN   17
 
#define GO_UP(y)   ((y) < 500)
 
#define GO_DOWN(y)   ((y) == 4095)
 
#define GO_LEFT(x)   ((x) < 500)
 

Enumerations

enum  sensorIDs {
  NOISE , TEMP , HUMIDITY , MOTION ,
  WATER , LIGHT
}
 Defines the sensor IDs. More...
 
enum  lcdView {
  MENU , SENSOR_MENU , SONG_MENU , SENSOR_VIEW ,
  SONG_VIEW , ALARM
}
 Defines the possible LCD view options. More...
 

Functions

void IRAM_ATTR onTimer32Hz ()
 ISR for Timer. Triggers buzzAlarmTask to run.
 
void IRAM_ATTR onDataRecv (const uint8_t *mac, const uint8_t *data, int len)
 ISR that gets called when a message is received. Updates sensor value.
 
void onDataSent (const uint8_t *mac_addr, esp_now_send_status_t status)
 Callback function for sending data to the baby board.
 
bool debounce (int *lastInputTime)
 Checks if the specified debounce interval has passed since the last recorded input time.
 
void receiveDataTask (void *arg)
 FreeRTOS task that handles data from the queue, parses sensor values, and checks if an alarm should trigger.
 
void moveCursor ()
 Moves the cursor on the LCD between lines 0 and 1.
 
void printMenu ()
 Prints the main menu screen to the LCD and handles navigation logic.
 
void printSensorPreviews ()
 Prints two sensor names to the LCD.
 
void printSongPreviews ()
 Prints two song names to the LCD.
 
void printSensorMenu ()
 Prints the sensor menu screen to the LCD and handles navigation logic.
 
void printSensorView ()
 Prints individual sensor info to the LCD and handles navigation logic.
 
void printSongMenu ()
 Prints the song menu screen to the LCD and handles navigation logic.
 
void printSongView ()
 Prints the selected song info to the LCD screen and handles navigation logic.
 
void printAlarm ()
 Prints the alarm display to the LCD screen and handles navigation logic.
 
void buzzAlarmTask (void *arg)
 FreeRTOS task that handles buzzing the alarm.
 
void lcdDisplayTask (void *arg)
 FreeRTOS task that handles LCD display updates.
 
bool checkNoise (float value)
 Checks if the given sensor value should trigger an alarm for noise.
 
bool checkTempurature (float value)
 Checks if the given sensor value should trigger an alarm for temperature.
 
bool checkHumidity (float value)
 Checks if the given sensor value should trigger an alarm for humidity.
 
bool checkMotion (float value)
 Checks if the given sensor value should trigger an alarm for motion.
 
bool checkWater (float value)
 Checks if the given sensor value should trigger an alarm for water.
 
bool checkLight (float value)
 Checks if the given sensor value should trigger an alarm for light.
 
LiquidCrystal_I2C lcd (0x27, 20, 4)
 
void setup ()
 
void loop ()
 

Variables

uint8_t broadcastAddress [6] = {0xDC, 0xDA, 0x0C, 0x21, 0x5B, 0x94}
 
volatile char incomingMessage [10]
 
SensorInfo sensorValues [6]
 
char * songs [3]
 Array of song names.
 
enum lcdView currLcdView = MENU
 
int sensorOnTopLcdLineID = 0
 
int songOnTopLcdLineID = 0
 Song ID for the top line of the LCD in the song menu.
 
int cursorLine = 0
 
int lastYInputTime = 0
 
int lastXInputTime = 0
 
int lastSwInputTime = 0
 
hw_timer_t * timer32Hz = NULL
 Hardware timer for 32Hz timing.
 
TaskHandle_t lcdDisplayTaskHandle
 
TaskHandle_t buzzAlarmTaskHandle
 Task handle for the buzzer alarm task.
 
TaskHandle_t receiveDataTaskHandle
 Task handle for the data reception task.
 
QueueHandle_t sensorDataQueue
 Queue handle for sensor data.
 
SemaphoreHandle_t lcdSemaphore
 Semaphore handle for LCD access.
 

Detailed Description

Defines the parent side of a baby monitoring system.

This file is intended to be uploaded to an Arduino Nano ESP32 board. It allows viewing values or sensors sent from the baby side, triggering an alarm if a value is in a bad setting, and sending a song to the baby.

Authors
Caitlyn Rawlings, Hao Tian
Date
8/12/24

Macro Definition Documentation

◆ BUZZER_PIN

#define BUZZER_PIN   9 /**> Buzzer pin number */

◆ GO_DOWN

#define GO_DOWN ( y)    ((y) == 4095)

Joystick down movement

◆ GO_LEFT

#define GO_LEFT ( x)    ((x) < 500)

Joystick left movement

◆ GO_UP

#define GO_UP ( y)    ((y) < 500)

Joystick up movement

◆ NUM_SENSORS

#define NUM_SENSORS   6 /**> Number of sensors in the system */

◆ SW_PIN

#define SW_PIN   17

Joystick SW pin

◆ X_PIN

#define X_PIN   13

Joystick VRX pin

◆ Y_PIN

#define Y_PIN   14

Joystick VRY pin

Enumeration Type Documentation

◆ lcdView

enum lcdView

Defines the possible LCD view options.

Enumerator
MENU 
SENSOR_MENU 

Menu displays all the sensor names.

SONG_MENU 

Menu displays all the song names.

SENSOR_VIEW 
SONG_VIEW 

View of one song and its value.

ALARM 

Display when an alarm is triggered.

◆ sensorIDs

enum sensorIDs

Defines the sensor IDs.

Enumerator
NOISE 
TEMP 
HUMIDITY 
MOTION 
WATER 
LIGHT 

Function Documentation

◆ buzzAlarmTask()

void buzzAlarmTask ( void * arg)

FreeRTOS task that handles buzzing the alarm.

This task manages the buzzer to sound the alarm at regular intervals. The buzzer is activated and deactivated to create an audible alarm when triggered by an interrupt.

Parameters
argPointer to task argument (unused).

◆ checkHumidity()

bool checkHumidity ( float value)

Checks if the given sensor value should trigger an alarm for humidity.

This function evaluates the sensor value and determines if it falls outside the acceptable range for humidity. If the value is out of range, the alarm is triggered, and the current LCD view is updated to the alarm screen.

Parameters
valueThe sensor value to check.
Returns
True if the sensor value triggers an alarm, otherwise false.

◆ checkLight()

bool checkLight ( float value)

Checks if the given sensor value should trigger an alarm for light.

This function evaluates the sensor value and determines if it indicates a high enough light level. If so, the alarm is triggered, and the current LCD view is updated to the alarm screen.

Parameters
valueThe sensor value to check.
Returns
True if the sensor value triggers an alarm, otherwise false.

◆ checkMotion()

bool checkMotion ( float value)

Checks if the given sensor value should trigger an alarm for motion.

This function evaluates the sensor value and determines if it indicates motion. If motion is detected, the alarm is triggered, and the current LCD view is updated to the alarm screen.

Parameters
valueThe sensor value to check.
Returns
True if the sensor value triggers an alarm, otherwise false.

◆ checkNoise()

bool checkNoise ( float value)

Checks if the given sensor value should trigger an alarm for noise.

This function evaluates the sensor value and determines if it exceeds the threshold for noise. If the threshold is exceeded, the alarm is triggered, and the current LCD view is updated to the alarm screen.

Parameters
valueThe sensor value to check.
Returns
True if the sensor value triggers an alarm, otherwise false.

◆ checkTempurature()

bool checkTempurature ( float value)

Checks if the given sensor value should trigger an alarm for temperature.

This function evaluates the sensor value and determines if it falls outside the acceptable range for temperature. If the value is out of range, the alarm is triggered, and the current LCD view is updated to the alarm screen.

Parameters
valueThe sensor value to check.
Returns
True if the sensor value triggers an alarm, otherwise false.

◆ checkWater()

bool checkWater ( float value)

Checks if the given sensor value should trigger an alarm for water.

This function evaluates the sensor value and determines if it indicates a high enough water level. If so, the alarm is triggered, and the current LCD view is updated to the alarm screen.

Parameters
valueThe sensor value to check.
Returns
True if the sensor value triggers an alarm, otherwise false.

◆ debounce()

bool debounce ( int * lastInputTime)

Checks if the specified debounce interval has passed since the last recorded input time.

Parameters
lastInputTimePointer to the last input time.
Returns
True if sufficient time has elapsed, otherwise false.

◆ lcd()

LiquidCrystal_I2C lcd ( 0x27 ,
20 ,
4  )

◆ lcdDisplayTask()

void lcdDisplayTask ( void * arg)

FreeRTOS task that handles LCD display updates.

This task manages the LCD display based on the current view. It updates the display according to the state of the currLcdView variable and handles the printing of menus and sensor/song information.

Parameters
argPointer to task argument (unused).

◆ loop()

void loop ( )

◆ moveCursor()

void moveCursor ( )

Moves the cursor on the LCD between lines 0 and 1.

This function moves the cursor on the LCD display from line 0 to line 1 or from line 1 to line 0.

◆ onDataRecv()

void IRAM_ATTR onDataRecv ( const uint8_t * mac,
const uint8_t * data,
int len )

ISR that gets called when a message is received. Updates sensor value.

Parameters
macPointer to the MAC address of the sender.
dataPointer to the received data.
lenLength of the received data.

This ISR handles incoming ESP-NOW messages by copying data into incomingMessage and sending it to sensorDataQueue.

◆ onDataSent()

void onDataSent ( const uint8_t * mac_addr,
esp_now_send_status_t status )

Callback function for sending data to the baby board.

Parameters
mac_addrPointer to the MAC address of the recipient.
statusStatus of the send operation.

◆ onTimer32Hz()

void IRAM_ATTR onTimer32Hz ( )

ISR for Timer. Triggers buzzAlarmTask to run.

This ISR is triggered by a timer interrupt at 32 Hz. It signals the buzzAlarmTask to run.

◆ printAlarm()

void printAlarm ( )

Prints the alarm display to the LCD screen and handles navigation logic.

This function shows which sensors triggered the alarm and allows the user to reset the alarm or send a song in response. It updates the LCD display based on user input and sensor status.

◆ printMenu()

void printMenu ( )

Prints the main menu screen to the LCD and handles navigation logic.

This function displays the main menu options on the LCD and handles user inputs to navigate between menu options.

◆ printSensorMenu()

void printSensorMenu ( )

Prints the sensor menu screen to the LCD and handles navigation logic.

This function displays the sensor menu options on the LCD and manages user navigation within the menu.

◆ printSensorPreviews()

void printSensorPreviews ( )

Prints two sensor names to the LCD.

This function retrieves and displays the names of two sensors on the LCD.

◆ printSensorView()

void printSensorView ( )

Prints individual sensor info to the LCD and handles navigation logic.

This function displays detailed information about a selected sensor and manages user navigation to go back to the sensor menu.

◆ printSongMenu()

void printSongMenu ( )

Prints the song menu screen to the LCD and handles navigation logic.

This function displays the song menu options on the LCD and manages user navigation within the menu.

◆ printSongPreviews()

void printSongPreviews ( )

Prints two song names to the LCD.

This function retrieves and displays the names of two songs on the LCD.

◆ printSongView()

void printSongView ( )

Prints the selected song info to the LCD screen and handles navigation logic.

This function displays the currently selected song and allows the user to send the song to the baby or return to the song menu. It handles button presses to send the song or navigate back.

◆ receiveDataTask()

void receiveDataTask ( void * arg)

FreeRTOS task that handles data from the queue, parses sensor values, and checks if an alarm should trigger.

Parameters
argPointer to task argument (unused).

This task processes sensor data from sensorDataQueue, parses the data to extract sensor IDs and values, updates sensor information, and checks for alarm conditions.

◆ setup()

void setup ( )

Variable Documentation

◆ broadcastAddress

uint8_t broadcastAddress[6] = {0xDC, 0xDA, 0x0C, 0x21, 0x5B, 0x94}

◆ buzzAlarmTaskHandle

TaskHandle_t buzzAlarmTaskHandle

Task handle for the buzzer alarm task.

This handle is used to manage the task responsible for triggering the buzzer alarm.

◆ currLcdView

enum lcdView currLcdView = MENU

◆ cursorLine

int cursorLine = 0

◆ incomingMessage

volatile char incomingMessage[10]

◆ lastSwInputTime

int lastSwInputTime = 0

◆ lastXInputTime

int lastXInputTime = 0

◆ lastYInputTime

int lastYInputTime = 0

◆ lcdDisplayTaskHandle

TaskHandle_t lcdDisplayTaskHandle

◆ lcdSemaphore

SemaphoreHandle_t lcdSemaphore

Semaphore handle for LCD access.

This handle is used to manage access to the LCD display, ensuring synchronized updates.

◆ receiveDataTaskHandle

TaskHandle_t receiveDataTaskHandle

Task handle for the data reception task.

This handle is used to manage the task responsible for receiving data from external sources.

◆ sensorDataQueue

QueueHandle_t sensorDataQueue

Queue handle for sensor data.

This handle is used to manage the queue that stores sensor data for processing.

◆ sensorOnTopLcdLineID

int sensorOnTopLcdLineID = 0

◆ sensorValues

SensorInfo sensorValues[6]
Initial value:
= {
{NOISE, "Noise level", 0, checkNoise, false},
{TEMP, "Temperature", 0, checkTemperature, false},
{HUMIDITY, "Humidity", 0, checkHumidity, false},
{MOTION, "Motion", 0, checkMotion, false},
{WATER, "Water level", 0, checkWater, false},
{LIGHT, "Light level", 0, checkLight, false}
}
@ MOTION
Definition ParentSide.c:58
@ TEMP
Definition ParentSide.c:58
@ WATER
Definition ParentSide.c:58
@ NOISE
Definition ParentSide.c:58
@ LIGHT
Definition ParentSide.c:58
@ HUMIDITY
Definition ParentSide.c:58
bool checkMotion(float value)
Checks if the given sensor value should trigger an alarm for motion.
Definition ParentSide.c:801
bool checkWater(float value)
Checks if the given sensor value should trigger an alarm for water.
Definition ParentSide.c:823
bool checkHumidity(float value)
Checks if the given sensor value should trigger an alarm for humidity.
Definition ParentSide.c:779
bool checkNoise(float value)
Checks if the given sensor value should trigger an alarm for noise.
Definition ParentSide.c:733
bool checkLight(float value)
Checks if the given sensor value should trigger an alarm for light.
Definition ParentSide.c:845

◆ songOnTopLcdLineID

int songOnTopLcdLineID = 0

Song ID for the top line of the LCD in the song menu.

This variable specifies which song will be displayed on the top line of the LCD when the song menu is shown.

◆ songs

char* songs[3]
Initial value:
= {
"Little Star",
"Mary's Lamb",
"Wheels on Bus"
}

Array of song names.

This array contains the names of the songs available for selection.

◆ timer32Hz

hw_timer_t* timer32Hz = NULL

Hardware timer for 32Hz timing.

This pointer represents a hardware timer configured to operate at 32Hz.