uint8_t Intel8255::readByPort(uint8_t p03) { switch (p03) { case 0: return readPortA(); case 1: return readPortB(); case 2: return readPortC(); case 3: return readControl(); } return 0; }
void main() { unsigned char *lcd = (unsigned char *)4294963716; unsigned char *control1 = (unsigned char *)8587830276; unsigned char *control2 = (unsigned char *)8587830272; int i; char id1; char id2; char move1; char move2; int x; int y; id1 = createObject(lcd, 1, 0, 0); id2 = createObject(lcd, 2, 0, 0); put_char('0' + id1); put_char(' '); put_char('0' + id2); put_char('\n'); while(1) { move1 = readControl(control1); move2 = readControl(control2); getPosition(lcd, id1, &x, &y); if(x >= 0 && x < 10) { put_char('0' + x); } put_char(' '); if(y >= 0 && y < 10) { put_char('0' + y); } put_char('\n'); if(move1 != 8) move(lcd, id1, readControl(control1), 1); for(i = 0; i < 1000; i++); if(move2 != 8) move(lcd, id2, readControl(control2), 1); } }
void Motor::readAccelerometers(float accels[3]) { /* Read the raw accelerometer values: */ unsigned char data[32]; size_t dataSize=readControl(0x40,0x32,0x0000,0x0000,data,sizeof(data)); if(dataSize>=8) { for(int i=0;i<3;++i) { int val=(int(data[i*2+2])<<8)|int(data[i*2+3]); if(val>=0x8000) val-=65536; accels[i]=float(val); } } else Misc::throwStdErr("Kinect::Motor::readAccelerometers: Short control packet, received %d bytes instead of 8",int(dataSize)); }
int parseLine(int sect, char *line) // // Input: sect = current section of input file // *line = line of text read from input file // Output: returns error code or 0 if no error found // Purpose: parses contents of a tokenized line of text read from input file. // { int j, err; switch (sect) { case s_TITLE: return readTitle(line); case s_RAINGAGE: j = Mobjects[GAGE]; err = gage_readParams(j, Tok, Ntokens); Mobjects[GAGE]++; return err; case s_TEMP: return climate_readParams(Tok, Ntokens); case s_EVAP: return climate_readEvapParams(Tok, Ntokens); case s_ADJUST: //(5.1.007) return climate_readAdjustments(Tok, Ntokens); //(5.1.007) case s_SUBCATCH: j = Mobjects[SUBCATCH]; err = subcatch_readParams(j, Tok, Ntokens); Mobjects[SUBCATCH]++; return err; case s_SUBAREA: return subcatch_readSubareaParams(Tok, Ntokens); case s_INFIL: return infil_readParams(InfilModel, Tok, Ntokens); case s_AQUIFER: j = Mobjects[AQUIFER]; err = gwater_readAquiferParams(j, Tok, Ntokens); Mobjects[AQUIFER]++; return err; case s_GROUNDWATER: return gwater_readGroundwaterParams(Tok, Ntokens); case s_GWF: return gwater_readFlowExpression(Tok, Ntokens); case s_SNOWMELT: return snow_readMeltParams(Tok, Ntokens); case s_JUNCTION: return readNode(JUNCTION); case s_OUTFALL: return readNode(OUTFALL); case s_STORAGE: return readNode(STORAGE); case s_DIVIDER: return readNode(DIVIDER); case s_CONDUIT: return readLink(CONDUIT); case s_PUMP: return readLink(PUMP); case s_ORIFICE: return readLink(ORIFICE); case s_WEIR: return readLink(WEIR); case s_OUTLET: return readLink(OUTLET); case s_XSECTION: return link_readXsectParams(Tok, Ntokens); case s_TRANSECT: return transect_readParams(&Mobjects[TRANSECT], Tok, Ntokens); case s_LOSSES: return link_readLossParams(Tok, Ntokens); case s_POLLUTANT: j = Mobjects[POLLUT]; err = landuse_readPollutParams(j, Tok, Ntokens); Mobjects[POLLUT]++; return err; case s_LANDUSE: j = Mobjects[LANDUSE]; err = landuse_readParams(j, Tok, Ntokens); Mobjects[LANDUSE]++; return err; case s_BUILDUP: return landuse_readBuildupParams(Tok, Ntokens); case s_WASHOFF: return landuse_readWashoffParams(Tok, Ntokens); case s_COVERAGE: return subcatch_readLanduseParams(Tok, Ntokens); case s_INFLOW: return inflow_readExtInflow(Tok, Ntokens); case s_DWF: return inflow_readDwfInflow(Tok, Ntokens); case s_PATTERN: return inflow_readDwfPattern(Tok, Ntokens); case s_RDII: return rdii_readRdiiInflow(Tok, Ntokens); case s_UNITHYD: return rdii_readUnitHydParams(Tok, Ntokens); case s_LOADING: return subcatch_readInitBuildup(Tok, Ntokens); case s_TREATMENT: return treatmnt_readExpression(Tok, Ntokens); case s_CURVE: return table_readCurve(Tok, Ntokens); case s_TIMESERIES: return table_readTimeseries(Tok, Ntokens); case s_CONTROL: return readControl(Tok, Ntokens); case s_REPORT: return report_readOptions(Tok, Ntokens); case s_FILE: return iface_readFileParams(Tok, Ntokens); case s_LID_CONTROL: return lid_readProcParams(Tok, Ntokens); case s_LID_USAGE: return lid_readGroupParams(Tok, Ntokens); default: return 0; } }
//lets you read the instantainious current int bq34z100::readInstantCurrent() { return readControl(0x18,0x00); }
int bq34z100::enableIT() { return readControl(0x21,0x00);//reading this will enable the IT algorithum }
int bq34z100::getFlags() { return readControl(0x0E,0x0F); }
int bq34z100::getStatus() { return readControl(0x00,0x00); }
bool TinyAmixerControl::accessHW(bool receive, std::string &error) { CAutoLog autoLog(getConfigurableElement(), "ALSA", isDebugEnabled()); // Mixer handle struct mixer *mixer; // Mixer control handle struct mixer_ctl *mixerControl; uint32_t elementCount; std::string controlName = getControlName(); // Debug conditionnaly enabled in XML logControlInfo(receive); // Check parameter type is ok (deferred error, no exceptions available :-() if (!isTypeSupported()) { error = "Parameter type not supported."; return false; } // Check card number int32_t cardIndex = getCardNumber(); if (cardIndex < 0) { error = "Card " + getCardName() + " not found. Error: " + strerror(-cardIndex); return false; } // Open alsa mixer // getMixerHandle is non-const; we need to forcefully remove the constness // then, we need to cast the generic subsystem into a TinyAlsaSubsystem. mixer = static_cast<TinyAlsaSubsystem *>( const_cast<CSubsystem *>(getSubsystem()))->getMixerHandle(cardIndex); if (!mixer) { error = "Failed to open mixer for card: " + getCardName(); return false; } // Get control handle if (isdigit(controlName[0])) { mixerControl = mixer_get_ctl(mixer, asInteger(controlName)); } else { mixerControl = mixer_get_ctl_by_name(mixer, controlName.c_str()); } // Check control has been found if (!mixerControl) { error = "Failed to open mixer control: " + controlName; return false; } // Get element count elementCount = getNumValues(mixerControl); uint32_t scalarSize = getScalarSize(); // Check available size if (elementCount * scalarSize != getSize()) { error = "ALSA: Control element count (" + asString(elementCount) + ") and configurable scalar element count (" + asString(getSize() / scalarSize) + ") mismatch"; return false; } // Read/Write element bool success; if (receive) { success = readControl(mixerControl, elementCount, error); } else { success = writeControl(mixerControl, elementCount, error); } return success; }
nsresult mozJSComponentLoader::StartFastLoad(nsIFastLoadService *flSvc) { if (!mFastLoadFile || !flSvc) { return NS_ERROR_NOT_AVAILABLE; } // Now set our IO object as current, and create our streams. if (!mFastLoadIO) { mFastLoadIO = new nsXPCFastLoadIO(mFastLoadFile); NS_ENSURE_TRUE(mFastLoadIO, NS_ERROR_OUT_OF_MEMORY); } nsresult rv = flSvc->SetFileIO(mFastLoadIO); NS_ENSURE_SUCCESS(rv, rv); if (!mFastLoadInput && !mFastLoadOutput) { // First time accessing the fastload file PRBool exists; mFastLoadFile->Exists(&exists); if (exists) { LOG(("trying to use existing fastload file\n")); nsCOMPtr<nsIInputStream> input; rv = mFastLoadIO->GetInputStream(getter_AddRefs(input)); NS_ENSURE_SUCCESS(rv, rv); rv = flSvc->NewInputStream(input, getter_AddRefs(mFastLoadInput)); if (NS_SUCCEEDED(rv)) { LOG(("opened fastload file for reading\n")); nsCOMPtr<nsIFastLoadReadControl> readControl(do_QueryInterface(mFastLoadInput)); if (readControl) { // Verify checksum, using the FastLoadService's // checksum cache to avoid computing more than once // per session. PRUint32 checksum; rv = readControl->GetChecksum(&checksum); if (NS_SUCCEEDED(rv)) { PRUint32 verified; rv = flSvc->ComputeChecksum(mFastLoadFile, readControl, &verified); if (NS_SUCCEEDED(rv) && verified != checksum) { LOG(("Incorrect checksum detected")); rv = NS_ERROR_FAILURE; } } } if (NS_SUCCEEDED(rv)) { /* Get the JS bytecode version number and validate it. */ PRUint32 version; rv = mFastLoadInput->Read32(&version); if (NS_SUCCEEDED(rv) && version != JSXDR_BYTECODE_VERSION) { LOG(("Bad JS bytecode version\n")); rv = NS_ERROR_UNEXPECTED; } } } if (NS_FAILED(rv)) { LOG(("Invalid fastload file detected, removing it\n")); if (mFastLoadInput) { mFastLoadInput->Close(); mFastLoadInput = nsnull; } else { input->Close(); } mFastLoadIO->SetInputStream(nsnull); mFastLoadFile->Remove(PR_FALSE); exists = PR_FALSE; } } if (!exists) { LOG(("Creating new fastload file\n")); nsCOMPtr<nsIOutputStream> output; rv = mFastLoadIO->GetOutputStream(getter_AddRefs(output)); NS_ENSURE_SUCCESS(rv, rv); rv = flSvc->NewOutputStream(output, getter_AddRefs(mFastLoadOutput)); if (NS_SUCCEEDED(rv)) rv = mFastLoadOutput->Write32(JSXDR_BYTECODE_VERSION); if (NS_FAILED(rv)) { LOG(("Fatal error, could not create fastload file\n")); if (mFastLoadOutput) { mFastLoadOutput->Close(); mFastLoadOutput = nsnull; } else { output->Close(); } mFastLoadIO->SetOutputStream(nsnull); mFastLoadFile->Remove(PR_FALSE); return rv; } } } flSvc->SetInputStream(mFastLoadInput); flSvc->SetOutputStream(mFastLoadOutput); // Start our update timer. This allows us to keep the stream open // when many components are loaded in succession, but close it once // there has been a period of inactivity. if (!mFastLoadTimer) { mFastLoadTimer = do_CreateInstance(NS_TIMER_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); rv = mFastLoadTimer->InitWithFuncCallback(&mozJSComponentLoader::CloseFastLoad, this, kFastLoadWriteDelay, nsITimer::TYPE_ONE_SHOT); } else { rv = mFastLoadTimer->SetDelay(kFastLoadWriteDelay); } return rv; }
int main() { int c1 = initControl(8587830272); int c2 = initControl(8587830276); int o1; int o2; int o3; int o4; int o5; int lcd = initLCD(); int read1; int read2; int vidas1 = 3; int vidas2 = 3; int dir = 3; int i = 0; Point *p1; Point *p2; Point *p3; Dimension *dim1; Dimension *dim2; Dimension *dim3; o4 = createObject(lcd, 4, 0, 0); o1 = createObject(lcd, 1, 60, 0); o2 = createObject(lcd, 2, 250, 0); o3 = createObject(lcd, 3, 0, 0); dim1 = getDimensions(lcd,o1); dim2 = getDimensions(lcd,o2); dim3 = getDimensions(lcd,o3); setPosition(lcd,o1,60,130-dim1->height); setPosition(lcd,o2,250,130-dim2->height); while(1) { read1 = readControl(c1); read2 = readControl(c2); if(read1 == 0 || read1 == 4) { move(lcd, o1, read1); } if(read2 == 0 || read2 == 4) { move(lcd, o2, read2); } move(lcd, o3, dir); p3 = getPosition(lcd, o3); p1 = getPosition(lcd, o1); p2 = getPosition(lcd, o2); if(dir == 5 || dir == 7) { if(((p3->x >=((p1->x + dim1->width)-8)) && (p3->x < ((p1->x + dim1->width)+4))) && ((p3->y >= (p1->y -12)) && (p3->y < (p1->y +(dim1->height/2))))) dir = 1; if(((p3->x >=((p1->x + dim1->width)-8)) && (p3->x < ((p1->x + dim1->width)+4))) && ((p3->y >= (p1->y +(dim1->height/2))) && (p3->y < (p1->y + dim1->height + 8)))) dir = 3; if (p3->x <= 0) { vidas1--; if(vidas1 == 0) { o5 = createObject(lcd, 5, 80, 110); break; } if(dir == 5) dir = 3; else dir = 1; } } else { //aqui es cuando dir == 3 || dir == 1 if((((p3->x + dim3->width) < (p2->x + 8)) && ((p3->x + dim3->width) >= (p2->x - 4))) && ((p3->y >= (p2->y - 12)) && (p3->y < (p2->y +(dim2->height/2))))) dir = 7; if((((p3->x + dim3->width) < (p2->x + 8)) && ((p3->x + dim3->width) >= (p2->x - 4))) && ((p3->y >= (p2->y +(dim2->height/2))) && (p3->y < (p2->y + dim2->height + 8)))) dir = 5; if((p3->x + dim3->width) >= 320) { vidas2--; if(vidas2 == 0) { o5 = createObject(lcd, 5, 80, 110); break; } if(dir == 3) dir = 5; else dir = 7; } } //Validar bordes superior e inferior if((p3->y + dim3->height) >= 240) { if(dir == 3) dir = 1; else dir = 7; } if(p3->y <= 0) { if(dir == 7) dir = 5; else dir = 3; } //printf("%u %u\n", p3->x, p3->y); //printf("%u %u\n", p2->x, p2->y); } stopLCD(lcd); return 0; }
// CONTROL void CamConfig::readControl() { LOG_DEBUG("CamConfig: readControl"); struct v4l2_queryctrl queryctrl_tmp; memset (&queryctrl_tmp, 0, sizeof (struct v4l2_queryctrl)); mCamCtrls.clear(); // Checks which controls are offered by the camera / device-driver. LOG_DEBUG("Check base control IDs"); for (int i = V4L2_CID_BASE; i < V4L2_CID_LASTP1; i++) { queryctrl_tmp.id = i; try { readControl(queryctrl_tmp); } catch (std::runtime_error& e) { LOG_WARN("Reading V4L2_CID_BASE control parameter %d: %s", i-V4L2_CID_BASE, e.what()); } } // MPEG LOG_DEBUG("Check MPEG base control IDs"); for (int i = V4L2_CID_MPEG_BASE; i < V4L2_CID_MPEG_BASE+8; i++) { queryctrl_tmp.id = i; try { readControl(queryctrl_tmp); } catch (std::runtime_error& e) { LOG_WARN("Reading V4L2_CID_MPEG_BASE control parameter %d: %s", i-V4L2_CID_MPEG_BASE, e.what()); } } LOG_DEBUG("Check MPEG audio base control IDs"); for (int i = V4L2_CID_MPEG_BASE+100; i < V4L2_CID_MPEG_BASE+112; i++) { queryctrl_tmp.id = i; try { readControl(queryctrl_tmp); } catch (std::runtime_error& e) { LOG_WARN("Reading V4L2_CID_MPEG_BASE control parameter %d: %s", i-V4L2_CID_MPEG_BASE, e.what()); } } LOG_DEBUG("Check MPEG video base control IDs"); for (int i = V4L2_CID_MPEG_BASE+200; i < V4L2_CID_MPEG_BASE+212; i++) { queryctrl_tmp.id = i; try { readControl(queryctrl_tmp); } catch (std::runtime_error& e) { LOG_WARN("Reading V4L2_CID_MPEG_BASE control parameter %d: %s", i-V4L2_CID_MPEG_BASE, e.what()); } } LOG_DEBUG("Check MPEG base control IDs specific to the CX2341x driver"); for (int i = V4L2_CID_MPEG_CX2341X_BASE+0; i < V4L2_CID_MPEG_CX2341X_BASE+12; i++) { queryctrl_tmp.id = i; try { readControl(queryctrl_tmp); } catch (std::runtime_error& e) { LOG_WARN("Reading V4L2_CID_MPEG_CX2341X_BASE control parameter %d: %s", i-V4L2_CID_MPEG_CX2341X_BASE, e.what()); } } // Camera class LOG_DEBUG("Check camera class control IDs"); for (int i = V4L2_CID_CAMERA_CLASS_BASE+1; i < V4L2_CID_CAMERA_CLASS_BASE+17; i++) { queryctrl_tmp.id = i; try { readControl(queryctrl_tmp); } catch (std::runtime_error& e) { LOG_WARN("Reading V4L2_CID_CAMERA_CLASS_BASE control parameter %d: %s", i-V4L2_CID_CAMERA_CLASS_BASE, e.what()); } } /* // FM Modulator LOG_DEBUG("FM Modulator class control IDs"); for (int i = V4L2_CID_FM_TX_CLASS_BASE + 1; i < V4L2_CID_FM_TX_CLASS_BASE + 7; i++) { queryctrl_tmp.id = i; readControl(queryctrl_tmp); } LOG_DEBUG("FM Modulator class control IDs"); for (int i = V4L2_CID_FM_TX_CLASS_BASE + 64; i < V4L2_CID_FM_TX_CLASS_BASE + 67; i++) { queryctrl_tmp.id = i; readControl(queryctrl_tmp); } LOG_DEBUG("FM Modulator class control IDs"); for (int i = V4L2_CID_FM_TX_CLASS_BASE + 80; i < V4L2_CID_FM_TX_CLASS_BASE + 85; i++) { queryctrl_tmp.id = i; readControl(queryctrl_tmp); } LOG_DEBUG("FM Modulator class control IDs"); for (int i = V4L2_CID_FM_TX_CLASS_BASE + 96; i < V4L2_CID_FM_TX_CLASS_BASE + 99; i++) { queryctrl_tmp.id = i; readControl(queryctrl_tmp); } LOG_DEBUG("FM Modulator class control IDs"); for (int i = V4L2_CID_FM_TX_CLASS_BASE + 112; i < V4L2_CID_FM_TX_CLASS_BASE + 115; i++) { queryctrl_tmp.id = i; readControl(queryctrl_tmp); } */ // Checks private controls of the e-CAM32_OMAP_GSTIX LOG_DEBUG("Check private base control IDs"); for (int i = V4L2_CID_PRIVATE_BASE + 1; i < V4L2_CID_PRIVATE_BASE + 17; i++) { queryctrl_tmp.id = i; try { readControl(queryctrl_tmp); } catch (std::runtime_error& e) { LOG_WARN("Reading V4L2_CID_PRIVATE_BASE control parameter %d: %s", i-V4L2_CID_PRIVATE_BASE, e.what()); } } }
void upscale(const Opm::parameter::ParameterGroup& param) { // Control structure. std::vector<double> saturations; Opm::SparseTable<double> all_pdrops; bool from_file = param.has("sat_pdrop_filename"); if (from_file) { std::string filename = param.get<std::string>("sat_pdrop_filename"); std::ifstream file(filename.c_str()); if (!file) { OPM_THROW(std::runtime_error, "Could not open file " << filename); } readControl(file, saturations, all_pdrops); } else { // Get a linear range of saturations. int num_sats = param.getDefault("num_sats", 4); double min_sat = param.getDefault("min_sat", 0.2); double max_sat = param.getDefault("max_sat", 0.8); saturations.resize(num_sats); for (int i = 0; i < num_sats; ++i) { double factor = num_sats == 1 ? 0 : double(i)/double(num_sats - 1); saturations[i] = (1.0 - factor)*min_sat + factor*max_sat; } // Get a logarithmic range of pressure drops. int num_pdrops = param.getDefault("num_pdrops", 5); double log_min_pdrop = std::log(param.getDefault("min_pdrop", 1e2)); double log_max_pdrop = std::log(param.getDefault("max_pdrop", 1e6)); std::vector<double> pdrops; pdrops.resize(num_pdrops); for (int i = 0; i < num_pdrops; ++i) { double factor = num_pdrops == 1 ? 0 : double(i)/double(num_pdrops - 1); pdrops[i] = std::exp((1.0 - factor)*log_min_pdrop + factor*log_max_pdrop); } // Assign the same pressure drops to all saturations. for (int i = 0; i < num_sats; ++i) { all_pdrops.appendRow(pdrops.begin(), pdrops.end()); } } int flow_direction = param.getDefault("flow_direction", 0); // Print the saturations and pressure drops. // writeControl(std::cout, saturations, all_pdrops); // Initialize upscaler. typedef SteadyStateUpscaler<Traits> Upscaler; typedef typename Upscaler::permtensor_t permtensor_t; Upscaler upscaler; upscaler.init(param); // First, compute an upscaled permeability. permtensor_t upscaled_K = upscaler.upscaleSinglePhase(); permtensor_t upscaled_K_copy = upscaled_K; upscaled_K_copy *= (1.0/(Opm::prefix::milli*Opm::unit::darcy)); std::cout.precision(15); std::cout << "Upscaled K in millidarcy:\n" << upscaled_K_copy << std::endl; std::cout << "Upscaled porosity: " << upscaler.upscalePorosity() << std::endl; // Create output streams for upscaled relative permeabilities std::string kr_filename = param.getDefault<std::string>("kr_filename", "upscaled_relperm"); std::string krw_filename = kr_filename + "_water"; std::string kro_filename = kr_filename + "_oil"; std::ofstream krw_out(krw_filename.c_str()); std::ofstream kro_out(kro_filename.c_str()); krw_out << "# Result from steady state upscaling" << std::endl; krw_out << "# Pressuredrop Sw Krxx Kryy Krzz" << std::endl; kro_out << "# Result from steady state upscaling" << std::endl; kro_out << "# Pressuredrop Sw Krxx Kryy Krzz" << std::endl; krw_out.precision(15); krw_out.setf(std::ios::scientific | std::ios::showpoint); kro_out.precision(15); kro_out.setf(std::ios::scientific | std::ios::showpoint); //#endif // Then, compute some upscaled relative permeabilities. int num_cells = upscaler.grid().size(0); int num_sats = saturations.size(); for (int i = 0; i < num_sats; ++i) { // Starting every computation with a trio of uniform profiles. std::vector<double> init_sat(num_cells, saturations[i]); const Opm::SparseTable<double>::row_type pdrops = all_pdrops[i]; int num_pdrops = pdrops.size(); for (int j = 0; j < num_pdrops; ++j) { double pdrop = pdrops[j]; std::pair<permtensor_t, permtensor_t> lambda = upscaler.upscaleSteadyState(flow_direction, init_sat, saturations[i], pdrop, upscaled_K); double usat = upscaler.lastSaturationUpscaled(); std::cout << "\n\nTensor of upscaled relperms for initial saturation " << saturations[i] << ", real steady-state saturation " << usat << " and pressure drop " << pdrop << ":\n\n[water]\n" << lambda.first << "\n[oil]\n" << lambda.second << std::endl; // Changing initial saturations for next pressure drop to equal the steady state of the last init_sat = upscaler.lastSaturationState(); writeRelPerm(krw_out, lambda.first , usat, pdrop); writeRelPerm(kro_out, lambda.second, usat, pdrop); } } }