Red Light Work

Fork of realtimeMMLib by Graham Nicholson

Committer:
ChrisAydon
Date:
Thu Feb 15 16:17:25 2018 +0000
Revision:
2:ed0430db9b2b
Parent:
1:b80e5f26b233
Pushing Latest Changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GTNicholson 0:9f82ee1feae7 1
GTNicholson 0:9f82ee1feae7 2 #include "MBedStation.h"
GTNicholson 0:9f82ee1feae7 3 #include "sensor_base.h"
GTNicholson 0:9f82ee1feae7 4 #include "qeihw.h"
GTNicholson 0:9f82ee1feae7 5 #include <cstdint>
GTNicholson 0:9f82ee1feae7 6
GTNicholson 0:9f82ee1feae7 7
ChrisAydon 2:ed0430db9b2b 8 MBedStation::MBedStation() :light_1(p17), light_2(LED4)
GTNicholson 0:9f82ee1feae7 9 {
ChrisAydon 1:b80e5f26b233 10
GTNicholson 0:9f82ee1feae7 11 }
GTNicholson 0:9f82ee1feae7 12
GTNicholson 0:9f82ee1feae7 13 //sensor_base MBed::sensors[1]
GTNicholson 0:9f82ee1feae7 14
GTNicholson 0:9f82ee1feae7 15 void MBedStation::setup()
GTNicholson 0:9f82ee1feae7 16 {
GTNicholson 0:9f82ee1feae7 17
GTNicholson 0:9f82ee1feae7 18 sensor_onoff sensor0(p5);
GTNicholson 0:9f82ee1feae7 19 sensor0.sensor_id = 1;
GTNicholson 0:9f82ee1feae7 20 sensor0.enabled = true;
GTNicholson 0:9f82ee1feae7 21 MBedStation::sensors[0] = sensor0;
GTNicholson 0:9f82ee1feae7 22 sensor_0 = sensor0;
GTNicholson 0:9f82ee1feae7 23
GTNicholson 0:9f82ee1feae7 24 sensor_vin sensor1(p15);
GTNicholson 0:9f82ee1feae7 25 sensor1.sensor_id = 2;
GTNicholson 0:9f82ee1feae7 26 sensor1.enabled = true;
GTNicholson 0:9f82ee1feae7 27 MBedStation::sensors[1] = sensor1;
GTNicholson 0:9f82ee1feae7 28 sensor_1 = sensor1;
GTNicholson 0:9f82ee1feae7 29
GTNicholson 0:9f82ee1feae7 30 sensor_vin sensor2(p16);
GTNicholson 0:9f82ee1feae7 31 sensor2.sensor_id = 3;
GTNicholson 0:9f82ee1feae7 32 sensor2.enabled = true;
GTNicholson 0:9f82ee1feae7 33 MBedStation::sensors[2] = sensor2;
GTNicholson 0:9f82ee1feae7 34 sensor_2 = sensor2;
GTNicholson 0:9f82ee1feae7 35
ChrisAydon 2:ed0430db9b2b 36 DigitalOut light1(p17);
ChrisAydon 1:b80e5f26b233 37 light_1 = light1;
ChrisAydon 1:b80e5f26b233 38
ChrisAydon 1:b80e5f26b233 39 DigitalOut light2(LED4);
ChrisAydon 1:b80e5f26b233 40 light_2 = light2;
ChrisAydon 1:b80e5f26b233 41
GTNicholson 0:9f82ee1feae7 42 /*
GTNicholson 0:9f82ee1feae7 43 sensor_pulse sensor3(p6);
GTNicholson 0:9f82ee1feae7 44 sensor3.sensor_id = 4;
GTNicholson 0:9f82ee1feae7 45 sensor3.enabled = true;
GTNicholson 0:9f82ee1feae7 46 MBedStation::sensors[3] = sensor3;
GTNicholson 0:9f82ee1feae7 47 sensor_3 = sensor3;
GTNicholson 0:9f82ee1feae7 48 */
GTNicholson 0:9f82ee1feae7 49 }
ChrisAydon 1:b80e5f26b233 50
ChrisAydon 1:b80e5f26b233 51 int MBedStation::ProcessResponse(char * Response)
ChrisAydon 1:b80e5f26b233 52 {
ChrisAydon 1:b80e5f26b233 53 int led_response;
ChrisAydon 1:b80e5f26b233 54 led_response = atoi(Response);
ChrisAydon 1:b80e5f26b233 55 if (led_response == 1 or led_response == 3)
ChrisAydon 1:b80e5f26b233 56 {
ChrisAydon 1:b80e5f26b233 57 light_1 = 1;
ChrisAydon 1:b80e5f26b233 58 }
ChrisAydon 1:b80e5f26b233 59 else
ChrisAydon 1:b80e5f26b233 60 {
ChrisAydon 1:b80e5f26b233 61 light_1 =0;
ChrisAydon 1:b80e5f26b233 62 }
ChrisAydon 1:b80e5f26b233 63
ChrisAydon 1:b80e5f26b233 64 if (led_response == 2 or led_response == 3)
ChrisAydon 1:b80e5f26b233 65 {
ChrisAydon 1:b80e5f26b233 66 light_2 = 1;
ChrisAydon 1:b80e5f26b233 67 }
ChrisAydon 1:b80e5f26b233 68 else
ChrisAydon 1:b80e5f26b233 69 {
ChrisAydon 1:b80e5f26b233 70 light_2 =0;
ChrisAydon 1:b80e5f26b233 71 }
ChrisAydon 1:b80e5f26b233 72 return 1;
ChrisAydon 1:b80e5f26b233 73 }