Javascript wrappers for LSM303AGR Sensor library
Dependencies: LSM303AGR
Diff: LSM303AGR_JS.cpp
- Revision:
- 3:d076984ee23b
- Parent:
- 2:ddbdfca82832
- Child:
- 4:ae1fba759405
--- a/LSM303AGR_JS.cpp Wed Oct 25 14:00:26 2017 +0200 +++ b/LSM303AGR_JS.cpp Tue Oct 31 16:23:10 2017 +0100 @@ -40,7 +40,7 @@ /* Includes ------------------------------------------------------------------*/ #include "LSM303AGR_JS.h" - +#include <inttypes.h> #include <stdlib.h> /* atoi */ #include "mbed.h" @@ -97,9 +97,8 @@ sprintf(ptr, ","); ptr = &str[strlen(str)]; } - sprintf(ptr, "\"%c\":%i", axes[i], data[i]); + sprintf(ptr, "\"%c\":%i", axes[i], static_cast<int>(data[i])); ptr = &str[strlen(str)]; - } sprintf(ptr, "}"); return str; @@ -107,19 +106,119 @@ /* Class Implementation ------------------------------------------------------*/ -/** Constructor - * @brief Initiaze the component. - * @param devI2c object of an helper class which handles the DevI2C peripheral +/** init_acc + * @brief Initializing the component. + * @param SPI object of an helper class which handles the SPI peripheral + * @param CS pin */ -LSM303AGR_JS::LSM303AGR_JS(DevI2C &devI2c){ - magnetometer = new LSM303AGRMagSensor (&devI2c); +void LSM303AGR_JS::init_acc(SPI &spi, PinName cs_pin){ + accelerometer = new LSM303AGRAccSensor (&spi, cs_pin); + accelerometer->init(NULL); + accelerometer->enable(); +} + +/** init_acc + * @brief Initializing the component. + * @param SPI object of an helper class which handles the SPI peripheral + * @param CS pin + * @param INT1 pin + * @param INT2 pin + */ +void LSM303AGR_JS::init_acc(SPI &spi, PinName cs_pin, PinName int1_pin, PinName int2_pin){ + accelerometer = new LSM303AGRAccSensor (&spi, cs_pin, int1_pin, int2_pin); + accelerometer->init(NULL); + accelerometer->enable(); +} + +/** init_acc + * @brief Initializing the component. + * @param DevI2c object of an helper class which handles the DevI2C peripheral + */ +void LSM303AGR_JS::init_acc(DevI2C &devI2c){ accelerometer = new LSM303AGRAccSensor (&devI2c); + accelerometer->init(NULL); + accelerometer->enable(); +} - magnetometer->init(NULL); +/** init_acc + * @brief Initializing the component. + * @param DevI2c object of an helper class which handles the DevI2C peripheral + * @param INT1 pin + * @param INT2 pin + */ +void LSM303AGR_JS::init_acc(DevI2C &devI2c, PinName int1_pin, PinName int2_pin){ + accelerometer = new LSM303AGRAccSensor (&devI2c, LSM303AGR_ACC_I2C_ADDRESS, int1_pin, int2_pin); + accelerometer->init(NULL); + accelerometer->enable(); +} + +/** init_acc + * @brief Initializing the component. + * @param DevI2c object of an helper class which handles the DevI2C peripheral + * @param INT1 pin + * @param INT2 pin + * @param Address + */ +void LSM303AGR_JS::init_acc(DevI2C &devI2c, PinName int1_pin, PinName int2_pin, uint8_t address){ + accelerometer = new LSM303AGRAccSensor (&devI2c, address, int1_pin, int2_pin); accelerometer->init(NULL); + accelerometer->enable(); +} +/** init_mag + * @brief Initializing the component. + * @param SPI object of an helper class which handles the SPI peripheral + * @param CS pin + */ +void LSM303AGR_JS::init_mag(SPI &spi, PinName cs_pin){ + magnetometer = new LSM303AGRMagSensor (&spi, cs_pin); + magnetometer->init(NULL); + magnetometer->enable(); +} + +/** init_mag + * @brief Initializing the component. + * @param SPI object of an helper class which handles the SPI peripheral + * @param CS pin + * @param INT pin + */ +void LSM303AGR_JS::init_mag(SPI &spi, PinName cs_pin, PinName int_pin){ + magnetometer = new LSM303AGRMagSensor (&spi, cs_pin, int_pin); + magnetometer->init(NULL); magnetometer->enable(); - accelerometer->enable(); +} + +/** init_mag + * @brief Initializing the component. + * @param DevI2c object of an helper class which handles the DevI2C peripheral + */ +void LSM303AGR_JS::init_mag(DevI2C &devI2c){ + magnetometer = new LSM303AGRMagSensor (&devI2c); + magnetometer->init(NULL); + magnetometer->enable(); +} + +/** init_mag + * @brief Initializing the component. + * @param DevI2c object of an helper class which handles the DevI2C peripheral + * @param INT pin + */ +void LSM303AGR_JS::init_mag(DevI2C &devI2c, PinName int_pin){ + magnetometer = new LSM303AGRMagSensor (&devI2c, LSM303AGR_MAG_I2C_ADDRESS, int_pin); + magnetometer->init(NULL); + magnetometer->enable(); +} + +/** init_mag + * @brief Initializing the component. + * @param DevI2c object of an helper class which handles the DevI2C peripheral + * @param INT pin + * @param Address + */ +void LSM303AGR_JS::init_mag(DevI2C &devI2c, PinName int_pin, uint8_t address){ + magnetometer = new LSM303AGRMagSensor (&devI2c, address, int_pin); + magnetometer->init(NULL); + magnetometer->enable(); } /** Destructor @@ -139,7 +238,7 @@ * @brief Read ID address of LSM303AGR Magnetometer * @retval The ID of the Sensor */ -uint8_t LSM303AGR_JS::readMagnetometerID(){ +uint8_t LSM303AGR_JS::read_magnetometer_id(){ uint8_t result; magnetometer->read_id(&result); return result; @@ -149,7 +248,7 @@ * @brief Read ID address of LSM303AGR Accelerometer * @retval The ID of the Sensor */ -uint8_t LSM303AGR_JS::readAccelerometerID(){ +uint8_t LSM303AGR_JS::read_accelerometer_id(){ uint8_t result; accelerometer->read_id(&result); return result;