Javascript wrappers for LSM6DSL Sensor library
Dependencies: LSM6DSL
Revision 3:87ac9fb0d287, committed 2017-10-23
- Comitter:
- akhtar.syedzeeshan@gmail.com
- Date:
- Mon Oct 23 16:41:14 2017 +0200
- Parent:
- 2:ebd484d17a02
- Child:
- 4:0eb0cded8861
- Commit message:
- Changed DevI2C to I2C in javascript. Currently casting I2C to DevI2C while using the driver
Changed in this revision
--- a/LSM6DSL_JS-js.cpp Thu Oct 12 11:10:53 2017 +0200 +++ b/LSM6DSL_JS-js.cpp Mon Oct 23 16:41:14 2017 +0200 @@ -150,22 +150,22 @@ CHECK_ARGUMENT_TYPE_ALWAYS(LSM6DSL_JS, __constructor, 0, object); // Unwrap native LSM6DSL_JS object - void *devI2c_ptr; - const jerry_object_native_info_t *devI2c_type_ptr; - bool devI2c_has_ptr = jerry_get_object_native_pointer(args[0], &devI2c_ptr, &devI2c_type_ptr); + void *i2c_ptr; + const jerry_object_native_info_t *i2c_type_ptr; + bool i2c_has_ptr = jerry_get_object_native_pointer(args[0], &i2c_ptr, &i2c_type_ptr); // Check if we have the i2c pointer - if (!devI2c_has_ptr) { + if (!i2c_has_ptr) { printf("Not a I2C input!"); return jerry_create_error(JERRY_ERROR_TYPE, (const jerry_char_t *) "Failed to get native DigitalOut pointer"); } // Cast the argument to C++ - DevI2C* devI2c = reinterpret_cast<DevI2C*>(devI2c_ptr); + I2C* i2c = reinterpret_cast<I2C*>(i2c_ptr); // Extract native LSM6DSL_JS pointer (from this object) - LSM6DSL_JS *native_ptr = new LSM6DSL_JS(*devI2c); + LSM6DSL_JS *native_ptr = new LSM6DSL_JS(*i2c); jerry_value_t js_object = jerry_create_object(); jerry_set_object_native_pointer(js_object, native_ptr, &native_obj_type_info);
--- a/LSM6DSL_JS.cpp Thu Oct 12 11:10:53 2017 +0200 +++ b/LSM6DSL_JS.cpp Mon Oct 23 16:41:14 2017 +0200 @@ -68,10 +68,10 @@ /* fill in leading fractional zeros */ for (i/=10;i>1; i/=10, ptr++) { - if (fractPart >= i) { - break; - } - *ptr = '0'; + if (fractPart >= i) { + break; + } + *ptr = '0'; } /* fill in (rest of) fractional part */ @@ -111,8 +111,8 @@ * @brief Initiaze the component. * @param i2c object of an helper class which handles the I2C peripheral */ -LSM6DSL_JS::LSM6DSL_JS(DevI2C &i2c){ - acc_gyro = new LSM6DSLSensor(&i2c, LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH,D4,D5); +LSM6DSL_JS::LSM6DSL_JS(I2C &i2c){ + acc_gyro = new LSM6DSLSensor(reinterpret_cast<DevI2C*>(&i2c), LSM6DSL_ACC_GYRO_I2C_ADDRESS_HIGH,D4,D5); acc_gyro->init(NULL); acc_gyro->enable_x(); acc_gyro->enable_g();
--- a/LSM6DSL_JS.h Thu Oct 12 11:10:53 2017 +0200 +++ b/LSM6DSL_JS.h Mon Oct 23 16:41:14 2017 +0200 @@ -61,7 +61,7 @@ public: /* Constructors */ LSM6DSL_JS(){ printf("calling empty constructor"); } - LSM6DSL_JS(DevI2C &devI2c); + LSM6DSL_JS(I2C &i2c); /* Destructor */ ~LSM6DSL_JS();