Javascript wrappers for HTS221 Sensor library

Dependencies:   HTS221

Dependents:   ST_SENSOR_JS

Files at this revision

API Documentation at this revision

Comitter:
akhtar.syedzeeshan@gmail.com
Date:
Wed Oct 11 10:08:12 2017 +0200
Parent:
0:89911ffe212d
Child:
2:c8589b137d5a
Commit message:
Updated Code to fix char * intialization

Changed in this revision

.hgignore Show annotated file Show diff for this revision Revisions of this file
HTS221_JS-js.cpp Show annotated file Show diff for this revision Revisions of this file
HTS221_JS.cpp Show annotated file Show diff for this revision Revisions of this file
HTS221_JS.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore	Wed Oct 11 10:08:12 2017 +0200
@@ -0,0 +1,1 @@
+.DS_Store
\ No newline at end of file
--- a/HTS221_JS-js.cpp	Tue Oct 10 11:51:26 2017 +0200
+++ b/HTS221_JS-js.cpp	Wed Oct 11 10:08:12 2017 +0200
@@ -95,7 +95,6 @@
     // Cast it back to JavaScript and return
     return jerry_create_number(result);
 
-    //return jerry_create_string((unsigned char*)"5C");
 }
 
 
@@ -126,7 +125,6 @@
     // Cast it back to JavaScript and return
     return jerry_create_number(result);
 
-    //return jerry_create_string((unsigned char*)"5C");
 }
 
 /**
@@ -185,15 +183,16 @@
     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 HTS221_JS pointer (from this object) 
     HTS221_JS *native_ptr = new HTS221_JS(*devI2c);
 
--- a/HTS221_JS.cpp	Tue Oct 10 11:51:26 2017 +0200
+++ b/HTS221_JS.cpp	Wed Oct 11 10:08:12 2017 +0200
@@ -126,18 +126,11 @@
  * @brief  Get the temperature reading from HTS221
  * @retval Temperature value in string
  */
-unsigned char *HTS221_JS::get_temperature_string(){
+char *HTS221_JS::get_temperature_string(char *buffer){
 	float value;
-	char buffer[32];
-	
 	hum_temp->get_temperature(&value);
     print_double(buffer, value);
-	unsigned char *r = new unsigned char[6];
-	for(int i = 0; i < 6; i++){
-		r[i] = buffer[i];
-	}
-	r[5] = '\0';
-	return r;
+	return buffer;
 }
 
 /**
@@ -154,25 +147,9 @@
  * @brief  Get the humidity reading from HTS221
  * @retval Humidity value in string
  */
-unsigned char *HTS221_JS::get_humidity_string(){
+char *HTS221_JS::get_humidity_string(char *buffer){
 	float value;
-	char buffer[32];
 	hum_temp->get_humidity(&value);
     print_double(buffer, value);
-	unsigned char *r = new unsigned char[6];
-	for(int i = 0; i < 6; i++){
-		r[i] = buffer[i];
-	}
-	r[5] = '\0';
-	return r;
-}
-uint8_t HTS221_JS::give(){
-	return 43;
-}
-
-/* Simple main function */
-void HTS221_JS::print_sensor_info(){
-	uint8_t id;
-	hum_temp->read_id(&id);
-  	printf("HTS221  humidity & temperature    = 0x%X\r\n", id);
+	return buffer;
 }
\ No newline at end of file
--- a/HTS221_JS.h	Tue Oct 10 11:51:26 2017 +0200
+++ b/HTS221_JS.h	Wed Oct 11 10:08:12 2017 +0200
@@ -69,11 +69,9 @@
     /* Declarations */
     uint8_t readID();
     float get_temperature();
-    unsigned char *get_temperature_string();
+    char *get_temperature_string(char *);
     float get_humidity();
-    unsigned char *get_humidity_string();
-    uint8_t give();
-    void print_sensor_info();
+    char *get_humidity_string(char *);
     void led_on(DigitalOut &led) {
         //printf("led status: %d\n", led);
         led = 1;