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@24:eeef4009640d, 2016-06-13 (annotated)
- Committer:
- joran
- Date:
- Mon Jun 13 13:41:25 2016 +0000
- Revision:
- 24:eeef4009640d
- Parent:
- 20:521f795ea9d7
Proximity controller calculates ml now, for a small flask.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sbouber1 | 11:1a0a8fd74bc0 | 1 | #include "AlarmController.h" |
sbouber1 | 11:1a0a8fd74bc0 | 2 | |
joran | 20:521f795ea9d7 | 3 | Timer temptimer; |
joran | 20:521f795ea9d7 | 4 | Timer salttimer; |
joran | 20:521f795ea9d7 | 5 | |
joran | 20:521f795ea9d7 | 6 | DigitalOut buzzer(p17); |
joran | 20:521f795ea9d7 | 7 | DigitalOut led1(LED1); |
joran | 20:521f795ea9d7 | 8 | DigitalOut led2(LED2); |
joran | 20:521f795ea9d7 | 9 | DigitalOut led3(LED3); |
joran | 20:521f795ea9d7 | 10 | DigitalOut led4(LED4); |
joran | 20:521f795ea9d7 | 11 | |
joran | 20:521f795ea9d7 | 12 | float temp_value_min_crit = 30.0f; |
joran | 20:521f795ea9d7 | 13 | float temp_value_min_undesired = 32.0f; |
joran | 20:521f795ea9d7 | 14 | float temp_value_max_crit = 40.0f; |
joran | 20:521f795ea9d7 | 15 | float temp_value_max_undesired = 38.0f; |
joran | 20:521f795ea9d7 | 16 | |
joran | 20:521f795ea9d7 | 17 | float salt_value_min_crit = 3.0f; |
joran | 20:521f795ea9d7 | 18 | float salt_value_min_undesired = 6.0f; |
joran | 20:521f795ea9d7 | 19 | float salt_value_max_crit = 12.0f; |
joran | 20:521f795ea9d7 | 20 | float salt_value_max_undesired = 9.0f; |
joran | 20:521f795ea9d7 | 21 | |
joran | 20:521f795ea9d7 | 22 | float readtemp; |
joran | 20:521f795ea9d7 | 23 | float readsalt; |
joran | 20:521f795ea9d7 | 24 | |
sbouber1 | 11:1a0a8fd74bc0 | 25 | void AlarmController::update() { |
joran | 20:521f795ea9d7 | 26 | readtemp = this->temp->getValue(); |
joran | 20:521f795ea9d7 | 27 | |
joran | 20:521f795ea9d7 | 28 | if ((readtemp < temp_value_min_undesired) || (readtemp > temp_value_max_undesired)) |
joran | 20:521f795ea9d7 | 29 | { |
joran | 20:521f795ea9d7 | 30 | if ((readtemp < temp_value_min_crit) || (readtemp > temp_value_max_crit)) |
joran | 20:521f795ea9d7 | 31 | { |
joran | 20:521f795ea9d7 | 32 | this->raiseAlarmTemp(true); |
joran | 20:521f795ea9d7 | 33 | } else { |
joran | 20:521f795ea9d7 | 34 | this->raiseAlarmTemp(false); |
joran | 20:521f795ea9d7 | 35 | } |
joran | 20:521f795ea9d7 | 36 | } else { |
joran | 20:521f795ea9d7 | 37 | //clear alarm |
joran | 20:521f795ea9d7 | 38 | temptimer.stop(); |
joran | 20:521f795ea9d7 | 39 | this->tempiscrit = false; |
joran | 20:521f795ea9d7 | 40 | } |
joran | 20:521f795ea9d7 | 41 | |
sbouber1 | 11:1a0a8fd74bc0 | 42 | |
sbouber1 | 11:1a0a8fd74bc0 | 43 | |
joran | 20:521f795ea9d7 | 44 | readsalt = this->salt->getValue(); |
joran | 20:521f795ea9d7 | 45 | |
joran | 20:521f795ea9d7 | 46 | if ((readsalt < salt_value_min_undesired) || (readsalt > salt_value_max_undesired)) |
joran | 20:521f795ea9d7 | 47 | { |
joran | 20:521f795ea9d7 | 48 | if ((readsalt < salt_value_min_crit) || (readsalt > salt_value_max_crit)) |
joran | 20:521f795ea9d7 | 49 | { |
joran | 20:521f795ea9d7 | 50 | this->raiseAlarmSalt(true); |
joran | 20:521f795ea9d7 | 51 | } else { |
joran | 20:521f795ea9d7 | 52 | this->raiseAlarmSalt(false); |
joran | 20:521f795ea9d7 | 53 | } |
joran | 20:521f795ea9d7 | 54 | } else { |
joran | 20:521f795ea9d7 | 55 | //clear alarm |
joran | 20:521f795ea9d7 | 56 | salttimer.stop(); |
joran | 20:521f795ea9d7 | 57 | this->saltiscrit = false; |
joran | 20:521f795ea9d7 | 58 | } |
joran | 20:521f795ea9d7 | 59 | |
joran | 20:521f795ea9d7 | 60 | } |
joran | 20:521f795ea9d7 | 61 | |
joran | 20:521f795ea9d7 | 62 | void AlarmController::raiseAlarmTemp(bool isCrit) |
joran | 20:521f795ea9d7 | 63 | { |
joran | 20:521f795ea9d7 | 64 | this->tempiscrit = isCrit; |
joran | 20:521f795ea9d7 | 65 | int readtimer = temptimer.read(); |
joran | 20:521f795ea9d7 | 66 | if (isCrit) printf("Received a critical temperature alarm (%.1f), timer is at %d\r\n",readtemp,readtimer); |
joran | 20:521f795ea9d7 | 67 | if (!isCrit) printf("Received a non-critical temperature alarm (%.1f), timer is at %d\r\n",readtemp,readtimer); |
joran | 20:521f795ea9d7 | 68 | if (readtimer > 0 ) { //already running |
joran | 20:521f795ea9d7 | 69 | if ((readtimer >= 30 && tempiscrit) || (readtimer >= 300 && !tempiscrit)) |
joran | 20:521f795ea9d7 | 70 | { |
joran | 24:eeef4009640d | 71 | this->error = true; |
joran | 20:521f795ea9d7 | 72 | printf("### Temperature alarm has been triggered after %d ###\r\n",readtimer); |
joran | 20:521f795ea9d7 | 73 | buzzOnce(); |
joran | 20:521f795ea9d7 | 74 | temptimer.stop(); |
joran | 20:521f795ea9d7 | 75 | temptimer.reset(); |
joran | 20:521f795ea9d7 | 76 | this->tempiscrit = false; |
joran | 20:521f795ea9d7 | 77 | } |
joran | 20:521f795ea9d7 | 78 | } else { |
joran | 20:521f795ea9d7 | 79 | temptimer.start(); |
joran | 20:521f795ea9d7 | 80 | } |
joran | 20:521f795ea9d7 | 81 | } |
joran | 20:521f795ea9d7 | 82 | |
joran | 20:521f795ea9d7 | 83 | void AlarmController::raiseAlarmSalt(bool isCrit) |
joran | 20:521f795ea9d7 | 84 | { |
joran | 20:521f795ea9d7 | 85 | this->saltiscrit = isCrit; |
joran | 20:521f795ea9d7 | 86 | int readtimer = salttimer.read(); |
joran | 20:521f795ea9d7 | 87 | if (isCrit) printf("Received a critical salt alarm (%.3f), timer is at %d\r\n",readsalt,readtimer); |
joran | 20:521f795ea9d7 | 88 | if (!isCrit) printf("Received a non-critical salt alarm (%.3f), timer is at %d\r\n",readsalt,readtimer); |
joran | 20:521f795ea9d7 | 89 | if (readtimer > 0 ) { //already running |
joran | 20:521f795ea9d7 | 90 | if ((readtimer >= 30 && saltiscrit) || (readtimer >= 300 && !saltiscrit)) |
joran | 20:521f795ea9d7 | 91 | { |
joran | 24:eeef4009640d | 92 | this->error = true; |
joran | 20:521f795ea9d7 | 93 | printf("### Salt alarm has been triggered after %d seconds ###\r\n",readtimer); |
joran | 20:521f795ea9d7 | 94 | buzzOnce(); |
joran | 20:521f795ea9d7 | 95 | salttimer.stop(); |
joran | 20:521f795ea9d7 | 96 | salttimer.reset(); |
joran | 20:521f795ea9d7 | 97 | this->saltiscrit = false; |
joran | 20:521f795ea9d7 | 98 | } |
joran | 20:521f795ea9d7 | 99 | } else { |
joran | 20:521f795ea9d7 | 100 | salttimer.start(); |
joran | 20:521f795ea9d7 | 101 | } |
sbouber1 | 11:1a0a8fd74bc0 | 102 | } |
sbouber1 | 11:1a0a8fd74bc0 | 103 | |
sbouber1 | 11:1a0a8fd74bc0 | 104 | std::string AlarmController::get_name() { |
sbouber1 | 11:1a0a8fd74bc0 | 105 | return "AlarmController"; |
sbouber1 | 11:1a0a8fd74bc0 | 106 | } |
sbouber1 | 11:1a0a8fd74bc0 | 107 | |
sbouber1 | 11:1a0a8fd74bc0 | 108 | bool AlarmController::is_error() { |
sbouber1 | 11:1a0a8fd74bc0 | 109 | return this->error; |
sbouber1 | 11:1a0a8fd74bc0 | 110 | } |
sbouber1 | 11:1a0a8fd74bc0 | 111 | |
sbouber1 | 11:1a0a8fd74bc0 | 112 | char *AlarmController::get_error_message() { |
sbouber1 | 11:1a0a8fd74bc0 | 113 | return this->error_msg; |
sbouber1 | 11:1a0a8fd74bc0 | 114 | } |
sbouber1 | 11:1a0a8fd74bc0 | 115 | |
sbouber1 | 11:1a0a8fd74bc0 | 116 | void AlarmController::activate_buzzer() { |
sbouber1 | 11:1a0a8fd74bc0 | 117 | printf("Should activate buzzer now\r\n"); |
joran | 20:521f795ea9d7 | 118 | } |
joran | 20:521f795ea9d7 | 119 | |
joran | 20:521f795ea9d7 | 120 | void AlarmController::buzzOnce() { |
joran | 20:521f795ea9d7 | 121 | |
joran | 20:521f795ea9d7 | 122 | buzzer = 1; |
joran | 20:521f795ea9d7 | 123 | led1=1; |
joran | 20:521f795ea9d7 | 124 | led2=1; |
joran | 20:521f795ea9d7 | 125 | led3=1; |
joran | 20:521f795ea9d7 | 126 | led4=1; |
joran | 20:521f795ea9d7 | 127 | wait(0.1); |
joran | 20:521f795ea9d7 | 128 | buzzer = 0; |
joran | 20:521f795ea9d7 | 129 | led1=0; |
joran | 20:521f795ea9d7 | 130 | led2=0; |
joran | 20:521f795ea9d7 | 131 | led3=0; |
joran | 20:521f795ea9d7 | 132 | led4=0; |
joran | 20:521f795ea9d7 | 133 | |
sbouber1 | 11:1a0a8fd74bc0 | 134 | } |