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
ProximityController.cpp@80:38e274c4dafa, 2016-06-24 (annotated)
- Committer:
- sbouber1
- Date:
- Fri Jun 24 13:51:42 2016 +0000
- Revision:
- 80:38e274c4dafa
- Parent:
- 72:f8c4f731f0fe
final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joran | 5:44ce56378b65 | 1 | #include "ProximityController.h" |
sbouber1 | 68:b769c0f23406 | 2 | #include "SensorAlarmController.h" |
joran | 5:44ce56378b65 | 3 | |
sbouber1 | 58:b5f0c0f305ff | 4 | static Ping pinger(p30); |
joran | 66:133398875949 | 5 | static DigitalOut alarmled(LED3); |
joran | 5:44ce56378b65 | 6 | |
sbouber1 | 10:fd4670ec0806 | 7 | void ProximityController::update() { |
joran | 5:44ce56378b65 | 8 | int range; |
joran | 5:44ce56378b65 | 9 | |
joran | 5:44ce56378b65 | 10 | pinger.Send(); |
sbouber1 | 10:fd4670ec0806 | 11 | Thread::wait(30); |
joran | 5:44ce56378b65 | 12 | range = pinger.Read_cm()/ 2; |
sbouber1 | 10:fd4670ec0806 | 13 | this->distance = (float)range; |
sbouber1 | 68:b769c0f23406 | 14 | |
sbouber1 | 72:f8c4f731f0fe | 15 | printf("Read distance: %.3f\r\n", distance); |
sbouber1 | 72:f8c4f731f0fe | 16 | |
sbouber1 | 68:b769c0f23406 | 17 | if(distance < 0.01) { |
sbouber1 | 68:b769c0f23406 | 18 | SensorAlarmController::buzzOnce(); |
sbouber1 | 68:b769c0f23406 | 19 | setLed(true); |
sbouber1 | 68:b769c0f23406 | 20 | } else { |
sbouber1 | 68:b769c0f23406 | 21 | setLed(false); |
sbouber1 | 68:b769c0f23406 | 22 | } |
sbouber1 | 10:fd4670ec0806 | 23 | } |
sbouber1 | 10:fd4670ec0806 | 24 | |
sbouber1 | 58:b5f0c0f305ff | 25 | float ProximityController::getDistance() { |
joran | 25:169672dbab91 | 26 | return this->distance; |
joran | 25:169672dbab91 | 27 | } |
sbouber1 | 10:fd4670ec0806 | 28 | |
sbouber1 | 10:fd4670ec0806 | 29 | float ProximityController::getValue() { |
sbouber1 | 68:b769c0f23406 | 30 | if(distance < 0.01) { |
sbouber1 | 68:b769c0f23406 | 31 | this->volume = -1.0f; |
sbouber1 | 68:b769c0f23406 | 32 | } else { |
sbouber1 | 72:f8c4f731f0fe | 33 | this->volume = (DISTANCE_TO_BASE - this->distance) * 76.92f; |
sbouber1 | 68:b769c0f23406 | 34 | } |
sbouber1 | 68:b769c0f23406 | 35 | |
joran | 25:169672dbab91 | 36 | return this->volume; |
sbouber1 | 10:fd4670ec0806 | 37 | } |
sbouber1 | 10:fd4670ec0806 | 38 | |
sbouber1 | 58:b5f0c0f305ff | 39 | std::string ProximityController::getName() { |
sbouber1 | 10:fd4670ec0806 | 40 | return "ProximityController"; |
joran | 66:133398875949 | 41 | } |
joran | 66:133398875949 | 42 | |
joran | 66:133398875949 | 43 | void ProximityController::setLed(bool value){ |
joran | 66:133398875949 | 44 | if (value) alarmled = 1; |
joran | 66:133398875949 | 45 | if (!value) alarmled = 0; |
sbouber1 | 10:fd4670ec0806 | 46 | } |