Marek Vitula / Mbed OS goal_counter_project

Dependencies:   GoalCounter WS2812 PixelArray

Committer:
nxf46245
Date:
Sat Jan 12 18:50:49 2019 +0000
Revision:
3:d74c47d2e933
Parent:
2:f04959a6fd61
Updated GoalCounter class

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxf46245 0:24f846b68c77 1 #include "GoalCounter.h"
nxf46245 0:24f846b68c77 2
nxf46245 3:d74c47d2e933 3 GoalCounter::GoalCounter(PinName pin1, PinName pin2) : _interrupt1(pin1) {
nxf46245 3:d74c47d2e933 4 _interrupt1.fall(callback(this, &GoalCounter::tstart1));
nxf46245 3:d74c47d2e933 5 _interrupt1.rise(callback(this, &GoalCounter::tstop1));
nxf46245 3:d74c47d2e933 6
nxf46245 3:d74c47d2e933 7 // _interrupt2.fall(callback(this, &GoalCounter::tstart2));
nxf46245 3:d74c47d2e933 8 // _interrupt2.rise(callback(this, &GoalCounter::tstop2));
nxf46245 3:d74c47d2e933 9
nxf46245 3:d74c47d2e933 10 Timer t1;
nxf46245 3:d74c47d2e933 11 Timer t2;
nxf46245 3:d74c47d2e933 12
nxf46245 3:d74c47d2e933 13 _score1 = 0;
nxf46245 3:d74c47d2e933 14 _score2 = 0;
nxf46245 3:d74c47d2e933 15
nxf46245 3:d74c47d2e933 16 _time1 = 0;
nxf46245 3:d74c47d2e933 17 _time2 = 0;
nxf46245 3:d74c47d2e933 18
nxf46245 3:d74c47d2e933 19 // _balltimes1 = {0};
nxf46245 3:d74c47d2e933 20 // _balltimes2 = {0};
nxf46245 3:d74c47d2e933 21
nxf46245 3:d74c47d2e933 22 is_goal1 = 0;
nxf46245 3:d74c47d2e933 23 is_goal2 = 0;
nxf46245 3:d74c47d2e933 24
nxf46245 0:24f846b68c77 25 }
nxf46245 0:24f846b68c77 26
nxf46245 3:d74c47d2e933 27 void GoalCounter::tstart1() {
nxf46245 3:d74c47d2e933 28 t1.start();
nxf46245 0:24f846b68c77 29 }
nxf46245 0:24f846b68c77 30
nxf46245 3:d74c47d2e933 31 void GoalCounter::tstop1() {
nxf46245 3:d74c47d2e933 32 t1.stop();
nxf46245 3:d74c47d2e933 33 _time1 = t1.read();
nxf46245 3:d74c47d2e933 34 t1.reset();
nxf46245 0:24f846b68c77 35
nxf46245 3:d74c47d2e933 36 if ( _time1 > 0 && _time1 < 2 && _score1 < 10) {
nxf46245 3:d74c47d2e933 37 _balltimes1[++_score1] = _time1;
nxf46245 3:d74c47d2e933 38 is_goal1 = 1;
nxf46245 3:d74c47d2e933 39 }
nxf46245 0:24f846b68c77 40 }
nxf46245 0:24f846b68c77 41
nxf46245 3:d74c47d2e933 42 void GoalCounter::tstart2() {
nxf46245 3:d74c47d2e933 43 t2.start();
nxf46245 3:d74c47d2e933 44 }
nxf46245 3:d74c47d2e933 45
nxf46245 3:d74c47d2e933 46 void GoalCounter::tstop2() {
nxf46245 3:d74c47d2e933 47 t2.stop();
nxf46245 3:d74c47d2e933 48 _time2 = t2.read();
nxf46245 3:d74c47d2e933 49 t2.reset();
nxf46245 3:d74c47d2e933 50
nxf46245 3:d74c47d2e933 51 if ( _time2 > 0 && _time2 < 2 && _score2 < 10) {
nxf46245 3:d74c47d2e933 52 _balltimes2[++_score2] = _time2;
nxf46245 3:d74c47d2e933 53 is_goal2 = 1;
nxf46245 3:d74c47d2e933 54 }
nxf46245 2:f04959a6fd61 55 }
nxf46245 2:f04959a6fd61 56
nxf46245 0:24f846b68c77 57 uint8_t GoalCounter::get_score() {
nxf46245 3:d74c47d2e933 58 return _score1;
nxf46245 0:24f846b68c77 59 }
nxf46245 0:24f846b68c77 60
nxf46245 0:24f846b68c77 61 float GoalCounter::get_balltime(uint8_t score) {
nxf46245 0:24f846b68c77 62 if (score <= 10 && score > 0)
nxf46245 3:d74c47d2e933 63 return _balltimes1[score];
nxf46245 0:24f846b68c77 64 else
nxf46245 0:24f846b68c77 65 return -1;
nxf46245 0:24f846b68c77 66 }
nxf46245 0:24f846b68c77 67
nxf46245 0:24f846b68c77 68 float GoalCounter::get_balltime() {
nxf46245 3:d74c47d2e933 69 return _balltimes1[_score1];
nxf46245 0:24f846b68c77 70
nxf46245 0:24f846b68c77 71 }
nxf46245 0:24f846b68c77 72
nxf46245 0:24f846b68c77 73 float GoalCounter::get_ballspeed(uint8_t score) {
nxf46245 0:24f846b68c77 74 if (score <= 10 && score > 0) {
nxf46245 3:d74c47d2e933 75 float speed = 0.034f/_balltimes1[score]*3.6f;
nxf46245 0:24f846b68c77 76 return speed;
nxf46245 0:24f846b68c77 77 }
nxf46245 0:24f846b68c77 78 else
nxf46245 0:24f846b68c77 79 return -1;
nxf46245 0:24f846b68c77 80 }
nxf46245 0:24f846b68c77 81
nxf46245 0:24f846b68c77 82 float GoalCounter::get_ballspeed() {
nxf46245 3:d74c47d2e933 83 float speed = 0.034f/_balltimes1[_score1]*3.6f;
nxf46245 0:24f846b68c77 84 return speed;
nxf46245 0:24f846b68c77 85 }
nxf46245 0:24f846b68c77 86
nxf46245 2:f04959a6fd61 87
nxf46245 0:24f846b68c77 88
nxf46245 0:24f846b68c77 89
nxf46245 0:24f846b68c77 90
nxf46245 0:24f846b68c77 91