From 4a2ba4b7105d168932163cbd07a062fdf2ba00e9 Mon Sep 17 00:00:00 2001 From: sicarius Date: Sat, 17 Feb 2007 00:35:01 +0000 Subject: +++ enhanced framework hardware interface --- source/Concept/Framework/dribbler.h | 118 ++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 source/Concept/Framework/dribbler.h (limited to 'source/Concept/Framework/dribbler.h') diff --git a/source/Concept/Framework/dribbler.h b/source/Concept/Framework/dribbler.h new file mode 100644 index 0000000..64c045a --- /dev/null +++ b/source/Concept/Framework/dribbler.h @@ -0,0 +1,118 @@ +#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; + } + else if(curSpeed < 0) + { + *hardwarePort |= pinReverse; + *hardwarePort &= ~pinForward; + } + else + { + *hardwarePort |= pinForward; + *hardwarePort |= pinReverse; + } + + *portPower |= pinPower; + } + 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 -- cgit v1.2.3