This repository has been archived on 2025-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
rc2007-soccer/source/Concept/Framework/modules/output/dribbler.h

120 lines
1.9 KiB
C
Raw Normal View History

2007-02-18 00:14:00 +00:00
#ifndef _DRIBBLER_H
#define _DRIBBLER_H
#include "../../stdafx.h"
class Dribbler : public IO_Module
{
public:
Dribbler()
{
this->enabled = false;
this->curSpeed = 0;
this->parent = NULL;
this->moduleId = 0;
this->hardwarePort = NULL;
this->portPower = NULL;
this->pinForward = 0;
this->pinReverse = 0;
this->pinPower = 0;
}
Dribbler(uint32 dribblerId)
{
this->enabled = false;
this->curSpeed = 1.0f;
this->parent = NULL;
this->moduleId = dribblerId;
switch(dribblerId)
{
case IO_DRIBBLER_MAIN:
this->hardwarePort = &PORTD;
this->portPower = &PORTA;
this->pinForward = (1 << 6);
this->pinReverse = (1 << 7);
this->pinPower = (1 << 5);
break;
default:
this->hardwarePort = NULL;
this->portPower = NULL;
this->pinForward = 0;
this->pinReverse = 0;
this->pinPower = 0;
break;
}
UpdateDirection();
}
protected:
bool enabled;
float curSpeed;
//Hardware
volatile uint8* hardwarePort;
volatile uint8* portPower;
uint8 pinForward;
uint8 pinReverse;
uint8 pinPower;
void UpdateDirection()
{
if(enabled)
{
if(curSpeed > 0)
{
*hardwarePort |= pinForward;
*hardwarePort &= ~pinReverse;
2007-02-22 13:12:03 +00:00
*portPower |= pinPower;
2007-02-18 00:14:00 +00:00
}
else if(curSpeed < 0)
{
*hardwarePort |= pinReverse;
*hardwarePort &= ~pinForward;
2007-02-22 13:12:03 +00:00
*portPower |= pinPower;
2007-02-18 00:14:00 +00:00
}
else
{
*hardwarePort |= pinForward;
*hardwarePort |= pinReverse;
2007-02-22 13:12:03 +00:00
*portPower &= ~pinPower;
}
2007-02-18 00:14:00 +00:00
}
else
{
*hardwarePort &= ~pinForward;
*hardwarePort &= ~pinReverse;
*portPower &= ~pinPower;
}
}
public:
float GetSpeed()
{
return curSpeed;
}
void SetSpeed(float newSpeed)
{
curSpeed = newSpeed;
UpdateDirection();
}
bool GetEnabled()
{
return enabled;
}
void SetEnabled(bool newStatus)
{
enabled = newStatus;
UpdateDirection();
}
};
#endif