diff options
author | sicarius <devnull@localhost> | 2007-02-18 01:14:00 +0100 |
---|---|---|
committer | sicarius <devnull@localhost> | 2007-02-18 01:14:00 +0100 |
commit | 3c3c628b617dc53f0b7b59285c7d67888074c33d (patch) | |
tree | 1d1848b37d14036542e7b704440f4eb4f4d8ef7b /source/Concept/Framework/modules/input | |
parent | 803027cbb45ebe01e4f8b427a7cc95728d6e5f47 (diff) | |
download | rc2007-soccer-3c3c628b617dc53f0b7b59285c7d67888074c33d.tar rc2007-soccer-3c3c628b617dc53f0b7b59285c7d67888074c33d.zip |
+++ Additional Codework
Diffstat (limited to 'source/Concept/Framework/modules/input')
10 files changed, 490 insertions, 0 deletions
diff --git a/source/Concept/Framework/modules/input/distance_sensor.c b/source/Concept/Framework/modules/input/distance_sensor.c new file mode 100755 index 0000000..977784f --- /dev/null +++ b/source/Concept/Framework/modules/input/distance_sensor.c @@ -0,0 +1,32 @@ +#include "distance_sensor.h"
+
+//-----------------------------------------------------------------------------
+float Distance_Sensor::GetDistance()
+{
+ uint32 result = 0;
+
+ //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
+
+ (parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print("pre 1", 4, 1);
+
+ //Wait for response
+ while(!(PINC & pin)){asm volatile("nop");}
+
+ (parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print("pre 2", 4, 1);
+
+ //Calculate duration of response
+ while(*hardwarePin & pin)
+ {
+ result++;
+ asm volatile("nop");
+ }
+
+ (parent->GetModule<Display>(IO_DISPLAY_MAIN))->Print("pre 3", 4, 1);
+
+ return (float(result) * DISTANCE_PER_VALUE);
+}
diff --git a/source/Concept/Framework/modules/input/distance_sensor.h b/source/Concept/Framework/modules/input/distance_sensor.h new file mode 100755 index 0000000..8e6aa21 --- /dev/null +++ b/source/Concept/Framework/modules/input/distance_sensor.h @@ -0,0 +1,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 diff --git a/source/Concept/Framework/modules/input/ir_sensor.c b/source/Concept/Framework/modules/input/ir_sensor.c new file mode 100755 index 0000000..c34feed --- /dev/null +++ b/source/Concept/Framework/modules/input/ir_sensor.c @@ -0,0 +1,9 @@ +#include "ir_sensor.h"
+
+//-----------------------------------------------------------------------------
+uint16 IR_Sensor::GetIRIntensity()
+{ + if(!parent) return 0;
+
+ return parent->GetADCValue(channel);
+}
diff --git a/source/Concept/Framework/modules/input/ir_sensor.h b/source/Concept/Framework/modules/input/ir_sensor.h new file mode 100755 index 0000000..30e6ea4 --- /dev/null +++ b/source/Concept/Framework/modules/input/ir_sensor.h @@ -0,0 +1,62 @@ +#ifndef _IR_SENSOR_H
+#define _IR_SENSOR_H
+
+#include "../../defines.h"
+#include "../../robot.h"
+#include "sensor.h"
+
+class IR_Sensor : public Sensor
+{
+public:
+ IR_Sensor()
+ {
+ this->parent = NULL;
+ this->moduleId = 0;
+ }
+
+ IR_Sensor(uint32 sensorId)
+ {
+ this->parent = NULL;
+ this->moduleId = sensorId;
+
+ switch(sensorId)
+ {
+ case IO_SENSOR_IR_0_DEG:
+ this->channel = 0;
+ break;
+ case IO_SENSOR_IR_30_DEG:
+ this->channel = 1;
+ break;
+ case IO_SENSOR_IR_60_DEG:
+ this->channel = 2;
+ break;
+ case IO_SENSOR_IR_100_DEG:
+ this->channel = 3;
+ break;
+ case IO_SENSOR_IR_180_DEG:
+ this->channel = 4;
+ break;
+ case IO_SENSOR_IR_260_DEG:
+ this->channel = 5;
+ break;
+ case IO_SENSOR_IR_300_DEG:
+ this->channel = 6;
+ break;
+ case IO_SENSOR_IR_330_DEG:
+ this->channel = 7;
+ break;
+ default:
+ this->channel = 8;
+ break;
+ }
+ }
+
+protected:
+ //Hardware
+ uint8 channel;
+
+public:
+ uint16 GetIRIntensity();
+};
+
+#endif diff --git a/source/Concept/Framework/modules/input/keyboard.c b/source/Concept/Framework/modules/input/keyboard.c new file mode 100755 index 0000000..65fc7cf --- /dev/null +++ b/source/Concept/Framework/modules/input/keyboard.c @@ -0,0 +1 @@ +#include "keyboard.h"
diff --git a/source/Concept/Framework/modules/input/keyboard.h b/source/Concept/Framework/modules/input/keyboard.h new file mode 100755 index 0000000..243bb6c --- /dev/null +++ b/source/Concept/Framework/modules/input/keyboard.h @@ -0,0 +1,87 @@ +#ifndef _KEYBOARD_H
+#define _KEYBOARD_H
+
+#include "../../stdafx.h"
+
+class Keyboard : public IO_Module
+{
+public:
+ Keyboard()
+ {
+ this->parent = NULL;
+ this->moduleId = 0;
+ this->commandSetting = 0;
+ this->settingClearBuffer = 0;
+ }
+
+ Keyboard(uint32 keyboardId)
+ {
+ this->parent = NULL;
+ this->moduleId = keyboardId;
+
+ switch(keyboardId)
+ {
+ case IO_KEYBOARD_MAIN:
+ this->commandSetting = 27;
+ this->settingClearBuffer = 123;
+ break;
+ default:
+ this->commandSetting = 0;
+ this->settingClearBuffer = 0;
+ break;
+ }
+ }
+
+protected:
+ //Commands
+ uint8 commandSetting;
+ //Settings
+ uint8 settingClearBuffer;
+
+ void SendCommand(uint8 newCommand)
+ {
+ switch(moduleId)
+ {
+ case IO_KEYBOARD_MAIN:
+ uart1_putc(newCommand);
+ break;
+ default:
+ break;
+ }
+ }
+
+public:
+ uint8 GetInput()
+ {
+ uint16 input = uart1_getc();
+
+ if(input == 0x100)//no data
+ {
+ return 0xEE;//empty
+ }
+ else if(input >= '0' && input <= '9')
+ {
+ return (uint8)(input - '0');
+ }
+ else if(input == '*')
+ {
+ return 10;
+ }
+ else if(input == '#')
+ {
+ return 11;
+ }
+ else
+ {
+ return 0xFF;//unknown
+ }
+ }
+
+ void ClearKeyBuffer()
+ {
+ SendCommand(commandSetting);
+ SendCommand(settingClearBuffer);
+ }
+};
+
+#endif diff --git a/source/Concept/Framework/modules/input/mouse_sensor.c b/source/Concept/Framework/modules/input/mouse_sensor.c new file mode 100755 index 0000000..214a13e --- /dev/null +++ b/source/Concept/Framework/modules/input/mouse_sensor.c @@ -0,0 +1 @@ +#include "mouse_sensor.h"
diff --git a/source/Concept/Framework/modules/input/mouse_sensor.h b/source/Concept/Framework/modules/input/mouse_sensor.h new file mode 100755 index 0000000..30f9d53 --- /dev/null +++ b/source/Concept/Framework/modules/input/mouse_sensor.h @@ -0,0 +1,199 @@ +#ifndef _MOUSE_SENSOR_H
+#define _MOUSE_SENSOR_H
+
+#include "../../stdafx.h"
+#include "sensor.h"
+
+class Mouse_Sensor : public Sensor
+{
+public:
+ Mouse_Sensor()
+ {
+ this->parent = NULL;
+ this->moduleId = 0;
+ this->hardwarePort = NULL;
+ this->hardwareDDR = NULL;
+ this->hardwarePin = NULL;
+ this->pinSDA = 0;
+ this->pinSCK = 0;
+ this->registerConfig = 0;
+ this->registerPixelData = 0;
+ this->registerSqual = 0;
+ this->registerDeltaX = 0;
+ this->registerDeltaY = 0;
+ this->configReset = 0;
+ this->configAwake = 0;
+ this->newImage = false;
+ }
+
+ Mouse_Sensor(uint32 sensorId)
+ {
+ this->parent = NULL;
+ this->moduleId = sensorId;
+ this->newImage = false;
+
+ switch(sensorId)
+ {
+ case IO_SENSOR_MOUSE_LEFT:
+ this->hardwarePort = &PORTC;
+ this->hardwareDDR = &DDRC;
+ this->hardwarePin = &PINC;
+ this->pinSDA = (1 << 4);
+ this->pinSCK = (1 << 6);
+ this->registerConfig = 0x00;
+ this->registerPixelData = 0x08;
+ this->registerSqual = 0x4;
+ this->registerDeltaX = 0x3;
+ this->registerDeltaY = 0x2;
+ this->configReset = 0x80;
+ this->configAwake = 0x01;
+ break;
+ case IO_SENSOR_MOUSE_RIGHT:
+ this->hardwarePort = &PORTC;
+ this->hardwareDDR = &DDRC;
+ this->hardwarePin = &PINC;
+ this->pinSDA = (1 << 5);
+ this->pinSCK = (1 << 7);
+ this->registerConfig = 0x00;
+ this->registerPixelData = 0x08;
+ this->registerSqual = 0x4;
+ this->registerDeltaX = 0x3;
+ this->registerDeltaY = 0x2;
+ this->configReset = 0x80;
+ this->configAwake = 0x01;
+ break;
+ default:
+ this->hardwarePort = NULL;
+ this->hardwareDDR = NULL;
+ this->hardwarePin = NULL;
+ this->pinSDA = 0;
+ this->pinSCK = 0;
+ this->registerConfig = 0;
+ this->registerPixelData = 0;
+ this->registerSqual = 0;
+ this->registerDeltaX = 0;
+ this->registerDeltaY = 0;
+ this->configReset = 0;
+ this->configAwake = 0;
+ break;
+ }
+
+ *hardwareDDR |= pinSCK;
+ *hardwarePort &= ~pinSCK;
+
+ Write(registerConfig, configReset);
+ Write(registerConfig, configAwake);
+ }
+
+protected:
+ //Hardware
+ volatile uint8* hardwarePort;
+ volatile uint8* hardwareDDR;
+ volatile uint8* hardwarePin;
+ uint8 pinSDA;
+ uint8 pinSCK;
+ bool newImage;
+ //Registers and Settings
+ uint8 registerConfig;
+ uint8 registerPixelData;
+ uint8 registerSqual;
+ uint8 registerDeltaX;
+ uint8 registerDeltaY;
+ uint8 configReset;
+ uint8 configAwake;
+
+public:
+ void WriteByte(uint8 newByte)
+ {
+ *hardwareDDR |= pinSDA;//Set SDA output
+
+ for(uint8 i = 0; i < 8; i++)
+ {
+ *hardwarePort &= ~pinSCK;//prepare SCK
+
+ //write data
+ *hardwarePort = (*hardwarePort & (~(*hardwarePin))) |
+ ((newByte >> 7) * pinSDA);
+
+ newByte = newByte << 1;//prepare next byte
+ asm volatile("nop");
+
+ *hardwarePort |= pinSCK;
+ }
+ }
+
+ void Write(int8 adr, uint8 data)
+ {
+ WriteByte(adr | 0x80);
+ WriteByte(data);
+ usleep(100);
+ }
+
+ uint8 ReadByte()
+ {
+ uint8 data=0;
+
+ *hardwareDDR &= ~pinSDA;//Set SDA input
+
+ for(uint8 i = 0; i < 8; i++)
+ {
+ *hardwarePort &= ~pinSCK;//Prepare data
+ data = data << 1;
+
+ asm volatile("nop");
+ *hardwarePort |= pinSCK;//Prepare for reading
+
+ data |= (*hardwarePin & pinSDA) / pinSDA;
+ }
+
+ return data;
+ }
+
+ uint8 Read(uint8 adr)
+ {
+ WriteByte(adr);
+ usleep(100);
+
+ return ReadByte();
+ }
+
+ void ImagePrepare()
+ {
+ Write(registerConfig, configAwake);
+ Write(registerPixelData, 0x00);
+
+ newImage = true;
+ }
+
+ uint8 ImageRead()
+ {
+ uint8 pixel = Read(registerPixelData);
+ if(newImage)
+ {
+ while (!(pixel & 0x80))//0x80 indicates first pixel
+ {
+ pixel=Read(registerPixelData);
+ }
+ newImage = false;
+ }
+
+ return pixel;
+ }
+
+ uint8 GetSqual()
+ {
+ return Read(registerSqual);
+ }
+
+ int8 GetXMovement()
+ {
+ return (int8)(Read(registerDeltaX));
+ }
+
+ int8 GetYMovement()
+ {
+ return (int8)(Read(registerDeltaY));
+ }
+};
+
+#endif diff --git a/source/Concept/Framework/modules/input/sensor.c b/source/Concept/Framework/modules/input/sensor.c new file mode 100755 index 0000000..3036159 --- /dev/null +++ b/source/Concept/Framework/modules/input/sensor.c @@ -0,0 +1 @@ +#include "sensor.h"
diff --git a/source/Concept/Framework/modules/input/sensor.h b/source/Concept/Framework/modules/input/sensor.h new file mode 100755 index 0000000..e44c739 --- /dev/null +++ b/source/Concept/Framework/modules/input/sensor.h @@ -0,0 +1,27 @@ +#ifndef _SENSOR_H
+#define _SENSOR_H
+
+#include "../../defines.h"
+#include "../io_module.h"
+
+class Sensor : public IO_Module
+{
+public:
+ Sensor()
+ {
+ this->parent = NULL;
+ this->moduleId = 0;
+ }
+
+ Sensor(uint32 sensorId)
+ {
+ this->parent = NULL;
+ this->moduleId = sensorId;
+ }
+
+protected:
+
+public:
+};
+
+#endif |