Program for the water play project for the course Software Testing Practical 2016 given at the VU University
Dependencies: mbed DRV88255 TextLCD Ping mbed-rtos
AlarmController.cpp
- Committer:
- joran
- Date:
- 2016-06-13
- Revision:
- 24:eeef4009640d
- Parent:
- 20:521f795ea9d7
File content as of revision 24:eeef4009640d:
#include "AlarmController.h" Timer temptimer; Timer salttimer; DigitalOut buzzer(p17); DigitalOut led1(LED1); DigitalOut led2(LED2); DigitalOut led3(LED3); DigitalOut led4(LED4); float temp_value_min_crit = 30.0f; float temp_value_min_undesired = 32.0f; float temp_value_max_crit = 40.0f; float temp_value_max_undesired = 38.0f; float salt_value_min_crit = 3.0f; float salt_value_min_undesired = 6.0f; float salt_value_max_crit = 12.0f; float salt_value_max_undesired = 9.0f; float readtemp; float readsalt; void AlarmController::update() { readtemp = this->temp->getValue(); if ((readtemp < temp_value_min_undesired) || (readtemp > temp_value_max_undesired)) { if ((readtemp < temp_value_min_crit) || (readtemp > temp_value_max_crit)) { this->raiseAlarmTemp(true); } else { this->raiseAlarmTemp(false); } } else { //clear alarm temptimer.stop(); this->tempiscrit = false; } readsalt = this->salt->getValue(); if ((readsalt < salt_value_min_undesired) || (readsalt > salt_value_max_undesired)) { if ((readsalt < salt_value_min_crit) || (readsalt > salt_value_max_crit)) { this->raiseAlarmSalt(true); } else { this->raiseAlarmSalt(false); } } else { //clear alarm salttimer.stop(); this->saltiscrit = false; } } void AlarmController::raiseAlarmTemp(bool isCrit) { this->tempiscrit = isCrit; int readtimer = temptimer.read(); if (isCrit) printf("Received a critical temperature alarm (%.1f), timer is at %d\r\n",readtemp,readtimer); if (!isCrit) printf("Received a non-critical temperature alarm (%.1f), timer is at %d\r\n",readtemp,readtimer); if (readtimer > 0 ) { //already running if ((readtimer >= 30 && tempiscrit) || (readtimer >= 300 && !tempiscrit)) { this->error = true; printf("### Temperature alarm has been triggered after %d ###\r\n",readtimer); buzzOnce(); temptimer.stop(); temptimer.reset(); this->tempiscrit = false; } } else { temptimer.start(); } } void AlarmController::raiseAlarmSalt(bool isCrit) { this->saltiscrit = isCrit; int readtimer = salttimer.read(); if (isCrit) printf("Received a critical salt alarm (%.3f), timer is at %d\r\n",readsalt,readtimer); if (!isCrit) printf("Received a non-critical salt alarm (%.3f), timer is at %d\r\n",readsalt,readtimer); if (readtimer > 0 ) { //already running if ((readtimer >= 30 && saltiscrit) || (readtimer >= 300 && !saltiscrit)) { this->error = true; printf("### Salt alarm has been triggered after %d seconds ###\r\n",readtimer); buzzOnce(); salttimer.stop(); salttimer.reset(); this->saltiscrit = false; } } else { salttimer.start(); } } std::string AlarmController::get_name() { return "AlarmController"; } bool AlarmController::is_error() { return this->error; } char *AlarmController::get_error_message() { return this->error_msg; } void AlarmController::activate_buzzer() { printf("Should activate buzzer now\r\n"); } void AlarmController::buzzOnce() { buzzer = 1; led1=1; led2=1; led3=1; led4=1; wait(0.1); buzzer = 0; led1=0; led2=0; led3=0; led4=0; }