void Thunderbird::analizeExternalEvents(qint32 eventsCount) { qDebug() << "Recieved from Thunderbird:" << eventsCount << "events"; m_addonPresenceTimer.start(); int events = eventsCount; emit messagesCount(events); if (events > 0) setLedMode(LED_RARE_BLINK); else setLedMode(LED_OFF); }
void CRC_PCA9635::init() { // Init writeRegister(PCA9635_REG_MODE1, 0x81); // AUTOINCR | NOSLEEP | ALLADRR // Set to PWM Mode for now for (int i = 0; i < 15; i++) { setLedMode(i, PCA9635_LEDPWM); } reset(); }
/***************************************************************************** * oak_digin_setup(..) *****************************************************************************/ int oak_digin_setup(int* deviceHandle, char* oakDiginDevice) { int oak_stat; oak_stat = CHECK_OAK_CALL(openDevice(oakDiginDevice, deviceHandle)); if (oak_stat != 0) return oak_stat; // get the device informations oak_stat = CHECK_OAK_CALL(getDeviceInfo(oakDiginHandle, &devInfo)); if (oak_stat != 0) return oak_stat; /* fprintf( stderr, "oak_digin_setup: Oak device: %s\n", devInfo.deviceName); */ /* fprintf( stderr, "oak_digin_setup: Volatile user device name: %s\n", devInfo.volatileUserDeviceName); */ /* fprintf( stderr, "oak_digin_setup: Persistent user device name: %s\n", devInfo.persistentUserDeviceName); */ /* fprintf( stderr, "oak_digin_setup: Serial number: %s\n", devInfo.serialNumber); */ /* fprintf( stderr, "oak_digin_setup: VendorID: 0x%.4x :: ProductID: 0x%.4x :: Version 0x%.4x\n", devInfo.vendorID, devInfo.productID, devInfo.version); */ /* fprintf( stderr, "oak_digin_setup: Number of channels: %d\n", devInfo.numberOfChannels); */ if (strcmp(devInfo.deviceName, "Toradex Optical Isolated Input")) { return -1; } // Set the LED Mode to indicate initialize state oak_stat = CHECK_OAK_CALL( setLedMode(*deviceHandle, eLedModeBlinkFast, false)); if (oak_stat != 0) return oak_stat; // Set the report Mode oak_stat = CHECK_OAK_CALL(setReportMode(*deviceHandle, eReportModeAfterSampling, false)); if (oak_stat != 0) return oak_stat; // Set the sample rate oak_stat = CHECK_OAK_CALL( setSampleRate(*deviceHandle, 50, false)); if (oak_stat != 0) return oak_stat; // Retrieve Channel infos /* wildi ToDo * ChannelInfo* channelInfos = xmalloc(devInfo.numberOfChannels *sizeof(ChannelInfo)); * ChannelInfo* chanInfo; * chanInfo = &channelInfos[1]; */ return 0; }
void Thunderbird::notifyAddonMissing() { emit addonIsAbsent(); setLedMode(LED_FREQUENT_BLINK); }
uint8_t XBOXUSB::Init(uint8_t parent, uint8_t port, bool lowspeed) { uint8_t buf[sizeof(USB_DEVICE_DESCRIPTOR)]; uint8_t rcode; UsbDevice *p = NULL; EpInfo *oldep_ptr = NULL; uint16_t PID; uint16_t VID; // get memory address of USB device address pool AddressPool &addrPool = pUsb->GetAddressPool(); #ifdef EXTRADEBUG Notify(PSTR("\r\nXBOXUSB Init")); #endif // check if address has already been assigned to an instance if (bAddress) { #ifdef DEBUG Notify(PSTR("\r\nAddress in use")); #endif return USB_ERROR_CLASS_INSTANCE_ALREADY_IN_USE; } // Get pointer to pseudo device with address 0 assigned p = addrPool.GetUsbDevicePtr(0); if (!p) { #ifdef DEBUG Notify(PSTR("\r\nAddress not found")); #endif return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; } if (!p->epinfo) { #ifdef DEBUG Notify(PSTR("\r\nepinfo is null")); #endif return USB_ERROR_EPINFO_IS_NULL; } // Save old pointer to EP_RECORD of address 0 oldep_ptr = p->epinfo; // Temporary assign new pointer to epInfo to p->epinfo in order to avoid toggle inconsistence p->epinfo = epInfo; p->lowspeed = lowspeed; // Get device descriptor rcode = pUsb->getDevDescr(0, 0, sizeof(USB_DEVICE_DESCRIPTOR), (uint8_t*)buf);// Get device descriptor - addr, ep, nbytes, data // Restore p->epinfo p->epinfo = oldep_ptr; if(rcode) goto FailGetDevDescr; VID = ((USB_DEVICE_DESCRIPTOR*)buf)->idVendor; PID = ((USB_DEVICE_DESCRIPTOR*)buf)->idProduct; if(VID != XBOX_VID && VID != MADCATZ_VID && VID != JOYTECH_VID) // We just check if it's a xbox controller using the Vendor ID goto FailUnknownDevice; if(PID == XBOX_WIRELESS_PID) { #ifdef DEBUG Notify(PSTR("\r\nYou have plugged in a wireless Xbox 360 controller - it doesn't support USB communication")); #endif goto FailUnknownDevice; } else if(PID == XBOX_WIRELESS_RECEIVER_PID || PID == XBOX_WIRELESS_RECEIVER_THIRD_PARTY_PID) { #ifdef DEBUG Notify(PSTR("\r\nThis library only supports Xbox 360 controllers via USB")); #endif goto FailUnknownDevice; } // Allocate new address according to device class bAddress = addrPool.AllocAddress(parent, false, port); if (!bAddress) return USB_ERROR_OUT_OF_ADDRESS_SPACE_IN_POOL; // Extract Max Packet Size from device descriptor epInfo[0].maxPktSize = (uint8_t)((USB_DEVICE_DESCRIPTOR*)buf)->bMaxPacketSize0; // Assign new address to the device rcode = pUsb->setAddr( 0, 0, bAddress ); if (rcode) { p->lowspeed = false; addrPool.FreeAddress(bAddress); bAddress = 0; #ifdef DEBUG Notify(PSTR("\r\nsetAddr: ")); #endif PrintHex<uint8_t>(rcode); return rcode; } #ifdef EXTRADEBUG Notify(PSTR("\r\nAddr: ")); PrintHex<uint8_t>(bAddress); #endif p->lowspeed = false; //get pointer to assigned address record p = addrPool.GetUsbDevicePtr(bAddress); if (!p) return USB_ERROR_ADDRESS_NOT_FOUND_IN_POOL; p->lowspeed = lowspeed; // Assign epInfo to epinfo pointer - only EP0 is known rcode = pUsb->setEpInfoEntry(bAddress, 1, epInfo); if (rcode) goto FailSetDevTblEntry; /* The application will work in reduced host mode, so we can save program and data memory space. After verifying the VID we will use known values for the configuration values for device, interface, endpoints and HID for the XBOX360 Controllers */ /* Initialize data structures for endpoints of device */ epInfo[ XBOX_INPUT_PIPE ].epAddr = 0x01; // XBOX 360 report endpoint epInfo[ XBOX_INPUT_PIPE ].epAttribs = EP_INTERRUPT; epInfo[ XBOX_INPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints epInfo[ XBOX_INPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE; epInfo[ XBOX_INPUT_PIPE ].bmSndToggle = bmSNDTOG0; epInfo[ XBOX_INPUT_PIPE ].bmRcvToggle = bmRCVTOG0; epInfo[ XBOX_OUTPUT_PIPE ].epAddr = 0x02; // XBOX 360 output endpoint epInfo[ XBOX_OUTPUT_PIPE ].epAttribs = EP_INTERRUPT; epInfo[ XBOX_OUTPUT_PIPE ].bmNakPower = USB_NAK_NOWAIT; // Only poll once for interrupt endpoints epInfo[ XBOX_OUTPUT_PIPE ].maxPktSize = EP_MAXPKTSIZE; epInfo[ XBOX_OUTPUT_PIPE ].bmSndToggle = bmSNDTOG0; epInfo[ XBOX_OUTPUT_PIPE ].bmRcvToggle = bmRCVTOG0; rcode = pUsb->setEpInfoEntry(bAddress, 3, epInfo); if( rcode ) goto FailSetDevTblEntry; delay(200);//Give time for address change rcode = pUsb->setConf(bAddress, epInfo[ XBOX_CONTROL_PIPE ].epAddr, 1); if( rcode ) goto FailSetConf; #ifdef DEBUG Notify(PSTR("\r\nXbox 360 Controller Connected")); #endif setLedMode(ROTATING); Xbox360Connected = true; bPollEnable = true; Notify(PSTR("\r\n")); return 0; // successful configuration /* diagnostic messages */ FailGetDevDescr: #ifdef DEBUG Notify(PSTR("\r\ngetDevDescr:")); #endif goto Fail; FailSetDevTblEntry: #ifdef DEBUG Notify(PSTR("\r\nsetDevTblEn:")); #endif goto Fail; FailSetConf: #ifdef DEBUG Notify(PSTR("\r\nsetConf:")); #endif goto Fail; FailUnknownDevice: #ifdef DEBUG Notify(PSTR("\r\nUnknown Device Connected - VID: ")); PrintHex<uint16_t>(VID); Notify(PSTR(" PID: ")); PrintHex<uint16_t>(PID); #endif rcode = USB_DEV_CONFIG_ERROR_DEVICE_NOT_SUPPORTED; goto Fail; Fail: #ifdef DEBUG Notify(PSTR("\r\nXbox 360 Init Failed, error code: ")); Serial.print(rcode,HEX); #endif Release(); return rcode; }
/****************************************************************************** * connectOakDevice(int connecting) *****************************************************************************/ int connectOakDiginDevice(int connecting) { int oak_stat; int thread_stat= -1; // if not set to 0 main program dies char oakDiginDevice[]="/dev/door_switch" ; if (connecting== OAKDIGIN_CMD_CONNECT) { strcpy( date_time, "undefined") ; oak_stat = oak_digin_setup(&oakDiginHandle, oakDiginDevice); if (oak_stat == 0) { fprintf( stderr, "connectOakDiginDevice: opened %s:\n", oakDiginDevice); // Set the LED Mode to OFF CHECK_OAK_CALL(setLedMode(oakDiginHandle, eLedModeOn, false)); // wildi ToDo int* values = xmalloc(devInfo.numberOfChannels * sizeof(int)); int* values = malloc( 64 * sizeof(int)); int rd_stat; oak_digin_thread_heart_beat= 0 ; rd_stat = readInterruptReport(oakDiginHandle, values); if ((rd_stat < 0) && (errno == EINTR)) { fprintf( stderr, "connectOakDiginDevice: no connection to OAK device") ; oak_thread_state= THREAD_STATE_UNDEFINED ; } else { oak_thread_state= THREAD_STATE_RUNNING ; } int bits = values[1] & 0xff; // it is the duty of connectSSD650vDevice() call to set the state first // setting the initial DS_ state if( motorState== SSD650V_MS_STOPPED) { // fprintf(stderr, "connectOakDiginDevice: motorState == SSD650V_MS_STOPPED\n") ; if( bits & OAK_MASK_CLOSED) { // true if OAK sees the door doorState= DS_STOPPED_CLOSED ; fprintf( stderr, "connectOakDiginDevice: state is DS_STOPPED_CLOSED\n") ; } else if( bits & OAK_MASK_OPENED) { doorState= DS_STOPPED_OPENED ; fprintf( stderr, "connectOakDiginDevice: state is DS_STOPPED_OPEN\n") ; } else { doorState= DS_UNDEF ; fprintf( stderr, "connectOakDiginDevice: state is DS_UNDEF, door not closed, motor is off\n") ; } } else if( bits & OAK_MASK_OPENED) { // true if OAK sees the door doorState= DS_UNDEF ; fprintf( stderr, "connectOakDiginDevice: state is DS_UNDEF, door is opened, motor is undefined\n") ; } else if( bits & OAK_MASK_CLOSED) { // true if OAK sees the door doorState= DS_UNDEF ; fprintf( stderr, "connectOakDiginDevice: state is DS_UNDEF, door is closed, motor is undefined\n") ; } else { doorState= DS_UNDEF ; fprintf( stderr, "connectOakDiginDevice: state is DS_UNDEF, door is undefined, motor is undefined\n") ; } // create receive communication thread thread_stat = pthread_create(&oak_digin_th_id, NULL, &oak_digin_thread, NULL); // 0 success if (thread_stat != 0) { oak_thread_state= THREAD_STATE_UNDEFINED ; fprintf( stderr, "connectOakDiginDevice: failure starting thread: error %d:\n", thread_stat); } } else { doorState= DS_UNDEF ; fprintf( stderr, "connectOakDiginDevice: state is DS_UNDEF, no connection to oak device\n") ; } } else { // if (connecting) /* Disconnect: prepare for reconnect. */ // Set the LED Mode to OFF if (oakDiginHandle >= 0) { thread_stat = pthread_cancel(oak_digin_th_id); // 0 = success if( thread_stat != 0 ) { fprintf( stderr, "connectOakDiginDevice: Oak thread NOT stopped\n"); return thread_stat ; } CHECK_OAK_CALL(setLedMode(oakDiginHandle, eLedModeOff, false)); CHECK_OAK_CALL(closeDevice(oakDiginHandle)); } if (oakDiginHandle >= 0) { fprintf( stderr, "connectOakDiginDevice: closed %s.\n", oakDiginDevice); } else { fprintf( stderr, "connectOakDiginDevice: reset for device %s.\n", oakDiginDevice); } fprintf( stderr, "connectOakDiginDevice: Oak thread stopped\n"); } return thread_stat ; }
int main( int argc, const char** argv ) { // Initialisation (prend au moins une seconde à cause du pwm) init_all(); // Variables; int isButtonFree = 1; int buttonPreviouslyPushed = 0; int mode = 0; int sliderValue = 0; int posInTab = 0; int posWhenReadingTab = 0; char* tab = malloc(SIZE_EEPROM); char* readingTab = malloc(SIZE_EEPROM); int isReadingTabInitalized = 0; // Affiche le mode 1 (mode = 0) setLedMode(mode); while (1) { // On lit la valeur du bouton isButtonFree = read_button(); // On regarde si le bouton est appuyé, s'il est appuyé on met buttonPreviouslyPushed à 1 if(!isButtonFree) { buttonPreviouslyPushed = 1; } // Si on a relaché le bouton (buttonPreviouslyPushed mais le bouton n'est plus activé maintenant) if(buttonPreviouslyPushed && isButtonFree){ // On remet le boolean à 0 buttonPreviouslyPushed = 0; // Si on etait en mode numero 3 (mode = 2), on enregistre dans l'eeprom le tableau if(mode == 2) { write_eeprom(tab, posInTab, 0); } // On change le mode mode++; mode %= 4; setLedMode(mode); } // Si on est sur le mode 1 if(mode == 0) { sliderValue = read_slider(); set_pwm_value(1000000+sliderValue); } // Si on est sur le mode 3 if(mode == 2) { sliderValue = read_slider(); set_pwm_value(1000000+sliderValue); // notre sliderValue est entre 0 et 1 000 000, on la convertie en angle tab[posInTab] = convertToAngle(sliderValue); posInTab++; tab[posInTab] = 127; // Si on arrive au maximum on change de mode if(posInTab >= SIZE_EEPROM - 1 ) { buttonPreviouslyPushed = 1; } // Attente de 50ms pour le mode 3 uniquement usleep(50000); } // Si on est sur le mode 4 if(mode == 3) { // On lit l'eeprom une seule fois if(!isReadingTabInitalized) { printf("Lecture de l'eeprom ... "); read_eeprom(readingTab, posInTab); printf("end\n"); isReadingTabInitalized = 1; } // On dit au servo de se déplacer à l'angle cmd_servo_hard(readingTab[posWhenReadingTab]); // On parcourt le tableau, si on atteint le max ou que on trouve 127 on repart à 0 posWhenReadingTab++; if(posWhenReadingTab >= posInTab || readingTab[posWhenReadingTab] == 127) { posWhenReadingTab = 0; printf("On recommence !\n"); // Le message de ce printf s'accumule et tous les messages ne s'affichent que au changement de mode } // Attente de 50ms pour le mode 4 uniquement usleep(50000); } // Temps de pause dans la boucle infinie pour alleger le processeur // Evite egalement les rebonds du bouton usleep(1000); } }