本文整理汇总了C++中read8函数的典型用法代码示例。如果您正苦于以下问题:C++ read8函数的具体用法?C++ read8怎么用?C++ read8使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read8函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read8
boolean Adafruit_TSL2561_Unified::begin(void)
{
Wire.begin();
/* Make sure we're actually connected */
uint8_t x = read8(TSL2561_REGISTER_ID);
if (!(x & 0x0A))
{
return false;
}
_tsl2561Initialised = true;
/* Set default integration time and gain */
setIntegrationTime(_tsl2561IntegrationTime);
setGain(_tsl2561Gain);
/* Note: by default, the device is in power down mode on bootup */
disable();
return true;
}
示例2: write8
bool Adafruit_LSM303_Mag_Unified::begin()
{
// Enable I2C
Wire.begin();
// Enable the magnetometer
write8(LSM303_ADDRESS_MAG, LSM303_REGISTER_MAG_MR_REG_M, 0x00);
// LSM303DLHC has no WHOAMI register so read CRA_REG_M to check
// the default value (0b00010000/0x10)
uint8_t reg1_a = read8(LSM303_ADDRESS_MAG, LSM303_REGISTER_MAG_CRA_REG_M);
if (reg1_a != 0x10)
{
return false;
}
// Set the gain to a known level
setMagGain(LSM303_MAGGAIN_1_3);
return true;
}
示例3: floor
void Adafruit_PWMServoDriver::setPWMFreq(float freq) {
//Serial.print("Attempting to set freq ");
//Serial.println(freq);
float prescaleval = 25000000;
prescaleval /= 4096;
prescaleval /= freq;
prescaleval -= 1;
Serial.print("Estimated pre-scale: "); Serial.println(prescaleval);
uint8_t prescale = floor(prescaleval + 0.5);
Serial.print("Final pre-scale: "); Serial.println(prescale);
uint8_t oldmode = read8(PCA9685_MODE1);
uint8_t newmode = (oldmode&0x7F) | 0x10; // sleep
write8(PCA9685_MODE1, newmode); // go to sleep
write8(PCA9685_PRESCALE, prescale); // set the prescaler
write8(PCA9685_MODE1, oldmode);
delay(5);
write8(PCA9685_MODE1, oldmode | 0x80);
// Serial.print("Mode now 0x"); Serial.println(read8(PCA9685_MODE1), HEX);
}
示例4: read8
void Adafruit_LSM303_Accel_Unified::read()
{
// Read the accelerometer
uint8_t xlo = read8((byte)LSM303_ADDRESS_ACCEL,(byte)LSM303_REGISTER_ACCEL_OUT_X_L_A) | 0x80; //s two compliment
uint8_t xhi = read8((byte)LSM303_ADDRESS_ACCEL,(byte)LSM303_REGISTER_ACCEL_OUT_X_H_A) | 0x80;
uint8_t ylo = read8((byte)LSM303_ADDRESS_ACCEL,(byte)LSM303_REGISTER_ACCEL_OUT_Y_L_A) | 0x80;
uint8_t yhi = read8((byte)LSM303_ADDRESS_ACCEL,(byte)LSM303_REGISTER_ACCEL_OUT_Y_H_A) | 0x80;
uint8_t zlo = read8((byte)LSM303_ADDRESS_ACCEL,(byte)LSM303_REGISTER_ACCEL_OUT_Z_L_A) | 0x80;
uint8_t zhi = read8((byte)LSM303_ADDRESS_ACCEL,(byte)LSM303_REGISTER_ACCEL_OUT_Z_H_A) | 0x80;
// Shift values to create properly formed integer (low byte first)
_accelData.x = (int16_t)(xlo | (xhi << 8)) >> 4;
_accelData.y = (int16_t)(ylo | (yhi << 8)) >> 4;
_accelData.z = (int16_t)(zlo | (zhi << 8)) >> 4;
}
示例5: while
bool QTranslatorPrivate::do_load(const uchar *data, int len)
{
if (!data || len < MagicLength || memcmp(data, magic, MagicLength))
return false;
bool ok = true;
const uchar *end = data + len;
data += MagicLength;
while (data < end - 4) {
quint8 tag = read8(data++);
quint32 blockLen = read32(data);
data += 4;
if (!tag || !blockLen)
break;
if (data + blockLen > end) {
ok = false;
break;
}
if (tag == QTranslatorPrivate::Contexts) {
contextArray = data;
contextLength = blockLen;
} else if (tag == QTranslatorPrivate::Hashes) {
offsetArray = data;
offsetLength = blockLen;
} else if (tag == QTranslatorPrivate::Messages) {
messageArray = data;
messageLength = blockLen;
} else if (tag == QTranslatorPrivate::NumerusRules) {
numerusRulesArray = data;
numerusRulesLength = blockLen;
}
data += blockLen;
}
return ok;
}
示例6: setting
int
PCA9685::setPWMFreq(float freq)
{
int ret = OK;
freq *= 0.9f; /* Correct for overshoot in the frequency setting (see issue
https://github.com/adafruit/Adafruit-PWM-Servo-Driver-Library/issues/11). */
float prescaleval = 25000000;
prescaleval /= 4096;
prescaleval /= freq;
prescaleval -= 1;
uint8_t prescale = uint8_t(prescaleval + 0.5f); //implicit floor()
uint8_t oldmode;
ret = read8(PCA9685_MODE1, oldmode);
if (ret != OK) {
return ret;
}
uint8_t newmode = (oldmode&0x7F) | 0x10; // sleep
ret = write8(PCA9685_MODE1, newmode); // go to sleep
if (ret != OK) {
return ret;
}
ret = write8(PCA9685_PRESCALE, prescale); // set the prescaler
if (ret != OK) {
return ret;
}
ret = write8(PCA9685_MODE1, oldmode);
if (ret != OK) {
return ret;
}
usleep(5000); //5ms delay (from arduino driver)
ret = write8(PCA9685_MODE1, oldmode | 0xa1); // This sets the MODE1 register to turn on auto increment.
if (ret != OK) {
return ret;
}
return ret;
}
示例7: switch
/**
* \brief Read raw data from record
*/
void Storage::readRawData(uint16_t &length, uint8_t* data_record, uint16_t &offset)
{
/* Read raw value */
switch (length) {
case 1:
sprintf(buffer.data(), "%" PRIu16, static_cast<int>(read8(data_record + offset)));
break;
case 2:
sprintf(buffer.data(), "%" PRIu16, ntohs(read16(data_record + offset)));
break;
case 4:
sprintf(buffer.data(), "%" PRIu32, ntohl(read32(data_record + offset)));
break;
case 8:
sprintf(buffer.data(), "%" PRIu64, be64toh(read64(data_record + offset)));
break;
default:
length = this->realLength(length, data_record, offset);
if (length == 0) {
STR_APPEND(record, "null");
return;
}
if (length * 2 > buffer.capacity()) {
buffer.reserve(length * 2 + 1);
}
/* Start the string with 0x and print the rest in hexa */
strncpy(buffer.data(), "0x", 3);
for (int i = 0; i < length; i++) {
sprintf(buffer.data() + i * 2 + 2, "%02x", (data_record + offset)[i]);
}
}
record += '"';
record += buffer.data();
record += '"';
}
示例8: testNotLargePageAligned2MRW
void testNotLargePageAligned2MRW(result_t *result, char abort, char quiet){
int fails = 0;
int testNr = 0;
for(testNr=0; testNr<(LARGE_PAGE_SIZE / MEDIUM_PAGE_SIZE); testNr++){
// write64(L_SANDBOXW + testNr * MEDIUM_PAGE_SIZE, testNr, 1);
// if(read8(L_SANDBOXR + testNr * MEDIUM_PAGE_SIZE, testNr, 0, 1)){
// fails++;
write8(L_SANDBOXW + testNr * MEDIUM_PAGE_SIZE, testNr, quiet);
read8(L_SANDBOXR + testNr * MEDIUM_PAGE_SIZE, testNr, abort, quiet);
// }
if(fails >= 5){
printString("Ending test prematurely due to too many failures\n", quiet);
break;
}
}
result_t localResult;
localResult.nrFailed = fails;
localResult.nrTests = testNr + 1;
addResults(result, &localResult);
}
示例9: while
int tu_file::read_string(char* dst, int max_length)
{
int i = 0;
while (i < max_length)
{
dst[i] = read8();
if (get_eof() == true || dst[i] == '\n' || dst[i] == 0)
{
// remove the last '\r'
if (i > 0 && dst[i - 1] == '\r')
{
i--;
}
dst[i] = 0;
return i + 1;
}
i++;
}
dst[i - 1] = 0; // force termination.
return i;
}
示例10: while
float Adafruit_MPL3115A2::getTemperature() {
uint16_t t;
uint8_t sta = 0;
while (! (sta & MPL3115A2_REGISTER_STATUS_TDR)) {
sta = read8(MPL3115A2_REGISTER_STATUS);
delay(10);
}
Wire.beginTransmission(MPL3115A2_ADDRESS); // start transmission to device
Wire.write(MPL3115A2_REGISTER_TEMP_MSB);
Wire.endTransmission(false); // end transmission
Wire.requestFrom((uint8_t)MPL3115A2_ADDRESS, (uint8_t)2);// send data n-bytes read
t = Wire.read(); // receive DATA
t <<= 8;
t |= Wire.read(); // receive DATA
t >>= 4;
float temp = t;
temp /= 16.0;
return temp;
}
示例11: read8
boolean Adafruit_TCS34725::begin(void)
{
_wire->begin();
/* Make sure we're actually connected */
uint8_t x = read8(TCS34725_ID);
Serial.println(x, HEX);
if (x != 0x44)
{
return false;
}
_tcs34725Initialised = true;
/* Set default integration time and gain */
setIntegrationTime(_tcs34725IntegrationTime);
setGain(_tcs34725Gain);
/* Note: by default, the device is in power down mode on bootup */
enable();
return true;
}
示例12: control_read
/* Read from the 0x0XXX range of ports */
static uint8_t control_read(const uint16_t pio) {
uint8_t index = pio & 0x7F;
uint8_t value;
switch (index) {
case 0x01:
value = control.cpuSpeed;
break;
case 0x02:
/* Set bit 1 to set battery state */
value = control.readBatteryStatus;
break;
case 0x03:
value = get_device_type();
break;
case 0x0B:
/* bit 2 set if charging */
value = control.ports[index] | (control.batteryCharging == true)<<1;
break;
case 0x0F:
value = control.ports[index];
if(control.USBConnected) { value |= 0x80; }
if(control.noPlugAInserted) { value |= 0x40; }
break;
case 0x1D:
case 0x1E:
case 0x1F:
value = read8(control.privileged, (index - 0x1D) << 3);
break;
case 0x28:
value = control.ports[index] | 0x08;
break;
default:
value = control.ports[index];
break;
}
return value;
}
示例13: hda_codec_detect
/**
* Probe for supported codecs
*/
int hda_codec_detect(u8 *base)
{
u8 reg8;
/* Set Bit 0 to 1 to exit reset state (BAR + 0x8)[0] */
if (set_bits(base + HDA_GCTL_REG, HDA_GCTL_CRST, HDA_GCTL_CRST) < 0)
goto no_codec;
/* Write back the value once reset bit is set. */
write16(base + HDA_GCAP_REG, read16(base + HDA_GCAP_REG));
/* Clear the "State Change Status Register" STATESTS bits
* for each of the "SDIN Stat Change Status Flag"
*/
write8(base + HDA_STATESTS_REG, 0xf);
/* Turn off the link and poll RESET# bit until it reads back as 0 */
if (set_bits(base + HDA_GCTL_REG, HDA_GCTL_CRST, ~HDA_GCTL_CRST) < 0)
goto no_codec;
/* Turn on the link and poll RESET# bit until it reads back as 1 */
if (set_bits(base + HDA_GCTL_REG, HDA_GCTL_CRST, HDA_GCTL_CRST) < 0)
goto no_codec;
/* Read in Codec location (BAR + 0xe)[2..0]*/
reg8 = read8(base + HDA_STATESTS_REG);
reg8 &= 0x0f;
if (!reg8)
goto no_codec;
return reg8;
no_codec:
/* Codec Not found */
/* Put HDA back in reset (BAR + 0x8) [0] */
set_bits(base + HDA_GCTL_REG, HDA_GCTL_CRST, 0);
printk(BIOS_DEBUG, "HDA: No codec!\n");
return 0;
}
示例14: get_emic
static void get_emic(struct xmp_context *ctx, int size, FILE *f)
{
struct xmp_player_context *p = &ctx->p;
struct xmp_mod_context *m = &p->m;
int i, ver;
ver = read16b(f);
fread(m->name, 1, 20, f);
fread(m->author, 1, 20, f);
m->xxh->bpm = read8(f);
m->xxh->ins = read8(f);
m->xxh->smp = m->xxh->ins;
m->xxh->flg |= XXM_FLG_MODRNG;
snprintf(m->type, XMP_NAMESIZE, "EMOD v%d (Quadra Composer)", ver);
MODULE_INFO();
INSTRUMENT_INIT();
reportv(ctx, 1, " Instrument name Len LBeg LEnd L Vol Fin\n");
for (i = 0; i < m->xxh->ins; i++) {
m->xxi[i] = calloc(sizeof (struct xxm_instrument), 1);
read8(f); /* num */
m->xxi[i][0].vol = read8(f);
m->xxs[i].len = 2 * read16b(f);
fread(m->xxih[i].name, 1, 20, f);
m->xxs[i].flg = read8(f) & 1 ? WAVE_LOOPING : 0;
m->xxi[i][0].fin = read8(f);
m->xxs[i].lps = 2 * read16b(f);
m->xxs[i].lpe = m->xxs[i].lps + 2 * read16b(f);
read32b(f); /* ptr */
m->xxih[i].nsm = 1;
m->xxi[i][0].pan = 0x80;
m->xxi[i][0].sid = i;
if (V(1) && (strlen((char *)m->xxih[i].name) || (m->xxs[i].len > 2))) {
report ("[%2X] %-20.20s %05x %05x %05x %c V%02x %+d\n",
i, m->xxih[i].name, m->xxs[i].len, m->xxs[i].lps,
m->xxs[i].lpe, m->xxs[i].flg & WAVE_LOOPING ? 'L' : ' ',
m->xxi[i][0].vol, m->xxi[i][0].fin >> 4);
}
}
示例15: while
void PX4Flow::update_integral()
{
//send 0x16 to PX4FLOW module and receive back 25 Bytes data
Wire.beginTransmission(PX4FLOW_ADDRESS);
Wire.write(0x16);
Wire.endTransmission();
// request 25 bytes from the module
Wire.requestFrom(PX4FLOW_ADDRESS, 25);
// wait for all data to be available
// TODO we could manage a timeout in order not to block
// the loop when no component is connected
while(Wire.available() < 25);
iframe.frame_count_since_last_readout = read16();
iframe.pixel_flow_x_integral = read16();
iframe.pixel_flow_y_integral = read16();
iframe.gyro_x_rate_integral = read16();
iframe.gyro_y_rate_integral = read16();
iframe.gyro_z_rate_integral = read16();
iframe.integration_timespan = read32();
iframe.sonar_timestamp = read32();
iframe.ground_distance = read16();
iframe.gyro_temperature = read16();
iframe.quality = read8();
// if too many bytes are available, we drain in order to be synched
// on next read
if(Wire.available()) {
#if PX4FLOW_DEBUG == true
{
Serial.println("ERROR [PX4Flow] : Too many bytes available.");
}
#endif
while(Wire.available()) {Wire.read();}
}
}