From dbf4b5a42f6bd6818708b878eae5bff1bf6a5e76 Mon Sep 17 00:00:00 2001 From: tiagosandoval Date: Wed, 21 May 2025 20:17:36 -0300 Subject: [PATCH] actualizacion --- modules/code/code.cpp | 108 ------ modules/code/code.h | 24 -- modules/date_and_time/date_and_time.cpp | 48 --- modules/date_and_time/date_and_time.h | 19 -- modules/display/display.cpp | 8 - modules/event_log/event_log.cpp | 117 ------- modules/event_log/event_log.h | 31 -- modules/fire_alarm/fire_alarm.cpp | 149 --------- modules/fire_alarm/fire_alarm.h | 21 -- modules/gas_sensor/gas_sensor.cpp | 38 --- modules/gas_sensor/gas_sensor.h | 18 - modules/matrix_keypad/matrix_keypad.cpp | 141 -------- modules/matrix_keypad/matrix_keypad.h | 17 - modules/pc_serial_com/pc_serial_com.cpp | 310 ------------------ modules/pc_serial_com/pc_serial_com.h | 21 -- modules/siren/siren.cpp | 61 ---- modules/siren/siren.h | 19 -- .../smart_home_system/smart_home_system.cpp | 10 +- modules/strobe_light/strobe_light.cpp | 60 ---- modules/strobe_light/strobe_light.h | 19 -- .../temperature_sensor/temperature_sensor.cpp | 86 ----- .../temperature_sensor/temperature_sensor.h | 20 -- modules/user_interface/user_interface.cpp | 117 +------ modules/user_interface/user_interface.h | 8 - 24 files changed, 6 insertions(+), 1464 deletions(-) delete mode 100644 modules/code/code.cpp delete mode 100644 modules/code/code.h delete mode 100644 modules/date_and_time/date_and_time.cpp delete mode 100644 modules/date_and_time/date_and_time.h delete mode 100644 modules/event_log/event_log.cpp delete mode 100644 modules/event_log/event_log.h delete mode 100644 modules/fire_alarm/fire_alarm.cpp delete mode 100644 modules/fire_alarm/fire_alarm.h delete mode 100644 modules/gas_sensor/gas_sensor.cpp delete mode 100644 modules/gas_sensor/gas_sensor.h delete mode 100644 modules/matrix_keypad/matrix_keypad.cpp delete mode 100644 modules/matrix_keypad/matrix_keypad.h delete mode 100644 modules/pc_serial_com/pc_serial_com.cpp delete mode 100644 modules/pc_serial_com/pc_serial_com.h delete mode 100644 modules/siren/siren.cpp delete mode 100644 modules/siren/siren.h delete mode 100644 modules/strobe_light/strobe_light.cpp delete mode 100644 modules/strobe_light/strobe_light.h delete mode 100644 modules/temperature_sensor/temperature_sensor.cpp delete mode 100644 modules/temperature_sensor/temperature_sensor.h diff --git a/modules/code/code.cpp b/modules/code/code.cpp deleted file mode 100644 index 818255e..0000000 --- a/modules/code/code.cpp +++ /dev/null @@ -1,108 +0,0 @@ -//=====[Libraries]============================================================= - -#include "mbed.h" -#include "arm_book_lib.h" - -#include "code.h" - -#include "user_interface.h" -#include "pc_serial_com.h" -#include "date_and_time.h" -#include "temperature_sensor.h" -#include "gas_sensor.h" -#include "matrix_keypad.h" - -//=====[Declaration of private defines]======================================== - -//=====[Declaration of private data types]===================================== - -//=====[Declaration and initialization of public global objects]=============== - -//=====[Declaration of external public global variables]======================= - -extern char codeSequenceFromUserInterface[CODE_NUMBER_OF_KEYS]; -extern char codeSequenceFromPcSerialCom[CODE_NUMBER_OF_KEYS]; - -//=====[Declaration and initialization of private global variables]============ - -static int numberOfIncorrectCodes = 0; -static char codeSequence[CODE_NUMBER_OF_KEYS] = { '1', '8', '0', '5' }; - -//=====[Declarations (prototypes) of private functions]======================== - -static bool codeMatch( char* codeToCompare ); -static void codeDeactivate(); - -//=====[Implementations of public functions]=================================== - -void codeWrite( char* newCodeSequence ) -{ - int i; - for (i = 0; i < CODE_NUMBER_OF_KEYS; i++) { - codeSequence[i] = newCodeSequence[i]; - } -} - -bool codeMatchFrom( codeOrigin_t codeOrigin ) -{ - bool codeIsCorrect = false; - switch (codeOrigin) { - case CODE_KEYPAD: - if( userInterfaceCodeCompleteRead() ) { - codeIsCorrect = codeMatch(codeSequenceFromUserInterface); - userInterfaceCodeCompleteWrite(false); - if ( codeIsCorrect ) { - codeDeactivate(); - } else { - incorrectCodeStateWrite(ON); - numberOfIncorrectCodes++; - } - } - - - break; - case CODE_PC_SERIAL: - if( pcSerialComCodeCompleteRead() ) { - codeIsCorrect = codeMatch(codeSequenceFromPcSerialCom); - pcSerialComCodeCompleteWrite(false); - if ( codeIsCorrect ) { - codeDeactivate(); - pcSerialComStringWrite( "\r\nThe code is correct\r\n\r\n" ); - } else { - incorrectCodeStateWrite(ON); - numberOfIncorrectCodes++; - pcSerialComStringWrite( "\r\nThe code is incorrect\r\n\r\n" ); - } - } - - break; - default: - break; - } - - if ( numberOfIncorrectCodes >= 5 ) { - systemBlockedStateWrite(ON); - } - - return codeIsCorrect; -} - -//=====[Implementations of private functions]================================== - -static bool codeMatch( char* codeToCompare ) -{ - int i; - for (i = 0; i < CODE_NUMBER_OF_KEYS; i++) { - if ( codeSequence[i] != codeToCompare[i] ) { - return false; - } - } - return true; -} - -static void codeDeactivate() -{ - systemBlockedStateWrite(OFF); - incorrectCodeStateWrite(OFF); - numberOfIncorrectCodes = 0; -} \ No newline at end of file diff --git a/modules/code/code.h b/modules/code/code.h deleted file mode 100644 index bd1606f..0000000 --- a/modules/code/code.h +++ /dev/null @@ -1,24 +0,0 @@ -//=====[#include guards - begin]=============================================== - -#ifndef _CODE_H_ -#define _CODE_H_ - -//=====[Declaration of public defines]========================================= - -#define CODE_NUMBER_OF_KEYS 4 - -//=====[Declaration of public data types]====================================== - -typedef enum{ - CODE_KEYPAD, - CODE_PC_SERIAL, -} codeOrigin_t; - -//=====[Declarations (prototypes) of public functions]========================= - -void codeWrite( char* newCodeSequence ); -bool codeMatchFrom( codeOrigin_t codeOrigin ); - -//=====[#include guards - end]================================================= - -#endif // _CODE_H_ \ No newline at end of file diff --git a/modules/date_and_time/date_and_time.cpp b/modules/date_and_time/date_and_time.cpp deleted file mode 100644 index 9f9b197..0000000 --- a/modules/date_and_time/date_and_time.cpp +++ /dev/null @@ -1,48 +0,0 @@ -//=====[Libraries]============================================================= - -#include "mbed.h" - -#include "date_and_time.h" - -//=====[Declaration of private defines]======================================== - -//=====[Declaration of private data types]===================================== - -//=====[Declaration and initialization of public global objects]=============== - -//=====[Declaration of external public global variables]======================= - -//=====[Declaration and initialization of public global variables]============= - -//=====[Declaration and initialization of private global variables]============ - -//=====[Declarations (prototypes) of private functions]======================== - -//=====[Implementations of public functions]=================================== - -char* dateAndTimeRead() -{ - time_t epochSeconds; - epochSeconds = time(NULL); - return ctime(&epochSeconds); -} - -void dateAndTimeWrite( int year, int month, int day, - int hour, int minute, int second ) -{ - struct tm rtcTime; - - rtcTime.tm_year = year - 1900; - rtcTime.tm_mon = month - 1; - rtcTime.tm_mday = day; - rtcTime.tm_hour = hour; - rtcTime.tm_min = minute; - rtcTime.tm_sec = second; - - rtcTime.tm_isdst = -1; - - set_time( mktime( &rtcTime ) ); -} - -//=====[Implementations of private functions]================================== - diff --git a/modules/date_and_time/date_and_time.h b/modules/date_and_time/date_and_time.h deleted file mode 100644 index 17b2ca7..0000000 --- a/modules/date_and_time/date_and_time.h +++ /dev/null @@ -1,19 +0,0 @@ -//=====[#include guards - begin]=============================================== - -#ifndef _DATE_AND_TIME_H_ -#define _DATE_AND_TIME_H_ - -//=====[Declaration of public defines]========================================= - -//=====[Declaration of public data types]====================================== - -//=====[Declarations (prototypes) of public functions]========================= - -char* dateAndTimeRead(); - -void dateAndTimeWrite( int year, int month, int day, - int hour, int minute, int second ); - -//=====[#include guards - end]================================================= - -#endif // _DATE_AND_TIME_H_ \ No newline at end of file diff --git a/modules/display/display.cpp b/modules/display/display.cpp index 985eec4..a52f3f6 100644 --- a/modules/display/display.cpp +++ b/modules/display/display.cpp @@ -58,10 +58,6 @@ //=====[Declaration and initialization of public global objects]=============== -DigitalOut displayD0( D0 ); -DigitalOut displayD1( D1 ); -DigitalOut displayD2( D2 ); -DigitalOut displayD3( D3 ); DigitalOut displayD4( D4 ); DigitalOut displayD5( D5 ); DigitalOut displayD6( D6 ); @@ -223,10 +219,6 @@ static void displayPinWrite( uint8_t pinName, int value ) switch( display.connection ) { case DISPLAY_CONNECTION_GPIO_8BITS: switch( pinName ) { - case DISPLAY_PIN_D0: displayD0 = value; break; - case DISPLAY_PIN_D1: displayD1 = value; break; - case DISPLAY_PIN_D2: displayD2 = value; break; - case DISPLAY_PIN_D3: displayD3 = value; break; case DISPLAY_PIN_D4: displayD4 = value; break; case DISPLAY_PIN_D5: displayD5 = value; break; case DISPLAY_PIN_D6: displayD6 = value; break; diff --git a/modules/event_log/event_log.cpp b/modules/event_log/event_log.cpp deleted file mode 100644 index a363035..0000000 --- a/modules/event_log/event_log.cpp +++ /dev/null @@ -1,117 +0,0 @@ -//=====[Libraries]============================================================= - -#include "mbed.h" -#include "arm_book_lib.h" - -#include "event_log.h" - -#include "siren.h" -#include "fire_alarm.h" -#include "user_interface.h" -#include "date_and_time.h" -#include "pc_serial_com.h" - -//=====[Declaration of private defines]======================================== - -//=====[Declaration of private data types]===================================== - -typedef struct systemEvent { - time_t seconds; - char typeOfEvent[EVENT_LOG_NAME_MAX_LENGTH]; -} systemEvent_t; - -//=====[Declaration and initialization of public global objects]=============== - -//=====[Declaration of external public global variables]======================= - -//=====[Declaration and initialization of public global variables]============= - -//=====[Declaration and initialization of private global variables]============ - -static bool sirenLastState = OFF; -static bool gasLastState = OFF; -static bool tempLastState = OFF; -static bool ICLastState = OFF; -static bool SBLastState = OFF; -static int eventsIndex = 0; -static systemEvent_t arrayOfStoredEvents[EVENT_LOG_MAX_STORAGE]; - -//=====[Declarations (prototypes) of private functions]======================== - -static void eventLogElementStateUpdate( bool lastState, - bool currentState, - const char* elementName ); - -//=====[Implementations of public functions]=================================== - -void eventLogUpdate() -{ - bool currentState = sirenStateRead(); - eventLogElementStateUpdate( sirenLastState, currentState, "ALARM" ); - sirenLastState = currentState; - - currentState = gasDetectorStateRead(); - eventLogElementStateUpdate( gasLastState, currentState, "GAS_DET" ); - gasLastState = currentState; - - currentState = overTemperatureDetectorStateRead(); - eventLogElementStateUpdate( tempLastState, currentState, "OVER_TEMP" ); - tempLastState = currentState; - - currentState = incorrectCodeStateRead(); - eventLogElementStateUpdate( ICLastState, currentState, "LED_IC" ); - ICLastState = currentState; - - currentState = systemBlockedStateRead(); - eventLogElementStateUpdate( SBLastState ,currentState, "LED_SB" ); - SBLastState = currentState; -} - -int eventLogNumberOfStoredEvents() -{ - return eventsIndex; -} - -void eventLogRead( int index, char* str ) -{ - str[0] = '\0'; - strcat( str, "Event = " ); - strcat( str, arrayOfStoredEvents[index].typeOfEvent ); - strcat( str, "\r\nDate and Time = " ); - strcat( str, ctime(&arrayOfStoredEvents[index].seconds) ); - strcat( str, "\r\n" ); -} - -void eventLogWrite( bool currentState, const char* elementName ) -{ - char eventAndStateStr[EVENT_LOG_NAME_MAX_LENGTH] = ""; - - strcat( eventAndStateStr, elementName ); - if ( currentState ) { - strcat( eventAndStateStr, "_ON" ); - } else { - strcat( eventAndStateStr, "_OFF" ); - } - - arrayOfStoredEvents[eventsIndex].seconds = time(NULL); - strcpy( arrayOfStoredEvents[eventsIndex].typeOfEvent, eventAndStateStr ); - if ( eventsIndex < EVENT_LOG_MAX_STORAGE -1 ) { - eventsIndex++; - } else { - eventsIndex = 0; - } - - pcSerialComStringWrite(eventAndStateStr); - pcSerialComStringWrite("\r\n"); -} - -//=====[Implementations of private functions]================================== - -static void eventLogElementStateUpdate( bool lastState, - bool currentState, - const char* elementName ) -{ - if ( lastState != currentState ) { - eventLogWrite( currentState, elementName ); - } -} diff --git a/modules/event_log/event_log.h b/modules/event_log/event_log.h deleted file mode 100644 index 4b2a84d..0000000 --- a/modules/event_log/event_log.h +++ /dev/null @@ -1,31 +0,0 @@ -//=====[#include guards - begin]=============================================== - -#ifndef _EVENT_LOG_H_ -#define _EVENT_LOG_H_ - -//=====[Declaration of public defines]========================================= - -#define EVENT_LOG_MAX_STORAGE 20 -#define EVENT_HEAD_STR_LENGTH 8 -#define EVENT_LOG_NAME_MAX_LENGTH 13 -#define DATE_AND_TIME_STR_LENGTH 18 -#define CTIME_STR_LENGTH 25 -#define NEW_LINE_STR_LENGTH 3 -#define EVENT_STR_LENGTH (EVENT_HEAD_STR_LENGTH + \ - EVENT_LOG_NAME_MAX_LENGTH + \ - DATE_AND_TIME_STR_LENGTH + \ - CTIME_STR_LENGTH + \ - NEW_LINE_STR_LENGTH) - -//=====[Declaration of public data types]====================================== - -//=====[Declarations (prototypes) of public functions]========================= - -void eventLogUpdate(); -int eventLogNumberOfStoredEvents(); -void eventLogRead( int index, char* str ); -void eventLogWrite( bool currentState, const char* elementName ); - -//=====[#include guards - end]================================================= - -#endif // _EVENT_LOG_H_ diff --git a/modules/fire_alarm/fire_alarm.cpp b/modules/fire_alarm/fire_alarm.cpp deleted file mode 100644 index b604ff4..0000000 --- a/modules/fire_alarm/fire_alarm.cpp +++ /dev/null @@ -1,149 +0,0 @@ -//=====[Libraries]============================================================= - -#include "mbed.h" -#include "arm_book_lib.h" - -#include "fire_alarm.h" - -#include "siren.h" -#include "strobe_light.h" -#include "user_interface.h" -#include "code.h" -#include "date_and_time.h" -#include "temperature_sensor.h" -#include "gas_sensor.h" -#include "matrix_keypad.h" - -//=====[Declaration of private defines]======================================== - -#define TEMPERATURE_C_LIMIT_ALARM 50.0 -#define STROBE_TIME_GAS 1000 -#define STROBE_TIME_OVER_TEMP 500 -#define STROBE_TIME_GAS_AND_OVER_TEMP 100 - -//=====[Declaration of private data types]===================================== - -//=====[Declaration and initialization of public global objects]=============== - -DigitalIn alarmTestButton(BUTTON1); - -//=====[Declaration of external public global variables]======================= - -//=====[Declaration and initialization of public global variables]============= - -//=====[Declaration and initialization of private global variables]============ - -static bool gasDetected = OFF; -static bool overTemperatureDetected = OFF; -static bool gasDetectorState = OFF; -static bool overTemperatureDetectorState = OFF; - -//=====[Declarations (prototypes) of private functions]======================== - -static void fireAlarmActivationUpdate(); -static void fireAlarmDeactivationUpdate(); -static void fireAlarmDeactivate(); -static int fireAlarmStrobeTime(); - -//=====[Implementations of public functions]=================================== - -void fireAlarmInit() -{ - temperatureSensorInit(); - gasSensorInit(); - sirenInit(); - strobeLightInit(); - - alarmTestButton.mode(PullDown); -} - -void fireAlarmUpdate() -{ - fireAlarmActivationUpdate(); - fireAlarmDeactivationUpdate(); - sirenUpdate( fireAlarmStrobeTime() ); - strobeLightUpdate( fireAlarmStrobeTime() ); -} - -bool gasDetectorStateRead() -{ - return gasDetectorState; -} - -bool overTemperatureDetectorStateRead() -{ - return overTemperatureDetectorState; -} - -bool gasDetectedRead() -{ - return gasDetected; -} - -bool overTemperatureDetectedRead() -{ - return overTemperatureDetected; -} - -//=====[Implementations of private functions]================================== - -static void fireAlarmActivationUpdate() -{ - temperatureSensorUpdate(); - gasSensorUpdate(); - - overTemperatureDetectorState = temperatureSensorReadCelsius() > - TEMPERATURE_C_LIMIT_ALARM; - - if ( overTemperatureDetectorState ) { - overTemperatureDetected = ON; - sirenStateWrite(ON); - strobeLightStateWrite(ON); - } - - gasDetectorState = !gasSensorRead(); - - if ( gasDetectorState ) { - gasDetected = ON; - sirenStateWrite(ON); - strobeLightStateWrite(ON); - } - - if( alarmTestButton ) { - overTemperatureDetected = ON; - gasDetected = ON; - sirenStateWrite(ON); - strobeLightStateWrite(ON); - } -} - -static void fireAlarmDeactivationUpdate() -{ - if ( sirenStateRead() ) { - if ( codeMatchFrom(CODE_KEYPAD) || - codeMatchFrom(CODE_PC_SERIAL) ) { - fireAlarmDeactivate(); - } - } -} - -static void fireAlarmDeactivate() -{ - sirenStateWrite(OFF); - strobeLightStateWrite(OFF); - overTemperatureDetected = OFF; - gasDetected = OFF; -} - -static int fireAlarmStrobeTime() -{ - if( gasDetectedRead() && overTemperatureDetectedRead() ) { - return STROBE_TIME_GAS_AND_OVER_TEMP; - } else if ( gasDetectedRead() ) { - return STROBE_TIME_GAS; - } else if ( overTemperatureDetectedRead() ) { - return STROBE_TIME_OVER_TEMP; - } else { - return 0; - } -} diff --git a/modules/fire_alarm/fire_alarm.h b/modules/fire_alarm/fire_alarm.h deleted file mode 100644 index ab85d31..0000000 --- a/modules/fire_alarm/fire_alarm.h +++ /dev/null @@ -1,21 +0,0 @@ -//=====[#include guards - begin]=============================================== - -#ifndef _FIRE_ALARM_H_ -#define _FIRE_ALARM_H_ - -//=====[Declaration of public defines]========================================= - -//=====[Declaration of public data types]====================================== - -//=====[Declarations (prototypes) of public functions]========================= - -void fireAlarmInit(); -void fireAlarmUpdate(); -bool gasDetectorStateRead(); -bool overTemperatureDetectorStateRead(); -bool gasDetectedRead(); -bool overTemperatureDetectedRead(); - -//=====[#include guards - end]================================================= - -#endif // _FIRE_ALARM_H_ \ No newline at end of file diff --git a/modules/gas_sensor/gas_sensor.cpp b/modules/gas_sensor/gas_sensor.cpp deleted file mode 100644 index 3ac4c9e..0000000 --- a/modules/gas_sensor/gas_sensor.cpp +++ /dev/null @@ -1,38 +0,0 @@ -//=====[Libraries]============================================================= - -#include "mbed.h" - -#include "gas_sensor.h" - -//=====[Declaration of private defines]======================================== - -//=====[Declaration of private data types]===================================== - -//=====[Declaration and initialization of public global objects]=============== - -DigitalIn mq2(PE_12); - -//=====[Declaration of external public global variables]======================= - -//=====[Declaration and initialization of public global variables]============= - -//=====[Declaration and initialization of private global variables]============ - -//=====[Declarations (prototypes) of private functions]======================== - -//=====[Implementations of public functions]=================================== - -void gasSensorInit() -{ -} - -void gasSensorUpdate() -{ -} - -bool gasSensorRead() -{ - return mq2; -} - -//=====[Implementations of private functions]================================== diff --git a/modules/gas_sensor/gas_sensor.h b/modules/gas_sensor/gas_sensor.h deleted file mode 100644 index b2d1bcd..0000000 --- a/modules/gas_sensor/gas_sensor.h +++ /dev/null @@ -1,18 +0,0 @@ -//=====[#include guards - begin]=============================================== - -#ifndef _GAS_SENSOR_H_ -#define _GAS_SENSOR_H_ - -//=====[Declaration of public defines]========================================= - -//=====[Declaration of public data types]====================================== - -//=====[Declarations (prototypes) of public functions]========================= - -void gasSensorInit(); -void gasSensorUpdate(); -bool gasSensorRead(); - -//=====[#include guards - end]================================================= - -#endif // _GAS_SENSOR_H_ diff --git a/modules/matrix_keypad/matrix_keypad.cpp b/modules/matrix_keypad/matrix_keypad.cpp deleted file mode 100644 index 4807f2b..0000000 --- a/modules/matrix_keypad/matrix_keypad.cpp +++ /dev/null @@ -1,141 +0,0 @@ -//=====[Libraries]============================================================= - -#include "mbed.h" -#include "arm_book_lib.h" - -#include "matrix_keypad.h" - -#include "date_and_time.h" - -//=====[Declaration of private defines]======================================== - -#define MATRIX_KEYPAD_NUMBER_OF_ROWS 4 -#define MATRIX_KEYPAD_NUMBER_OF_COLS 4 -#define DEBOUNCE_KEY_TIME_MS 40 - -//=====[Declaration of private data types]===================================== - -typedef enum { - MATRIX_KEYPAD_SCANNING, - MATRIX_KEYPAD_DEBOUNCE, - MATRIX_KEYPAD_KEY_HOLD_PRESSED -} matrixKeypadState_t; - -//=====[Declaration and initialization of public global objects]=============== - -DigitalOut keypadRowPins[MATRIX_KEYPAD_NUMBER_OF_ROWS] = {PB_3, PB_5, PC_7, PA_15}; -DigitalIn keypadColPins[MATRIX_KEYPAD_NUMBER_OF_COLS] = {PB_12, PB_13, PB_15, PC_6}; - -//=====[Declaration of external public global variables]======================= - -//=====[Declaration and initialization of public global variables]============= - -//=====[Declaration and initialization of private global variables]============ - -static matrixKeypadState_t matrixKeypadState; -static int timeIncrement_ms = 0; - -//=====[Declarations (prototypes) of private functions]======================== - -static char matrixKeypadScan(); -static void matrixKeypadReset(); - -//=====[Implementations of public functions]=================================== - -void matrixKeypadInit( int updateTime_ms ) -{ - timeIncrement_ms = updateTime_ms; - matrixKeypadState = MATRIX_KEYPAD_SCANNING; - int pinIndex = 0; - for( pinIndex=0; pinIndex= - DEBOUNCE_KEY_TIME_MS ) { - keyDetected = matrixKeypadScan(); - if( keyDetected == matrixKeypadLastKeyPressed ) { - matrixKeypadState = MATRIX_KEYPAD_KEY_HOLD_PRESSED; - } else { - matrixKeypadState = MATRIX_KEYPAD_SCANNING; - } - } - accumulatedDebounceMatrixKeypadTime = - accumulatedDebounceMatrixKeypadTime + timeIncrement_ms; - break; - - case MATRIX_KEYPAD_KEY_HOLD_PRESSED: - keyDetected = matrixKeypadScan(); - if( keyDetected != matrixKeypadLastKeyPressed ) { - if( keyDetected == '\0' ) { - keyReleased = matrixKeypadLastKeyPressed; - } - matrixKeypadState = MATRIX_KEYPAD_SCANNING; - } - break; - - default: - matrixKeypadReset(); - break; - } - return keyReleased; -} - -//=====[Implementations of private functions]================================== - -static char matrixKeypadScan() -{ - int row = 0; - int col = 0; - int i = 0; - - char matrixKeypadIndexToCharArray[] = { - '1', '2', '3', 'A', - '4', '5', '6', 'B', - '7', '8', '9', 'C', - '*', '0', '#', 'D', - }; - - for( row=0; row= CODE_NUMBER_OF_KEYS ) { - pcSerialComMode = PC_SERIAL_COMMANDS; - codeComplete = true; - numberOfCodeChars = 0; - } -} - -static void pcSerialComSaveNewCodeUpdate( char receivedChar ) -{ - static char newCodeSequence[CODE_NUMBER_OF_KEYS]; - - newCodeSequence[numberOfCodeChars] = receivedChar; - pcSerialComStringWrite( "*" ); - numberOfCodeChars++; - if ( numberOfCodeChars >= CODE_NUMBER_OF_KEYS ) { - pcSerialComMode = PC_SERIAL_COMMANDS; - numberOfCodeChars = 0; - codeWrite( newCodeSequence ); - pcSerialComStringWrite( "\r\nNew code configured\r\n\r\n" ); - } -} - -static void pcSerialComCommandUpdate( char receivedChar ) -{ - switch (receivedChar) { - case '1': commandShowCurrentAlarmState(); break; - case '2': commandShowCurrentGasDetectorState(); break; - case '3': commandShowCurrentOverTemperatureDetectorState(); break; - case '4': commandEnterCodeSequence(); break; - case '5': commandEnterNewCode(); break; - case 'c': case 'C': commandShowCurrentTemperatureInCelsius(); break; - case 'f': case 'F': commandShowCurrentTemperatureInFahrenheit(); break; - case 's': case 'S': commandSetDateAndTime(); break; - case 't': case 'T': commandShowDateAndTime(); break; - case 'e': case 'E': commandShowStoredEvents(); break; - default: availableCommands(); break; - } -} - -static void availableCommands() -{ - pcSerialComStringWrite( "Available commands:\r\n" ); - pcSerialComStringWrite( "Press '1' to get the alarm state\r\n" ); - pcSerialComStringWrite( "Press '2' to get the gas detector state\r\n" ); - pcSerialComStringWrite( "Press '3' to get the over temperature detector state\r\n" ); - pcSerialComStringWrite( "Press '4' to enter the code to deactivate the alarm\r\n" ); - pcSerialComStringWrite( "Press '5' to enter a new code to deactivate the alarm\r\n" ); - pcSerialComStringWrite( "Press 'f' or 'F' to get lm35 reading in Fahrenheit\r\n" ); - pcSerialComStringWrite( "Press 'c' or 'C' to get lm35 reading in Celsius\r\n" ); - pcSerialComStringWrite( "Press 's' or 'S' to set the date and time\r\n" ); - pcSerialComStringWrite( "Press 't' or 'T' to get the date and time\r\n" ); - pcSerialComStringWrite( "Press 'e' or 'E' to get the stored events\r\n" ); - pcSerialComStringWrite( "\r\n" ); -} - -static void commandShowCurrentAlarmState() -{ - if ( sirenStateRead() ) { - pcSerialComStringWrite( "The alarm is activated\r\n"); - } else { - pcSerialComStringWrite( "The alarm is not activated\r\n"); - } -} - -static void commandShowCurrentGasDetectorState() -{ - if ( gasDetectorStateRead() ) { - pcSerialComStringWrite( "Gas is being detected\r\n"); - } else { - pcSerialComStringWrite( "Gas is not being detected\r\n"); - } -} - -static void commandShowCurrentOverTemperatureDetectorState() -{ - if ( overTemperatureDetectorStateRead() ) { - pcSerialComStringWrite( "Temperature is above the maximum level\r\n"); - } else { - pcSerialComStringWrite( "Temperature is below the maximum level\r\n"); - } -} - -static void commandEnterCodeSequence() -{ - if( sirenStateRead() ) { - pcSerialComStringWrite( "Please enter the four digits numeric code " ); - pcSerialComStringWrite( "to deactivate the alarm: " ); - pcSerialComMode = PC_SERIAL_GET_CODE; - codeComplete = false; - numberOfCodeChars = 0; - } else { - pcSerialComStringWrite( "Alarm is not activated.\r\n" ); - } -} - -static void commandEnterNewCode() -{ - pcSerialComStringWrite( "Please enter the new four digits numeric code " ); - pcSerialComStringWrite( "to deactivate the alarm: " ); - numberOfCodeChars = 0; - pcSerialComMode = PC_SERIAL_SAVE_NEW_CODE; - -} - -static void commandShowCurrentTemperatureInCelsius() -{ - char str[100] = ""; - sprintf ( str, "Temperature: %.2f \xB0 C\r\n", - temperatureSensorReadCelsius() ); - pcSerialComStringWrite( str ); -} - -static void commandShowCurrentTemperatureInFahrenheit() -{ - char str[100] = ""; - sprintf ( str, "Temperature: %.2f \xB0 C\r\n", - temperatureSensorReadFahrenheit() ); - pcSerialComStringWrite( str ); -} - -static void commandSetDateAndTime() -{ - char year[5] = ""; - char month[3] = ""; - char day[3] = ""; - char hour[3] = ""; - char minute[3] = ""; - char second[3] = ""; - - pcSerialComStringWrite("\r\nType four digits for the current year (YYYY): "); - pcSerialComStringRead( year, 4); - pcSerialComStringWrite("\r\n"); - - pcSerialComStringWrite("Type two digits for the current month (01-12): "); - pcSerialComStringRead( month, 2); - pcSerialComStringWrite("\r\n"); - - pcSerialComStringWrite("Type two digits for the current day (01-31): "); - pcSerialComStringRead( day, 2); - pcSerialComStringWrite("\r\n"); - - pcSerialComStringWrite("Type two digits for the current hour (00-23): "); - pcSerialComStringRead( hour, 2); - pcSerialComStringWrite("\r\n"); - - pcSerialComStringWrite("Type two digits for the current minutes (00-59): "); - pcSerialComStringRead( minute, 2); - pcSerialComStringWrite("\r\n"); - - pcSerialComStringWrite("Type two digits for the current seconds (00-59): "); - pcSerialComStringRead( second, 2); - pcSerialComStringWrite("\r\n"); - - pcSerialComStringWrite("Date and time has been set\r\n"); - - dateAndTimeWrite( atoi(year), atoi(month), atoi(day), - atoi(hour), atoi(minute), atoi(second) ); -} - -static void commandShowDateAndTime() -{ - char str[100] = ""; - sprintf ( str, "Date and Time = %s", dateAndTimeRead() ); - pcSerialComStringWrite( str ); - pcSerialComStringWrite("\r\n"); -} - -static void commandShowStoredEvents() -{ - char str[EVENT_STR_LENGTH] = ""; - int i; - for (i = 0; i < eventLogNumberOfStoredEvents(); i++) { - eventLogRead( i, str ); - pcSerialComStringWrite( str ); - pcSerialComStringWrite( "\r\n" ); - } -} \ No newline at end of file diff --git a/modules/pc_serial_com/pc_serial_com.h b/modules/pc_serial_com/pc_serial_com.h deleted file mode 100644 index dcad96c..0000000 --- a/modules/pc_serial_com/pc_serial_com.h +++ /dev/null @@ -1,21 +0,0 @@ -//=====[#include guards - begin]=============================================== - -#ifndef _PC_SERIAL_COM_H_ -#define _PC_SERIAL_COM_H_ - -//=====[Declaration of public defines]========================================= - -//=====[Declaration of public data types]====================================== - -//=====[Declarations (prototypes) of public functions]========================= - -void pcSerialComInit(); -char pcSerialComCharRead(); -void pcSerialComStringWrite( const char* str ); -void pcSerialComUpdate(); -bool pcSerialComCodeCompleteRead(); -void pcSerialComCodeCompleteWrite( bool state ); - -//=====[#include guards - end]================================================= - -#endif // _PC_SERIAL_COM_H_ \ No newline at end of file diff --git a/modules/siren/siren.cpp b/modules/siren/siren.cpp deleted file mode 100644 index 38380f0..0000000 --- a/modules/siren/siren.cpp +++ /dev/null @@ -1,61 +0,0 @@ -//=====[Libraries]============================================================= - -#include "mbed.h" -#include "arm_book_lib.h" - -#include "siren.h" - -#include "smart_home_system.h" - -//=====[Declaration of private defines]======================================== - -//=====[Declaration of private data types]===================================== - -//=====[Declaration and initialization of public global objects]=============== - -DigitalOut sirenPin(PE_10); - -//=====[Declaration of external public global variables]======================= - -//=====[Declaration and initialization of public global variables]============= - -//=====[Declaration and initialization of private global variables]============ - -static bool sirenState = OFF; - -//=====[Declarations (prototypes) of private functions]======================== - -//=====[Implementations of public functions]=================================== - -void sirenInit() -{ - sirenPin = ON; -} - -bool sirenStateRead() -{ - return sirenState; -} - -void sirenStateWrite( bool state ) -{ - sirenState = state; -} - -void sirenUpdate( int strobeTime ) -{ - static int accumulatedTimeAlarm = 0; - accumulatedTimeAlarm = accumulatedTimeAlarm + SYSTEM_TIME_INCREMENT_MS; - - if( sirenState ) { - if( accumulatedTimeAlarm >= strobeTime ) { - accumulatedTimeAlarm = 0; - sirenPin= !sirenPin; - } - } else { - sirenPin = ON; - } -} - -//=====[Implementations of private functions]================================== - diff --git a/modules/siren/siren.h b/modules/siren/siren.h deleted file mode 100644 index 8743f17..0000000 --- a/modules/siren/siren.h +++ /dev/null @@ -1,19 +0,0 @@ -//=====[#include guards - begin]=============================================== - -#ifndef _SIREN_H_ -#define _SIREN_H_ - -//=====[Declaration of public defines]========================================= - -//=====[Declaration of public data types]====================================== - -//=====[Declarations (prototypes) of public functions]========================= - -void sirenInit(); -bool sirenStateRead(); -void sirenStateWrite( bool state ); -void sirenUpdate( int strobeTime ); - -//=====[#include guards - end]================================================= - -#endif // _SIREN_H_ diff --git a/modules/smart_home_system/smart_home_system.cpp b/modules/smart_home_system/smart_home_system.cpp index 9a09c5e..0da981d 100644 --- a/modules/smart_home_system/smart_home_system.cpp +++ b/modules/smart_home_system/smart_home_system.cpp @@ -4,11 +4,8 @@ #include "smart_home_system.h" -#include "siren.h" #include "user_interface.h" -#include "fire_alarm.h" -#include "pc_serial_com.h" -#include "event_log.h" + //=====[Declaration of private defines]======================================== @@ -29,16 +26,11 @@ void smartHomeSystemInit() { userInterfaceInit(); - fireAlarmInit(); - pcSerialComInit(); } void smartHomeSystemUpdate() { userInterfaceUpdate(); - fireAlarmUpdate(); - pcSerialComUpdate(); - eventLogUpdate(); delay(SYSTEM_TIME_INCREMENT_MS); } diff --git a/modules/strobe_light/strobe_light.cpp b/modules/strobe_light/strobe_light.cpp deleted file mode 100644 index 327407a..0000000 --- a/modules/strobe_light/strobe_light.cpp +++ /dev/null @@ -1,60 +0,0 @@ -//=====[Libraries]============================================================= - -#include "mbed.h" -#include "arm_book_lib.h" - -#include "strobe_light.h" -#include "smart_home_system.h" - -//=====[Declaration of private defines]======================================== - -//=====[Declaration of private data types]===================================== - -//=====[Declaration and initialization of public global objects]=============== - -DigitalOut strobeLight(LED1); - -//=====[Declaration of external public global variables]======================= - -//=====[Declaration and initialization of public global variables]============= - -//=====[Declaration and initialization of private global variables]============ - -static bool strobeLightState = OFF; - -//=====[Declarations (prototypes) of private functions]======================== - -//=====[Implementations of public functions]=================================== - -void strobeLightInit() -{ - strobeLight = OFF; -} - -bool strobeLightStateRead() -{ - return strobeLightState; -} - -void strobeLightStateWrite( bool state ) -{ - strobeLightState = state; -} - -void strobeLightUpdate( int strobeTime ) -{ - static int accumulatedTimeAlarm = 0; - accumulatedTimeAlarm = accumulatedTimeAlarm + SYSTEM_TIME_INCREMENT_MS; - - if( strobeLightState ) { - if( accumulatedTimeAlarm >= strobeTime ) { - accumulatedTimeAlarm = 0; - strobeLight= !strobeLight; - } - } else { - strobeLight = OFF; - } -} - -//=====[Implementations of private functions]================================== - diff --git a/modules/strobe_light/strobe_light.h b/modules/strobe_light/strobe_light.h deleted file mode 100644 index 41b246e..0000000 --- a/modules/strobe_light/strobe_light.h +++ /dev/null @@ -1,19 +0,0 @@ -//=====[#include guards - begin]=============================================== - -#ifndef _STROBE_LIGHT_H_ -#define _STROBE_LIGHT_H_ - -//=====[Declaration of public defines]========================================= - -//=====[Declaration of public data types]====================================== - -//=====[Declarations (prototypes) of public functions]========================= - -void strobeLightInit(); -bool strobeLightStateRead(); -void strobeLightStateWrite( bool state ); -void strobeLightUpdate( int strobeTime ); - -//=====[#include guards - end]================================================= - -#endif // _STROBE_LIGHT_H_ \ No newline at end of file diff --git a/modules/temperature_sensor/temperature_sensor.cpp b/modules/temperature_sensor/temperature_sensor.cpp deleted file mode 100644 index df0798f..0000000 --- a/modules/temperature_sensor/temperature_sensor.cpp +++ /dev/null @@ -1,86 +0,0 @@ -//=====[Libraries]============================================================= - -#include "mbed.h" - -#include "temperature_sensor.h" - -#include "smart_home_system.h" - -//=====[Declaration of private defines]======================================== - -#define LM35_NUMBER_OF_AVG_SAMPLES 10 - -//=====[Declaration of private data types]===================================== - -//=====[Declaration and initialization of public global objects]=============== - -AnalogIn lm35(A1); - -//=====[Declaration of external public global variables]======================= - -//=====[Declaration and initialization of public global variables]============= - -//=====[Declaration and initialization of private global variables]============ - -float lm35TemperatureC = 0.0; -float lm35ReadingsArray[LM35_NUMBER_OF_AVG_SAMPLES]; - -//=====[Declarations (prototypes) of private functions]======================== - -static float analogReadingScaledWithTheLM35Formula( float analogReading ); - -//=====[Implementations of public functions]=================================== - -void temperatureSensorInit() -{ - int i; - - for( i=0; i= LM35_NUMBER_OF_AVG_SAMPLES) { - lm35SampleIndex = 0; - } - - lm35ReadingsSum = 0.0; - for (i = 0; i < LM35_NUMBER_OF_AVG_SAMPLES; i++) { - lm35ReadingsSum = lm35ReadingsSum + lm35ReadingsArray[i]; - } - lm35ReadingsAverage = lm35ReadingsSum / LM35_NUMBER_OF_AVG_SAMPLES; - lm35TemperatureC = analogReadingScaledWithTheLM35Formula ( lm35ReadingsAverage ); -} - - -float temperatureSensorReadCelsius() -{ - return lm35TemperatureC; -} - -float temperatureSensorReadFahrenheit() -{ - return celsiusToFahrenheit( lm35TemperatureC ); -} - -float celsiusToFahrenheit( float tempInCelsiusDegrees ) -{ - return ( tempInCelsiusDegrees * 9.0 / 5.0 + 32.0 ); -} - -//=====[Implementations of private functions]================================== - -static float analogReadingScaledWithTheLM35Formula( float analogReading ) -{ - return ( analogReading * 3.3 / 0.01 ); -} diff --git a/modules/temperature_sensor/temperature_sensor.h b/modules/temperature_sensor/temperature_sensor.h deleted file mode 100644 index b45c314..0000000 --- a/modules/temperature_sensor/temperature_sensor.h +++ /dev/null @@ -1,20 +0,0 @@ -//=====[#include guards - begin]=============================================== - -#ifndef _TEMPERATURE_SENSOR_H_ -#define _TEMPERATURE_SENSOR_H_ - -//=====[Declaration of public defines]========================================= - -//=====[Declaration of public data types]====================================== - -//=====[Declarations (prototypes) of public functions]========================= - -void temperatureSensorInit(); -void temperatureSensorUpdate(); -float temperatureSensorReadCelsius(); -float temperatureSensorReadFahrenheit(); -float celsiusToFahrenheit( float tempInCelsiusDegrees ); - -//=====[#include guards - end]================================================= - -#endif // _TEMPERATURE_SENSOR_H_ \ No newline at end of file diff --git a/modules/user_interface/user_interface.cpp b/modules/user_interface/user_interface.cpp index 5bf0f74..0efac81 100644 --- a/modules/user_interface/user_interface.cpp +++ b/modules/user_interface/user_interface.cpp @@ -5,14 +5,7 @@ #include "user_interface.h" -#include "code.h" -#include "siren.h" #include "smart_home_system.h" -#include "fire_alarm.h" -#include "date_and_time.h" -#include "temperature_sensor.h" -#include "gas_sensor.h" -#include "matrix_keypad.h" #include "display.h" //=====[Declaration of private defines]======================================== @@ -23,29 +16,14 @@ //=====[Declaration and initialization of public global objects]=============== -DigitalOut incorrectCodeLed(LED3); -DigitalOut systemBlockedLed(LED2); - //=====[Declaration of external public global variables]======================= //=====[Declaration and initialization of public global variables]============= -char codeSequenceFromUserInterface[CODE_NUMBER_OF_KEYS]; - //=====[Declaration and initialization of private global variables]============ -static bool incorrectCodeState = OFF; -static bool systemBlockedState = OFF; - -static bool codeComplete = false; -static int numberOfCodeChars = 0; - //=====[Declarations (prototypes) of private functions]======================== -static void userInterfaceMatrixKeypadUpdate(); -static void incorrectCodeIndicatorUpdate(); -static void systemBlockedIndicatorUpdate(); - static void userInterfaceDisplayInit(); static void userInterfaceDisplayUpdate(); @@ -53,81 +31,14 @@ static void userInterfaceDisplayUpdate(); void userInterfaceInit() { - incorrectCodeLed = OFF; - systemBlockedLed = OFF; - matrixKeypadInit( SYSTEM_TIME_INCREMENT_MS ); userInterfaceDisplayInit(); } void userInterfaceUpdate() { - userInterfaceMatrixKeypadUpdate(); - incorrectCodeIndicatorUpdate(); - systemBlockedIndicatorUpdate(); userInterfaceDisplayUpdate(); } -bool incorrectCodeStateRead() -{ - return incorrectCodeState; -} - -void incorrectCodeStateWrite( bool state ) -{ - incorrectCodeState = state; -} - -bool systemBlockedStateRead() -{ - return systemBlockedState; -} - -void systemBlockedStateWrite( bool state ) -{ - systemBlockedState = state; -} - -bool userInterfaceCodeCompleteRead() -{ - return codeComplete; -} - -void userInterfaceCodeCompleteWrite( bool state ) -{ - codeComplete = state; -} - -//=====[Implementations of private functions]================================== - -static void userInterfaceMatrixKeypadUpdate() -{ - static int numberOfHashKeyReleased = 0; - char keyReleased = matrixKeypadUpdate(); - - if( keyReleased != '\0' ) { - - if( sirenStateRead() && !systemBlockedStateRead() ) { - if( !incorrectCodeStateRead() ) { - codeSequenceFromUserInterface[numberOfCodeChars] = keyReleased; - numberOfCodeChars++; - if ( numberOfCodeChars >= CODE_NUMBER_OF_KEYS ) { - codeComplete = true; - numberOfCodeChars = 0; - } - } else { - if( keyReleased == '#' ) { - numberOfHashKeyReleased++; - if( numberOfHashKeyReleased >= 2 ) { - numberOfHashKeyReleased = 0; - numberOfCodeChars = 0; - codeComplete = false; - incorrectCodeState = OFF; - } - } - } - } - } -} static void userInterfaceDisplayInit() { @@ -153,40 +64,22 @@ static void userInterfaceDisplayUpdate() accumulatedDisplayTime = 0; - sprintf(temperatureString, "%.0f", temperatureSensorReadCelsius()); + displayCharPositionWrite ( 12,0 ); - displayStringWrite( temperatureString ); + displayStringWrite( "0 " ); displayCharPositionWrite ( 14,0 ); displayStringWrite( "'C" ); displayCharPositionWrite ( 4,1 ); + displayStringWrite( "Detected " ); - if ( gasDetectorStateRead() ) { - displayStringWrite( "Detected " ); - } else { - displayStringWrite( "Not Detected" ); - } displayCharPositionWrite ( 6,2 ); - - if ( sirenStateRead() ) { - displayStringWrite( "ON " ); - } else { - displayStringWrite( "OFF" ); - } + displayStringWrite( "ON " ); + } else { accumulatedDisplayTime = accumulatedDisplayTime + SYSTEM_TIME_INCREMENT_MS; } -} - -static void incorrectCodeIndicatorUpdate() -{ - incorrectCodeLed = incorrectCodeStateRead(); -} - -static void systemBlockedIndicatorUpdate() -{ - systemBlockedLed = systemBlockedState; } \ No newline at end of file diff --git a/modules/user_interface/user_interface.h b/modules/user_interface/user_interface.h index e1e596c..e2b3d50 100644 --- a/modules/user_interface/user_interface.h +++ b/modules/user_interface/user_interface.h @@ -11,14 +11,6 @@ void userInterfaceInit(); void userInterfaceUpdate(); -bool userInterfaceCodeCompleteRead(); -void userInterfaceCodeCompleteWrite( bool state ); - -bool incorrectCodeStateRead(); -void incorrectCodeStateWrite( bool state ); - -bool systemBlockedStateRead(); -void systemBlockedStateWrite( bool state ); //=====[#include guards - end]=================================================