Javascript wrappers for LSM6DSL Sensor library

Dependencies:   LSM6DSL

Dependents:   ST_SENSOR_JS

Revision:
1:7e5e76bf3efe
Parent:
0:7eb29414734d
Child:
2:ebd484d17a02
diff -r 7eb29414734d -r 7e5e76bf3efe LSM6DSL_JS-js.cpp
--- a/LSM6DSL_JS-js.cpp	Tue Oct 10 11:52:24 2017 +0200
+++ b/LSM6DSL_JS-js.cpp	Wed Oct 11 10:11:19 2017 +0200
@@ -91,10 +91,11 @@
     LSM6DSL_JS *native_ptr = static_cast<LSM6DSL_JS*>(void_ptr);
  
     // Get the result from the C++ API
-    unsigned char *result = native_ptr->get_accelerometer_axes_json();
+    char *result = new char[128];
+    native_ptr->get_accelerometer_axes_json(result);
     
     // Cast it back to JavaScript
-    jerry_value_t out = jerry_create_string(result);
+    jerry_value_t out = jerry_create_string((unsigned char *)result);
     
     // Recycle the result from function
     delete result;
@@ -126,10 +127,11 @@
     LSM6DSL_JS *native_ptr = static_cast<LSM6DSL_JS*>(void_ptr);
  
     // Get the result from the C++ API
-    unsigned char *result = native_ptr->get_gyroscope_axes_json();
+    char *result = new char[128];
+    native_ptr->get_gyroscope_axes_json(result);
     
     // Cast it back to JavaScript
-    jerry_value_t out = jerry_create_string(result);
+    jerry_value_t out = jerry_create_string((unsigned char *)result);
     
     // Recycle the result from function
     delete result;
@@ -152,14 +154,15 @@
     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);
 
+    // Check if we have the i2c pointer
     if (!devI2c_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);
-    
 
     // Extract native LSM6DSL_JS pointer (from this object) 
     LSM6DSL_JS *native_ptr = new LSM6DSL_JS(*devI2c);