From 3c3c628b617dc53f0b7b59285c7d67888074c33d Mon Sep 17 00:00:00 2001 From: sicarius Date: Sun, 18 Feb 2007 00:14:00 +0000 Subject: +++ Additional Codework --- source/Concept/Framework/modules/output/display.c | 1 + source/Concept/Framework/modules/output/display.h | 198 +++++++++++++++++++++ source/Concept/Framework/modules/output/dribbler.c | 1 + source/Concept/Framework/modules/output/dribbler.h | 118 ++++++++++++ source/Concept/Framework/modules/output/engine.c | 1 + source/Concept/Framework/modules/output/engine.h | 124 +++++++++++++ source/Concept/Framework/modules/output/kicker.c | 1 + source/Concept/Framework/modules/output/kicker.h | 84 +++++++++ source/Concept/Framework/modules/output/led.c | 1 + source/Concept/Framework/modules/output/led.h | 65 +++++++ 10 files changed, 594 insertions(+) create mode 100755 source/Concept/Framework/modules/output/display.c create mode 100755 source/Concept/Framework/modules/output/display.h create mode 100755 source/Concept/Framework/modules/output/dribbler.c create mode 100755 source/Concept/Framework/modules/output/dribbler.h create mode 100755 source/Concept/Framework/modules/output/engine.c create mode 100755 source/Concept/Framework/modules/output/engine.h create mode 100755 source/Concept/Framework/modules/output/kicker.c create mode 100755 source/Concept/Framework/modules/output/kicker.h create mode 100755 source/Concept/Framework/modules/output/led.c create mode 100755 source/Concept/Framework/modules/output/led.h (limited to 'source/Concept/Framework/modules/output') diff --git a/source/Concept/Framework/modules/output/display.c b/source/Concept/Framework/modules/output/display.c new file mode 100755 index 0000000..82fbb41 --- /dev/null +++ b/source/Concept/Framework/modules/output/display.c @@ -0,0 +1 @@ +#include "display.h" diff --git a/source/Concept/Framework/modules/output/display.h b/source/Concept/Framework/modules/output/display.h new file mode 100755 index 0000000..e221120 --- /dev/null +++ b/source/Concept/Framework/modules/output/display.h @@ -0,0 +1,198 @@ +#ifndef _DISPLAY_H +#define _DISPLAY_H + +#include "../../stdafx.h" + +class Display : public IO_Module +{ +public: + Display() + { + this->parent = NULL; + this->moduleId = 0; + this->cursorVisible = false; + this->illuminationEnabled = true; + this->commandClear = 0; + this->commandReturnCursor = 0; + this->commandNewLine = 0; + this->commandSetting = 0; + this->settingCursorVisible = 0; + this->settingIllumination = 0; + this->settingCursorPosition = 0; + } + + Display(uint32 displayId) + { + this->parent = NULL; + this->moduleId = displayId; + this->cursorVisible = false; + this->illuminationEnabled = true; + + switch(displayId) + { + case IO_DISPLAY_MAIN: + this->commandClear = 12; + this->commandReturnCursor = 13; + this->commandNewLine = 10; + this->commandSetting = 27; + this->settingCursorVisible = 67; + this->settingIllumination = 76; + this->settingCursorPosition = 79; + msleep(100); + uart1_init(103);//9600 BAUD at 16MHz Atmel + msleep(100); + break; + default: + this->commandClear = 0; + this->commandReturnCursor = 0; + this->commandNewLine = 0; + this->commandSetting = 0; + this->settingCursorVisible = 0; + this->settingIllumination = 0; + this->settingCursorPosition = 0; + break; + } + } + +protected: + bool cursorVisible; + bool illuminationEnabled; + //Commands + uint8 commandClear; + uint8 commandReturnCursor; + uint8 commandNewLine; + uint8 commandSetting; + //Settings + uint8 settingCursorVisible; + uint8 settingIllumination; + uint8 settingCursorPosition; + + void SendCommand(uint8 newCommand) + { + switch(moduleId) + { + case IO_DISPLAY_MAIN: + uart1_putc(newCommand); + break; + default: + break; + } + } + +public: + void Print(char* newString) + { + switch(moduleId) + { + case IO_DISPLAY_MAIN: + uart1_puts(newString); + break; + default: + break; + } + } + + void Print(int32 newInteger) + { + char buffer[12]; + ltoa(newInteger, buffer, 10); + Print(buffer); + } + + void PrintFloat(float newFloat) + { + Print((int32)(newFloat)); + Print("."); + Print(abs((uint32)(newFloat - float((int32)(newFloat)) * 100000))); + } + + void Print(char* newString, uint8 xPos, uint8 yPos) + { + SetCursorPosition(xPos, yPos); + Print(newString); + } + + void Print(int32 newInteger, uint8 xPos, uint8 yPos) + { + SetCursorPosition(xPos, yPos); + Print(newInteger); + } + + void PrintFloat(float newFloat, uint8 xPos, uint8 yPos) + { + SetCursorPosition(xPos, yPos); + PrintFloat(newFloat); + } + + void Clear() + { + SendCommand(commandClear); + } + + void ReturnCursor() + { + SendCommand(commandReturnCursor); + } + + void NewLine() + { + SendCommand(commandNewLine); + } + + bool GetCursorVisible() + { + return cursorVisible; + } + + void SetCursorVisible(bool newStatus) + { + cursorVisible = newStatus; + + SendCommand(commandSetting); + SendCommand(settingCursorVisible); + + if(cursorVisible) + { + SendCommand(1); + } + else + { + SendCommand(0); + } + } + + bool GetLightingEnabled() + { + return illuminationEnabled; + } + + void SetLightingEnabled(bool newStatus) + { + illuminationEnabled = newStatus; + + SendCommand(commandSetting); + SendCommand(settingIllumination); + + if(illuminationEnabled) + { + SendCommand(1); + } + else + { + SendCommand(0); + } + } + + void SetCursorPosition(uint8 newX, uint8 newY) + { + if(!newX || newX > 20) return; + if(!newY || newY > 4) return; + + SendCommand(commandSetting); + SendCommand(settingCursorPosition); + SendCommand(newX); + SendCommand(newY); + } +}; + +#endif diff --git a/source/Concept/Framework/modules/output/dribbler.c b/source/Concept/Framework/modules/output/dribbler.c new file mode 100755 index 0000000..20557e4 --- /dev/null +++ b/source/Concept/Framework/modules/output/dribbler.c @@ -0,0 +1 @@ +#include "dribbler.h" diff --git a/source/Concept/Framework/modules/output/dribbler.h b/source/Concept/Framework/modules/output/dribbler.h new file mode 100755 index 0000000..b11af69 --- /dev/null +++ b/source/Concept/Framework/modules/output/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 diff --git a/source/Concept/Framework/modules/output/engine.c b/source/Concept/Framework/modules/output/engine.c new file mode 100755 index 0000000..5c14c17 --- /dev/null +++ b/source/Concept/Framework/modules/output/engine.c @@ -0,0 +1 @@ +#include "engine.h" diff --git a/source/Concept/Framework/modules/output/engine.h b/source/Concept/Framework/modules/output/engine.h new file mode 100755 index 0000000..27b9905 --- /dev/null +++ b/source/Concept/Framework/modules/output/engine.h @@ -0,0 +1,124 @@ +#ifndef _ENGINE_H +#define _ENGINE_H + +#include "../../stdafx.h" + +class Engine : public IO_Module +{ +public: + Engine() + { + this->enabled = false; + this->curSpeed = 0; + this->parent = NULL; + this->moduleId = 0; + this->hardwarePort = NULL; + this->pwmSpeed = NULL; + this->pinForward = 0; + this->pinReverse = 0; + } + + Engine(uint32 engineId) + { + this->enabled = false; + this->curSpeed = 0; + this->parent = NULL; + this->moduleId = engineId; + + switch(engineId) + { + case IO_ENGINE_DRIVE_LEFT: + this->hardwarePort = &PORTB; + this->pwmSpeed = &OCR1A; + this->pinForward = (1 << 0); + this->pinReverse = (1 << 1); + break; + case IO_ENGINE_DRIVE_BACK: + this->hardwarePort = &PORTB; + this->pwmSpeed = &OCR1B; + this->pinForward = (1 << 2); + this->pinReverse = (1 << 3); + break; + case IO_ENGINE_DRIVE_RIGHT: + this->hardwarePort = &PORTD; + this->pwmSpeed = &OCR3A; + this->pinForward = (1 << 5); + this->pinReverse = (1 << 4); + break; + default: + this->hardwarePort = NULL; + this->pwmSpeed = NULL; + this->pinForward = 0; + this->pinReverse = 0; + break; + } + + *this->pwmSpeed = 0; + } + +protected: + bool enabled; + float curSpeed; + + //Hardware + volatile uint8* hardwarePort; + volatile uint16* pwmSpeed; + uint8 pinForward; + uint8 pinReverse; + + void UpdateDirection() + { + if(enabled) + { + if(curSpeed > 0) + { + *hardwarePort |= pinForward; + *hardwarePort &= ~pinReverse; + } + else if(curSpeed < 0) + { + *hardwarePort |= pinReverse; + *hardwarePort &= ~pinForward; + } + else + { + *hardwarePort |= pinForward; + *hardwarePort |= pinReverse; + } + } + else + { + *hardwarePort &= ~pinForward; + *hardwarePort &= ~pinReverse; + } + } + +public: + float GetSpeed() + { + return curSpeed; + } + + void SetSpeed(float newSpeed) + { + curSpeed = newSpeed; + + *pwmSpeed = (abs((int16)(newSpeed / SPEED_PER_PWM))); + + UpdateDirection(); + } + + bool GetEnabled() + { + return enabled; + } + + void SetEnabled(bool newStatus) + { + enabled = newStatus; + + UpdateDirection(); + } +}; + +#endif diff --git a/source/Concept/Framework/modules/output/kicker.c b/source/Concept/Framework/modules/output/kicker.c new file mode 100755 index 0000000..6670efb --- /dev/null +++ b/source/Concept/Framework/modules/output/kicker.c @@ -0,0 +1 @@ +#include "kicker.h" diff --git a/source/Concept/Framework/modules/output/kicker.h b/source/Concept/Framework/modules/output/kicker.h new file mode 100755 index 0000000..080666a --- /dev/null +++ b/source/Concept/Framework/modules/output/kicker.h @@ -0,0 +1,84 @@ +#ifndef _KICKER_H +#define _KICKER_H + +#include "../../stdafx.h" + +class Kicker : public IO_Module +{ +public: + Kicker() + { + this->enabled = false; + this->parent = NULL; + this->moduleId = 0; + this->portPower = NULL; + this->portForward = NULL; + this->portReverse = NULL; + this->pinPower = 0; + this->pinForward = 0; + this->pinReverse = 0; + } + + Kicker(uint32 kickerId) + { + this->enabled = false; + this->parent = NULL; + this->moduleId = kickerId; + + switch(kickerId) + { + case IO_KICKER_MAIN: + this->portPower = &PORTG; + this->portForward = &PORTA; + this->portReverse = &PORTE; + this->pinPower = (1 << 3); + this->pinForward = (1 << 2); + this->pinReverse = (1 << 6); + break; + default: + this->portPower = NULL; + this->portForward = NULL; + this->portReverse = NULL; + this->pinPower = 0; + this->pinForward = 0; + this->pinReverse = 0; + break; + } + + *this->portForward |= this->pinForward; + *this->portReverse &= ~this->pinReverse; + } + +protected: + bool enabled; + + //Hardware + volatile uint8* portPower; + volatile uint8* portForward; + volatile uint8* portReverse; + uint8 pinPower; + uint8 pinForward; + uint8 pinReverse; + +public: + bool GetEnabled() + { + return enabled; + } + + void SetEnabled(bool newStatus) + { + enabled = newStatus; + + if(enabled) + { + *portPower |= pinPower; + } + else + { + *portPower &= ~pinPower; + } + } +}; + +#endif diff --git a/source/Concept/Framework/modules/output/led.c b/source/Concept/Framework/modules/output/led.c new file mode 100755 index 0000000..687b2db --- /dev/null +++ b/source/Concept/Framework/modules/output/led.c @@ -0,0 +1 @@ +#include "led.h" diff --git a/source/Concept/Framework/modules/output/led.h b/source/Concept/Framework/modules/output/led.h new file mode 100755 index 0000000..08e7466 --- /dev/null +++ b/source/Concept/Framework/modules/output/led.h @@ -0,0 +1,65 @@ +#ifndef _LED_H +#define _LED_H + +#include "../../stdafx.h" + +class Led : public IO_Module +{ +public: + Led() + { + this->enabled = false; + this->parent = NULL; + this->moduleId = 0; + this->hardwarePort = NULL; + this->pinPower = 0; + } + + Led(uint32 ledId) + { + this->enabled = false; + this->parent = NULL; + this->moduleId = ledId; + + switch(ledId) + { + case IO_LED_MAIN: + this->hardwarePort = &PORTB; + this->pinPower = (1 << 1); + break; + default: + this->hardwarePort = NULL; + this->pinPower = 0; + break; + } + } + +protected: + bool enabled; + + //Hardware + volatile uint8* hardwarePort; + uint8 pinPower; + +public: + bool GetEnabled() + { + return enabled; + } + + void SetEnabled(bool newStatus) + { + enabled = newStatus; + + if(enabled) + { + *hardwarePort &= ~pinPower; + } + else + { + *hardwarePort |= pinPower; + } + } +}; + +#endif -- cgit v1.2.3