Codework
This commit is contained in:
parent
9525458918
commit
655dd7522f
14 changed files with 212 additions and 166 deletions
|
@ -5,21 +5,36 @@ float Distance_Sensor::GetDistance()
|
|||
{
|
||||
uint32 result = 0;
|
||||
|
||||
//(parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print("Gen Pulse; Pin:",1,4);
|
||||
//(parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print((int)(*hardwarePin & pin));
|
||||
|
||||
msleep(500);
|
||||
|
||||
//Generate pulse
|
||||
*hardwareDDR |= pin;//Set pin output
|
||||
*hardwarePort |= pin;//Activate port
|
||||
usleep(10);//Wait for 10µs
|
||||
*hardwarePort &= ~pin;//Deactivate port
|
||||
*hardwareDDR &= ~pin;//Set pin input
|
||||
*hardwarePort &= ~pin;//Deactivate port
|
||||
|
||||
//(parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print("Wait response; Pin:",1,4);
|
||||
//(parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print((int)(*hardwarePin & pin));
|
||||
|
||||
uint16 i;
|
||||
//Wait for response
|
||||
for(uint16 i = 0; (!(*hardwarePin & pin)) && (i < 1000); i++) { asm volatile("nop"); }
|
||||
for(i = 0; (!(*hardwarePin & pin)) && (i < 1000); i++) { asm volatile("nop"); }
|
||||
|
||||
//Calculate duration of response
|
||||
while((*hardwarePin & pin)&&(result < 300000))
|
||||
{
|
||||
result++;
|
||||
asm volatile("nop");
|
||||
asm volatile("nop");
|
||||
asm volatile("nop");
|
||||
asm volatile("nop");
|
||||
asm volatile("nop");
|
||||
asm volatile("nop");
|
||||
asm volatile("nop");
|
||||
}
|
||||
|
||||
return (float(result) * DISTANCE_PER_VALUE);
|
||||
|
|
|
@ -5,5 +5,5 @@ uint16 IR_Sensor::GetIRIntensity()
|
|||
{
|
||||
if(!parent) return 0;
|
||||
|
||||
return parent->GetADCValue(channel);
|
||||
return min(parent->GetADCValue(channel) + this->intensityCorrection, 1023);
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@ public:
|
|||
{
|
||||
this->parent = NULL;
|
||||
this->moduleId = 0;
|
||||
this->intensityCorrection = 0;
|
||||
}
|
||||
|
||||
IR_Sensor(uint32 sensorId)
|
||||
{
|
||||
this->parent = NULL;
|
||||
this->moduleId = sensorId;
|
||||
this->intensityCorrection = 0;
|
||||
|
||||
switch(sensorId)
|
||||
{
|
||||
|
@ -32,12 +34,15 @@ public:
|
|||
break;
|
||||
case IO_SENSOR_IR_100_DEG:
|
||||
this->channel = 3;
|
||||
this->intensityCorrection = 40;
|
||||
break;
|
||||
case IO_SENSOR_IR_180_DEG:
|
||||
this->channel = 4;
|
||||
this->intensityCorrection = 50;
|
||||
break;
|
||||
case IO_SENSOR_IR_260_DEG:
|
||||
this->channel = 5;
|
||||
this->intensityCorrection = 70;
|
||||
break;
|
||||
case IO_SENSOR_IR_300_DEG:
|
||||
this->channel = 6;
|
||||
|
@ -55,6 +60,8 @@ protected:
|
|||
//Hardware
|
||||
uint8 channel;
|
||||
|
||||
uint8 intensityCorrection;
|
||||
|
||||
public:
|
||||
uint16 GetIRIntensity();
|
||||
};
|
||||
|
|
Reference in a new issue