/**@file eyebot_sensors.cc * @author Joshua Petitt * @author Stefan Schmitt * @date 2003-06 * * Implements eyebot_sensors.hh. */ #ifdef EYEBOT #include "eyebot_sensors.hh" #include "cam.h" //#include "rs232.h" #include "librobi/librobi.h" #include namespace EyeMind { #if 0 /** * Keypad Port */ Keypad::Keypad() : Port() { key = 0; } bool Keypad::Update() { int k = key; key = KEYRead(); return (k != key); } #endif /** * Psd Port */ // define static member var Psd *Psd::psds[] = { NULL }; Psd::Psd(DeviceSemantics device) : Port() { unsigned i = 0; PSDHandle bitmask = 0; x = 0; dx = 0; rawmode = false; handle = PSDInit(device); // add this PSD to list do { if (psds[i] == NULL) { psds[i] = this; break; }; } while (++i < PSD_LIST_SIZE); OSPanicIf(i > PSD_LIST_SIZE, "Too many Psd objects"); // loop through other PSDs, restarting them; for (i = 0; i < PSD_LIST_SIZE; ++i) if (psds[i] != NULL) bitmask |= psds[i]->handle; PSDStart(bitmask, TRUE); } Psd::~Psd() { unsigned i; PSDHandle bitmask = 0; // delete this PSD from list // loop through other PSDs, restarting them; for (i = 0; i < PSD_LIST_SIZE; ++i) { if (psds[i] == this) psds[i] = NULL; if (psds[i] != NULL) bitmask |= psds[i]->handle; }; PSDStop(); OSWait(20); PSDStart(bitmask, TRUE); }; bool Psd::Update() { if (rawmode) dx = PSDGetRaw(handle) - x; else dx = PSDGet(handle) - x; x += dx; return 0 != dx; } /** * Compass Port */ Compass::Compass() { angle = 0; COMPASSInit(COMPASS); COMPASSStart(1); Active(true); } Compass::~Compass() { COMPASSRelease(); } int Compass::Angle() { return angle; } bool Compass::Update() { angle = 180 - COMPASSGet(); angle = clip(angle,-180,180); return true; } /** * Camera Port */ Camera::Camera() : Port() { cam_id = CAMInit(NORMAL); Active(true); } Camera::~Camera() { CAMRelease(); } colimage* Camera::Image() { return ℑ } bool Camera::Update() { CAMGetColFrame(&image, 0); return true; } #if 0 /** * Microphone Port */ Microphone::Microphone() : Port() { // intialize the sound buffer memset(sndbuffer,0,DEFAULT_MICROPHONE_BUFFER_LENGTH); length = 0; freq = DEFAULT_MICROPHONE_FREQUENCY; sndthreshold = DEFAULT_MICROPHONE_SOUND_THRESHOLD; } Microphone::~Microphone() { // delete the sound buffer memset(sndbuffer,0,DEFAULT_MICROPHONE_BUFFER_LENGTH); length = 0; } bool Microphone::Update() { int s = AUCaptureMic(); if(s>sndthreshold) return true; else return false; } void Microphone::Record(int len) { if(!AUCheckRecord() && len0) { error = RADIOSend(BROADCAST,obuffer_length, obuffer); //DEBUG_PRINTF("%d\n",obuffer_length); if(!error) { obuffer_length = 0; error_count = 0; } else { DEBUG_PRINTF("radio error %d\n",error); error_count++; if (error_count > max_error_count) { obuffer_length = 0; error_count = 0; } } } return true; } char* RadioComm::Message() { if (msg_flag == OK) msg_flag = NOK; return (char*) ibuffer; } int RadioComm::Message(BYTE* mes) { int i = 0; while ( (mes[i] != (char) 0) && (i