错误:数字常量之前的预期unqualified-id - Arduino帮助! [英] error: expected unqualified-id before numeric constant - Arduino HELP!

查看:323
本文介绍了错误:数字常量之前的预期unqualified-id - Arduino帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编译代码时,这是我得到的错误:



MS561101BA_altitude.pde中包含的文件:31:

C:\Program Files(x86)\ Arduino \libraries \ MS561101BA / MS561101BA.h:82:错误:数字常量前的预期unqualified-id



我想编译的代码是:





When I compile a code, this is the error I get:

In file included from MS561101BA_altitude.pde:31:
C:\Program Files (x86)\Arduino\libraries\MS561101BA/MS561101BA.h:82: error: expected unqualified-id before numeric constant

The code I am trying to compile is:


#include <wire.h>
//#include <debugutils.h>
#include <ms561101ba.h>   // <-------------------------------------------Line 31





#define MOVAVG_SIZE 32



MS561101BA baro = MS561101BA();



float movavg_buff[MOVAVG_SIZE];

int movavg_i=0;



const float sea_press = 1013.25;

float press, temperature;



void setup() {

  Wire.begin();

  Serial.begin(115200);

  delay(1000);



  // Suppose that the CSB pin is connected to GND.

  // You'll have to check this on your breakout schematics

  baro.init(MS561101BA_ADDR_CSB_LOW); 

  delay(100);

  

  // populate movavg_buff before starting loop

  for(int i=0; i<movavg_size;>    movavg_buff[i] = baro.getPressure(MS561101BA_OSR_4096);
  }
}

void loop() {
  Serial.print(" temp: ");
  temperature = baro.getTemperature(MS561101BA_OSR_4096);
  Serial.print(temperature);
  Serial.print(" degC pres: ");
  
  press = baro.getPressure(MS561101BA_OSR_4096);
  pushAvg(press);
  press = getAvg(movavg_buff, MOVAVG_SIZE);
  Serial.print(press);
  Serial.print(" mbar altitude: ");
  Serial.print(getAltitude(press, temperature));
  Serial.println(" m");
}

float getAltitude(float press, float temp) {
  //return (1.0f - pow(press/101325.0f, 0.190295f)) * 4433000.0f;
  return ((pow((sea_press / press), 1/5.257) - 1.0) * (temp + 273.15)) / 0.0065;
}

void pushAvg(float val) {
  movavg_buff[movavg_i] = val;
  movavg_i = (movavg_i + 1) % MOVAVG_SIZE;
}

float getAvg(float * buff, int size) {
  float sum = 0.0;
  for(int i=0; i<size;>    sum += buff[i];
  }
  return sum / size;
}



MS561101BA.h的代码是:






Code of MS561101BA.h is:


#ifndef MS561101BA_h
#define MS561101BA_h

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif

#include "Arduino.h"
#include <wire.h>

//#define DEBUG_V
//#define DEBUG
//#include <debugutils.h>

// addresses of the device
#define MS561101BA_ADDR_CSB_HIGH  0x76   //CBR=1 0x76 I2C address when CSB is connected to HIGH (VCC)
#define MS561101BA_ADDR_CSB_LOW   0x77   //CBR=0 0x77 I2C address when CSB is connected to LOW (GND)

// registers of the device
#define MS561101BA_D1 0x40
#define MS561101BA_D2 0x50
#define MS561101BA_RESET 0x1E

// D1 and D2 result size (bytes)
#define MS561101BA_D1D2_SIZE 3

// OSR (Over Sampling Ratio) constants
#define MS561101BA_OSR_256 0x00
#define MS561101BA_OSR_512 0x02
#define MS561101BA_OSR_1024 0x04
#define MS561101BA_OSR_2048 0x06
#define MS561101BA_OSR_4096 0x08

#define MS561101BA_PROM_BASE_ADDR 0xA2 // by adding ints from 0 to 6 we can read all the prom configuration values. 
// C1 will be at 0xA2 and all the subsequent are multiples of 2
#define MS561101BA_PROM_REG_COUNT 6 // number of registers in the PROM
#define MS561101BA_PROM_REG_SIZE 2 // size in bytes of a prom registry.



class MS561101BA {
  public:
    MS561101BA();
    void init(uint8_t addr);
    float getPressure(uint8_t OSR);
    float getTemperature(uint8_t OSR);
    int32_t getDeltaTemp(uint8_t OSR);
    uint32_t rawPressure(uint8_t OSR);
    uint32_t rawTemperature(uint8_t OSR);
    int readPROM();
    void reset();
    uint32_t lastPresConv, lastTempConv;
  private:
    void startConversion(uint8_t command);
    uint32_t getConversion(uint8_t command);
    uint8_t _addr;
    uint16_t _C[MS561101BA_PROM_REG_COUNT];  //  <--------------------Line 82
    uint32_t pressCache, tempCache;
};

#endif // MS561101BA_h





在消除此错误时,将获得任何帮助。 :)



Any help would be apprecited in eliminating this error. :)

推荐答案

这篇关于错误:数字常量之前的预期unqualified-id - Arduino帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆