Javascript wrappers for HTS221 Sensor library
Dependencies: HTS221
HTS221_JS-js.cpp@0:89911ffe212d, 2017-10-10 (annotated)
- Committer:
- akhtar.syedzeeshan@gmail.com
- Date:
- Tue Oct 10 11:51:26 2017 +0200
- Revision:
- 0:89911ffe212d
- Child:
- 1:924fb53eb7f8
Initial Commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 1 | /** |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 2 | ****************************************************************************** |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 3 | * @file HTS221_JS.cpp |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 4 | * @author ST |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 5 | * @version V1.0.0 |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 6 | * @date 9 October 2017 |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 7 | * @brief Implementation of an HTS221 Humidity and Temperature sensor for use |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 8 | * with Javascript. |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 9 | ****************************************************************************** |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 10 | * @attention |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 11 | * |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 12 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 13 | * |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 14 | * Redistribution and use in source and binary forms, with or without modification, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 15 | * are permitted provided that the following conditions are met: |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 17 | * this list of conditions and the following disclaimer. |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 19 | * this list of conditions and the following disclaimer in the documentation |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 20 | * and/or other materials provided with the distribution. |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 22 | * may be used to endorse or promote products derived from this software |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 23 | * without specific prior written permission. |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 24 | * |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 35 | * |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 36 | ****************************************************************************** |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 37 | */ |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 38 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 39 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 40 | /* Includes ------------------------------------------------------------------*/ |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 41 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 42 | #include "jerryscript-mbed-util/logging.h" |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 43 | #include "jerryscript-mbed-library-registry/wrap_tools.h" |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 44 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 45 | // Load the library that we'll wrap |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 46 | #include "HTS221_JS.h" |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 47 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 48 | #include "mbed.h" |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 49 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 50 | /* Class Implementation ------------------------------------------------------*/ |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 51 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 52 | /** |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 53 | * HTS221_JS#destructor |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 54 | * |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 55 | * Called if/when the HTS221_JS is GC'ed. |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 56 | */ |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 57 | void NAME_FOR_CLASS_NATIVE_DESTRUCTOR(HTS221_JS)(void *void_ptr) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 58 | delete static_cast<HTS221_JS*>(void_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 59 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 60 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 61 | /** |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 62 | * Type infomation of the native HTS221_JS pointer |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 63 | * |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 64 | * Set HTS221_JS#destructor as the free callback. |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 65 | */ |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 66 | static const jerry_object_native_info_t native_obj_type_info = { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 67 | .free_cb = NAME_FOR_CLASS_NATIVE_DESTRUCTOR(HTS221_JS) |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 68 | }; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 69 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 70 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 71 | /** |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 72 | * HTS221_JS#get_temperature (native JavaScript method) |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 73 | * |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 74 | * @returns temperature |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 75 | */ |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 76 | DECLARE_CLASS_FUNCTION(HTS221_JS, get_temperature) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 77 | CHECK_ARGUMENT_COUNT(HTS221_JS, get_temperature, (args_count == 0)); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 78 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 79 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 80 | // Unwrap native HTS221_JS object |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 81 | void *void_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 82 | const jerry_object_native_info_t *type_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 83 | bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 84 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 85 | if (!has_ptr || type_ptr != &native_obj_type_info) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 86 | return jerry_create_error(JERRY_ERROR_TYPE, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 87 | (const jerry_char_t *) "Failed to get native HTS221_JS pointer"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 88 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 89 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 90 | HTS221_JS *native_ptr = static_cast<HTS221_JS*>(void_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 91 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 92 | // Get the result from the C++ API |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 93 | float result = native_ptr->get_temperature(); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 94 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 95 | // Cast it back to JavaScript and return |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 96 | return jerry_create_number(result); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 97 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 98 | //return jerry_create_string((unsigned char*)"5C"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 99 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 100 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 101 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 102 | /** |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 103 | * HTS221_JS#get_humidity (native JavaScript method) |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 104 | * |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 105 | * @returns humidity |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 106 | */ |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 107 | DECLARE_CLASS_FUNCTION(HTS221_JS, get_humidity) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 108 | CHECK_ARGUMENT_COUNT(HTS221_JS, get_humidity, (args_count == 0)); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 109 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 110 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 111 | // Unwrap native HTS221_JS object |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 112 | void *void_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 113 | const jerry_object_native_info_t *type_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 114 | bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 115 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 116 | if (!has_ptr || type_ptr != &native_obj_type_info) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 117 | return jerry_create_error(JERRY_ERROR_TYPE, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 118 | (const jerry_char_t *) "Failed to get native HTS221_JS pointer"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 119 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 120 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 121 | HTS221_JS *native_ptr = static_cast<HTS221_JS*>(void_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 122 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 123 | // Get the result from the C++ API |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 124 | float result = native_ptr->get_humidity(); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 125 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 126 | // Cast it back to JavaScript and return |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 127 | return jerry_create_number(result); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 128 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 129 | //return jerry_create_string((unsigned char*)"5C"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 130 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 131 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 132 | /** |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 133 | * HTS221_JS#led_on (native JavaScript method) |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 134 | * @param pin DigitalOut pin to blink |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 135 | */ |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 136 | DECLARE_CLASS_FUNCTION(HTS221_JS, led_on) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 137 | // Check that we have 1 argument, and that it's an object |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 138 | CHECK_ARGUMENT_COUNT(HTS221_JS, led_on, (args_count == 1)); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 139 | CHECK_ARGUMENT_TYPE_ALWAYS(HTS221_JS, led_on, 0, object); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 140 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 141 | // Unwrap native HTS221_JS object |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 142 | void *void_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 143 | const jerry_object_native_info_t *type_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 144 | bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 145 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 146 | if (!has_ptr || type_ptr != &native_obj_type_info) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 147 | return jerry_create_error(JERRY_ERROR_TYPE, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 148 | (const jerry_char_t *) "Failed to get native HTS221_JS pointer"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 149 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 150 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 151 | HTS221_JS *native_ptr = static_cast<HTS221_JS*>(void_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 152 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 153 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 154 | // Cast the LED argument |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 155 | void *led_void_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 156 | const jerry_object_native_info_t *led_type_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 157 | bool led_has_ptr = jerry_get_object_native_pointer(args[0], &led_void_ptr, &led_type_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 158 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 159 | if (!led_has_ptr) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 160 | printf("Not a DigitalOut input!"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 161 | return jerry_create_error(JERRY_ERROR_TYPE, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 162 | (const jerry_char_t *) "Failed to get native DigitalOut pointer"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 163 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 164 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 165 | DigitalOut *pin_ptr = reinterpret_cast<DigitalOut*>(led_void_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 166 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 167 | // Call the function from the C++ API |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 168 | native_ptr->led_on(*pin_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 169 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 170 | // Return |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 171 | return jerry_create_undefined(); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 172 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 173 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 174 | /** |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 175 | * HTS221_JS (native JavaScript constructor) |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 176 | * |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 177 | * @returns a JavaScript object representing HTS221_JS. |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 178 | */ |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 179 | DECLARE_CLASS_CONSTRUCTOR(HTS221_JS) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 180 | CHECK_ARGUMENT_COUNT(HTS221_JS, __constructor, args_count == 1); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 181 | CHECK_ARGUMENT_TYPE_ALWAYS(HTS221_JS, __constructor, 0, object); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 182 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 183 | // Extract native DevI2C argument (objects are always pointers) |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 184 | void *devI2c_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 185 | const jerry_object_native_info_t *devI2c_type_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 186 | bool devI2c_has_ptr = jerry_get_object_native_pointer(args[0], &devI2c_ptr, &devI2c_type_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 187 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 188 | if (!devI2c_has_ptr) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 189 | printf("Not a I2C input!"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 190 | return jerry_create_error(JERRY_ERROR_TYPE, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 191 | (const jerry_char_t *) "Failed to get native DigitalOut pointer"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 192 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 193 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 194 | DevI2C* devI2c = reinterpret_cast<DevI2C*>(devI2c_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 195 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 196 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 197 | // Extract native HTS221_JS pointer (from this object) |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 198 | HTS221_JS *native_ptr = new HTS221_JS(*devI2c); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 199 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 200 | jerry_value_t js_object = jerry_create_object(); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 201 | jerry_set_object_native_pointer(js_object, native_ptr, &native_obj_type_info); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 202 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 203 | // attach methods |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 204 | ATTACH_CLASS_FUNCTION(js_object, HTS221_JS, get_temperature); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 205 | ATTACH_CLASS_FUNCTION(js_object, HTS221_JS, get_humidity); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 206 | ATTACH_CLASS_FUNCTION(js_object, HTS221_JS, led_on); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 207 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 208 | return js_object; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 209 | } |