Javascript wrappers for LSM6DSL Sensor library

Dependencies:   LSM6DSL

Dependents:   ST_SENSOR_JS

Revision:
5:4f29cb91aaef
Parent:
4:0eb0cded8861
Child:
6:97726929e01f
--- a/LSM6DSL_JS.cpp	Wed Oct 25 13:59:25 2017 +0200
+++ b/LSM6DSL_JS.cpp	Tue Oct 31 16:21:19 2017 +0100
@@ -41,7 +41,7 @@
 
 #include "LSM6DSL_JS.h"
 
-#include <stdlib.h>     /* atoi */
+#include <stdlib.h>     /* atof */
 #include "mbed.h"
 
 /* Helper function for printing floats & doubles */
@@ -97,7 +97,7 @@
 			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)];
 		
 	}
@@ -108,11 +108,117 @@
 /* Class Implementation ------------------------------------------------------*/
 
 /** Constructor
- * @brief     Initiaze the component.
- * @param devI2c object of an helper class which handles the DevI2C peripheral
+ * @brief	Initializing the component.
+ * @param	DevI2c object of helper class which handles the DevI2C peripheral
  */
 LSM6DSL_JS::LSM6DSL_JS(DevI2C &devI2c){
-	acc_gyro = new LSM6DSLSensor(&devI2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH,D4,D5);
+	init(devI2c);
+}
+
+/** init
+ * @brief	Initializing the component.
+ * @param	DevI2c object of helper class which handles the DevI2C peripheral
+ */
+void LSM6DSL_JS::init(DevI2C &devI2c){
+	acc_gyro = new LSM6DSLSensor(&devI2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH, D4, D5);
+	acc_gyro->init(NULL);
+	acc_gyro->enable_x();
+	acc_gyro->enable_g();
+}
+
+/** Constructor
+ * @brief	Initializing the component.
+ * @param	DevI2c object of helper class which handles the DevI2C peripheral
+ * @param	INT1 pin
+ * @param	INT2 pin
+ */
+LSM6DSL_JS::LSM6DSL_JS(DevI2C &devI2c, PinName int1_pin, PinName int2_pin){
+	init(devI2c, int1_pin, int2_pin);
+}
+
+/** init
+ * @brief	Initializing the component.
+ * @param	DevI2c object of helper class which handles the DevI2C peripheral
+ * @param	INT1 pin
+ * @param	INT2 pin
+ */
+void LSM6DSL_JS::init(DevI2C &devI2c, PinName int1_pin, PinName int2_pin){
+	acc_gyro = new LSM6DSLSensor(&devI2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH, int1_pin, int2_pin);
+	acc_gyro->init(NULL);
+	acc_gyro->enable_x();
+	acc_gyro->enable_g();
+}
+
+/** Constructor
+ * @brief	Initializing the component.
+ * @param	DevI2c object of helper class which handles the DevI2C peripheral
+ * @param	INT1 pin
+ * @param	INT2 pin
+ * @param	Address
+ */
+LSM6DSL_JS::LSM6DSL_JS(DevI2C &devI2c, PinName int1_pin, PinName int2_pin, uint8_t address){
+	init(devI2c, int1_pin, int2_pin, address);
+}
+
+/** init
+ * @brief	Initializing the component.
+ * @param	DevI2c object of helper class which handles the DevI2C peripheral
+ * @param	INT1 pin
+ * @param	INT2 pin
+ * @param	Address
+ */
+void LSM6DSL_JS::init(DevI2C &devI2c, PinName int1_pin, PinName int2_pin, uint8_t address){
+	acc_gyro = new LSM6DSLSensor(&devI2c, address, int1_pin, int2_pin);
+	acc_gyro->init(NULL);
+	acc_gyro->enable_x();
+	acc_gyro->enable_g();
+}
+
+/** Constructor
+ * @brief	Initializing the component.
+ * @param	SPI object of helper class which handles the SPI peripheral
+ * @param	CS pin
+ */
+LSM6DSL_JS::LSM6DSL_JS(SPI &spi, PinName cs_pin){
+	init(spi, cs_pin);
+}
+
+/** init
+ * @brief	Initializing the component.
+ * @param	SPI object of helper class which handles the SPI peripheral
+ * @param	CS pin
+ */
+void LSM6DSL_JS::init(SPI &spi, PinName cs_pin){
+	//acc_gyro = new LSM6DSLSensor(&spi, PB_12, NC, PA_2, LSM6DSLSensor::SPI3W);
+	acc_gyro = new LSM6DSLSensor(&spi, cs_pin);
+	acc_gyro->init(NULL);
+	acc_gyro->enable_x();
+	acc_gyro->enable_g();
+}
+
+/** Constructor
+ * @brief	Initializing the component.
+ * @param	SPI object of helper class which handles the SPI peripheral
+ * @param	CS pin
+ * @param	INT1 pin
+ * @param	INT2 pin
+ * @param	SPI Type
+ */
+LSM6DSL_JS::LSM6DSL_JS(SPI &spi, PinName cs_pin, PinName int1_pin, PinName int2_pin, int spi_type){
+	init(spi, cs_pin, int1_pin, int2_pin, spi_type);
+}
+
+/** init
+ * @brief	Initializing the component.
+ * @param	SPI object of helper class which handles the SPI peripheral
+ * @param	CS pin
+ * @param	INT1 pin
+ * @param	INT2 pin
+ * @param	SPI Type
+ */
+void LSM6DSL_JS::init(SPI &spi, PinName cs_pin, PinName int1_pin, PinName int2_pin, int spi_type){
+	//acc_gyro = new LSM6DSLSensor(&spi, PB_12, NC, PA_2, LSM6DSLSensor::SPI3W);
+	acc_gyro = new LSM6DSLSensor(&spi, cs_pin, int1_pin, int2_pin, spi_type == 3? LSM6DSLSensor::SPI3W: LSM6DSLSensor::SPI4W);
 	acc_gyro->init(NULL);
 	acc_gyro->enable_x();
 	acc_gyro->enable_g();