Code-Work by Marian

This commit is contained in:
sicarius 2007-02-14 17:47:03 +00:00
parent ab9cf92c1a
commit 29618453d2
24 changed files with 1266 additions and 1012 deletions

View file

@ -92,6 +92,29 @@ int Board::GetADC(uint8_t channel) {
return result;
}
// Gibt den Wert vom Abstandsensor zurück
int Board::GetAbstand(int i) {
int result = -1;
if((i < 0) || (i > 3)) return result; // Ungültige Nummern rausfiltern
// Sende zunächst einen Impuls aus
ABSTAND_DDR |= (1 << i); // Konfiguriere Pin als Ausgang
ABSTAND_PORT |= (1 << i); // Und setze ihn auf High
usleep(10); // Warte jetzt 10us
ABSTAND_PORT &= ~(1 << i); // Und setze den Pin wieder auf Low
ABSTAND_DDR &= ~(1 << i); // Konfiguriere Pin als Eingang
// Jetzt warten wir auf die Antwort vom Sensor
while(!(ABSTAND_PIN & i)) {} // während er low ist nichts machen
while(ABSTAND_PIN & i) { // Und während er high ist
result++; //schleifendurchläufe zähenlen (unsauber, ich weiß)
asm volatile("nop"); // ein ganz bisschen warten
}
// Die Zahl der Schleifendurchläufe geben wir dann zurück
return result;
}
void Board::beep(int freq) {
beepFreq = freq;
}

View file

@ -5,6 +5,7 @@
#include <avr/interrupt.h>
#include <stdlib.h>
#include "uart.h"
#include "../global.h"
//#define abs(a) ((a < 0)? -a : a)
@ -31,6 +32,11 @@
#define DRIBBLER_A (1 << 2)
#define DRIBBLER_B (1 << 3)
// Definiere Konstanten für Abstandsensoren
#define ABSTAND_PORT PORTC
#define ABSTAND_DDR DDRC
#define ABSTAND_PIN PINC
#define UART_BAUD_RATE 9600
class Board
@ -40,7 +46,9 @@ public:
Board();
~Board();
int GetADC(uint8_t channel);
int GetADC(uint8_t channel);
int GetAbstand(int i);
void beep(int freq);
void ledOn();
void ledOff();

View file

@ -1,6 +1,15 @@
#include "maussensor.h"
Maussensor::Maussensor(int index) {
Maussensor::Maussensor() {
}
Maussensor::~Maussensor() {
}
// Initialisiert den Maussensor
void Maussensor::init(int index) {
// Setze die Pins entsprechend dem übergebenen Index
if(index == MAUSSENSOR0) {
sda_pin = MAUS0_SDA;
@ -15,9 +24,6 @@ Maussensor::Maussensor(int index) {
maus_sens_init();
}
Maussensor::~Maussensor() {
}
// Gibt die X-Koordinate Zurück
uint8 Maussensor::GetX() {
return maus_sens_read(MOUSE_DELTA_X_REG);

View file

@ -111,9 +111,11 @@ void maus_image_prepare(void);
*/
public:
Maussensor(int index);
Maussensor();
~Maussensor();
void init(int index);
uint8 GetX();
uint8 GetY();
uint8 GetSqual();