Javascript wrappers for HTS221 Sensor library
Dependencies: HTS221
HTS221_JS-js.cpp@4:6043b9511072, 2017-10-25 (annotated)
- Committer:
- akhtar.syedzeeshan@gmail.com
- Date:
- Wed Oct 25 13:58:13 2017 +0200
- Revision:
- 4:6043b9511072
- Parent:
- 3:df24cbc8aaf0
- Child:
- 5:bbe15d3cac27
Fully implemented DevI2C support
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 | 2:c8589b137d5a | 3 | * @file HTS221_JS-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 | } |
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 | * HTS221_JS#get_humidity (native JavaScript method) |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 103 | * |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 104 | * @returns humidity |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 105 | */ |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 106 | DECLARE_CLASS_FUNCTION(HTS221_JS, get_humidity) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 107 | CHECK_ARGUMENT_COUNT(HTS221_JS, get_humidity, (args_count == 0)); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 108 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 109 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 110 | // Unwrap native HTS221_JS object |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 111 | void *void_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 112 | const jerry_object_native_info_t *type_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 113 | bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 114 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 115 | if (!has_ptr || type_ptr != &native_obj_type_info) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 116 | return jerry_create_error(JERRY_ERROR_TYPE, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 117 | (const jerry_char_t *) "Failed to get native HTS221_JS pointer"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 118 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 119 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 120 | HTS221_JS *native_ptr = static_cast<HTS221_JS*>(void_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 121 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 122 | // Get the result from the C++ API |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 123 | float result = native_ptr->get_humidity(); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 124 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 125 | // Cast it back to JavaScript and return |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 126 | return jerry_create_number(result); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 127 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 128 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 129 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 130 | /** |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 131 | * HTS221_JS#led_on (native JavaScript method) |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 132 | * @param pin DigitalOut pin to blink |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 133 | */ |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 134 | DECLARE_CLASS_FUNCTION(HTS221_JS, led_on) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 135 | // Check that we have 1 argument, and that it's an object |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 136 | CHECK_ARGUMENT_COUNT(HTS221_JS, led_on, (args_count == 1)); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 137 | CHECK_ARGUMENT_TYPE_ALWAYS(HTS221_JS, led_on, 0, object); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 138 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 139 | // Unwrap native HTS221_JS object |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 140 | void *void_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 141 | const jerry_object_native_info_t *type_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 142 | bool has_ptr = jerry_get_object_native_pointer(this_obj, &void_ptr, &type_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 143 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 144 | if (!has_ptr || type_ptr != &native_obj_type_info) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 145 | return jerry_create_error(JERRY_ERROR_TYPE, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 146 | (const jerry_char_t *) "Failed to get native HTS221_JS pointer"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 147 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 148 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 149 | HTS221_JS *native_ptr = static_cast<HTS221_JS*>(void_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 150 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 151 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 152 | // Cast the LED argument |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 153 | void *led_void_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 154 | const jerry_object_native_info_t *led_type_ptr; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 155 | bool led_has_ptr = jerry_get_object_native_pointer(args[0], &led_void_ptr, &led_type_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 156 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 157 | if (!led_has_ptr) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 158 | printf("Not a DigitalOut input!"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 159 | return jerry_create_error(JERRY_ERROR_TYPE, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 160 | (const jerry_char_t *) "Failed to get native DigitalOut pointer"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 161 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 162 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 163 | DigitalOut *pin_ptr = reinterpret_cast<DigitalOut*>(led_void_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 164 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 165 | // Call the function from the C++ API |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 166 | native_ptr->led_on(*pin_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 167 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 168 | // Return |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 169 | return jerry_create_undefined(); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 170 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 171 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 172 | /** |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 173 | * HTS221_JS (native JavaScript constructor) |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 174 | * |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 175 | * @returns a JavaScript object representing HTS221_JS. |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 176 | */ |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 177 | DECLARE_CLASS_CONSTRUCTOR(HTS221_JS) { |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 178 | CHECK_ARGUMENT_COUNT(HTS221_JS, __constructor, args_count == 1); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 179 | CHECK_ARGUMENT_TYPE_ALWAYS(HTS221_JS, __constructor, 0, object); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 180 | |
akhtar.syedzeeshan@gmail.com | 4:6043b9511072 | 181 | // Extract native DevI2C argument (objects are always pointers) |
akhtar.syedzeeshan@gmail.com | 4:6043b9511072 | 182 | void *devI2c_ptr; |
akhtar.syedzeeshan@gmail.com | 4:6043b9511072 | 183 | const jerry_object_native_info_t *devI2c_type_ptr; |
akhtar.syedzeeshan@gmail.com | 4:6043b9511072 | 184 | bool devI2c_has_ptr = jerry_get_object_native_pointer(args[0], &devI2c_ptr, &devI2c_type_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 185 | |
akhtar.syedzeeshan@gmail.com | 4:6043b9511072 | 186 | // Check if we have the devI2c pointer |
akhtar.syedzeeshan@gmail.com | 4:6043b9511072 | 187 | if (!devI2c_has_ptr) { |
akhtar.syedzeeshan@gmail.com | 4:6043b9511072 | 188 | printf("Not a DevI2C input!"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 189 | return jerry_create_error(JERRY_ERROR_TYPE, |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 190 | (const jerry_char_t *) "Failed to get native DigitalOut pointer"); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 191 | } |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 192 | |
akhtar.syedzeeshan@gmail.com | 1:924fb53eb7f8 | 193 | // Cast the argument to C++ |
akhtar.syedzeeshan@gmail.com | 4:6043b9511072 | 194 | DevI2C* devI2c = reinterpret_cast<DevI2C*>(devI2c_ptr); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 195 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 196 | // Extract native HTS221_JS pointer (from this object) |
akhtar.syedzeeshan@gmail.com | 4:6043b9511072 | 197 | HTS221_JS *native_ptr = new HTS221_JS(*devI2c); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 198 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 199 | jerry_value_t js_object = jerry_create_object(); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 200 | jerry_set_object_native_pointer(js_object, native_ptr, &native_obj_type_info); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 201 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 202 | // attach methods |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 203 | ATTACH_CLASS_FUNCTION(js_object, HTS221_JS, get_temperature); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 204 | ATTACH_CLASS_FUNCTION(js_object, HTS221_JS, get_humidity); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 205 | ATTACH_CLASS_FUNCTION(js_object, HTS221_JS, led_on); |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 206 | |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 207 | return js_object; |
akhtar.syedzeeshan@gmail.com | 0:89911ffe212d | 208 | } |