void readACC(int *a) { uint8_t block[6]; selectDevice(file,ACC_ADDRESS); readBlock(0x80 | OUT_X_L_A, sizeof(block), block); *a = (int16_t)(block[0] | block[1] << 8); *(a+1) = (int16_t)(block[2] | block[3] << 8); *(a+2) = (int16_t)(block[4] | block[5] << 8); }
void readMAG(int *m) { uint8_t block[6]; selectDevice(file,MAG_ADDRESS); readBlock(0x80 | OUT_X_L_M, sizeof(block), block); *m = (int16_t)(block[0] | block[1] << 8); *(m+1) = (int16_t)(block[2] | block[3] << 8); *(m+2) = (int16_t)(block[4] | block[5] << 8); }
int main(int argc, char **argv) { int fd; unsigned char buf[16]; if ((fd = open("/dev/i2c-1", O_RDWR)) < 0) { // Open port for reading and writing fprintf(stderr, "Failed to open i2c bus\n"); return 1; } /* initialise ADXL345 */ selectDevice(fd, HMC5883L_I2C_ADDR, "HMC5883L"); //writeToDevice(fd, 0x01, 0); writeToDevice(fd, 0x01, 32); writeToDevice(fd, 0x02, 0); for (int i = 0; i < 10000; ++i) { buf[0] = 0x03; if ((write(fd, buf, 1)) != 1) { // Send the register to read from fprintf(stderr, "Error writing to i2c slave\n"); } if (read(fd, buf, 6) != 6) { fprintf(stderr, "Unable to read from HMC5883L\n"); } else { short x = (buf[0] << 8) | buf[1]; short y = (buf[4] << 8) | buf[5]; short z = (buf[2] << 8) | buf[3]; float angle = atan2(y, x) * 180 / 3.14; //for (int b=0; b<6; ++b) //{ // printf("%02x ",buf[b]); //} //printf("\n"); printf("x=%d, y=%d, z=%d\n", x, y, z); printf("angle = %0.1f\n\n", angle); } usleep(50 * 1000); } return 0; }
void writeAccReg(uint8_t reg, uint8_t value) { selectDevice(file,ACC_ADDRESS); int result = i2c_smbus_write_byte_data(file, reg, value); if (result == -1) { printf ("Failed to write byte to I2C Mag."); exit(1); } }
void IMUReader::initSensors() { /* initialize ADXL345 */ selectDevice(file, ADXL345_I2C_ADDR, "ADXL345"); writeToDevice(file, "\x2d\x00", 2); writeToDevice(file, "\x2d\x10", 2); writeToDevice(file, "\x2d\x08", 2); writeToDevice(file, "\x31\x00", 2); writeToDevice(file, "\x31\x0b", 2); /* initialize HMC5883L */ selectDevice(file, HMC5883L_I2C_ADDR, "HMC5883L"); writeToDevice(file, "\x02\x00", 2); /* initialize ITG3200 */ selectDevice(file, ITG3200_I2C_ADDR, "ITG3200"); //writeToDevice(file, "\x16\b00011000", 2); writeToDevice(file, "\x3E\x00", 2); writeToDevice(file, "\x15\x07", 2); writeToDevice(file, "\x16\x1E", 2); writeToDevice(file, "\x17\x00", 2); }
void onBeforeExecute(DeviceContext* pDC) { // if the shadow device has somehow become the active device // then switch to the rstudio device. note this can occur if the // user creates another device such as windows() or postscript() and // then does a dev.off pGEDevDesc pCurrentDevice = NoDevices() ? NULL : GEcurrentDevice(); ShadowDeviceData* pShadowDevData = (ShadowDeviceData*)pDC->pDeviceSpecific; if (pCurrentDevice != NULL && pShadowDevData != NULL) { if (pCurrentDevice->dev == pShadowDevData->pShadowPngDevice) { // select the rstudio device selectDevice(ndevNumber(pDC->dev)); } } }
uint8_t LSM303C::I2C_ByteWrite(I2C_ADDR_t slaveAddress, uint8_t reg, uint8_t data) { uint8_t ret = IMU_GENERIC_ERROR; ret = selectDevice(file, slaveAddress); if (ret != IMU_SUCCESS) { return ret; } int result = i2c_smbus_write_byte_data(file, reg, data); if (result == -1) { printf ("Failed to write byte to I2C Acc."); ret = IMU_HW_ERROR; } else { ret = IMU_SUCCESS; } return ret; }
void audioSink::set_streamSelector (int idx) { int16_t outputDevice; if (idx == 0) return; outputDevice = outTable [idx]; if (!isValidDevice (outputDevice)) { return; } stop (); if (!selectDevice (outputDevice)) { fprintf (stderr, "error selecting device\n"); selectDefaultDevice (); return; } qWarning () << "selected output device " << idx << outputDevice; }
//------------------------------------------------------------------------------ static tOplkError initPowerlink(UINT32 cycleLen_p, char* pszCdcFileName_p, const BYTE* macAddr_p) { tOplkError ret = kErrorOk; static tOplkApiInitParam initParam; static char devName[128]; printf("Initializing openPOWERLINK stack...\n"); #if defined(CONFIG_USE_PCAP) if (selectPcapDevice(devName) < 0) return kErrorIllegalInstance; #elif defined(__COBALT__) if (selectDevice(devName) < 0) return kErrorIllegalInstance; #endif memset(&initParam, 0, sizeof(initParam)); initParam.sizeOfInitParam = sizeof(initParam); // pass selected device name to Edrv initParam.hwParam.pDevName = devName; initParam.nodeId = NODEID; initParam.ipAddress = (0xFFFFFF00 & IP_ADDR) | initParam.nodeId; /* write 00:00:00:00:00:00 to MAC address, so that the driver uses the real hardware address */ memcpy(initParam.aMacAddress, macAddr_p, sizeof(initParam.aMacAddress)); initParam.fAsyncOnly = FALSE; initParam.featureFlags = UINT_MAX; initParam.cycleLen = cycleLen_p; // required for error detection initParam.isochrTxMaxPayload = 256; // const initParam.isochrRxMaxPayload = 256; // const initParam.presMaxLatency = 50000; // const; only required for IdentRes initParam.preqActPayloadLimit = 36; // required for initialisation (+28 bytes) initParam.presActPayloadLimit = 36; // required for initialisation of Pres frame (+28 bytes) initParam.asndMaxLatency = 150000; // const; only required for IdentRes initParam.multiplCylceCnt = 0; // required for error detection initParam.asyncMtu = 1500; // required to set up max frame size initParam.prescaler = 2; // required for sync initParam.lossOfFrameTolerance = 500000; initParam.asyncSlotTimeout = 3000000; initParam.waitSocPreq = 1000; initParam.deviceType = UINT_MAX; // NMT_DeviceType_U32 initParam.vendorId = UINT_MAX; // NMT_IdentityObject_REC.VendorId_U32 initParam.productCode = UINT_MAX; // NMT_IdentityObject_REC.ProductCode_U32 initParam.revisionNumber = UINT_MAX; // NMT_IdentityObject_REC.RevisionNo_U32 initParam.serialNumber = UINT_MAX; // NMT_IdentityObject_REC.SerialNo_U32 initParam.subnetMask = SUBNET_MASK; initParam.defaultGateway = DEFAULT_GATEWAY; sprintf((char*)initParam.sHostname, "%02x-%08x", initParam.nodeId, initParam.vendorId); initParam.syncNodeId = C_ADR_SYNC_ON_SOA; initParam.fSyncOnPrcNode = FALSE; // set callback functions initParam.pfnCbEvent = processEvents; #if defined(CONFIG_KERNELSTACK_DIRECTLINK) initParam.pfnCbSync = processSync; #else initParam.pfnCbSync = NULL; #endif // initialize POWERLINK stack ret = oplk_init(&initParam); if (ret != kErrorOk) { fprintf(stderr, "oplk_init() failed with \"%s\" (0x%04x)\n", debugstr_getRetValStr(ret), ret); return ret; } ret = oplk_setCdcFilename(pszCdcFileName_p); if (ret != kErrorOk) { fprintf(stderr, "oplk_setCdcFilename() failed with \"%s\" (0x%04x)\n", debugstr_getRetValStr(ret), ret); return ret; } return kErrorOk; }
bool audioSink::selectDefaultDevice (void) { return selectDevice (Pa_GetDefaultOutputDevice ()); }
int main(void) { int device; PaStreamParameters inputParameters, outputParameters; PaStream* stream; PaError err = paNoError; paTestData data; int i; int totalFrames; int numSamples; int numBytes; SAMPLE max, val; double average; int numDevices; printf("patest_record.c\n"); fflush(stdout); data.maxFrameIndex = totalFrames = NUM_SECONDS * SAMPLE_RATE; /* Record for a few seconds. */ data.frameIndex = 0; numSamples = totalFrames * NUM_CHANNELS; numBytes = numSamples * sizeof(SAMPLE); data.recordedSamples = (SAMPLE *) malloc( numBytes ); /* From now on, recordedSamples is initialised. */ if( data.recordedSamples == NULL ) { printf("Could not allocate record array.\n"); goto done; } for( i=0; i<numSamples; i++ ) data.recordedSamples[i] = 0; err = Pa_Initialize(); if( err != paNoError ) goto done; numDevices = 2; // input stream: device = selectDevice(); inputParameters.device = device; /* default input device */ if (inputParameters.device == paNoDevice) { fprintf(stderr,"Error: No default input device.\n"); goto done; } inputParameters.channelCount = 2; /* stereo input */ inputParameters.sampleFormat = PA_SAMPLE_TYPE; inputParameters.suggestedLatency = Pa_GetDeviceInfo( inputParameters.device )->defaultLowInputLatency; inputParameters.hostApiSpecificStreamInfo = NULL; /* Record some audio. -------------------------------------------- */ err = Pa_OpenStream( &stream, &inputParameters, NULL, /* &outputParameters, */ SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff, /* we won't output out of range samples so don't bother clipping them */ recordCallback, &data ); if( err != paNoError ) goto done; err = Pa_StartStream( stream ); if( err != paNoError ) goto done; printf("\n=== Now recording!! Please speak into the microphone. ===\n"); fflush(stdout); // while active: while( ( err = Pa_IsStreamActive( stream ) ) == 1 ) { Pa_Sleep(100); printf("index = %d; amplitude = %f\n", data.frameIndex, data.recordedSamples[data.frameIndex] ); fflush(stdout); } if( err < 0 ) goto done; err = Pa_CloseStream( stream ); if( err != paNoError ) goto done; /* Measure maximum peak amplitude. */ max = 0; average = 0.0; for( i=0; i<numSamples; i++ ) { val = data.recordedSamples[i]; if( val < 0 ) val = -val; /* ABS */ if( val > max ) { max = val; } average += val; } average = average / (double)numSamples; printf("sample max amplitude = "PRINTF_S_FORMAT"\n", max ); printf("sample average = %lf\n", average ); /* Write recorded data to a file. */ #if WRITE_TO_FILE { FILE *fid; fid = fopen("recorded.raw", "wb"); if( fid == NULL ) { printf("Could not open file."); } else { fwrite( data.recordedSamples, NUM_CHANNELS * sizeof(SAMPLE), totalFrames, fid ); fclose( fid ); printf("Wrote data to 'recorded.raw'\n"); } } #endif /* Playback recorded data. -------------------------------------------- */ data.frameIndex = 0; outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */ if (outputParameters.device == paNoDevice) { fprintf(stderr,"Error: No default output device.\n"); goto done; } outputParameters.channelCount = 2; /* stereo output */ outputParameters.sampleFormat = PA_SAMPLE_TYPE; outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency; outputParameters.hostApiSpecificStreamInfo = NULL; printf("\n=== Now playing back. ===\n"); fflush(stdout); err = Pa_OpenStream( &stream, NULL, /* no input */ &outputParameters, SAMPLE_RATE, FRAMES_PER_BUFFER, paClipOff, /* we won't output out of range samples so don't bother clipping them */ playCallback, &data ); if( err != paNoError ) goto done; if( stream ) { err = Pa_StartStream( stream ); if( err != paNoError ) goto done; printf("Waiting for playback to finish.\n"); fflush(stdout); while( ( err = Pa_IsStreamActive( stream ) ) == 1 ) Pa_Sleep(100); if( err < 0 ) goto done; err = Pa_CloseStream( stream ); if( err != paNoError ) goto done; printf("Done.\n"); fflush(stdout); } done: Pa_Terminate(); if( data.recordedSamples ) /* Sure it is NULL or valid. */ free( data.recordedSamples ); if( err != paNoError ) { fprintf( stderr, "An error occured while using the portaudio stream\n" ); fprintf( stderr, "Error number: %d\n", err ); fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) ); err = 1; /* Always return 0 or 1, but no other return codes. */ } return err; }
void IMUReader::readSensors(IMUSensorsData& data, GyroState& gyroState, bool calibration) { short x, y, z; unsigned char buf[16]; selectDevice(file, HMC5883L_I2C_ADDR, "HMC5883L"); writeToDevice(file, "\x03", 1); if (read(file, buf, 6) != 6) { printf("Unable to read from HMC5883L\n"); } else { x = __swab16(*(short*) &buf[0]); z = __swab16(*(short*) &buf[2]); y = __swab16(*(short*) &buf[4]); data.rawCompassX = x; data.rawCompassY = y; data.rawCompassZ = z; } selectDevice(file, ADXL345_I2C_ADDR, "ADXL345"); writeToDevice(file, "\x32", 1); if (read(file, buf, 6) != 6) { printf("Unable to read from ADXL345\n"); } else { x = buf[1] << 8 | buf[0]; y = buf[3] << 8 | buf[2]; z = buf[5] << 8 | buf[4]; data.rawAccelX = x; data.rawAccelY = y; data.rawAccelZ = z; } selectDevice(file, ITG3200_I2C_ADDR, "ITG3200"); writeToDevice(file, "\x1D", 1); if (read(file, buf, 6) != 6) { printf("Unable to read from ITG3200\n"); } else { x = __swab16(*(short*) &buf[0]); y = __swab16(*(short*) &buf[2]); z = __swab16(*(short*) &buf[4]); data.rawGyroX = x; data.rawGyroY = y; data.rawGyroZ = z; if (calibration) { gyroState.offsetX += x; gyroState.offsetY += y; gyroState.offsetZ += z; } } }
int main(void) { int data; short x, y, z; float xa, ya, za; unsigned char buf[16]; int count, b; if ((file = open(I2CDEV, O_RDWR)) < 0) { printf("Failed to open the bus."); exit(1); } /* initialise ADXL345 */ selectDevice(file, ADXL345_I2C_ADDR, "ADXL345"); writeToDevice(file, "\x2d\x00", 2); writeToDevice(file, "\x2d\x10", 2); writeToDevice(file, "\x2d\x08", 2); writeToDevice(file, "\x31\x00", 2); writeToDevice(file, "\x31\x0b", 2); /* initialise HMC5883L */ selectDevice(file, HMC5883L_I2C_ADDR, "HMC5883L"); writeToDevice(file, "\x02\x00", 2); /* initialise ITG3200 */ selectDevice(file, ITG3200_I2C_ADDR, "ITG3200"); //writeToDevice(file, "\x16\b00011000", 2); writeToDevice(file, "\x3E\x00", 2); writeToDevice(file, "\x15\x07", 2); writeToDevice(file, "\x16\x1E", 2); writeToDevice(file, "\x17\x00", 2); /* initialise BMA180 */ selectDevice(file, BMA180_I2C_ADDR, "BMA180"); writeToDevice(file, "\x10\xB6", 2); // wake up mode writeToDevice(file, "\x0D\x10", 2); // low pass filter while (1) { selectDevice(file, HMC5883L_I2C_ADDR, "HMC5883L"); writeToDevice(file, "\x03", 1); if (read(file, buf, 6) != 6) { printf("Unable to read from HMC5883L\n"); } else { x = buf[1]<<8| buf[0]; y = buf[3]<<8| buf[2]; z = buf[5]<<8| buf[4]; xa = (90.0 / 256.0) * (float) x; ya = (90.0 / 256.0) * (float) y; za = (90.0 / 256.0) * (float) z; //printf("HMC: x=%d, y=%d, z=%d xa=%4.0f ya=%4.0f za=%4.0f\n", x, y, z, xa, ya, za); printf("HMC: x=%d, y=%d, z=%d\n", x, y, z); } selectDevice(file, BMA180_I2C_ADDR, "BMA180"); writeToDevice(file, "\x02", 1); if (read(file, buf, 6) != 6) { printf("Unable to read from BMA180\n"); } else { x = buf[1]<<8| buf[0]; y = buf[3]<<8| buf[2]; z = buf[5]<<8| buf[4]; printf("BMA180: x=%d, y=%d, z=%d\n", x, y, z); } /* selectDevice(file, ADXL345_I2C_ADDR, "ADXL345"); writeToDevice(file, "\x32", 1); if (read(file, buf, 6) != 6) { printf("Unable to read from ADXL345\n"); } else { x = buf[1]<<8| buf[0]; y = buf[3]<<8| buf[2]; z = buf[5]<<8| buf[4]; xa = (90.0 / 256.0) * (float) x; ya = (90.0 / 256.0) * (float) y; za = (90.0 / 256.0) * (float) z; //printf("ADXL %d %d %d, %4.0f %4.0f %4.0f\n", x, y, z, xa, ya, za); printf("ADXL %d %d %d\n", x, y, z); } */ selectDevice(file, ITG3200_I2C_ADDR, "ITG3200"); writeToDevice(file, "\x1D", 1); if (read(file, buf, 6) != 6) { printf("Unable to read from ITG3200\n"); } else { x = buf[0]<<8| buf[1]; y = buf[2]<<8| buf[3]; z = buf[4]<<8| buf[5]; xa = (90.0 / 256.0) * (float) x; ya = (90.0 / 256.0) * (float) y; za = (90.0 / 256.0) * (float) z; //printf("ITG: x=%d, y=%d, z=%d xa=%4.0f ya=%4.0f za=%4.0f\n", x, y, z, xa, ya, za); printf("ITG: x=%d, y=%d, z=%d\n", x, y, z); } usleep(10000); } }
void writeAccReg( uint8_t regstr, uint8_t value ) { selectDevice( file, ACCELEROMETER_ADDRESS ); i2c_smbus_write_byte_data( file, regstr, value ); }
void writeGyrReg( uint8_t regstr, uint8_t value ) { selectDevice( file, GYROSCOPE_ADDRESS ); i2c_smbus_write_byte_data( file, regstr, value ); }
void writeMagReg( uint8_t regstr, uint8_t value ) { selectDevice( file, MAGNETOMETER_ADDRESS ); i2c_smbus_write_byte_data( file, regstr, value ); }
int main(int argc, char **argv) { int len, addr, page, answer, i; int done = FALSE; SMALLINT bank = 1; uchar data[552]; int portnum = 0; uchar AllSN[MAXDEVICES][8]; int NumDevices; int owd; char msg[132]; // check for required port name if (argc != 2) { sprintf(msg,"1-Wire Net name required on command line!\n" " (example: \"COM1\" (Win32 DS2480),\"/dev/cua0\" " "(Linux DS2480),\"{1,5}\" (Win32 TMEX)\n"); printf("%s\n",msg); return 0; } printf("\n1-Wire Memory utility console application Version 0.01\n"); if((portnum = owAcquireEx(argv[1])) < 0) { OWERROR_DUMP(stdout); return 0; } else { // loop to do menu do { // Main menu switch (menuSelect(MAIN_MENU,&AllSN[0][0])) { case MAIN_SELECT_DEVICE : // find all parts // loop to find all of the devices up to MAXDEVICES NumDevices = 0; do { // perform the search if (!owNext(portnum,TRUE, FALSE)) break; owSerialNum(portnum,AllSN[NumDevices], TRUE); NumDevices++; } while (NumDevices < (MAXDEVICES - 1)); /* for test devices without a serial number if(NumDevices == 0) { for(i=0;i<8;i++) AllSN[0][i] = 0x00; NumDevices++; }*/ // select a device owd = selectDevice(NumDevices,&AllSN[0]); // display device info printDeviceInfo(portnum,&AllSN[owd][0]); // select a bank bank = selectBank(bank, &AllSN[owd][0]); if((AllSN[owd][0] == 0x33) || (AllSN[owd][0] == 0xB3)) bank = optionSHAEE(bank,portnum,&AllSN[owd][0]); // display bank information displayBankInformation(bank,portnum,&AllSN[owd][0]); // loop on bank menu do { switch (menuSelect(BANK_MENU,&AllSN[owd][0])) { case BANK_INFO : // display bank information displayBankInformation(bank,portnum,&AllSN[owd][0]); break; case BANK_READ_BLOCK : // read a block printf("Enter the address to start reading: "); addr = getNumber(0, (owGetSize(bank,&AllSN[owd][0])-1)); printf("\n"); printf("Enter the length of data to read: "); len = getNumber(0, owGetSize(bank, &AllSN[owd][0])); printf("\n"); if(!dumpBankBlock(bank,portnum,&AllSN[owd][0],addr,len)) OWERROR_DUMP(stderr); break; case BANK_READ_PAGE : printf("Enter the page number to read: "); page = getNumber(0, (owGetNumberPages(bank,&AllSN[owd][0])-1)); printf("\n"); if(!dumpBankPage(bank,portnum,&AllSN[owd][0],page)) OWERROR_DUMP(stderr); break; case BANK_READ_UDP : printf("Enter the page number to read: "); page = getNumber(0, (owGetNumberPages(bank,&AllSN[owd][0])-1)); printf("\n"); if(!dumpBankPagePacket(bank,portnum,&AllSN[owd][0],page)) OWERROR_DUMP(stderr); break; case BANK_WRITE_BLOCK : // write a block printf("Enter the address to start writing: "); addr = getNumber(0, (owGetSize(bank,&AllSN[owd][0])-1)); if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT) len = getData(data,MAX_LEN,MODE_TEXT); else len = getData(data,MAX_LEN,MODE_HEX); if(!bankWriteBlock(bank,portnum,&AllSN[owd][0],addr,data,len)) { OWERROR_DUMP(stderr); break; } if(owCanRedirectPage(bank,&AllSN[owd][0])) { printf("Enter if you want to redirect page (0 no, 1 yes): "); answer = getNumber(0,1); if(answer) { printf("What page would you like to redirect:"); page = getNumber(0,255); printf("Where would you like to redirect:"); addr = getNumber(0,255); if(!redirectPage(bank,portnum,&AllSN[owd][0],page,addr)) { OWERROR_DUMP(stderr); break; } } } if(owCanLockPage(bank,&AllSN[owd][0])) { printf("Enter if you want to lock page (0 no, 1 yes):"); answer = getNumber(0,1); if(answer) { printf("What page would you like to lock?"); page = getNumber(0,255); if(!lockPage(bank,portnum,&AllSN[owd][0],page)) { OWERROR_DUMP(stderr); break; } } } if(owCanLockRedirectPage(bank,&AllSN[owd][0])) { printf("Enter if you want to lock redirected page (0 no, 1 yes):"); answer = getNumber(0,1); if(answer) { printf("Which redirected page do you want to lock:"); page = getNumber(0,255); if(!lockRedirectPage(bank,portnum,&AllSN[owd][0],page)) { OWERROR_DUMP(stderr); break; } } } break; case BANK_WRITE_UDP : printf("Enter the page number to write a UDP to: "); page = getNumber(0, (owGetNumberPages(bank,&AllSN[owd][0])-1)); if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT) len = getData(data,MAX_LEN,MODE_TEXT); else len = getData(data,MAX_LEN,MODE_HEX); if(!bankWritePacket(bank,portnum,&AllSN[owd][0],page,data,len)) OWERROR_DUMP(stderr); break; case BANK_BM_READ_PASS: printf("Enter the 8 byte read only password if less 0x00 will be filled in."); if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT) len = getData(data,8,MODE_TEXT); else len = getData(data,8,MODE_HEX); if(len != 8) { for(i=len;i<8;i++) data[i] = 0x00; } if(!owSetBMReadOnlyPassword(portnum,&AllSN[owd][0],data)) OWERROR_DUMP(stderr); break; case BANK_BM_RW_PASS: printf("Enter the 8 byte read/write password if less 0x00 will be filled in."); if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT) len = getData(data,8,MODE_TEXT); else len = getData(data,8,MODE_HEX); if(len != 8) { for(i=len;i<8;i++) data[i] = 0x00; } if(!owSetBMReadWritePassword(portnum,&AllSN[owd][0],data)) OWERROR_DUMP(stderr); break; case BANK_READ_PASS: printf("Enter the 8 byte read only password if less 0x00 will be filled in."); if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT) len = getData(data,8,MODE_TEXT); else len = getData(data,8,MODE_HEX); if(len != 8) { for(i=len;i<8;i++) data[i] = 0x00; } if(!owSetReadOnlyPassword(portnum,&AllSN[owd][0],data)) OWERROR_DUMP(stderr); break; case BANK_RW_PASS: printf("Enter the 8 byte read/write password if less 0x00 will be filled in."); if(menuSelect(ENTRY_MENU,&AllSN[owd][0]) == MODE_TEXT) len = getData(data,8,MODE_TEXT); else len = getData(data,8,MODE_HEX); if(len != 8) { for(i=len;i<8;i++) data[i] = 0x00; } if(!owSetReadWritePassword(portnum,&AllSN[owd][0],data)) OWERROR_DUMP(stderr); break; case BANK_ENABLE_PASS: if(!owSetPasswordMode(portnum,&AllSN[owd][0],ENABLE_PSW)) OWERROR_DUMP(stderr); break; case BANK_DISABLE_PASS: if(!owSetPasswordMode(portnum,&AllSN[owd][0],DISABLE_PSW)) OWERROR_DUMP(stderr); break; case BANK_NEW_BANK : // select a bank bank = selectBank(bank,&AllSN[owd][0]); if((AllSN[owd][0] == 0x33) || (AllSN[owd][0] == 0xB3)) bank = optionSHAEE(bank,portnum,&AllSN[owd][0]); // display bank information displayBankInformation(bank,portnum,&AllSN[owd][0]); break; case BANK_MAIN_MENU : done = TRUE; break; } } while (!done); done = FALSE; break; case MAIN_QUIT : done = TRUE; break; } // Main menu switch } while (!done); // loop to do menu owRelease(portnum); } // else for owAcquire return 1; }
int CUpnpBrowserGui::exec(CMenuTarget* parent, const std::string & /*actionKey*/) { CAudioPlayer::getInstance()->init(); if (parent) { parent->hide(); } g_Zapit->stopPlayBack(); #ifndef EVOLUX videoDecoder->ShowPicture(DATADIR "/neutrino/icons/mp3.jpg"); #endif // tell neutrino we're in audio mode CNeutrinoApp::getInstance()->handleMsg( NeutrinoMessages::CHANGEMODE , NeutrinoMessages::mode_audio ); // remember last mode #if 0 CZapitClient::responseGetLastChannel firstchannel; g_Zapit->getLastChannel(firstchannel.channelNumber, firstchannel.mode); if ((firstchannel.mode == 'r') ? (CNeutrinoApp::getInstance()->zapto_radio_on_init_done) : (CNeutrinoApp::getInstance()->zapto_tv_on_init_done)) m_LastMode=(CNeutrinoApp::getInstance()->getLastMode() | NeutrinoMessages::norezap); else m_LastMode=(CNeutrinoApp::getInstance()->getLastMode()); #endif m_LastMode=(CNeutrinoApp::getInstance()->getLastMode()); m_width=(g_settings.screen_EndX - g_settings.screen_StartX) - ConnectLineBox_Width; m_height = (g_settings.screen_EndY - g_settings.screen_StartY); m_sheight = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight(); m_buttonHeight = std::min(25, m_sheight); m_theight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(); m_mheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); m_fheight = g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->getHeight(); m_title_height = m_mheight*2 + 20 + m_sheight + 4; m_info_height = m_mheight*2; m_listmaxshow = (m_height - m_info_height - m_title_height - m_theight - 2*m_buttonHeight) / (m_fheight); m_height = m_theight + m_info_height + m_title_height + 2*m_buttonHeight + m_listmaxshow * m_fheight; // recalc height m_x=getScreenStartX( m_width + ConnectLineBox_Width ) + ConnectLineBox_Width; m_y=getScreenStartY( m_height ); // Stop sectionsd g_Sectionsd->setPauseScanning(true); m_indexdevice=0; m_selecteddevice=0; selectDevice(); if (CAudioPlayer::getInstance()->getState() != CBaseDec::STOP) CAudioPlayer::getInstance()->stop(); //g_Zapit->setStandby(false); // Start Sectionsd g_Sectionsd->setPauseScanning(false); videoDecoder->StopPicture(); CNeutrinoApp::getInstance()->handleMsg( NeutrinoMessages::CHANGEMODE , m_LastMode ); g_RCInput->postMsg( NeutrinoMessages::SHOW_INFOBAR, 0 ); return menu_return::RETURN_EXIT_ALL; }
bool paWriter::selectDefaultDevice (void) { return selectDevice (Pa_GetDefaultOutputDevice ()); }
K3b::Device::Device* K3b::DeviceSelectionDialog::selectWriter( QWidget* parent, const QString& text ) { return selectDevice( parent, k3bcore->deviceManager()->burningDevices(), text ); }
int main(void) { selectDevice(); }
int CUpnpBrowserGui::exec(CMenuTarget* parent, const std::string & /*actionKey*/) { CAudioPlayer::getInstance()->init(); if(parent) { parent->hide(); } if(g_settings.video_Format != CControldClient::VIDEOFORMAT_4_3) g_Controld->setVideoFormat(CControldClient::VIDEOFORMAT_4_3); #ifdef HAVE_DBOX_HARDWARE // If Audiomode is OST then save setting and switch to AVS-Mode if(g_settings.audio_avs_Control == CControld::TYPE_OST) { m_vol_ost = true; g_settings.audio_avs_Control = CControld::TYPE_AVS; } else #endif m_vol_ost = false; // tell neutrino we're in audio mode CNeutrinoApp::getInstance()->handleMsg( NeutrinoMessages::CHANGEMODE , NeutrinoMessages::mode_audio ); // remember last mode CZapitClient::responseGetLastChannel firstchannel; g_Zapit->getLastChannel(firstchannel.channelNumber, firstchannel.mode); if ((firstchannel.mode == 'r') ? (CNeutrinoApp::getInstance()->zapto_radio_on_init_done) : (CNeutrinoApp::getInstance()->zapto_tv_on_init_done)) m_LastMode=(CNeutrinoApp::getInstance()->getLastMode() | NeutrinoMessages::norezap); else m_LastMode=(CNeutrinoApp::getInstance()->getLastMode()); // set zapit in standby mode g_Zapit->setStandby(true); m_width = w_max(710, ConnectLineBox_Width); m_height = h_max(570, 0); m_sheight = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight(); m_buttonHeight = std::min(25, m_sheight); m_frameBuffer->getIconSize(NEUTRINO_ICON_UPNP, &m_ticonwidth, &m_ticonheight); m_theight = std::max(m_ticonheight, g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight()); m_mheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); m_fheight = g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->getHeight(); m_title_height = m_mheight*2 + 20 + m_sheight + 4; m_info_height = m_mheight*2; m_listmaxshow = (m_height - m_info_height - m_title_height - m_theight - 2*m_buttonHeight) / (m_fheight); m_height = m_theight + m_info_height + m_title_height + 2*m_buttonHeight + m_listmaxshow * m_fheight; // recalc height m_x = getScreenStartX(m_width + ConnectLineBox_Width) + ConnectLineBox_Width; m_y = getScreenStartY(m_height); // Stop sectionsd g_Sectionsd->setPauseScanning(true); #ifdef HAVE_DBOX_HARDWARE // disable iec aka digi out g_Zapit->IecOff(); #endif m_indexdevice=0; m_selecteddevice=0; selectDevice(); if(CAudioPlayer::getInstance()->getState() != CBaseDec::STOP) CAudioPlayer::getInstance()->stop(); g_Zapit->setStandby(false); #ifdef HAVE_DBOX_HARDWARE if(m_vol_ost) { g_Controld->setVolume(100, CControld::TYPE_AVS); g_settings.audio_avs_Control = CControld::TYPE_OST; } #endif // Start Sectionsd g_Sectionsd->setPauseScanning(false); #ifdef HAVE_DBOX_HARDWARE // enable iec aka digi out g_Zapit->IecOn(); #endif CNeutrinoApp::getInstance()->handleMsg( NeutrinoMessages::CHANGEMODE , m_LastMode ); g_RCInput->postMsg( NeutrinoMessages::SHOW_INFOBAR, 0 ); return menu_return::RETURN_EXIT_ALL; }
CL::TinyCL::TinyCL(DEVICE dev, bool interop, bool profile) { if (interop) selectInteropDevice(dev, profile); else selectDevice(dev, profile); }
int CUpnpBrowserGui::exec(CMenuTarget* parent, const std::string & /*actionKey*/) { dprintf(DEBUG_NORMAL, "CUpnpBrowserGui::exec:\n"); CAudioPlayer::getInstance()->init(); if(parent) parent->hide(); // tell neutrino we're in audio mode CNeutrinoApp::getInstance()->handleMsg( NeutrinoMessages::CHANGEMODE , NeutrinoMessages::mode_audio); // remember last mode m_LastMode = (CNeutrinoApp::getInstance()->getLastMode()); m_width = (g_settings.screen_EndX - g_settings.screen_StartX) - ConnectLineBox_Width; m_height = (g_settings.screen_EndY - g_settings.screen_StartY); m_frameBuffer->getIconSize(NEUTRINO_ICON_UPNP, &icon_head_w, &icon_head_h); m_sheight = g_Font[SNeutrinoSettings::FONT_TYPE_INFOBAR_SMALL]->getHeight(); m_frameBuffer->getIconSize(NEUTRINO_ICON_BUTTON_OKAY, &icon_foot_w, &icon_foot_h); m_buttonHeight = std::max(icon_foot_h, m_sheight) + 10; //foot m_theight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU_TITLE]->getHeight(); //title m_mheight = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getHeight(); m_fheight = g_Font[SNeutrinoSettings::FONT_TYPE_FILEBROWSER_ITEM]->getHeight(); m_title_height = m_mheight*2 + 20 + m_sheight + 4; // title info m_info_height = m_mheight*2; //info m_listmaxshow = (m_height - (m_title_height + m_theight + m_info_height + 2*m_buttonHeight)) / (m_fheight); m_height = m_title_height + m_theight + m_listmaxshow*m_fheight + m_buttonHeight + m_info_height; // recalc height m_x = (((g_settings.screen_EndX - g_settings.screen_StartX) - (m_width + ConnectLineBox_Width)) / 2) + g_settings.screen_StartX + ConnectLineBox_Width; m_y = (((g_settings.screen_EndY- g_settings.screen_StartY) - m_height)/ 2) + g_settings.screen_StartY; // if(CNeutrinoApp::getInstance()->getLastMode() == NeutrinoMessages::mode_iptv) { if(webtv) webtv->stopPlayBack(); } else { // stop playback g_Zapit->lockPlayBack(); // Stop sectionsd g_Sectionsd->setPauseScanning(true); } m_indexdevice = 0; m_selecteddevice = 0; selectDevice(); // if(CAudioPlayer::getInstance()->getState() != CBaseDec::STOP) CAudioPlayer::getInstance()->stop(); // if(CNeutrinoApp::getInstance()->getLastMode() == NeutrinoMessages::mode_iptv) { if(webtv) webtv->startPlayBack(webtv->getTunedChannel()); } else { // start playback g_Zapit->unlockPlayBack(); // Start Sectionsd g_Sectionsd->setPauseScanning(false); } CNeutrinoApp::getInstance()->handleMsg( NeutrinoMessages::CHANGEMODE , m_LastMode ); g_RCInput->postMsg( NeutrinoMessages::SHOW_INFOBAR, 0 ); // always repaint return menu_return::RETURN_REPAINT; }
int main() { try { std::vector<cl::Device> devices; // select platform cl::Platform platform = selectPlatform(); // select device platform.getDevices(CL_DEVICE_TYPE_ALL, &devices); cl::Device device = selectDevice(devices); // create context context = cl::Context(devices); // create command queue queue = cl::CommandQueue(context, device, CL_QUEUE_PROFILING_ENABLE); // load opencl source std::ifstream cl_file("inclusive_scan.cl"); std::string cl_string{std::istreambuf_iterator<char>(cl_file), std::istreambuf_iterator<char>()}; cl::Program::Sources source(1, std::make_pair(cl_string.c_str(), cl_string.length() + 1)); // create programm program = cl::Program(context, source); // compile opencl source try { program.build(devices); size_t input_size; std::ifstream input_file("input.txt"); input_file >> input_size; std::vector<float> input(input_size); // for (size_t i = 0; i < input_size; ++i) { // input[i] = i % 10; // } for (int i = 0; i < input_size; i++) { input_file >> input[i]; } std::vector<float> output(input_size, 0); cl::Buffer dev_input (context, CL_MEM_READ_ONLY, sizeof(float) * input_size); queue.enqueueWriteBuffer(dev_input, CL_TRUE, 0, sizeof(float) * input_size, &input[0]); cl::Buffer dev_output = inclusive_scan(dev_input, input_size); queue.enqueueReadBuffer(dev_output, CL_TRUE, 0, sizeof(float) * input_size, &output[0]); queue.finish(); cpu_check(input, output); std::ofstream output_file("output.txt"); for (int i = 0; i < input_size; i++) { output_file << output[i] << " "; } } catch (cl::Error const & e) { std::string log_str = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(device); std::cout << std::endl << e.what() << " : " << e.err() << std::endl; std::cout << log_str; return 0; } } catch (cl::Error const & e) { std::cout << "Error: " << e.what() << " #" << e.err() << std::endl; } return 0; }