summaryrefslogtreecommitdiffstats
path: root/source/Concept/Framework/distance_sensor.h
blob: 832e556af097b1f4f048d75fef650b79463302ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _DISTANCE_SENSOR_H
#define _DISTANCE_SENSOR_H

#include "stdafx.h"
#include "sensor.h"

class Distance_Sensor : public Sensor
{
public:
	Distance_Sensor()
	{
		this->parent = NULL;
		this->moduleId = 0;
		this->hardwarePort = NULL;
		this->hardwareDDR = NULL;
		this->hardwarePin = NULL;
		this->pin = 0;
	}

	Distance_Sensor(uint32 sensorId)
	{
		this->parent = NULL;
		this->moduleId = sensorId;

		switch(sensorId)
		{
			case IO_SENSOR_DISTANCE_0_DEG:
				this->hardwarePort = &PORTC;
				this->hardwareDDR = &DDRC;
				this->hardwarePin = &PINC;
				this->pin = (1 << 0);
				break;
			case IO_SENSOR_DISTANCE_90_DEG:
				this->hardwarePort = &PORTC;
				this->hardwareDDR = &DDRC;
				this->hardwarePin = &PINC;
				this->pin = (1 << 1);
				break;
			case IO_SENSOR_DISTANCE_180_DEG:
				this->hardwarePort = &PORTC;
				this->hardwareDDR = &DDRC;
				this->hardwarePin = &PINC;
				this->pin = (1 << 2);
				break;
			case IO_SENSOR_DISTANCE_270_DEG:
				this->hardwarePort = &PORTC;
				this->hardwareDDR = &DDRC;
				this->hardwarePin = &PINC;
				this->pin = (1 << 3);
				break;
			default:
				this->hardwarePort = NULL;
				this->hardwareDDR = NULL;
				this->hardwarePin = NULL;
				this->pin = 0;
				break;
		}
	}

protected:
	//Hardware
	volatile uint8* hardwarePort;
	volatile uint8* hardwareDDR;
	volatile uint8* hardwarePin;
	uint8 pin;

public:
	float GetDistance();
};

#endif