Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API mbed nRF51822
Fork of BLE_UARTConsole by
BaseSensor.h
00001 #ifndef MBED_BASE_SENSOR_H 00002 #define MBED_BASE_SENSOR_H 00003 00004 #include "mbed.h" 00005 00006 #define LOG(...) do { if (debug) { debug( __VA_ARGS__); } } while (0) 00007 00008 /* Constants */ 00009 #define SENSORS_GRAVITY_EARTH (9.80665F) /**< Earth's gravity in m/s^2 */ 00010 #define SENSORS_GRAVITY_MOON (1.6F) /**< The moon's gravity in m/s^2 */ 00011 #define SENSORS_GRAVITY_SUN (275.0F) /**< The sun's gravity in m/s^2 */ 00012 #define SENSORS_GRAVITY_STANDARD (SENSORS_GRAVITY_EARTH) 00013 #define SENSORS_MAGFIELD_EARTH_MAX (60.0F) /**< Maximum magnetic field on Earth's surface */ 00014 #define SENSORS_MAGFIELD_EARTH_MIN (30.0F) /**< Minimum magnetic field on Earth's surface */ 00015 #define SENSORS_PRESSURE_SEALEVELHPA (1013.25F) /**< Average sea level pressure is 1013.25 hPa */ 00016 #define SENSORS_DPS_TO_RADS (0.017453293F) /**< Degrees/s to rad/s multiplier */ 00017 #define SENSORS_GAUSS_TO_MICROTESLA (100) /**< Gauss to micro-Tesla multiplier */ 00018 00019 00020 #define DOWN 0 00021 #define UP 1 00022 00023 /* Errors */ 00024 #define ERROR_WRONG_DEVICE_ID 1 00025 #define ERROR_WRONG_DEVICE_STATE 2 00026 #define ERROR_DEVICE_SLEEPING 3 00027 #define ERROR_ACCE_SELF_TEST_FAILED 4 00028 #define ERROR_GYRO_SELF_TEST_FAILED 5 00029 #define ERROR_MAGN_SELF_TEST_FAILED 6 00030 00031 /** Sensor types */ 00032 typedef enum 00033 { 00034 SENSOR_TYPE_ACCELEROMETER = (1), /**< Gravity + linear acceleration */ 00035 SENSOR_TYPE_MAGNETIC_FIELD = (2), 00036 SENSOR_TYPE_ORIENTATION = (3), 00037 SENSOR_TYPE_GYROSCOPE = (4), 00038 SENSOR_TYPE_LIGHT = (5), 00039 SENSOR_TYPE_PRESSURE = (6), 00040 SENSOR_TYPE_PROXIMITY = (8), 00041 SENSOR_TYPE_GRAVITY = (9), 00042 SENSOR_TYPE_LINEAR_ACCELERATION = (10), /**< Acceleration not including gravity */ 00043 SENSOR_TYPE_ROTATION_VECTOR = (11), 00044 SENSOR_TYPE_RELATIVE_HUMIDITY = (12), 00045 SENSOR_TYPE_AMBIENT_TEMPERATURE = (13), 00046 SENSOR_TYPE_VOLTAGE = (15), 00047 SENSOR_TYPE_CURRENT = (16), 00048 SENSOR_TYPE_COLOR = (17) 00049 } sensors_type_t; 00050 00051 /* Sensor details (40 bytes) */ 00052 /** struct sensor_s is used to describe basic information about a specific sensor. */ 00053 typedef struct 00054 { 00055 char name[12]; /**< sensor name */ 00056 int32_t version; /**< version of the hardware + driver */ 00057 int32_t sensor_id; /**< unique sensor identifier */ 00058 int32_t type; /**< this sensor's type (ex. SENSOR_TYPE_LIGHT) */ 00059 float max_value; /**< maximum value of this sensor's value in SI units */ 00060 float min_value; /**< minimum value of this sensor's value in SI units */ 00061 float resolution; /**< smallest difference between two values reported by this sensor */ 00062 int32_t min_delay; /**< min delay in microseconds between events. zero = not a constant rate */ 00063 } sensor_t; 00064 00065 class BaseSensor { 00066 public: 00067 //constructor 00068 BaseSensor(void (*debug_)(const char* format, ...)=0); 00069 //get sensor details from actual implementation 00070 virtual char* getSimpleName() = 0; 00071 virtual void getSensorDetails(sensor_t*) = 0; 00072 //verify basic integrity of underlining hardware 00073 virtual uint32_t verifyIntegrity(uint32_t*) = 0; 00074 void (*debug)(const char* format, ...); 00075 private: 00076 00077 }; 00078 00079 #endif
Generated on Wed Jul 13 2022 08:05:01 by
 1.7.2
 1.7.2 
    