Hello! I’ve dabbled with arduino for a while and decided to write a library for the BMP280 to learn more.
I am however having some issues with my enums (first time using them).
I am using them to define some types, to prevent arbitrary values being passed to the chips registers.
Anyhow.
I have the enums in my header (pasted below), and they work fine in the BMP280i2c.h and BMP280i2c.cpp, but in my main.cpp they show as undefined.
The actual constructor and other functions are recognized just fine though, eg. if i write the following:
bmp.Init();
bmp.Config(STANDBY_125MS,IIR_FILTER_OFF);
bmp.Init(); passes just fine, bmp.Config() in itself passes just fine, but the standby and filter are both flagged as undefined.
#ifndef BMP280i2c_h #define BMP280i2c_h #include <Arduino.h> #include <hardwareSerial.h> #include <Wire.h> #define BMP280Addr (0x76) class BMP280i2c { public: enum standbyPeriod { STANDBY_0_5MS = 0, STANDBY_62_5MS = 1, STANDBY_125MS = 2, STANDBY_250MS = 3, STANDBY_500MS = 4, STANDBY_1000MS = 5, STANDBY_2000MS = 6, STANDBY_4000MS = 7 }; enum filterCoeff { IIR_FILTER_OFF = 0, IIR_FILTER_X2 = 1, IIR_FILTER_X4 = 2, IIR_FILTER_X8 = 3, IIR_FILTER_X16 = 4 }; enum commType { I2C = 0, SPI = 1 }; enum powerMode { BMP_SLEEP = 0, BMP_FORCED = 1, BMP_NORMAL = 3 }; enum Sampling { SAMPLE_SKIP = 0, SAMPLE_X1 = 1, SAMPLE_X2 = 2, SAMPLE_X4 = 3, SAMPLE_X8 = 4, SAMPLE_X16 = 5 }; BMP280i2c(); bool Init(); void PrintDetails(); bool SetMeas(powerMode pwr, Sampling pressSamp, Sampling tempSamp); bool Config(standbyPeriod stbyDur, filterCoeff filter); uint32_t GetPressurePA(); float GetPressureHPA(); float GetAltitude(); float GetTemperature(); bool Confirm(); private: //Structure for storing calibration data struct BMP280_Calibration_Data{ unsigned short dig_T1; short dig_T2; short dig_T3; unsigned short dig_P1; short dig_P2; short dig_P3; short dig_P4; short dig_P5; short dig_P6; short dig_P7; short dig_P8; short dig_P9; } bmpCalib; //BMP280 Register Addresses enum { BMP280Reg_dig_T1_LSB = 0x88, BMP280Reg_dig_T1_MSB = 0x89, BMP280Reg_dig_T2_LSB = 0x8A, BMP280Reg_dig_T2_MSB = 0x8B, BMP280Reg_dig_T3_LSB = 0x8C, BMP280Reg_dig_T3_MSB = 0x8D, BMP280Reg_dig_P1_LSB = 0x8E, BMP280Reg_dig_P1_MSB = 0x8F, BMP280Reg_dig_P2_LSB = 0x90, BMP280Reg_dig_P2_MSB = 0x91, BMP280Reg_dig_P3_LSB = 0x92, BMP280Reg_dig_P3_MSB = 0x93, BMP280Reg_dig_P4_LSB = 0x94, BMP280Reg_dig_P4_MSB = 0x95, BMP280Reg_dig_P5_LSB = 0x96, BMP280Reg_dig_P5_MSB = 0x97, BMP280Reg_dig_P6_LSB = 0x98, BMP280Reg_dig_P6_MSB = 0x99, BMP280Reg_dig_P7_LSB = 0x9A, BMP280Reg_dig_P7_MSB = 0x9B, BMP280Reg_dig_P8_LSB = 0x9C, BMP280Reg_dig_P8_MSB = 0x9D, BMP280Reg_dig_P9_LSB = 0x9E, BMP280Reg_dig_P9_MSB = 0x9F, BMP280Reg_ID = 0xD0, BMP280Reg_RESET = 0xE0, BMP280Reg_CTRL_MEAS = 0xF4, BMP280Reg_CONFIG = 0xF5, BMP280Reg_PRESSURE_MSB = 0xF7, BMP280Reg_PRESSURE_LSB = 0xF8, BMP280Reg_PRESSURE_XLSB = 0xF9, BMP280Reg_TEMP_MSB = 0xFA, BMP280Reg_TEMP_LSB = 0xFB, BMP280Reg_TEMP_XLSB = 0xFC }; uint8_t pressureOversampling; uint8_t temperatureOversampling; int32_t t_fine; void printByte(uint8_t byte, bool newLine); void GetCalibration(); uint8_t readReg(uint8_t reg); }; #endif