├── .gitignore ├── LICENSE ├── README.md ├── Welle_Api.md ├── Welle_Protocol_Dev_0.7.0.md ├── display ├── assets │ ├── img │ │ └── splash.png │ └── js │ │ ├── lib │ │ ├── dat.gui.js │ │ ├── jquery-3.2.1.min.js │ │ ├── p5.dom.js │ │ ├── p5.gui.js │ │ ├── p5.js │ │ ├── p5.sound.js │ │ └── quicksettings.js │ │ └── sketch.js ├── index.html └── index.js ├── driver ├── Win7 │ ├── dpinst_amd64.exe │ ├── dpinst_x86.exe │ ├── stmcdc.cat │ └── stmcdc.inf ├── Win8 │ ├── dpinst_amd64.exe │ ├── dpinst_x86.exe │ ├── stmcdc.cat │ └── stmcdc.inf └── readme.txt ├── example.js ├── image ├── MessageSequence.jpeg ├── MessageSequence.jpg └── welle_display.gif ├── package-lock.json ├── package.json └── src ├── C_API ├── Commands ├── Makefile ├── README.md ├── example.c └── src │ ├── welleAPI.c │ ├── welleAPI.h │ ├── welleCONST.c │ ├── welleCONST.h │ ├── welleDecoder.c │ ├── welleDecoder.h │ ├── welleSerial.c │ └── welleSerial.h ├── welle_api.js ├── welle_const.js ├── welle_decoder.js └── welle_serial.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Readme 2 | 3 | Welle Android app is offially out! You can download it from [here](http://p0jjxwlzf.bkt.clouddn.com/android/1516980436welle_signed_v1.0.1.apk)! 4 | 5 | This repo is for those who love Welle, want to play with Welle, and eager to dig deeper into Welle. We are happy to present you the Welle protocol and Welle api in nodejs. With Welle protocol, you can 6 | 7 | 1. Interact with Welle via your favorite coding language 8 | 2. Get your hand dirty on digit signal processing 9 | 3. Tune your own finger tracking filter 10 | 4. Test your own handwriting recognition algorithm 11 | 5. Build your own gesture control projects 12 | 6. Many more possibilities, only limited by your imagination 13 | 14 | 15 | [**Click Here to GET Welle**](https://www.indiegogo.com/projects/Welle-turn-any-surface-into-a-smart-interface-gadget) and get started ! 16 | 17 | ![Welle_display](image/welle_display.gif) 18 | 19 | ----- 20 | 21 | 22 | 23 | ### Repo Outline 24 | 25 | - src 26 | 27 | Folder that contains source code of api implementation (nodejs) 28 | 29 | - driver 30 | 31 | Folder that contains USB virtual comport driver for win7/8. 32 | 33 | - display 34 | 35 | Data visualization project code 36 | 37 | - Welle_Protocol.md 38 | 39 | Documentation of the Welle protocol and related data structure. 40 | 41 | - Welle_Api.md 42 | 43 | 44 | Welle Api Documentation for Nodejs 45 | 46 | - Readme.md 47 | 48 | --- 49 | 50 | ### Connectivity 51 | 52 | Welle provide USB and BLE access. Following steps guide you to correctly connet to Welle 53 | 54 | 55 | 56 | **Connect Welle via USB** 57 | 58 | Welle USB port will act as virtual com port when connected to your PC or laptop. 59 | 60 | - For MacOS users, there will be a tty device indicating that Welle is connected. 61 | 62 | ```shell 63 | $ ls /dev/tty.usb* 64 | /dev/tty.usbmodem1411 65 | ``` 66 | 67 | - For linux user,there will be a tty device indicating that Welle is connected. (tested on Ubuntu 16.04) 68 | 69 | ```Shell 70 | $ ls /dev/ttyACM* 71 | /dev/ttyACM0 72 | ``` 73 | 74 | - For win10 users, the system will find the necessary driver automatically. Then goto device manager, you will find a new comport i.e., COM3. 75 | - For other windows user, first follow the instruction in folder `driver` to install suitable driver. Then goto device manager, you will find a new comport i.e., COM3. 76 | 77 | 78 | 79 | **Recommanded Serial Tools** 80 | 81 | After you find your com port, use your favorite serial tool to connect to Welle. 82 | 83 | - For mac, `coolterm` is recommended 84 | - For window, `taraterm` will be a nice choice 85 | - For linux, 86 | 87 | Select the correct com port. Select the highest baudrate your serial tool supports. Then connect to Welle. 88 | 89 | 90 | 91 | **Connect Welle via BLE** 92 | 93 | - First make sure Welle is in active mode, (interactive LED is on or blinking) 94 | - Scan for BLE device with your favorite BLE tool. (LightBlue on iOS or android recommended) 95 | - The Welle BLE name will be Welle-xxxxxxxx 96 | - Connect 97 | 98 | ​ 99 | 100 | --- 101 | 102 | ### Setup 103 | 104 | - Install Node **v7.4.0** and above 105 | 106 | - Run `npm install` to install project dependencies specified in `package.json` 107 | 108 | - After dependencies have been installed, follow the **Quick Start** guidline to kickoff, or you can run `node example.js` to have a further understanding of the Welle Api 109 | 110 | ​ 111 | 112 | --- 113 | 114 | ### Quick Start 115 | 116 | **Getting gesture output** 117 | 118 | 1. Run the following command in `node` runtime under the project parent directory 119 | 120 | 2. Import Welle Api: `var WelleAPI = require('./src/Welle_api.js');` 121 | 122 | 3. Connect to Welle device: `WelleAPI.connectAny();` 123 | 124 | 4. Enable gesture output: `WelleAPI.enableGestureOutput();` 125 | 126 | 5. Register gesture event handler: 127 | 128 | ```javascript 129 | WelleAPI.on('gesture', function(gesture){ 130 | console.log('onGesture: ', gesture); 131 | }); 132 | ``` 133 | 134 | 6. Make sure you **disable gesture output** before exit: `WelleAPI.disableGestureOutput()` 135 | 136 | 137 | 138 | **Getting coordinate data flow output** 139 | 140 | 1. Run the following command in `node` runtime under the project parent directory 141 | 142 | 2. Import Welle Api: `var WelleAPI = require('./src/Welle_api.js');` 143 | 144 | 3. Connect to Welle device: `WelleAPI.connectAny();` 145 | 146 | 4. Config output dataflow type: `WelleAPI.configOutputData(['wPOSITION_FILTERED']);` 147 | 148 | 5. Register dataflow event handler: 149 | 150 | ```javascript 151 | WelleAPI.on('data', function(data){ 152 | console.log('onData: ', data); 153 | }); 154 | ``` 155 | 156 | 6. Start dataflow: `WelleAPI.startDataflow();` 157 | 158 | 7. Make sure you **stop dataflow before you exit**: `WelleAPI.stopDataflow();` 159 | 160 | 161 | To dig deeper into Welle, please refers to Welle_protocol for detail instructions. 162 | 163 | 164 | Enjoy your days with Welle 165 | 166 | --- 167 | 168 | ### Data Visualization 169 | 170 | 171 | To quickly visualize what the data look like, we prepare a little project for you to interact with. To get started please follow the instruction beblow. 172 | 173 | - Go to **display** directory: `cd display` 174 | - Run node command: `node index.js` 175 | - Open your web browser and enter: `http://localhost:3000` 176 | - Choose the data you wish to play with in the setting panel. 177 | 178 | 179 | ![Welle_display](image/welle_display.gif) 180 | 181 | -------------------------------------------------------------------------------- /Welle_Api.md: -------------------------------------------------------------------------------- 1 | ### Welle Api Documentation for Nodejs 2 | 3 | --- 4 | 5 | 6 | 7 | #### Well Api Soure Code 8 | 9 | Under the `src` directory are the Welle api code, there are: 10 | 11 | - `welle_const.js`: Welle predefined constant for communication protocol. 12 | - `welle_serial.js`: Welle serialport communication utilities. 13 | - `welle_decoder.js`: Welle message utilities for data interpretation. 14 | - `welle_api.js`: Welle api related code module. 15 | 16 | #### Welle Api Functions 17 | 18 | | Function | Properties | 19 | | ---------------------------------------- | ---------------------------------------- | 20 | | `connectAny([open, close, error])` | Periodically finds Welle device and connect to it, if suceeded, `open`, `close` and `error` callback will be called when serial port is **open**, **close** and **error** ocurred repectively. | 21 | | `startDataflow([success, fail])` | Send start dataflow command to Welle, **success** and **fail** callback will be invoke based on return command status. If no dataflow output is set, it will output all the data by default. | 22 | | ` stopDataflow([success, fail])` | Send start dataflow command to Welle, **success** and **fail** callback will be invoke based on return command status. | 23 | | `enableGestureOutput([success, fail])` | Enable gesture outptut, **success** and **fail** callback will be invoke based on return command status. | 24 | | `disableGestureOutputt([success, fail])` | Disable gesture outptut, **success** and **fail** callback will be invoke based on return command status. | 25 | | `configOutputAllData([success, fail])` | Setup Welle data output type as output-all-data, **success** and **fail** callback will be invoke based on return command status. | 26 | | `configOutputData([cofig, success, fail])` | Setup Welle data output type as `config` option, **success** and **fail** callback will be invoke based on return command status. | 27 | | `getDeviceInfo([success, fail])` | Get Device info, **success** and **fail** callback will be invoke based on return command status. | 28 | | `setLedMode(led, mode, success, error)` | Set led blick mode, **success** and **fail** callback will be invoke based on return command status. | 29 | | `recalibrate([success, error])` | Recalibating Welle hardware, **success** and **fail** callback will be invoke based on return command status. A success recalibration process will set green led blink tree times. | 30 | | `on(event, handler)` | Register `event` handler, events are: `data` `gesture`. When an event is triggered, the corresponding data will be passed to event `handler` function. | 31 | | setDebug(flag) | Set debug mode `true` or `false`, it will print sending and recieving data buffer to the terminal if debug is set to `true`. | 32 | | | | 33 | | | | 34 | 35 | **event data structure** 36 | 37 | | Event Type | Data Structure | 38 | | ---------- | ---------------------------------------- | 39 | | `data` | `{ wPEAK_RAW: [peak_ch1, peak_ch2], wPEAK_FILTERED: [peak_ch1, peak_ch2], wPOSITION_RAW: [x, y, z(not used)], wPOSITION_FILTERED: [x, y, z(not used)], wENVELOPE: [0:599(ch1), 600:1199(ch2)], wRAW: [0:1359(ch1), 1360:2719(ch2)] }` | 40 | | `gesture` | `{ gesture_code: 254, gesture: 'wUNKNOWN', led: 'wLED_1', led_code: 65281 }` | 41 | | | | 42 | 43 | 44 | 45 | #### -------------------------------------------------------------------------------- /Welle_Protocol_Dev_0.7.0.md: -------------------------------------------------------------------------------- 1 | # Welle_Protocol_Dev_0.7.0 2 | 3 | 4 | 5 | [TOC] 6 | 7 | * [Welle_Protocol_Dev_0.7.0](#welle_protocol_dev_070) 8 | * [1. Message Sequence](#1-message-sequence) 9 | * [2. Welle Message](#2-welle-message) 10 | * [2.1 Structure of Message](#21-structure-of-message) 11 | * [2.1.1 Request Message Structure](#211-request-message-structure) 12 | * [2.1.2 Response Message Structure](#212-response-message-structure) 13 | * [2.2 Message Field Parse](#22-message-field-parse) 14 | * [2.2.1 Message Header](#221-message-header) 15 | * [2.2.2 Message Length](#222-message-length) 16 | * [2.2.3 Message Type](#223-message-type) 17 | * [2.2.4 Message Param](#224-message-param) 18 | * [2.2.5 Message Status](#225-message-status) 19 | * [2.3 Message Example](#23-message-example) 20 | * [2.3.1 GET/SET Req/Resp Message](#231-getset-reqresp-message) 21 | * [2.3.2 Dataflow Request Message](#232-dataflow-request-message) 22 | * [2.3.3 Dataflow Response Message](#233-dataflow-response-message) 23 | * [2.3.4 SYSTEM Message](#234-system-message) 24 | * [2.3.5 NOTIFICATION Message](#235-notification-message) 25 | * [3. How to get data from Welle](#3-how-to-get-data-from-welle) 26 | * [4. Welle with BLE](#4-welle-with-ble) 27 | * [4.1 Welle BLE info](#41-welle-ble-info) 28 | * [4.2 Command over BLE](#42-command-over-ble) 29 | * [Recommended Tools](#recommended-tools) 30 | * [Contact](#contact) 31 | 32 | --- 33 | 34 | 35 | 36 | ## 1. Message Sequence 37 | 38 | ![MessageSequence.jpeg](https://github.com/MaxusDev/WelleAPI/blob/master/image/MessageSequence.jpg) 39 | 40 | 41 | 42 | --- 43 | 44 | 45 | 46 | ## 2. Welle Message 47 | 48 | As we can see from the above flow chart, welle messages are divided into two types, ***Request*** and ***Response***. 49 | 50 | There are six types of ***Request*** that host can make: 51 | 52 | > - GET 53 | > - SET 54 | > - DATAFLOW CONFIG 55 | > - DATAFLOW START 56 | > - DATAFLOW STOP 57 | > - SYSCMD 58 | 59 | There are seven types of ***Response*** that host can make: 60 | 61 | > - GET Response 62 | > - SET Response 63 | > - DATAFLOW CONFIG Response 64 | > - DATAFLOW START Response 65 | > - DATAFLOW STOP Response 66 | > - SYSCMD Response 67 | > - NOTIFICATION Response 68 | 69 | 70 | 71 | 72 | 73 | ### 2.1 Structure of Message 74 | 75 | #### 2.1.1 Request Message Structure 76 | 77 | | Header | Length | Type | Param | Body | 78 | | :-------------: | :----: | :----: | :----: | :--: | 79 | | '######' 6bytes | 2bytes | 2bytes | 2bytes | Vary | 80 | 81 | #### 2.1.2 Response Message Structure 82 | 83 | | Header | Length | Type | Param | Status | Body | 84 | | :------------: | :----: | :----: | :----: | :----: | :--: | 85 | | '######'6bytes | 2bytes | 2bytes | 2bytes | 2bytes | Vary | 86 | 87 | 88 | 89 | ### 2.2 Message Field Parse 90 | 91 | #### 2.2.1 Message Header 92 | 93 | - All messages start with '######' regardless of request or response data 94 | 95 | #### 2.2.2 Message Length 96 | 97 | - Total message length in bytes excludes message header 98 | 99 | #### 2.2.3 Message Type 100 | 101 | - The message type in Request and Response should be in its corresponding pair. Cooreponding field defined as follow 102 | ```C 103 | enum MSG_TYPE { 104 | // Get and Get command response 105 | wGET = 0x1001, 106 | wGET_RESP = 0x1002, 107 | // Set and Set command response 108 | wSET = 0x2001, 109 | wSET_RESP = 0x2002, 110 | // Dataflow command and response 111 | wDATAFLOW = 0x3001, 112 | wDATAFLOW_RESP = 0x3002, 113 | // System command and response 114 | wSYSCMD = 0x4001, 115 | wSYSCMD_RESP = 0x4002, 116 | // Notification for Async Data: Battery, Gesture 117 | wNotification = 0x5001, 118 | }; 119 | ``` 120 | 121 | #### 2.2.4 Message Param 122 | 123 | Different type of message has different parameter set. 124 | 125 | - GET/SET Message Param 126 | 127 | ```C 128 | enum SYSTEM_PARA { 129 | //---------------------GET parameters---------------- 130 | wDEVICE_INFO = 0x0200, 131 | //---------------------SET parameters---------------- 132 | // Gesture result Output Control 133 | // Default on for BLE, default off for USB 134 | wGESTURE_RESULT = 0x0021, 135 | 136 | // LEDs 137 | wLED_1 = 0xFF01, 138 | wLED_2 = 0xFF02 139 | }; 140 | ``` 141 | 142 | - DATAFLOW Param 143 | 144 | Check bitwise to filter out DATAFLOW parameters. Note that the DataFlow message is further classified into three types, DataFlow **START**, DataFlow **STOP**, DataFlow **CONFIG**. 145 | 146 | | Parm field | Description | 147 | | ---------- | ---------------------------------------- | 148 | | bit-15 | Reserved | 149 | | bit-12~14 | 001: start dataflow message; 010: stop dataflow message; 100: config dataflow message | 150 | | bit-6~11 | Reserved | 151 | | bit-5 | set 1 to enable envelop output; 0 to disable envelop output | 152 | | bit-4 | set 1 to enable filtered position output; 0 to disable filtered position output | 153 | | bit-3 | set 1 to enable raw position output; 0 to disable raw position output | 154 | | bit-2 | set 1 to enable filtered peak index output; 0 to disable filtered peak index output | 155 | | bit-1 | set 1 to enable raw peak index output; 0 to disable raw peak index output | 156 | | bit-0 | set 1 to enable raw signal output; 0 to disable raw signal output | 157 | 158 | Corresponding data structure. 159 | 160 | ```C 161 | enum DATAFLOW_PARA { 162 | //dataflow control byte 163 | wSTART = 0x1000, 164 | wSTOP = 0x2000, 165 | wCONFIG = 0x4000, 166 | //dataflow output type bytes 167 | wRAW = 0x0001, 168 | wPEAK_RAW = 0x0002, 169 | wPEAK_FILTERED = 0x0004, 170 | wPOSITION_RAW = 0x0008, 171 | wPOSITION_FILTERED = 0x0010, 172 | wENVELOPE = 0x0020, 173 | wOUTPUT_USB_DEFAULT = wRAW | wPEAK_RAW | wPEAK_FILTERED | wPOSITION_RAW | wPOSITION_FILTERED | wENVELOPE, 174 | wOUTPUT_BLE_DEFAULT = wPOSITION_FILTERED 175 | }; 176 | ``` 177 | 178 | - SYSCMD Param 179 | 180 | | Parm field | Description | 181 | | ---------- | ---------------------------------------- | 182 | | bit-4~15 | Reserved | 183 | | bit-3 | set 1 to recalibrate system | 184 | | bit-2 | set 1 to restart the system | 185 | | bit-1 | set 1 to reset system to boot in normal mode | 186 | | bit-0 | set 1 to reset system to boot in bootloader mode | 187 | 188 | Corresponding data structure. **Note that** *the wRESET_BOOT/wRESET_APP/wRESTART is only allowed to be used for firmware upgrade purpose. Developers should not misuse these function. System will be broken down, otherwise.* 189 | 190 | ```C 191 | enum SYSCMD_PARA { 192 | wRESET_BOOT = 0x0001, // only used in firmware upgrade 193 | wRESET_APP = 0x0002, // only used in firmware upgrade 194 | wRESTART = 0x0004, // only used in firmware upgrade 195 | wRECAL = 0x0008 196 | }; 197 | ``` 198 | 199 | - NOTIFICATION PARAM 200 | 201 | These two params indicate whether the notification is generated by gesture performed or charging status changed. 202 | 203 | | Parm field | Description | 204 | | ---------- | ---------------------------------------- | 205 | | bit-2~15 | Reserved | 206 | | bit-1 | 1: indicates message contains battery info | 207 | | bit-0 | 1: indicates message contains gesture info | 208 | 209 | Corresponding data structure. 210 | 211 | ```C 212 | enum NOTIFICATION_PARA { 213 | wBATTERY = 0x0001, 214 | wGESTURE = 0x0002 215 | }; 216 | ``` 217 | 218 | 219 | 220 | #### 2.2.5 Message Status 221 | Only contained in Response and Notification message,indicating the status of the prior request 222 | ```C 223 | enum WELLE_STATUS{ 224 | //Succes 225 | wSUCCESS = 0x0000, 226 | // General error 227 | wERR = 0x0001, 228 | //Parameter invalid 229 | wERR_INVALID_PARAMETER = 0x0002, 230 | //A provided parameter value was out of its allowed range. 231 | wERR_OUT_OF_RANGE = 0x0003, 232 | //Read only parameter 233 | wERR_READONLY_PARAMETER = 0x0004, 234 | //Invalid Datalength 235 | wERR_INVALID_DATALENGTH = 0x0005 236 | }; 237 | ``` 238 | 239 | 240 | 241 | ### 2.3 Message Example 242 | 243 | All data presented will be in HEX view. 244 | 245 | #### 2.3.1 GET/SET Req/Resp Message 246 | 247 | - Get device info message 248 | 249 | `0x232323232323` `0x0006` `0x1001` `0x0200` 250 | 251 | | Header | Length | Type | Param | 252 | | :------: | :----: | :--: | :----------: | 253 | | '######' | 6 | wGET | wDEVICE_INFO | 254 | - Get device info response 255 | 256 | In the example case, 257 | 258 | `0x232323232323` `0x0016` `0x1002` `0x0200` `0x0000` `0x004D004B` `0x312E3030` `0x0164` `0xFF01` `0x2222` 259 | 260 | **Note that** you may get reversed bytes for Welle is little endian while serial transfer is big endian. Such as, 261 | 262 | `0x232323232323` `0x1600` `0x0210` `0x0002` `0x0000` `0x4D004B00` `0x2E313030` `0x6410` `0x01FF` `0x2222` 263 | 264 | Make sure you handle this reversed bytes correctly. 265 | 266 | | Header | Length | Type | Param | Status | Body | 267 | | :------: | :----: | :-------: | :----------: | :------: | :--------------------------------------: | 268 | | '######' | 22 | wGET_RESP | wDEVICE_INFO | wSUCCESS | UUID(4bytes) \| Firmware_version(4bytes) \| Battery_info(2bytes) \| cur_control(2bytes) \| shortcuts(2bytes) | 269 | 270 | 271 | The body field contains 16 bytes in total. 272 | 273 | `UUID` : Device ID, in this case, `0x004D004B` 274 | 275 | `Firmware_version` : device version, in this case version is 1.00 in Ascii, `0x312E3030` in hex. 276 | 277 | `Battery_info` : The first byte indicates the charging states: `0x00` not charging, `0x01` charging. The second byte indicates the percentage of power level, in this case `0x64` is 100% 278 | 279 | `cur_control` : Welle has tow predefined controll states, which can be allocated to two connected smart device through welleApp. Two LEDs are used to indicate thses states, Green and Blue. The first bytes is reserved to `0xFF`. The second bytes `0x01` corresponds to Green and `0x02` corresponds to Blue 280 | 281 | `shortcuts` : A **Hold** gesture is predefined for switching between the above two controlling states. `0x2222` is fixed for this field. 282 | 283 | 284 | 285 | #### 2.3.2 Dataflow Request Message 286 | 287 | Welle can output several types of data, such as, raw echo signal, peak of raw echo, raw position (calculated coordinates without smoothing), filtered position, (coordinates with smoothing), the echo signal envelop. By default, welle output all the above data when connected to usb host, while only filtered position is output when connected to BLE for its speed limitation. 288 | 289 | ```C 290 | wRAW = 0x0001, 291 | wPEAK_RAW = 0x0002, 292 | wPEAK_FILTERED = 0x0004, 293 | wPOSITION_RAW = 0x0008, 294 | wPOSITION_FILTERED = 0x0010, 295 | wENVELOPE = 0x0020, 296 | wOUTPUT_USB_DEFAULT = wRAW | wPEAK_RAW | wPEAK_FILTERED | wPOSITION_RAW | wPOSITION_FILTERED |wENVELOPE, 297 | wOUTPUT_BLE_DEFAULT = wPOSITION_FILTERED 298 | ``` 299 | 300 | User can config their interested part of data to output following the next few steps. 301 | 302 | - **Configuration** 303 | 304 | Configure Dataflow to output **RAW signal** and **POSITION_FILTERED coordinate** via **USB**. 305 | 306 | `0x232323232323` `0006` `3001` `4011` 307 | 308 | | Header | Length | Type | Param | Body | 309 | | :------: | :----: | :-------: | :-----------------------------------: | :--: | 310 | | '######' | 6 | wDATAFLOW | wCONFIG \| wRAW \| wPOSITION_FILTERED | None | 311 | 312 | - **Start Dataflow** 313 | 314 | By default welle will not output any data unless DataFlow START cmd is received. 315 | 316 | `0x232323232323` `0006` `3001` `1000` 317 | 318 | | Header | Length | Type | Param | Body | 319 | | :------: | :----: | :-------: | :----: | :--: | 320 | | '######' | 6 | wDATAFLOW | wSTART | None | 321 | - **Stop Dataflow** 322 | 323 | `0x232323232323` `0006` `3001` `2000` 324 | 325 | | Header | Length | Type | Param | Body | 326 | | :------: | :----: | :-------: | :---: | :--: | 327 | | '######' | 6 | wDATAFLOW | wSTOP | None | 328 | 329 | 330 | #### 2.3.3 Dataflow Response Message 331 | The Body of the response message are consists of 2 bytes, the data type is int16. 332 | 333 | 334 | 335 | | Header | Length | Type | Param | Status | Body | 336 | | :------: | :----: | :------------: | :--------------------------------------: | :------: | :--: | 337 | | '######' | 2bytes | wDATAFLOW_RESP | wRAW \|wPEAK_RAW\| wPEAK_FILTERED\|wPOSITION_FILTERED\|wPOSITION_FILTERED\|wENVELOPE | wSUCCESS | Vary | 338 | 339 | Data Type Format:(**Please Check Param Flag in the Following Order**) 340 | 341 | | DATA TYPE | FORMAT | LENGTH | Notes | 342 | | ------------------ | ------ | ----------------- | ---------------------------------------- | 343 | | wPEAK_RAW | int16 | 2 | 2 channels' raw echo position | 344 | | wPEAK_FILTERED | int16 | 2 | 2 channels' filtered echo position | 345 | | wPOSITION_RAW | int16 | 3 | raw target position[x,y,z(currently unused)] in mm | 346 | | wPOSITION_FILTERED | int16 | 3 | iltered target position[x,y,z(currently unused)] in mm | 347 | | wENVELOPE | int16 | 2 channels * 600 | 2 channel's signal envelop, each has 600 points. We ignore the first 200 point sof the raw signal, and compute the envelop of data points 201~ 800 | 348 | | wRAW | uint16 | 2 channels * 1360 | 2 channel's raw signal, each has 1360 points value range [0~4095] | 349 | 350 | **Please Note that**: wRAW data are consisted of two channels' raw sampled recieved by two microphones. They are in alternated order. All the even indices data are channel 1 data, and all the odd indices are channel 2 data. For example: 351 | | Index | Channel | 352 | | :---: | :-------: | 353 | | 0 | Channel 1 | 354 | | 1 | Channel 2 | 355 | | 2 | Channel 1 | 356 | | 3 | Channel 2 | 357 | 358 | 359 | 360 | 361 | #### 2.3.4 SYSTEM Message 362 | 363 | - **Recal CMD** 364 | 365 | You may want to recalibrate welle if it doesn't output smooth data or doesn't work well in recognizing gesture. Note that welle need a relatively big clean surface for better performance. Green LED will blink 3 times if recal succeeds. Or it will be stucked in Blue blink. Transfer welle to a more clean surface and the recal procedure will continue and Green LED blinks. 366 | 367 | `0x232323232323` `0006` `4001` `0008` 368 | 369 | 370 | 371 | | Header | Length | Type | Param | Body | 372 | | :------: | :----: | :-----: | :----: | :--: | 373 | | '######' | 6 | wSYSCMD | wRECAL | None | 374 | 375 | - **Other CMD** 376 | 377 | **Cautions !!!** The following three parameter is used when welle needs firmware upgrade. User **MUST** not issue these system cmd. 378 | 379 | ``` 380 | wRESET_BOOT = 0x0001, 381 | wRESET_APP = 0x0002, 382 | wRESTART = 0x0004, 383 | ``` 384 | 385 | `wRESET_BOOT` : when this parameter is set, sys cmd tells welle to enter boatload mode. 386 | 387 | `wRESET_APP`: when this parameter is set, sys cmd tells welle to boot to normal mode. 388 | 389 | `wRESTART`: when this parameter is set, sys cmd tells welle to reboot. 390 | 391 | 392 | 393 | #### 2.3.5 NOTIFICATION Message 394 | 395 | Notification message is **asynchronous message** initiated by Welle once a certain conditions are met. 396 | For example: 397 | 398 | 1. When a gesture is performed, the resulting gesture output will be sent by **NOTIFICATION** Message to the host. 399 | 2. When Welle charging status is changed, a battery **NOTIFICATION** message will be triggered. 400 | 401 | **Predefined Gesture Code** 402 | 403 | ```c 404 | enum WELLE_GESTURE { 405 | wUNKNOWN = 0x00FE, 406 | wLEFT_RIGHT = 0x0001, 407 | wRIGHT_LEFT = 0x0002, 408 | wUP_DOWN = 0x0003, 409 | wDOWN_UP = 0x0004, 410 | wCLOCKWISE = 0x0005, 411 | wANTI_CLOCKWISE = 0x0006, 412 | wHOLD = 0x0022 413 | }; 414 | ``` 415 | 416 | 417 | 418 | Before we can get any gesture notification message, a SET CMD is need to trigger the gesture output. 419 | 420 | - **SET GestureOn** 421 | 422 | `0x232323232323` `0x000A` `0x2001` `0x0021` `0x3f800000` 423 | 424 | 425 | 426 | | Header | Length | Type | Param | Body | 427 | | :------: | :----: | :--: | :-------------: | :-------: | 428 | | '######' | 10 | SET | wGESTURE_RESULT | GestureOn | 429 | 430 | **Note**, `3f800000` is a hex value which translated from a float32 value 1.0 indicating GestureOn. 431 | 432 | 433 | 434 | - **Notification with gesture** 435 | 436 | `0x232323232323` `0x000C` `0x5001` `0x0002` `0x0000` `0x0003` `0xFF01` 437 | 438 | 439 | 440 | | Header | Length | Type | Param | Status | Body | 441 | | :------: | :----: | :-----------: | :------: | :------: | ------------------------------- | 442 | | '######' | 12 | wNotification | wGESTURE | wSUCCESS | wUP_DOWN \| wLED_1(current LED) | 443 | 444 | 445 | 446 | - **Battery Status Notification** 447 | 448 | `0x232323232323` `0x000A` `0x5001` `0x0203` `0x0000` `0x0164` 449 | 450 | 451 | 452 | | Header | Length | Type | Param | Status | Body | 453 | | :------: | :----: | :-----------: | :------: | :------: | ------------------- | 454 | | '######' | 10 | wNotification | wBATTERY | wSUCCESS | wCHARGING \|\| 100% | 455 | 456 | 457 | 458 | --- 459 | 460 | 461 | 462 | ## 3. How to get data from Welle 463 | 464 | Welle provide many type of data for user to play with. 465 | 466 | You can get data from welle via usb by, first cofiguring dataflow to enable the insterested type of data, starting dataflow, and then stoping dataflow at the end. 467 | 468 | You can also recalibrate the system if you think welle is not working well. 469 | 470 | - **Configure Dataflow** 471 | 472 | configure dataflow to output POSITION_FILTERED coordinate via USB. 473 | 474 | > **Request**: `0x232323232323` `0006` `3001` `4010` 475 | 476 | 477 | | Header | Length | Type | Param | Body | 478 | | :------: | :----: | :-------: | :---------------------------: | :--: | 479 | | '######' | 6 | wDATAFLOW | wCONFIG \| wPOSITION_FILTERED | None | 480 | 481 | 482 | > **Response**: `0x232323232323` `0008` `3002` `4010` `0000` 483 | 484 | 485 | | Header | Length | Type | Param | Status | Body | 486 | | :------: | :----: | :------------: | :----------------------------: | :------: | :--: | 487 | | '######' | 8 | wDATAFLOW_RESP | wCONFIG \| wPOSITION_FILTERED | wSUCCESS | None | 488 | 489 | - **Dataflow Start** 490 | 491 | > **Request**: `0x232323232323` `0006` `3001` `1000` 492 | 493 | 494 | | Header | Length | Type | Param | Body | 495 | | :------: | :----: | :-------: | :----: | :--: | 496 | | '######' | 6 | wDATAFLOW | wSTART | None | 497 | 498 | 499 | 500 | > **Response**: `0x232323232323` `000E` `3002` `1210` `0000` `FFDC` `FF55` `0023` 501 | 502 | 503 | | Header | Length | Type | Param | Status | Body | 504 | | :------: | :----: | :------------: | :--------------------------: | :------: | :----------------: | 505 | | '######' | 14 | wDATAFLOW_RESP | wSTART \| wPOSITION_FILTERED | wSUCCESS | coordinates[x,y,z] | 506 | 507 | The response body will contain three int16 data representing the filtered coordinates (x,y,z) in mm. 508 | 509 | In this case, (`FFDC` `FF55` `0023`) is (x y z) . 510 | 511 | \* z is a fixed value`0023` reserved for later use. 512 | 513 | - **Dataflow Stop** 514 | 515 | A Good practice is to stop dataflow when your program exits. This make sure Welle won't send dataflow continuously even if host is not ready to receive data. 516 | 517 | > **Request**: `0x232323232323` `0006` `3001` `2000` 518 | 519 | 520 | | Header | Length | Type | Param | Body | 521 | | :------: | :----: | :-------: | :---: | :--: | 522 | | '######' | 6 | wDATAFLOW | wSTOP | None | 523 | 524 | 525 | 526 | > **Response**: `0x232323232323` `0008` `3002` `2000` `0000` 527 | 528 | 529 | | Header | Length | Type | Param | Status | Body | 530 | | :------: | :----: | :------------: | :---: | :------: | :--: | 531 | | '######' | 8 | wDATAFLOW_RESP | wSTOP | wSUCCESS | None | 532 | 533 | - **Recalibration** 534 | 535 | > **Request**: `0x232323232323` `0006` `4001` `0008` 536 | 537 | 538 | 539 | | Header | Length | Type | Param | Body | 540 | | :------: | :----: | :-----: | :----: | :--: | 541 | | '######' | 6 | wSYSCMD | wRECAL | None | 542 | 543 | 544 | 545 | > **Response**: `0x232323232323` `0008` `4002` `0008` `0000` 546 | 547 | 548 | 549 | | Header | Length | Type | Param | Status | Body | 550 | | :------: | :----: | :-----: | :----: | :------: | :--: | 551 | | '######' | 8 | wSYSCMD | wRECAL | wSUCCESS | None | 552 | 553 | 554 | 555 | --- 556 | 557 | 558 | 559 | ## 4. Welle with BLE 560 | Welle supports BLE data transfer, however due to the speed limitation of BLE, only a few of the command work on BLE mode. 561 | 562 | #### 4.1 Welle BLE info 563 | 564 | - **BLE Device Name** 565 | - Welle-xxxxxxxx 566 | - **BLE Characteristics Write** 567 | - Service UUID: FFE5 568 | - Characteristics UUID: FFE9 569 | - **BLE Characteristics Read/Notify** 570 | - Service UUID: FFE0 571 | - Characteristics UUID: FFE4 572 | Write '1' to this Characteristics to enable notification 573 | 574 | #### 4.2 Command over BLE 575 | The protocol is simplified in BLE data communication, Welle only responses to the following commands sent over BLE. 576 | 577 | 1. **DATAFLOW CONFIG** as output **POSITION_FILTERED** over BLE 578 | 2. **DATAFLOW START** and **DATAFLOW STOP** 579 | 3. **SYSCMD RECAL** 580 | 4. **NOTIFICATION** message 581 | 5. **GET** / **SET** for a certain commands 582 | 583 | Configure Dataflow to output **POSITION_FILTERED coordinate** only via **BLE**. 584 | 585 | The most of the steps are the same except for **Dataflow Start Response**. BLE transmission speed is slow so the Dataflow Start Response structure is reduced. 586 | 587 | Once BLE is connected you do not need to specify output data type, since BLE can only output **FILTERED COORDINATE**. 588 | 589 | **Dataflow Start** 590 | > **Request**: `0x232323232323` `0006` `3001` `1000` 591 | 592 | 593 | | Header | Length | Type | Param | Body | 594 | | :------: | :----: | :-------: | :----: | :--: | 595 | | '######' | 6 | wDATAFLOW | wSTART | None | 596 | 597 | 598 | 599 | > **Dataflow Start Response**: `0x232323232323` `0008` `3002` `1001` `0000` 600 | 601 | 602 | | Header | Length | Type | Param | Status | Body | 603 | | :------: | :----: | :------------: | :--------------------------: | :------: | :--: | 604 | | '######' | 2bytes | wDATAFLOW_RESP | wSTART \| wPOSITION_FILTERED | wSUCCESS | None | 605 | 606 | 607 | 608 | 609 | > **Data Response**: `0x2121` `FFDC` `21` `FF55` 610 | 611 | 612 | | Header | X Coor | ! | Y Coor | 613 | | :-----: | :----------: | :--: | :----------: | 614 | | ' ! ! ' | 2bytes int16 | ! | 2bytes int16 | 615 | 616 | --- 617 | ## Recommended Tools 618 | **Serial Tools** 619 | - Nodejs: serialport module 620 | - Python: pyserial module 621 | - Mac: CoolTerm 622 | - Windows: putty 623 | 624 | **BLE Tools** 625 | - iOS/Mac: LightBlue 626 | - Nodejs: noble module 627 | - Python: pybluez module 628 | 629 | ## Contact 630 | Email: developer@maxustech.com 631 | 632 | 633 | 634 | 635 | 636 | 637 | -------------------------------------------------------------------------------- /display/assets/img/splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxusDev/WelleAPI/0a3d92712a8dde942a503f4f6645b1bfd3271b48/display/assets/img/splash.png -------------------------------------------------------------------------------- /display/assets/js/lib/p5.gui.js: -------------------------------------------------------------------------------- 1 | // 2 | 3 | (function() { 4 | 5 | // list of guis 6 | var guis = []; 7 | 8 | // default slider params 9 | var sliderMin = 0; 10 | var sliderMax = 100; 11 | var sliderStep = 1; 12 | 13 | // default gui provider 14 | var guiProvider = 'QuickSettings'; 15 | 16 | // Create a GUI using QuickSettings (or DAT.GUI or ...) 17 | p5.prototype.createGui = function(label, x, y, provider) { 18 | 19 | label = label || 'GUI'; 20 | x = x || 20; 21 | y = y || 20; 22 | provider = provider || guiProvider; 23 | 24 | var gui; 25 | 26 | // create a gui using the provider 27 | if(provider === 'QuickSettings') { 28 | if(QuickSettings) { 29 | console.log('Creating p5.gui powered by QuickSettings.'); 30 | gui = new QSGui(label, x, y); 31 | } else { 32 | console.log('QuickSettings not found. Is the script included in your HTML?'); 33 | gui = new DummyGui(label, x, y); 34 | } 35 | } else { 36 | console.log('Unknown GUI provider ' + provider); 37 | gui = new DummyGui(label, x, y); 38 | } 39 | 40 | // add it to the list of guis 41 | guis.push(gui); 42 | 43 | // return it 44 | return gui; 45 | 46 | }; 47 | 48 | 49 | p5.prototype.removeGui = function(gui) { 50 | // TODO: implement this 51 | }; 52 | 53 | // update defaults used for creation of sliders 54 | p5.prototype.sliderRange = function(vmin, vmax, vstep) { 55 | sliderMin = vmin; 56 | sliderMax = vmax; 57 | sliderStep = vstep; 58 | }; 59 | 60 | // extend default behaviour of noLoop() 61 | p5.prototype.noLoop = function() { 62 | this._loop = false; 63 | for(var i = 0; i < guis.length; i++) { 64 | guis[i].noLoop(); 65 | } 66 | }; 67 | 68 | // extend default behaviour of loop() 69 | p5.prototype.loop = function() { 70 | for(var i = 0; i < guis.length; i++) { 71 | guis[i].loop(); 72 | } 73 | this._loop = true; 74 | this._draw(); 75 | }; 76 | 77 | 78 | // interface for quicksettings 79 | function QSGui(label, x, y) { 80 | 81 | var qs = QuickSettings.create(x, y, label); 82 | this.prototype = qs; 83 | 84 | // addGlobals(global1, global2, ...) to add the selected globals 85 | this.addGlobals = function() { 86 | qs.bindGlobals(arguments); 87 | }; 88 | 89 | // addObject(object) to add all params of the object 90 | // addObject(object, param1, param2, ...) to add selected params 91 | this.addObject = function() { 92 | // get object 93 | object = arguments[0]; 94 | // convert arguments object to array 95 | var params = []; 96 | if(arguments.length > 1) { 97 | params = Array.prototype.slice.call(arguments) 98 | params = params.slice(1); 99 | } 100 | // if no arguments are provided take all keys of the object 101 | if(params.length === 0) { 102 | params = object.keys(); 103 | } 104 | qs.bindParams(object, params); 105 | }; 106 | 107 | // noLoop() to call draw every time the gui changes when we are not looping 108 | this.noLoop = function() { 109 | qs.setGlobalChangeHandler(draw); 110 | }; 111 | 112 | this.loop = function() { 113 | qs.setGlobalChangeHandler(null); 114 | }; 115 | 116 | this.addButton = function(title, callback) { 117 | qs.addButton(title, callback); 118 | }; 119 | 120 | this.show = function() { qs.show(); }; 121 | this.hide = function() { qs.hide(); }; 122 | this.toggleVisibility = function() { qs.toggleVisibility(); }; 123 | 124 | } 125 | 126 | // Just a Dummy object that provides the GUI interface 127 | function DummyGui() { 128 | var f = function() {}; 129 | this.addGlobals = f; 130 | this.noLoop = f; 131 | this.addObject = f; 132 | this.show = f; 133 | } 134 | 135 | // Extend Quicksettings 136 | // so it can magically create a GUI for parameters passed by name 137 | QuickSettings.bindParams = function(object, params) { 138 | 139 | // iterate over all the arguments 140 | for(var i = 0; i < params.length; i++) { 141 | 142 | var arg = params[i]; 143 | var val = object[arg]; 144 | var typ = typeof val; 145 | 146 | // console.log(typ, arg, val); 147 | 148 | switch(typ) { 149 | 150 | case 'object': 151 | 152 | // color triple ? 153 | if(val instanceof Array && val.length === 3 && typeof val[0] === 'number') { 154 | // create color according to the current color mode 155 | var c = color(val[0], val[1], val[2]); 156 | // get decimal RGB values 157 | var c2 = c.levels.slice(0,3); 158 | // create HTML color code 159 | var vcolor = '#' + c2.map(function(value) { 160 | return ('0' + value.toString(16)).slice(-2); 161 | }).join(''); 162 | this.bindColor(arg, vcolor, object); 163 | } else { 164 | // multiple choice drop down list 165 | this.bindDropDown(arg, val, object); 166 | object[arg] = val[0]; 167 | } 168 | break; 169 | 170 | case 'number': 171 | 172 | // values as defined by magic variables or gui.sliderRange() 173 | var vmin = object[arg + 'Min'] || object[arg + 'min'] || sliderMin; 174 | var vmax = object[arg + 'Max'] || object[arg + 'max'] || sliderMax; 175 | var vstep = object[arg + 'Step'] || object[arg + 'step'] || sliderStep; 176 | 177 | // the actual values can still overrule the limits set by magic 178 | var vmin = min(val, vmin); 179 | var vmax = max(val, vmax); 180 | 181 | // set the range 182 | this.bindRange(arg, vmin, vmax, val, vstep, object); 183 | 184 | break; 185 | 186 | case 'string': 187 | 188 | var HEX6 = /^#([a-f0-9]{2})([a-f0-9]{2})([a-f0-9]{2})$/i; 189 | if(HEX6.test(val)) { 190 | // HTML color value (such as #ff0000) 191 | this.bindColor(arg, val, object); 192 | } else { 193 | // String value 194 | this.bindText(arg, val, object); 195 | } 196 | break; 197 | 198 | case 'boolean': 199 | 200 | this.bindBoolean(arg, object[arg], object); 201 | break; 202 | 203 | } 204 | } 205 | }; 206 | 207 | // bind params that are defined globally 208 | QuickSettings.bindGlobals = function(params) { 209 | this.bindParams(window, params); 210 | }; 211 | 212 | })(); 213 | -------------------------------------------------------------------------------- /display/assets/js/sketch.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Welle Api for developer to create their own gesture controlled applications 3 | * Copyright (C) 2015 - 2017 Maxustech Technologies Inc. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * See www.maxustech.com for more details. 19 | * All requests should be sent to info@maxustech.com. 20 | */ 21 | 22 | // gui 23 | var visible = true; 24 | var shrink_ratio = 2; 25 | var gui; 26 | var canvas; 27 | var paths_raw = []; 28 | var paths_filtered = []; 29 | var ch1_envelope_data = new Array(600); 30 | var ch2_envelope_data = new Array(600); 31 | var ch1_raw_Data = new Array(1360); 32 | var ch2_raw_Data = new Array(1360); 33 | var position_raw_data = new Array(3); 34 | var position_filtered_data = new Array(3); 35 | var peak_filtered_data = new Array(2); 36 | var peak_raw_data = new Array(2); 37 | 38 | var ch1_envelope = false; 39 | var ch2_envelope = false; 40 | var ch1_raw = true; 41 | var ch2_raw = true; 42 | var position_raw = false; 43 | var position_filtered = true; 44 | var peak_filtered = false; 45 | var peak_raw = false; 46 | 47 | function setup() { 48 | canvas = createCanvas(window.innerWidth/shrink_ratio, window.innerHeight/shrink_ratio); 49 | canvas.position(0, 0); 50 | canvas.style('width', '100%'); 51 | canvas.style('height', '100%'); 52 | 53 | // Create Layout GUI 54 | gui = createGui('Maxutech', width * shrink_ratio - 220, 20); 55 | gui.addGlobals('ch1_raw', 'ch2_raw', 'ch1_envelope', 'ch2_envelope', 'peak_raw', 'peak_filtered', 'position_raw', 'position_filtered'); 56 | 57 | gui.addButton('Recalibrate', function(){ 58 | socket.emit('recalibrate', true); 59 | }) 60 | } 61 | 62 | function draw() { 63 | rectMode(CENTER); 64 | fill(0x19,0x26,0x31); 65 | noStroke(); 66 | rectMode(CENTER); 67 | rect(width/2, height/2, width, height); 68 | app.draw(); 69 | } 70 | 71 | function windowResized() { 72 | resizeCanvas(window.innerWidth/shrink_ratio, window.innerHeight/shrink_ratio); 73 | canvas.position(0, 0); 74 | canvas.style('width', '100%'); 75 | canvas.style('height', '100%'); 76 | } 77 | 78 | var app = {}; 79 | 80 | app.draw = function(){ 81 | this.drawRaw(ch1_raw_Data, width * 0.1, height * 0.15, color('#0E85C9'), width * 0.8, height * 0.2, 'Raw_Ch1', color(255, 255, 255), ch1_raw) 82 | this.drawRaw(ch2_raw_Data, width * 0.1, height * 0.40, color('#1CD182'), width * 0.8, height * 0.2, 'Raw_Ch2', color(255, 255, 255), ch2_raw) 83 | 84 | this.drawEnvelope(ch1_envelope_data, width * 0.1, height * 0.65, color('#0E85C9'), width*0.39, height*0.2, 'Envelope_Ch1', color(255, 255, 255), ch1_envelope, 85 | peak_raw, peak_filtered, peak_raw_data[0], peak_filtered_data[0]); 86 | this.drawEnvelope(ch2_envelope_data, width * 0.1, height * 0.90, color('#1CD182'), width*0.39, height*0.2, 'Envelope_Ch2', color(255, 255, 255), ch2_envelope, 87 | peak_raw, peak_filtered, peak_raw_data[1], peak_filtered_data[1]); 88 | 89 | this.drawPosition(width * 0.51, height * 0.55, width * 0.39, height * 0.5); 90 | 91 | } 92 | 93 | app.drawPosition = function(translateX, translateY, width, height) { 94 | push(); 95 | translate(translateX, translateY); 96 | rectMode(CORNER); 97 | fill(0x22, 0x33, 0x3F); 98 | noStroke(); 99 | rect(0, 0, width, height); 100 | displayText('Position', 0, 0, 10, color(255), 'ARIAL', LEFT, BOTTOM) 101 | 102 | var offset = 0; 103 | var text_offset = 0; 104 | if (position_raw){ 105 | offset += 10 * 3.8 + 10; 106 | fill('#FC4750') 107 | ellipse(width - offset, -5, 10, 10); 108 | displayText('Raw Pos', width, 0, 10, color(255), "ARIAL", RIGHT, BOTTOM); 109 | } 110 | 111 | if (position_filtered){ 112 | if (offset != 0){ 113 | text_offset = offset + 10; 114 | offset += 10 * 5.1 + 20; 115 | } 116 | else { 117 | offset += 10 * 5.1 + 10; 118 | } 119 | 120 | fill('#71E2E0') 121 | ellipse(width - offset, -5, 10, 10); 122 | displayText('Filtered Pos', width - text_offset, 0, 10, color(255), "ARIAL", RIGHT, BOTTOM); 123 | } 124 | 125 | pop(); 126 | for (var i = paths_raw.length - 1; i >= 0; i--) { 127 | var c = paths_raw[i]; 128 | if (!c.isDead()) { 129 | c.update(); 130 | c.display(translateX, translateY, width, height); 131 | } else { 132 | paths_raw.splice(i, 1); 133 | } 134 | } 135 | 136 | for (var i = paths_filtered.length - 1; i >= 0; i--) { 137 | var c = paths_filtered[i]; 138 | if (!c.isDead()) { 139 | c.update(); 140 | c.display(translateX, translateY, width, height); 141 | } else { 142 | paths_filtered.splice(i, 1); 143 | } 144 | } 145 | } 146 | 147 | app.drawEnvelope = function(plot, plotX, plotY, color, width, height, text, text_color, drawFlag, peakRawFlag, peakFilteredFlag, peakRaw, peakFiltered) { 148 | var plotWidth = width; 149 | var plotHeight = height; 150 | var ratio = (plot.length) / plotWidth; 151 | var magnitude = 4000; 152 | var shift = plotX; 153 | 154 | rectMode(CENTER); 155 | fill(0x22, 0x33, 0x3F); 156 | // fill(81, 93, 108); 157 | noStroke(); 158 | rect(plotWidth/2 + shift, plotY, plotWidth, plotHeight); 159 | 160 | 161 | displayText(text, plotX, plotY - plotHeight / 2, 10, text_color, "ARIAL", LEFT, BOTTOM); 162 | 163 | if (drawFlag){ 164 | stroke(color); 165 | strokeWeight(2); 166 | 167 | for (var i = 1; i < plotWidth - 10; i++){ 168 | var yp = -this.calcY(plot[int((i + 1) * ratio)], plotHeight, magnitude) + plotY; 169 | var yc = -this.calcY(plot[int(i * ratio)], plotHeight, magnitude) + plotY; 170 | line(i + 1 + shift, yp, i + shift, yc); 171 | } 172 | } 173 | 174 | var offset = 0; 175 | var text_offset = 0; 176 | if (drawFlag && peakRawFlag){ 177 | stroke('#FC4750'); 178 | strokeWeight(2); 179 | var x = peakRaw / 600 * plotWidth + shift; 180 | line(x, plotY - plotHeight / 2, x, plotY + plotHeight / 2) 181 | 182 | offset += 10 * 4.5 + 10; 183 | fill('#FC4750') 184 | ellipse(plotX + plotWidth - offset, plotY - plotHeight / 2 - 5, 10, 10); 185 | displayText('Raw Peak', plotX + plotWidth, plotY - plotHeight / 2, 10, text_color, "ARIAL", RIGHT, BOTTOM); 186 | } 187 | 188 | if (drawFlag && peakFilteredFlag){ 189 | stroke('#71E2E0'); 190 | strokeWeight(2); 191 | var x = peakFiltered / 600 * plotWidth + shift; 192 | line(x, plotY - plotHeight / 2, x, plotY + plotHeight / 2) 193 | 194 | if (offset != 0){ 195 | text_offset = offset + 10; 196 | offset += 10 * 5.8 + 20; 197 | } 198 | else { 199 | offset += 10 * 5.8 + 10; 200 | } 201 | 202 | fill('#71E2E0') 203 | ellipse(plotX + plotWidth - offset, plotY - plotHeight / 2 - 5, 10, 10); 204 | displayText('Filtered Peak', plotX + plotWidth - text_offset, plotY - plotHeight / 2, 10, text_color, "ARIAL", RIGHT, BOTTOM); 205 | } 206 | } 207 | 208 | app.drawRaw = function(plot, plotX, plotY, color, width, height, text, text_color, drawFlag) { 209 | var plotWidth = width; 210 | var plotHeight = height; 211 | var ratio = (plot.length) / plotWidth; 212 | var magnitude = 4096; 213 | var shift = plotX; 214 | 215 | rectMode(CENTER); 216 | fill(0x22, 0x33, 0x3F); 217 | // fill(81, 93, 108); 218 | noStroke(); 219 | rect(plotWidth/2 + shift, plotY, plotWidth, plotHeight); 220 | 221 | displayText(text, plotX, plotY - plotHeight / 2, 10, text_color, "ARIAL", LEFT, BOTTOM); 222 | 223 | if (drawFlag){ 224 | stroke(color); 225 | strokeWeight(2); 226 | 227 | for (var i = 0; i < plotWidth; i++){ 228 | var yp = -this.calcY(plot[int((i + 1) * ratio)], plotHeight, magnitude) + plotY + height / 2; 229 | var yc = -this.calcY(plot[int(i * ratio)], plotHeight, magnitude) + plotY + height / 2; 230 | line(i + 1 + shift, yp, i + shift, yc); 231 | } 232 | } 233 | } 234 | 235 | app.calcY = function(i, plotHeight, magnitude){ 236 | return (i * plotHeight) / magnitude; 237 | } 238 | 239 | function pushData(data) { 240 | if ( data.wENVELOPE ){ 241 | ch1_envelope_data = data.wENVELOPE.slice(0, data.wENVELOPE.length / 2); 242 | ch2_envelope_data = data.wENVELOPE.slice(data.wENVELOPE.length / 2, data.wENVELOPE.length); 243 | } 244 | 245 | if (data.wRAW ){ 246 | ch1_raw_Data = data.wRAW.slice(0, data.wRAW.length / 2); 247 | ch2_raw_Data = data.wRAW.slice(data.wRAW.length / 2, data.wRAW.length); 248 | } 249 | 250 | if (data.wPOSITION_RAW && position_raw){ 251 | if((data.wPOSITION_RAW[0] != 0 || data.wPOSITION_RAW[1] != 0) && abs(data.wPOSITION_RAW[0]) < 150 && abs(data.wPOSITION_RAW[1] < 300)){ 252 | paths_raw.push(new circle(createVector(data.wPOSITION_RAW[0], data.wPOSITION_RAW[1]), 0.012*width, color('#FC4750'))); 253 | } 254 | } 255 | 256 | if (data.wPOSITION_FILTERED && position_filtered){ 257 | if((data.wPOSITION_FILTERED[0] != 0 || data.wPOSITION_FILTERED[1] != 0) && abs(data.wPOSITION_FILTERED[0]) < 150 && abs(data.wPOSITION_FILTERED[1] < 300)){ 258 | paths_filtered.push(new circle(createVector(data.wPOSITION_FILTERED[0], data.wPOSITION_FILTERED[1]), 0.012*width, color('#71E2E0'))); 259 | } 260 | } 261 | 262 | if (data.wPEAK_FILTERED && peak_filtered){ 263 | peak_filtered_data = data.wPEAK_FILTERED; 264 | } 265 | 266 | if (data.wPEAK_RAW && peak_raw){ 267 | peak_raw_data = data.wPEAK_RAW; 268 | } 269 | } 270 | 271 | // check for keyboard events 272 | function keyPressed() { 273 | switch(key) { 274 | // type [F1] to hide / show the GUI 275 | case 'p': 276 | visible = !visible; 277 | if(visible) gui.show(); else gui.hide(); 278 | break; 279 | } 280 | } 281 | 282 | function displayText(content, x, y, size, color, font, verticalAlign, horizontalAlign) { 283 | fill(color); 284 | noStroke(); 285 | textFont("ARIAL"); 286 | textStyle(NORMAL); 287 | textSize(size); 288 | textAlign(verticalAlign, horizontalAlign); 289 | text(content, x, y); 290 | } 291 | 292 | function circle(pos, r, color) { 293 | this.pos = pos; 294 | this.opac = 255; 295 | this.decr = 8; 296 | this.r = r; 297 | this.color = color; 298 | } 299 | 300 | circle.prototype.update = function() { 301 | this.opac -= this.decr; 302 | } 303 | 304 | circle.prototype.display = function(translateX, translateY, width, height) { 305 | push(); 306 | translate(translateX, translateY); 307 | fill(this.color.levels[0], this.color.levels[1], this.color.levels[2], this.opac); 308 | noStroke(); 309 | ellipse(map(this.pos.x, -160, 160, -width * 0.5, width * 0.5) + width / 2, map(this.pos.y, -80, -350, -height * 0.4, height * 0.4) + height * 0.5, this.r, this.r); 310 | pop(); 311 | } 312 | 313 | circle.prototype.isDead = function() { 314 | if (this.opac < 0) { 315 | return true; 316 | } else { 317 | return false; 318 | } 319 | } 320 | -------------------------------------------------------------------------------- /display/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | MaxusTech 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /display/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Welle Api for developer to create their own gesture controlled applications 3 | * Copyright (C) 2015 - 2017 Maxustech Technologies Inc. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * See www.maxustech.com for more details. 19 | * All requests should be sent to info@maxustech.com. 20 | */ 21 | 22 | var express = require('express'); 23 | var app = express(); 24 | var path = require('path'); 25 | var server = require('http').createServer(app); 26 | var io = require('socket.io')(server); 27 | var port = process.env.PORT || 3000; 28 | var welleAPI = require('../src/welle_api.js'); 29 | 30 | // Static 31 | app.use(express.static('assets')) 32 | 33 | // Router 34 | app.get('/', function(req, res) { 35 | res.sendFile(path.join(__dirname + '/index.html')) 36 | }) 37 | 38 | // HTTP Server 39 | server.listen(port, function() { 40 | console.log('Server listening at port %d', port); 41 | }) 42 | 43 | // Socket IO 44 | io.on('connection', function(socket) { 45 | 46 | console.log('a user connected'); 47 | 48 | socket.on('disconnect', function() { 49 | console.log('user disconnected'); 50 | }); 51 | 52 | socket.on('recalibrate', function(flag){ 53 | if (flag){ 54 | welleAPI.recalibrate(); 55 | } 56 | }) 57 | }); 58 | 59 | // Disable debug message 60 | welleAPI.setDebug(false); 61 | 62 | // Welle Connect any available device 63 | welleAPI.connectAny( 64 | // Port Open Callback 65 | function(){ 66 | 67 | console.log('Port Open!') 68 | 69 | welleAPI.configOutputAllData( 70 | function(){ 71 | console.log('configOutputAllData success'); 72 | }, 73 | function(){ 74 | console.log('configOutputAllData fail'); 75 | } 76 | ); 77 | 78 | welleAPI.startDataflow( 79 | function(){ 80 | console.log('startDataflow success'); 81 | }, 82 | function(){ 83 | console.log('startDataflow fail'); 84 | } 85 | ) 86 | 87 | }, 88 | // Port Close! Callback 89 | function(){ 90 | console.log('Port Close!') 91 | }, 92 | // Port Error! Callback 93 | function(){ 94 | console.log('Port Error!') 95 | } 96 | ); 97 | 98 | // Register 'Data' event handler 99 | welleAPI.on('data', function(data){ 100 | // console.log('onData: ', data); 101 | io.sockets.emit('onData', data); 102 | }); 103 | 104 | // Make Sure to Stop Dataflow when Program Exit. 105 | process.on('SIGINT', function() { 106 | welleAPI.stopDataflow(); 107 | welleAPI.stopDataflow(); 108 | setTimeout(function(){ 109 | process.exit(); 110 | }, 1000); 111 | }); 112 | 113 | -------------------------------------------------------------------------------- /driver/Win7/dpinst_amd64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxusDev/WelleAPI/0a3d92712a8dde942a503f4f6645b1bfd3271b48/driver/Win7/dpinst_amd64.exe -------------------------------------------------------------------------------- /driver/Win7/dpinst_x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxusDev/WelleAPI/0a3d92712a8dde942a503f4f6645b1bfd3271b48/driver/Win7/dpinst_x86.exe -------------------------------------------------------------------------------- /driver/Win7/stmcdc.cat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxusDev/WelleAPI/0a3d92712a8dde942a503f4f6645b1bfd3271b48/driver/Win7/stmcdc.cat -------------------------------------------------------------------------------- /driver/Win7/stmcdc.inf: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ 2 | ; STMicroelectronics Comunication Device Class driver (CDC) INF FILE 3 | ; (C)2010 Copyright STMicroelectronics 4 | ;------------------------------------------------------------------------------ 5 | 6 | [Version] 7 | Signature="$Windows NT$" 8 | Class=Ports 9 | ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 10 | Provider=%PRVDR% 11 | CatalogFile=stmcdc.cat 12 | DriverVer=04/25/2010,1.3.1 13 | 14 | [SourceDisksNames] 15 | 1=%DriversDisk%,,, 16 | 17 | [SourceDisksFiles] 18 | 19 | [Manufacturer] 20 | %MFGNAME%=DeviceList,NT,NTamd64 21 | 22 | [DestinationDirs] 23 | DefaultDestDir = 12 24 | 25 | ;------------------------------------------------------------------------------ 26 | ; VID/PID Settings 27 | ;------------------------------------------------------------------------------ 28 | [DeviceList.NT] 29 | %DESCRIPTION%=DriverInstall,USB\VID_0483&PID_5740 30 | 31 | [DeviceList.NTamd64] 32 | %DESCRIPTION%=DriverInstall,USB\VID_0483&PID_5740 33 | 34 | [DriverInstall.NT] 35 | Include=mdmcpq.inf 36 | CopyFiles=FakeModemCopyFileSection 37 | AddReg=DriverInstall.NT.AddReg 38 | 39 | [DriverInstall.NT.AddReg] 40 | HKR,,DevLoader,,*ntkern 41 | HKR,,NTMPDriver,,usbser.sys 42 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 43 | 44 | [DriverInstall.NT.Services] 45 | AddService=usbser, 0x00000002, DriverServiceInst 46 | 47 | [DriverServiceInst] 48 | DisplayName=%SERVICE% 49 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 50 | StartType = 3 ; SERVICE_DEMAND_START 51 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 52 | ServiceBinary= %12%\usbser.sys 53 | LoadOrderGroup = Base 54 | 55 | ;------------------------------------------------------------------------------ 56 | ; String Definitions 57 | ;------------------------------------------------------------------------------ 58 | 59 | [Strings] 60 | PRVDR = "STMicroelectronics" 61 | MFGNAME = "STMicroelectronics." 62 | DESCRIPTION = "STMicroelectronics Virtual COM Port" 63 | SERVICE = "STM Virtual COM Port" 64 | DriversDisk = "STM Drivers Disk" -------------------------------------------------------------------------------- /driver/Win8/dpinst_amd64.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxusDev/WelleAPI/0a3d92712a8dde942a503f4f6645b1bfd3271b48/driver/Win8/dpinst_amd64.exe -------------------------------------------------------------------------------- /driver/Win8/dpinst_x86.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxusDev/WelleAPI/0a3d92712a8dde942a503f4f6645b1bfd3271b48/driver/Win8/dpinst_x86.exe -------------------------------------------------------------------------------- /driver/Win8/stmcdc.cat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxusDev/WelleAPI/0a3d92712a8dde942a503f4f6645b1bfd3271b48/driver/Win8/stmcdc.cat -------------------------------------------------------------------------------- /driver/Win8/stmcdc.inf: -------------------------------------------------------------------------------- 1 | ;------------------------------------------------------------------------------ 2 | ; STMicroelectronics Comunication Device Class driver (CDC) INF FILE 3 | ; (C)2013 Copyright STMicroelectronics 4 | ;------------------------------------------------------------------------------ 5 | 6 | [Version] 7 | Signature="$Windows NT$" 8 | Class=Ports 9 | ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318} 10 | Provider=%PRVDR% 11 | CatalogFile=stmcdc.cat 12 | DriverVer=08/02/2013,1.4.0 13 | 14 | [SourceDisksNames] 15 | 1=%DriversDisk%,,, 16 | 17 | [SourceDisksFiles] 18 | 19 | [Manufacturer] 20 | %MFGNAME%=DeviceList,NT,NTamd64 21 | 22 | [DestinationDirs] 23 | DefaultDestDir = 12 24 | 25 | ;------------------------------------------------------------------------------ 26 | ; VID/PID Settings 27 | ;------------------------------------------------------------------------------ 28 | [DeviceList.NT] 29 | %DESCRIPTION%=DriverInstall,USB\VID_0483&PID_5740 30 | 31 | [DeviceList.NTamd64] 32 | %DESCRIPTION%=DriverInstall,USB\VID_0483&PID_5740 33 | 34 | [DriverInstall.NT] 35 | Include=mdmcpq.inf 36 | CopyFiles=FakeModemCopyFileSection 37 | AddReg=DriverInstall.NT.AddReg 38 | 39 | [DriverInstall.NT.AddReg] 40 | HKR,,DevLoader,,*ntkern 41 | HKR,,NTMPDriver,,usbser.sys 42 | HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider" 43 | 44 | [DriverInstall.NT.Services] 45 | AddService=usbser, 0x00000002, DriverServiceInst 46 | 47 | [DriverServiceInst] 48 | DisplayName=%SERVICE% 49 | ServiceType = 1 ; SERVICE_KERNEL_DRIVER 50 | StartType = 3 ; SERVICE_DEMAND_START 51 | ErrorControl = 1 ; SERVICE_ERROR_NORMAL 52 | ServiceBinary= %12%\usbser.sys 53 | LoadOrderGroup = Base 54 | 55 | [FakeModemCopyFileSection] 56 | 57 | ;------------------------------------------------------------------------------ 58 | ; String Definitions 59 | ;------------------------------------------------------------------------------ 60 | 61 | [Strings] 62 | PRVDR = "STMicroelectronics" 63 | MFGNAME = "STMicroelectronics." 64 | DESCRIPTION = "STMicroelectronics Virtual COM Port" 65 | SERVICE = "STM Virtual COM Port" 66 | DriversDisk = "STM Drivers Disk" -------------------------------------------------------------------------------- /driver/readme.txt: -------------------------------------------------------------------------------- 1 | Supported OS 2 | *************** 3 | 4 | + Windows 98SE, 2000, XP, Vista, Seven, 8.x (x86 & x64 Windows platforms) 5 | 6 | Contents 7 | *********** 8 | + win7 9 | + win8 10 | + readme.txt 11 | 12 | How to use 13 | *************** 14 | Go to Your OS version directory ([Win7] or [Win8]) 15 | + Then : 16 | - Double click on dpinst_x86.exe if you are running a 32-bits OS version 17 | - Double click on dpinst_amd64.exe if you are running a 64-bits OS version 18 | + Follow the instructions. 19 | -------------------------------------------------------------------------------- /example.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Welle Api for developer to create their own gesture controlled applications 3 | * Copyright (C) 2015 - 2017 Maxustech Technologies Inc. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * See www.maxustech.com for more details. 19 | * All requests should be sent to info@maxustech.com. 20 | */ 21 | 22 | var welleAPI = require('./src/welle_api.js'); 23 | 24 | welleAPI.connectAny( 25 | // Port Open Callback 26 | function(){ 27 | 28 | console.log('Port Open!') 29 | 30 | welleAPI.enableGestureOutput( 31 | function(){ 32 | console.log('enableGestureOutput success'); 33 | }, 34 | function(){ 35 | console.log('enableGestureOutput fail'); 36 | } 37 | ); 38 | 39 | welleAPI.configOutputAllData( 40 | function(){ 41 | console.log('configOutputAllData success'); 42 | }, 43 | function(){ 44 | console.log('configOutputAllData fail'); 45 | } 46 | ); 47 | 48 | welleAPI.configOutputData( 49 | ['wPEAK_RAW', 'wPOSITION_FILTERED'], 50 | function(){ 51 | console.log('configOutputData success'); 52 | }, 53 | function(){ 54 | console.log('configOutputData fail'); 55 | } 56 | ); 57 | 58 | welleAPI.setLedMode('wLED_1', 'wLED_FLICK_FAST', 59 | function(){ 60 | console.log('setLedMode success'); 61 | }, 62 | function(){ 63 | console.log('setLedMode fail'); 64 | } 65 | ) 66 | 67 | welleAPI.getDeviceInfo( 68 | function(deviceInfo){ 69 | console.log('getDeviceInfo success'); 70 | console.log(deviceInfo.message); 71 | }, 72 | function(){ 73 | console.log('getDeviceInfo fail'); 74 | } 75 | ) 76 | 77 | // welleAPI.recalibrate( 78 | // function(){ 79 | // console.log('recalibrate success'); 80 | // }, 81 | // function(){ 82 | // console.log('recalibrate fail'); 83 | // } 84 | // ) 85 | 86 | // welleAPI.startDataflow( 87 | // function(){ 88 | // console.log('startDataflow success'); 89 | // }, 90 | // function(){ 91 | // console.log('startDataflow fail'); 92 | // } 93 | // ) 94 | 95 | }, 96 | // Port Close! Callback 97 | function(){ 98 | console.log('Port Close!') 99 | }, 100 | // Port Error! Callback 101 | function(){ 102 | console.log('Port Error!') 103 | } 104 | ); 105 | 106 | welleAPI.on('data', function(data){ 107 | console.log('onData: ', data); 108 | }); 109 | 110 | welleAPI.on('gesture', function(gesture){ 111 | console.log('onGesture: ', gesture); 112 | }); 113 | 114 | // Make Sure to Stop Dataflow when Program Exit. 115 | process.on('SIGINT', function() { 116 | welleAPI.stopDataflow(); 117 | welleAPI.stopDataflow(); 118 | setTimeout(function(){ 119 | process.exit(); 120 | }, 1000); 121 | }); 122 | 123 | -------------------------------------------------------------------------------- /image/MessageSequence.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxusDev/WelleAPI/0a3d92712a8dde942a503f4f6645b1bfd3271b48/image/MessageSequence.jpeg -------------------------------------------------------------------------------- /image/MessageSequence.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxusDev/WelleAPI/0a3d92712a8dde942a503f4f6645b1bfd3271b48/image/MessageSequence.jpg -------------------------------------------------------------------------------- /image/welle_display.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaxusDev/WelleAPI/0a3d92712a8dde942a503f4f6645b1bfd3271b48/image/welle_display.gif -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "welle_api", 3 | "version": "1.0.0", 4 | "description": "welle api project for all developers", 5 | "main": "index.js", 6 | "dependencies": { 7 | "serialport": "^4.0.4", 8 | "bootstrap": "^3.3.7", 9 | "express": "^4.14.0", 10 | "jquery": "^3.1.1", 11 | "socket.io": "^1.5.1" 12 | }, 13 | "devDependencies": {}, 14 | "scripts": { 15 | "test": "echo \"Error: no test specified\" && exit 1" 16 | }, 17 | "author": "Maxustech Inc Developer", 18 | "license": "ISC" 19 | } 20 | -------------------------------------------------------------------------------- /src/C_API/Commands: -------------------------------------------------------------------------------- 1 | Config 2 | 23 23 23 23 23 23 00 06 30 01 40 3f 3 | Start 4 | 23 23 23 23 23 23 00 06 30 01 10 00 5 | Stop 6 | 23 23 23 23 23 23 00 06 30 01 20 00 7 | 8 | 9 | 10 | char cmdConfig[12] = {0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x00, 0x06, 0x30, 0x01, 0x40, 0x3f} 11 | char respConfig[14] = {0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x08, 0x00, 0x02, 0x30, 0x3f, 0x40, 0x00, 0x00} 12 | 13 | char cmdStart[12] = {0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x00, 0x06, 0x30, 0x01, 0x10, 0x00} 14 | char respConfig[14] = {0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x08, 0x00, 0x02, 0x30, 0x00, 0x10, 0x00, 0x00} 15 | 16 | char cmdStop[12] = {0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x00, 0x06, 0x30, 0x01, 0x20, 0x00} 17 | char respConfig[14] = {0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x08, 0x00, 0x02, 0x30, 0x00, 0x20, 0x00, 0x00} 18 | 19 | 20 | Config 21 | 23232323232300063001403f 22 | receive: 232323232323080002303f400000 23 | Start 24 | 232323232323000630011000 25 | receive: 2323232323230800023000100000 26 | Stop 27 | 232323232323000630012000 28 | receive: 2323232323230800023000200000 29 | -------------------------------------------------------------------------------- /src/C_API/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | 3 | example: example.c 4 | $(CC) -Wall -c -o $@ $^ -I"./src" 5 | 6 | clean: 7 | rm example 8 | -------------------------------------------------------------------------------- /src/C_API/README.md: -------------------------------------------------------------------------------- 1 | # Welle C API 2 | 3 | This folder is for developers who want to program Welle in C language. It contains basic api to interact with Welle. The framework of this api is almost the same with the one in Javascript. 4 | 5 | #### Folder Outline 6 | 7 | - src 8 | Folder that contains source code of api implementation (C language) 9 | - example.c 10 | One example for reading filtered **Position Data** from Welle 11 | - Makefile 12 | Make the example program with ```make``` 13 | 14 | #### Example 15 | 16 | ##### Connectivity 17 | 18 | ```C 19 | // Port configuration 20 | int baud = 115200; // Set baudrate to 115200 21 | printf("Set baudrate to %d\n", baud); 22 | char *portname = "/dev/tty.usbmodem1421"; // Change the portname accordingly 23 | int fd = wsOpen(portname); 24 | ``` 25 | 26 | ##### Initialization & Configuration 27 | 28 | ``` C 29 | // Initialize basic commands to configure data output 30 | wcInitlaizeBasicCmds(); 31 | // Initialize data decoder 32 | wdInitializeDecoder(); 33 | // Configure data output 34 | configDataOutput(fd) 35 | ``` 36 | 37 | ##### Read/Write 38 | 39 | ```c 40 | // Start data flow 41 | startDataFlow(fd); 42 | // Read & decode data flow 43 | readDataFlow(fd); 44 | ``` 45 | 46 | There's no ```stopDataFlow``` command right now. To stop the data flow, please simply type ```ctrl_c```. 47 | 48 | #### Usage 49 | 50 | For developers who want to integrate the API with their own programs, please take a look at the file ```welleDecoder.c```. 51 | 52 | In the comment block, you can call ```envData.data```, ```peakData.data```, ```peakData_f.data```, ```posData.data```, or ```posData_f.data``` to get the output data. Each of the data is array type, so be sure you get the right data for your program. 53 | 54 | #### TODO 55 | 56 | In the future version of C API, I will improve the code for 57 | 58 | - *configDataOutput*: Add more arguments to read different data. 59 | - *readDataFlow*: Add more arguments to specify the targeted output data. 60 | - *stopDataFlow* -------------------------------------------------------------------------------- /src/C_API/example.c: -------------------------------------------------------------------------------- 1 | #include "welleAPI.h" 2 | 3 | int main(int argc, char const *argv[]) 4 | { 5 | 6 | // Port configuration 7 | int baud = 115200; 8 | printf("Set baudrate to %d\n", baud); 9 | char *portname = "/dev/tty.usbmodem1421"; 10 | int fd = wsOpen(portname); 11 | if(!wsConfig(fd, baud)) 12 | { 13 | 14 | wcInitlaizeBasicCmds(); 15 | wdInitializeDecoder(); 16 | 17 | // Config Data, return 0 when success 18 | configDataOutput(fd); 19 | 20 | // Config Data, return 0 when success 21 | startDataFlow(fd); 22 | 23 | // Decode data 24 | readDataFlow(fd); 25 | 26 | } 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /src/C_API/src/welleAPI.c: -------------------------------------------------------------------------------- 1 | #include "welleAPI.h" 2 | 3 | int configDataOutput(int fd) 4 | { 5 | return wsWriteAndResp(fd, wcConfigPosData_f, sizeof(wcConfigPosData_f.cmd)); 6 | // return wsWriteAndResp(fd, wcConfigAllData, sizeof(wcConfigAllData.cmd)); 7 | } 8 | 9 | int startDataFlow(int fd) 10 | { 11 | return wsWriteAndResp(fd, wcStartDataFlow, sizeof(wcStartDataFlow.cmd)); 12 | } 13 | 14 | int readDataFlow(int fd) 15 | { 16 | char buf[1] = {0}; 17 | // buf = (char *)malloc(sizeof(char)); 18 | while(1) 19 | { 20 | wdDecode(fd, buf); 21 | 22 | /* 23 | Your code here: 24 | You can play with following data according to your configuration. 25 | - Envelop data 26 | - Peak data (filtered) 27 | - Position data (filtered) 28 | Raw data will be supported in next version of the API. 29 | */ 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/C_API/src/welleAPI.h: -------------------------------------------------------------------------------- 1 | #include "welleSerial.h" 2 | #include "welleDecoder.h" 3 | 4 | #ifndef __WELLEAPI_H__ 5 | #define __WELLEAPI_H__ 6 | 7 | 8 | extern int configDataOutput(int fd); 9 | extern int startDataFlow(int fd); 10 | extern int readDataFlow(int fd); 11 | #endif 12 | -------------------------------------------------------------------------------- /src/C_API/src/welleCONST.c: -------------------------------------------------------------------------------- 1 | #include "welleCONST.h" 2 | 3 | void wcInitlaizeBasicCmds() 4 | { 5 | wcConfigAllData.msgType = "configAllData"; 6 | wcConfigAllData.cmdLength = 12; 7 | wcConfigAllData.rspLength = 14; 8 | wcConfigAllData.cmd = (char *)malloc(sizeof(char) * wcConfigAllData.cmdLength); 9 | wcConfigAllData.rsp = (char *)malloc(sizeof(char) * wcConfigAllData.rspLength); 10 | memcpy(wcConfigAllData.cmd, ((char []){0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x00, 0x06, 0x30, 0x01, 0x40, 0x3f}), 12); 11 | memcpy(wcConfigAllData.rsp, ((char []){0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x08, 0x00, 0x02, 0x30, 0x3f, 0x40, 0x00, 0x00}), 14); 12 | 13 | wcConfigPosData_f.msgType = "configPosDataFiltered"; 14 | wcConfigPosData_f.cmdLength = 12; 15 | wcConfigPosData_f.rspLength = 14; 16 | wcConfigPosData_f.cmd = (char *)malloc(sizeof(char) * wcConfigPosData_f.cmdLength); 17 | wcConfigPosData_f.rsp = (char *)malloc(sizeof(char) * wcConfigPosData_f.rspLength); 18 | memcpy(wcConfigPosData_f.cmd, ((char []){0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x00, 0x06, 0x30, 0x01, 0x40, 0x10}), 12); 19 | memcpy(wcConfigPosData_f.rsp, ((char []){0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x08, 0x00, 0x02, 0x30, 0x10, 0x40, 0x00, 0x00}), 14); 20 | 21 | wcStartDataFlow.msgType = "startDataFlow"; 22 | wcStartDataFlow.cmdLength = 12; 23 | wcStartDataFlow.rspLength = 14; 24 | wcStartDataFlow.cmd = (char *)malloc(sizeof(char) * wcStartDataFlow.cmdLength); 25 | wcStartDataFlow.rsp = (char *)malloc(sizeof(char) * wcStartDataFlow.rspLength); 26 | memcpy(wcStartDataFlow.cmd, ((char []){0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x00, 0x06, 0x30, 0x01, 0x10, 0x00}), 12); 27 | memcpy(wcStartDataFlow.rsp, ((char []){0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x08, 0x00, 0x02, 0x30, 0x00, 0x10, 0x00, 0x00}), 12); 28 | 29 | wcStopDataFlow.msgType = "stopDataFlow"; 30 | wcStopDataFlow.cmdLength = 12; 31 | wcStopDataFlow.rspLength = 14; 32 | wcStopDataFlow.cmd = (char *)malloc(sizeof(char) * wcStopDataFlow.cmdLength); 33 | wcStopDataFlow.rsp = (char *)malloc(sizeof(char) * wcStopDataFlow.rspLength); 34 | memcpy(wcStopDataFlow.cmd, ((char []){0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x00, 0x06, 0x30, 0x01, 0x20, 0x00}), 12); 35 | memcpy(wcStopDataFlow.rsp, ((char []){0x23, 0x23, 0x23, 0x23, 0x23, 0x23, 0x08, 0x00, 0x02, 0x30, 0x00, 0x20, 0x00, 0x00}), 12); 36 | } 37 | -------------------------------------------------------------------------------- /src/C_API/src/welleCONST.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #ifndef __WELLECONST_H__ 12 | #define __WELLECONST_H__ 13 | 14 | 15 | // MSG_TYPE 16 | #define wGET 0x1001 17 | #define wGET_RESP 0x1002 18 | #define wSET 0x2001 19 | #define wSET_RESP 0x2002 20 | #define wDATAFLOW 0x3001 21 | #define wDATAFLOW_RESP 0x3002 22 | #define wSYSCMD 0x4001 23 | #define wSYSCMD_RESP 0x4002 24 | #define wNOTIFICATION 0x5001 25 | #define wRESERVED 0xFFF1 26 | #define wRESERVED_RESP 0xFFF 27 | 28 | // SYSTEM_PARA 29 | #define wREFRESH_RATE 0x0001 30 | #define wPOWER_STABLE_LENGTH 0x0002 31 | #define wPOWER_STABLE_VAR 0x0003 32 | #define wPEAK_STABLE_LENGTH 0x0004 33 | #define wPEAK_STABLE_VAR 0x0005 34 | #define wKALMAN_1D_CV 0x0006 35 | #define wKALMAN_1D_CA 0x0007 36 | #define wKALMAN_2D_CV 0x0008 37 | #define wKALMAN_2D_CA 0x0009 38 | #define wKALMAN_1D_P_VAR 0x0010 39 | #define wKALMAN_1D_Q_VAR 0x0011 40 | #define wKALMAN_2D_P_VAR 0x0012 41 | #define wKALMAN_2D_Q_VAR 0x0013 42 | #define wCHIDISTGAMMA 0x001 43 | #define wTRACKER_STATE_FRAMES 0x0015 44 | #define wAVERAGE_FILTER_SIZE 0x001 45 | #define wTHRESHOLD 0x0017 46 | #define wXYZ_STABLE_SIZE 0x0019 47 | #define wXYZ_STABLE_VAR 0x0020 48 | #define wRECOGNIZING 0x0021 49 | #define wBLE_CONNECTION_INTERVAL 0x0100 50 | #define wBLE_ADV_INTERVAL 0x0101 51 | #define wBLE_RESET 0x0102 52 | #define wLED_1 0xFF01 53 | #define wLED_2 0xFF02 54 | #define wLED_ALL 0xFF03 55 | #define wDEVICE_INFO 0x020 56 | 57 | // SYSCMD_PARA 58 | 59 | #define wRESET_BOOT 0x0001 60 | #define wRESET_APP 0x0002 61 | #define wRESTART 0x0004 62 | #define wRECAL 0x000 63 | 64 | // DATAFLOW_PARA 65 | #define wSTART 0x1000 66 | #define wSTOP 0x2000 67 | #define wCONFIG 0x4000 68 | #define wOUTPUT_BLE 0x0100 69 | #define wOUTPUT_USB 0x0200 70 | #define wPEAK_RAW 0x0002 71 | #define wPEAK_FILTERED 0x0004 72 | #define wPOSITION_RAW 0x0008 73 | #define wPOSITION_FILTERED 0x0010 74 | #define wENVELOPE 0x0020 75 | #define wRAW 0x000 76 | 77 | // NOTIFICATION_PARA 78 | #define wBATTERY 0x0001 79 | #define wGESTURE 0x0002 80 | 81 | // STATUS 82 | #define wSUCCESS 0x0000, 83 | #define wERR 0x0001, // General error 84 | #define wERR_INVALID_PARAMETER 0x0002, 85 | #define wERR_OUT_OF_RANGE 0x0002, //A provided parameter value was out of its allowed range. 86 | #define wERR_READONLY_PARAMETER 0x0003, //General Welle error. 87 | #define wERR_INVALID_DATALENGTH 0x0004 //Invalid Datalength 88 | 89 | 90 | // WELLE_GESTURE 91 | #define wNONE 0xFF 92 | #define wUNKNOWN 0xFE 93 | #define wLEFT_RIGHT 0x01 94 | #define wRIGHT_LEFT 0x02 95 | #define wUP_DOWN 0x03 96 | #define wDOWN_UP 0x04 97 | #define wCLOCKWISE 0x05 98 | #define wANTI_CLOCKWISE 0x06 99 | #define wA 0x07 100 | #define wB 0x08 101 | #define wC 0x09 102 | #define wD 0x0A 103 | #define wE 0x0B 104 | #define wF 0x0C 105 | #define wG 0x0D 106 | #define wH 0x0E 107 | #define wI 0x0F 108 | #define wJ 0x10 109 | #define wK 0x11 110 | #define wL 0x12 111 | #define wM 0x13 112 | #define wN 0x14 113 | #define wO 0x15 114 | #define wP 0x16 115 | #define wQ 0x17 116 | #define wR 0x18 117 | #define wS 0x19 118 | #define wT 0x1A 119 | #define wU 0x1B 120 | #define wV 0x1C 121 | #define wW 0x1D 122 | #define wX 0x1E 123 | #define wY 0x1F 124 | #define wZ 0x20 125 | #define wINVL 0x21 126 | #define wHOLD 0x22 127 | 128 | // BATTERY_STATUS 129 | #define wNOTCHARGING 0x00 130 | #define wCHARGING 0x01 131 | 132 | // LED_MODE 133 | #define wLED_OFF 0x00 134 | #define wLED_ON 0x01 135 | #define wLED_FLICK_SLOW 0x02 136 | #define wLED_FLICK_FAST 0x03 137 | 138 | // BLE_INTERVAL 139 | #define w20MS 0x00 140 | #define w30MS 0x01 141 | #define w50MS 0x02 142 | #define w100MS 0x03 143 | #define w200MS 0x04 144 | #define w300MS 0x05 145 | #define w400MS 0x06 146 | #define w500MS 0x07 147 | #define w1000MS 0x08 148 | #define w1500MS 0x09 149 | #define w2000MS 0x0A 150 | #define w2500MS 0x0B 151 | #define w3000MS 0x0C 152 | #define w4000MS 0x0D 153 | #define w5000MS 0x0E 154 | #endif 155 | 156 | typedef struct COMMAND 157 | { 158 | char *msgType; 159 | 160 | char *cmd; 161 | int cmdLength; 162 | 163 | char *rsp; 164 | int rspLength; 165 | } command_t; 166 | 167 | command_t wcConfigAllData; 168 | command_t wcStartDataFlow; 169 | command_t wcStopDataFlow; 170 | command_t wcConfigPosData_f; 171 | 172 | extern void wcInitlaizeBasicCmds(); 173 | -------------------------------------------------------------------------------- /src/C_API/src/welleDecoder.c: -------------------------------------------------------------------------------- 1 | #include "welleDecoder.h" 2 | #include "welleSerial.h" 3 | 4 | void wdInitializeDecoder() 5 | { 6 | wdDecoder.decodeState = STATE_HEADER; 7 | wdDecoder.headerCount = 0; 8 | wdDecoder.byteCount = 0; 9 | wdDecoder.msgLength = 0; 10 | wdDecoder.dataBuffer = (char *)malloc(sizeof(char) * 2); // Cannot make it (char *){0} nor NULL 11 | wdDecoder.prevByte = NULL; 12 | wdDecoder.messageBuffer = NULL; 13 | 14 | rawData.flag = wRAW; 15 | rawData.dataLength = 1360 * 2; 16 | rawData.data = (int *)malloc(rawData.dataLength * sizeof(int)); 17 | 18 | envData.flag = wENVELOPE; 19 | envData.dataLength = 1200; 20 | envData.data = (int *)malloc(envData.dataLength * sizeof(int)); 21 | 22 | peakData.flag = wPEAK_RAW; 23 | peakData.dataLength = 2; 24 | peakData.data = (int *)malloc(peakData.dataLength * sizeof(int)); 25 | 26 | peakData_f.flag = wPEAK_FILTERED; 27 | peakData_f.dataLength = 2; 28 | peakData_f.data = (int *)malloc(peakData_f.dataLength * sizeof(int)); 29 | 30 | posData.flag = wPOSITION_RAW; 31 | posData.dataLength = 3; 32 | posData.data = (int *)malloc(posData.dataLength * sizeof(int)); 33 | 34 | posData_f.flag = wPOSITION_FILTERED; 35 | posData_f.dataLength = 3; 36 | posData_f.data = (int *)malloc(posData_f.dataLength * sizeof(int)); 37 | } 38 | 39 | void wdDecode(int fd, char *buf) 40 | { 41 | int readNum = -1; 42 | while(readNum < 0) 43 | { 44 | usleep(1000); 45 | readNum = wsRead(fd, buf, 1); 46 | } 47 | // printf("Data: %x\n", buf[0]); 48 | switch (wdDecoder.decodeState) 49 | { 50 | case STATE_HEADER: 51 | wdDecodeHeader(buf); 52 | break; 53 | case STATE_DATALENGTH: 54 | wdDecodeDataLength(buf); 55 | break; 56 | case STATE_MESSAGE: 57 | wdDecodeDataMessage(buf); 58 | break; 59 | } 60 | } 61 | 62 | void wdDecodeHeader(char *data) 63 | { 64 | if (data[0] == DATA_HEADER) 65 | { 66 | wdDecoder.headerCount++; 67 | if (wdDecoder.headerCount == DATA_HEADER_LENGTH) 68 | { 69 | wdDecoder.headerCount = 0; 70 | free(wdDecoder.dataBuffer); 71 | wdDecoder.dataBuffer = (char *)malloc(sizeof(char) * 2); 72 | wdDecoder.decodeState = STATE_DATALENGTH; 73 | // printf("Decode header succeed\n"); 74 | } 75 | 76 | } else { 77 | wdDecoder.headerCount = 0; 78 | } 79 | wdDecoder.prevByte = data; 80 | } 81 | 82 | void wdDecodeDataLength(char *data) 83 | { 84 | wdDecoder.dataBuffer[wdDecoder.byteCount++] = data[0]; 85 | if (wdDecoder.byteCount == 2) 86 | { 87 | // printf("%x %x\n", wdDecoder.dataBuffer[0], wdDecoder.dataBuffer[1]); 88 | wdDecoder.msgLength = (wdDecoder.dataBuffer[1]<<8) + wdDecoder.dataBuffer[0]; 89 | wdDecoder.messageBuffer = (char *)malloc(sizeof(char) * wdDecoder.msgLength); 90 | wdDecoder.messageBuffer[0] = wdDecoder.dataBuffer[0]; 91 | wdDecoder.messageBuffer[1] = wdDecoder.dataBuffer[1]; 92 | wdDecoder.decodeState = STATE_MESSAGE; 93 | // printf("Decode data length succeed, dataLength = %d\n", wdDecoder.msgLength); 94 | } 95 | } 96 | 97 | void wdDecodeDataMessage(char *data) 98 | { 99 | wdDecoder.messageBuffer[wdDecoder.byteCount++] = data[0]; 100 | if (wdDecoder.byteCount == wdDecoder.msgLength) 101 | { 102 | char *dataCpy = (char *)malloc(sizeof(wdDecoder.messageBuffer)); 103 | wdReverseBuffer(wdDecoder.messageBuffer, dataCpy); 104 | if(wdDecodePackBodyMessage(dataCpy)) 105 | { 106 | printf("x: %d, y: %d\n", posData_f.data[0], posData_f.data[1]); 107 | } 108 | free(dataCpy); 109 | free(wdDecoder.messageBuffer); 110 | wdResetDecoder(); 111 | } 112 | } 113 | 114 | int wdDecodePackBodyMessage(char *data) 115 | { 116 | // printf("Decoding Packbody Message\n"); 117 | int msgLength = (data[0]<<8) + data[1]; 118 | // printf("%d %d\n", msgLength, wdDecoder.msgLength); 119 | if (msgLength != wdDecoder.msgLength) 120 | { 121 | return -1; 122 | } 123 | 124 | // for (int i = 0; i < msgLength; ++i) 125 | // { 126 | // printf("%x ", data[i]); 127 | // } 128 | // printf("\n"); 129 | 130 | int dataLength = (msgLength - 8)/2; 131 | int msgType = (data[2]<<8) + data[3]; 132 | int para = (data[4]<<8) + data[5]; 133 | // printf("%x\n", para & 0xFF); 134 | // int status = (data[6]<<8) + data[7]; 135 | 136 | if (msgType == wDATAFLOW_RESP) 137 | { 138 | if (dataLength) 139 | { 140 | int dataIndex = 8; 141 | switch (para & 0xFF) 142 | { 143 | case wRAW: 144 | for (int i = 0; i < rawData.dataLength; ++i) 145 | { 146 | rawData.data[i] = wdConv2Int16(data, dataIndex); 147 | dataIndex += 2; 148 | } 149 | break; 150 | case wENVELOPE: 151 | for (int i = 0; i < envData.dataLength; ++i) 152 | { 153 | envData.data[i] = wdConv2Int16(data, dataIndex); 154 | dataIndex += 2; 155 | } 156 | break; 157 | case wPEAK_RAW: 158 | for (int i = 0; i < peakData.dataLength; ++i) 159 | { 160 | peakData.data[i] = wdConv2Int16(data, dataIndex); 161 | dataIndex += 2; 162 | } 163 | break; 164 | case wPEAK_FILTERED: 165 | for (int i = 0; i < peakData_f.dataLength; ++i) 166 | { 167 | peakData_f.data[i] = wdConv2Int16(data, dataIndex); 168 | dataIndex += 2; 169 | } 170 | break; 171 | case wPOSITION_RAW: 172 | for (int i = 0; i < posData.dataLength; ++i) 173 | { 174 | posData.data[i] = wdConv2Int16(data, dataIndex); 175 | dataIndex += 2; 176 | } 177 | break; 178 | case wPOSITION_FILTERED: 179 | // printf("Get filtered position"); 180 | for (int i = 0; i < posData_f.dataLength; ++i) 181 | { 182 | posData_f.data[i] = wdConv2Int16(data, dataIndex); 183 | dataIndex += 2; 184 | } 185 | break; 186 | } 187 | return 1; 188 | } 189 | return 0; 190 | } 191 | return -1; 192 | } 193 | 194 | // void wdPackRequestData() 195 | // { 196 | 197 | // } 198 | 199 | void wdReverseBuffer(char *data, char *dataCpy) 200 | { 201 | for (int i = 0; i < wdDecoder.byteCount; i+=2) 202 | { 203 | dataCpy[i] = data[i+1]; 204 | dataCpy[i+1] = data[i]; 205 | } 206 | 207 | // printf("Databuffer: "); 208 | // for (int i = 0; i < wdDecoder.byteCount; ++i) 209 | // { 210 | // printf("%x ", dataCpy[i]); 211 | // } 212 | // printf("\nReversed buffer: "); 213 | // for (int i = 0; i < wdDecoder.byteCount; ++i) 214 | // { 215 | // printf("%x ", dataCpy[i]); 216 | // } 217 | } 218 | 219 | int wdConv2Int16(char *data, int index) 220 | { 221 | // printf("To convert: %x %x\n", data[index], data[index+1]); 222 | return (data[index]<<8) | data[index + 1]; 223 | } 224 | 225 | 226 | void wdResetDecoder() 227 | { 228 | wdDecoder.decodeState = STATE_HEADER; 229 | wdDecoder.headerCount = 0; 230 | wdDecoder.byteCount = 0; 231 | wdDecoder.msgLength = 0; 232 | free(wdDecoder.dataBuffer); 233 | wdDecoder.dataBuffer = (char *)malloc(sizeof(char) * 2); 234 | wdDecoder.prevByte = NULL; 235 | wdDecoder.messageBuffer = NULL; 236 | } 237 | -------------------------------------------------------------------------------- /src/C_API/src/welleDecoder.h: -------------------------------------------------------------------------------- 1 | #include "welleCONST.h" 2 | 3 | #define STATE_UNKNOW -1 4 | #define STATE_HEADER 1 5 | #define STATE_DATALENGTH 2 6 | #define STATE_MESSAGE 3 7 | #define STATE_DATAFLOW 4 8 | #define DATA_HEADER 0x23 9 | #define DATA_HEADER_LENGTH 6 10 | #define DATAFLOW_LENGTH 5 11 | #define DATATYPES 6 12 | 13 | #ifndef __WELLEDECODER_H__ 14 | #define __WELLEDECODER_H__ 15 | 16 | typedef struct WELLEDECODER 17 | { 18 | int decodeState; 19 | int headerCount; 20 | int byteCount; 21 | int msgLength; 22 | char *dataBuffer; 23 | char *prevByte; 24 | char *messageBuffer; 25 | 26 | } welleDecoder_t; 27 | 28 | typedef struct AVAILABLEDATA 29 | { 30 | int flag; 31 | int dataLength; 32 | int *data; 33 | } availableData_t; 34 | 35 | welleDecoder_t wdDecoder; 36 | availableData_t rawData; 37 | availableData_t envData; 38 | availableData_t peakData; 39 | availableData_t peakData_f; 40 | availableData_t posData; 41 | availableData_t posData_f; 42 | 43 | extern void wdInitializeDecoder(); 44 | extern void wdDecode(int fd, char *buf); 45 | extern void wdDecodeHeader(char *data); 46 | extern void wdDecodeDataLength(char *data); 47 | extern void wdDecodeDataMessage(char *data); 48 | extern int wdDecodePackBodyMessage(char *data); 49 | // extern void wdPackRequestData(); 50 | extern void wdReverseBuffer(char *data, char *dataCpy); 51 | extern int wdConv2Int16(char *data, int index); 52 | extern void wdResetDecoder(); 53 | 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /src/C_API/src/welleSerial.c: -------------------------------------------------------------------------------- 1 | #include "welleSerial.h" 2 | 3 | typedef struct WELLESERIAL 4 | { 5 | // welleDecoder *decoder; 6 | void (*msgCallback)(); 7 | int debug; 8 | } welleSerial; 9 | 10 | int wsConfig (int fd, int speed) 11 | { 12 | struct termios tty; 13 | memset (&tty, 0, sizeof tty); 14 | if (tcgetattr (fd, &tty) != 0) 15 | { 16 | printf("error %d from tcgetattr", errno); 17 | return -1; 18 | } 19 | 20 | cfsetospeed (&tty, speed); 21 | cfsetispeed (&tty, speed); 22 | 23 | tty.c_cflag = (tty.c_cflag & ~CSIZE) | CS8; // 8-bit chars 24 | // disable IGNBRK for mismatched speed tests; otherwise receive break 25 | // as \000 chars 26 | tty.c_iflag &= ~IGNBRK; // disable break processing 27 | tty.c_lflag = 0; // no signaling chars, no echo, 28 | // no canonical processing 29 | tty.c_oflag = 0; // no remapping, no delays 30 | tty.c_cc[VMIN] = 0; // read doesn't block 31 | tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout 32 | 33 | tty.c_iflag &= ~(IXON | IXOFF | IXANY); // shut off xon/xoff ctrl 34 | 35 | tty.c_cflag |= (CLOCAL | CREAD); // ignore modem controls, 36 | // enable reading 37 | tty.c_cflag &= ~(PARENB | PARODD); // shut off parity 38 | tty.c_cflag |= 0; // parity = 0 39 | tty.c_cflag &= ~CSTOPB; 40 | tty.c_cflag &= ~CRTSCTS; 41 | 42 | if (tcsetattr (fd, TCSANOW, &tty) != 0) 43 | { 44 | printf("error %d from tcsetattr", errno); 45 | return -1; 46 | } 47 | return 0; 48 | } 49 | 50 | // Set UART blocking 51 | 52 | void wsSetblocking (int fd, int should_block) 53 | { 54 | struct termios tty; 55 | memset (&tty, 0, sizeof tty); 56 | if (tcgetattr (fd, &tty) != 0) 57 | { 58 | printf("error %d from tggetattr", errno); 59 | return; 60 | } 61 | 62 | tty.c_cc[VMIN] = should_block ? 1 : 0; 63 | tty.c_cc[VTIME] = 5; // 0.5 seconds read timeout 64 | 65 | if (tcsetattr (fd, TCSANOW, &tty) != 0) 66 | { 67 | printf("error %d setting term attributes", errno); 68 | } 69 | } 70 | 71 | // Open a UART port 72 | 73 | int wsOpen(char *portname) 74 | { 75 | printf("Portname = %s\n", portname); 76 | // int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC); 77 | int fd = open (portname, O_RDWR | O_NOCTTY | O_NONBLOCK); 78 | printf("File description = %d\n", fd); 79 | if (fd < 0) 80 | { 81 | printf("error %d opening %s: %s", errno, portname, strerror (errno)); 82 | } 83 | else { 84 | sleep(1); 85 | while(tcflush(fd, TCIFLUSH) != 0); 86 | printf("Port Opened, fileDescription = %d\n", fd); 87 | } 88 | return fd; 89 | } 90 | 91 | int wsRead(int fd, char *buffer, int bufferSize) 92 | { 93 | return read(fd, buffer, bufferSize); 94 | } 95 | 96 | int wsWriteAndResp(int fd, command_t command, int commandSize) 97 | { 98 | int rspState = -1; 99 | printf("Write %s request\n", command.msgType); 100 | while(rspState != 0) 101 | { 102 | write(fd, command.cmd, command.cmdLength); 103 | // if debug then print 104 | sleep(1); 105 | rspState = wsCheckResp(fd, command.rsp, command.rspLength); 106 | // Check response, return 0 if response is right 107 | } 108 | 109 | return rspState; 110 | } 111 | 112 | int wsFlush(int fd) 113 | { 114 | sleep(1); 115 | tcflush(fd,TCIOFLUSH); 116 | return 0; 117 | } 118 | 119 | int wsCheckResp(int fd, char *targetResponse, int rspLength) 120 | { 121 | int readNum = -1; 122 | char *buf; 123 | buf = (char *)malloc(sizeof(char) * rspLength); 124 | while(readNum < 0) 125 | { 126 | readNum = wsRead(fd, buf, rspLength); 127 | } 128 | // if debug 129 | printf("Response: "); 130 | for (int i = 0; i < rspLength; ++i) 131 | { 132 | printf("%x ", buf[i]); 133 | } 134 | printf("\n"); 135 | return memcmp(buf, targetResponse, rspLength); 136 | } 137 | 138 | 139 | -------------------------------------------------------------------------------- /src/C_API/src/welleSerial.h: -------------------------------------------------------------------------------- 1 | #include "welleCONST.h" 2 | 3 | #ifdef __APPLE__ 4 | #include 5 | #include 6 | #include 7 | #endif 8 | 9 | 10 | #ifndef __WELLESERIAL_H__ 11 | #define __WELLESERIAL_H__ 12 | 13 | extern int wsConfig (int fd, int speed); 14 | extern void wsSetblocking (int fd, int shouldBlock); 15 | extern int wsOpen(char *name); 16 | extern int wsRead(int fd, char *buffer, int bufferSize); 17 | extern int wsWriteAndResp(int fd, command_t command, int commandSize); 18 | extern int wsFlush(int fd); 19 | extern int wsCheckResp(int fd, char *targetResponse, int rspLength); 20 | #endif 21 | -------------------------------------------------------------------------------- /src/welle_api.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Welle Api for developer to create their own gesture controlled applications 3 | * Copyright (C) 2015 - 2017 Maxustech Technologies Inc. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * See www.maxustech.com for more details. 19 | * All requests should be sent to info@maxustech.com. 20 | */ 21 | 22 | var WELLE_CONST = require('./welle_const.js'); 23 | var welleDecoder = require('./welle_decoder.js'); 24 | var welleSerial = require('./welle_serial.js'); 25 | 26 | function welle(){ 27 | this.welleSerial = new welleSerial(welleDecoder, this.msgCallback.bind(this)); 28 | this.messagesQueue = []; 29 | this.sendTimer = null; 30 | this.messageRate = 50; 31 | this.recievingTimeout = 200; 32 | this.emitterEventListeners = {}; 33 | this.commandCallbackPairs = []; 34 | this.currentCommandCallbackPair = null; 35 | } 36 | 37 | welle.prototype.setDebug = function(flag){ 38 | this.welleSerial.setDebug(flag); 39 | } 40 | 41 | welle.prototype.connectAny = function(openClb, closeClb, errorClb){ 42 | this.welleSerial.periodicConnect(openClb, closeClb, errorClb); 43 | } 44 | 45 | welle.prototype.startDataflow = function(success, error){ 46 | var msg_type = WELLE_CONST.MSG_TYPE.wDATAFLOW; 47 | var param = WELLE_CONST.DATAFLOW_PARA.wSTART; 48 | var cmd = welleDecoder.packRequestData({msg_type : msg_type, param : param, data : undefined}); 49 | this.send(cmd, {command:"startDataflow", successCallback:success, errorCallback:error, msg_type : msg_type, param : param}); 50 | } 51 | 52 | welle.prototype.stopDataflow = function(success, error){ 53 | var msg_type = WELLE_CONST.MSG_TYPE.wDATAFLOW; 54 | var param = WELLE_CONST.DATAFLOW_PARA.wSTOP; 55 | var cmd = welleDecoder.packRequestData({msg_type : msg_type, param : param, data : undefined}); 56 | this.send(cmd, {command:"stopDataflow", successCallback:success, errorCallback:error, msg_type : msg_type, param : param}) 57 | } 58 | 59 | welle.prototype.enableGestureOutput = function(success, error){ 60 | var msg_type = WELLE_CONST.MSG_TYPE.wSET; 61 | var param = WELLE_CONST.SYSTEM_PARA.wRECOGNIZING; 62 | var cmd = welleDecoder.packRequestData({msg_type : msg_type, param : param, data : 1}); 63 | this.send(cmd, {command:"enableGestureOutput", successCallback:success, errorCallback:error, msg_type : msg_type, param : param}); 64 | } 65 | 66 | welle.prototype.disableGestureOutput = function(success, error){ 67 | var msg_type = WELLE_CONST.MSG_TYPE.wSET; 68 | var param = WELLE_CONST.SYSTEM_PARA.wRECOGNIZING; 69 | var cmd = welleDecoder.packRequestData({msg_type : msg_type, param : param, data : 0}); 70 | this.send(cmd, {command:"disableGestureOutput", successCallback:success, errorCallback:error, msg_type : msg_type, param : param}); 71 | } 72 | 73 | welle.prototype.configOutputAllData = function(success, error){ 74 | var msg_type = WELLE_CONST.MSG_TYPE.wDATAFLOW; 75 | var param = WELLE_CONST.DATAFLOW_PARA.wCONFIG | WELLE_CONST.DATAFLOW_PARA.wRAW 76 | | WELLE_CONST.DATAFLOW_PARA.wPEAK_RAW | WELLE_CONST.DATAFLOW_PARA.wPEAK_FILTERED 77 | | WELLE_CONST.DATAFLOW_PARA.wPOSITION_RAW | WELLE_CONST.DATAFLOW_PARA.wPOSITION_FILTERED 78 | | WELLE_CONST.DATAFLOW_PARA.wENVELOPE; 79 | 80 | var cmd = welleDecoder.packRequestData({msg_type : msg_type, param : param, data : undefined}); 81 | this.send(cmd, {command:"configOutputAllData", successCallback:success, errorCallback:error, msg_type : msg_type, param : param}); 82 | } 83 | 84 | welle.prototype.configOutputData = function(config, success, error){ 85 | var msg_type = WELLE_CONST.MSG_TYPE.wDATAFLOW; 86 | var param = WELLE_CONST.DATAFLOW_PARA.wCONFIG; 87 | 88 | for (p in config){ 89 | if (WELLE_CONST.DATAFLOW_PARA[config[p]]){ 90 | param |= WELLE_CONST.DATAFLOW_PARA[config[p]]; 91 | } 92 | else { 93 | console.log('Invalid Parameter: ' + config[p]); 94 | error && error(); 95 | return; 96 | } 97 | } 98 | 99 | var cmd = welleDecoder.packRequestData({msg_type : msg_type, param : param, data : undefined}); 100 | this.send(cmd, {command:"configOutputData", successCallback:success, errorCallback:error, msg_type : msg_type, param : param}); 101 | } 102 | 103 | welle.prototype.getDeviceInfo = function(success, error){ 104 | var msg_type = WELLE_CONST.MSG_TYPE.wGET; 105 | var param = WELLE_CONST.SYSTEM_PARA.wDEVICE_INFO; 106 | var cmd = welleDecoder.packRequestData({msg_type : msg_type, param : param, data : undefined}); 107 | this.send(cmd, {command:"getDeviceInfo", successCallback:success, errorCallback:error, msg_type : msg_type, param : param}); 108 | } 109 | 110 | welle.prototype.setLedMode = function(led, mode, success, error){ 111 | var led_name = ['wLED_1', 'wLED_2', 'wLED_ALL']; 112 | var led_mode = ['wLED_OFF', 'wLED_ON', 'wLED_FLICK_SLOW', 'wLED_FLICK_FAST']; 113 | var msg_type = WELLE_CONST.MSG_TYPE.wSET; 114 | var param; 115 | var data; 116 | 117 | if (led_name.indexOf(led) >= 0 && WELLE_CONST.SYSTEM_PARA[led]){ 118 | param = WELLE_CONST.SYSTEM_PARA[led]; 119 | } 120 | else { 121 | console.log('Invalid Parameter: ' + led); 122 | return; 123 | } 124 | 125 | if (led_mode.indexOf(mode) >= 0 && WELLE_CONST.LED_MODE[mode]){ 126 | data = WELLE_CONST.LED_MODE[mode] 127 | } 128 | else { 129 | console.log('Invalid Led Mode: ' + mode); 130 | return; 131 | } 132 | 133 | var cmd = welleDecoder.packRequestData({msg_type : msg_type, param : param, data : data}); 134 | this.send(cmd, {command:"setLedMode", successCallback:success, errorCallback:error, msg_type : msg_type, param : param}); 135 | } 136 | 137 | welle.prototype.recalibrate = function(success, error){ 138 | var msg_type = WELLE_CONST.MSG_TYPE.wSYSCMD; 139 | var param = WELLE_CONST.SYSCMD_PARA.wRECAL; 140 | var cmd = welleDecoder.packRequestData({msg_type : msg_type, param : param, data : 0}); 141 | this.send(cmd, {command:"recalibrate", successCallback:success, errorCallback:error, msg_type : msg_type, param : param}); 142 | } 143 | 144 | welle.prototype.msgCallback = function(msg){ 145 | var self = this; 146 | // console.log('msg: ', msg) 147 | if (msg.response.msg_type == 'wDATAFLOW_RESP' && msg.response.dataLen){ 148 | this.emit('onData', msg.response.data); 149 | } 150 | else if (msg.response.msg_type == 'wNOTIFICATION' && msg.response.param == 'wGESTURE'){ 151 | this.emit('onGesture', msg.message); 152 | } 153 | 154 | this.checkRecievingCommand(msg); 155 | } 156 | 157 | welle.prototype.send = function(cmd, commandCallbackPair){ 158 | this.messagesQueue.unshift(cmd); 159 | this.commandCallbackPairs.unshift(commandCallbackPair); 160 | this.startSendingProcess(); 161 | } 162 | 163 | welle.prototype.checkRecievingCommand = function(msg){ 164 | var correct_response = false; 165 | if (this.currentCommandCallbackPair != null){ 166 | if (WELLE_CONST.MSG_TYPE[msg.response.msg_type] == this.currentCommandCallbackPair.msg_type + 1){ 167 | if (msg.response.msg_type == 'wDATAFLOW_RESP'){ 168 | var param = msg.response.param.split(' '); 169 | var paramCode = 0; 170 | for (var p in param){ 171 | if ( WELLE_CONST.DATAFLOW_PARA[param[p]]){ 172 | paramCode |= WELLE_CONST.DATAFLOW_PARA[param[p]]; 173 | } 174 | } 175 | if (paramCode == this.currentCommandCallbackPair.param){ 176 | correct_response = true; 177 | } 178 | } 179 | else if (msg.response.msg_type == 'wSYSCMD_RESP'){ 180 | var param = msg.response.param.split(' '); 181 | for (var p in param){ 182 | if (WELLE_CONST.SYSCMD_PARA[param[p]] == this.currentCommandCallbackPair.param){ 183 | correct_response = true; 184 | } 185 | } 186 | } 187 | else if (msg.response.msg_type == 'wGET_RESP' || msg.response.msg_type == 'wSET_RESP'){ 188 | var param = msg.response.param.split(' '); 189 | for (var p in param){ 190 | if (WELLE_CONST.SYSTEM_PARA[param[p]] == this.currentCommandCallbackPair.param){ 191 | correct_response = true; 192 | } 193 | } 194 | } 195 | } 196 | } 197 | if (correct_response){ 198 | this.currentCommandCallbackPair.successCallback && this.currentCommandCallbackPair.successCallback(msg); 199 | this.currentCommandCallbackPair = null; 200 | } 201 | } 202 | 203 | welle.prototype.setRecievingProcessTimeout = function(){ 204 | var self = this; 205 | setTimeout(function(){ 206 | if (self.currentCommandCallbackPair){ 207 | self.currentCommandCallbackPair.errorCallback && self.currentCommandCallbackPair.errorCallback(self.currentCommandCallbackPair.command + ' Timeout, No Response!'); 208 | self.currentCommandCallbackPair = null; 209 | } 210 | }, self.recievingTimeout) 211 | } 212 | 213 | welle.prototype.sendingProcess = function(){ 214 | if (!this.welleSerial.isConnected()){ 215 | this.stopSendingProcess(); 216 | console.log('Welle is not connected!'); 217 | return; 218 | } 219 | 220 | if (!this.currentCommandCallbackPair && this.messagesQueue.length > 0){ 221 | var msg = this.messagesQueue.pop(); 222 | this.currentCommandCallbackPair = this.commandCallbackPairs.pop(); 223 | this.welleSerial.write(msg); 224 | console.log('Sending '+ this.currentCommandCallbackPair.command + ' Message') 225 | this.setRecievingProcessTimeout(); 226 | } 227 | else if (!this.messagesQueue.length){ 228 | this.stopSendingProcess(); 229 | } 230 | } 231 | 232 | welle.prototype.stopSendingProcess = function(){ 233 | if (this.sendTimer !== null) { 234 | clearInterval(this.sendTimer); 235 | this.sendTimer = null; 236 | } 237 | } 238 | 239 | welle.prototype.startSendingProcess = function(){ 240 | if (this.sendTimer === null) { 241 | this.sendTimer = setInterval(this.sendingProcess.bind(this), this.messageRate); 242 | } 243 | } 244 | 245 | welle.prototype.normalizeEventName = function(eventName) { 246 | if (eventName.indexOf('on') !== 0) { 247 | if (eventName[0] !== eventName[0].toUpperCase()) { 248 | eventName = 'on' + eventName[0].toUpperCase() + eventName.substring(1); 249 | } else { 250 | eventName = 'on' + eventName; 251 | } 252 | } 253 | return eventName; 254 | } 255 | 256 | welle.prototype.emit = function(eventName, data) { 257 | var i; 258 | if (this.emitterEventListeners[eventName]) { 259 | for (i = 0; i < this.emitterEventListeners[eventName].length; i++) { 260 | this.emitterEventListeners[eventName][i](data); 261 | } 262 | } 263 | } 264 | 265 | welle.prototype.on = function(eventName, handler) { 266 | eventName = this.normalizeEventName(eventName); 267 | if (!this.emitterEventListeners[eventName]) { 268 | this.emitterEventListeners[eventName] = []; 269 | } 270 | this.emitterEventListeners[eventName].push(handler); 271 | return; 272 | } 273 | 274 | welle.prototype.off = function(eventName, handler) { 275 | var i; 276 | eventName = this.normalizeEventName(eventName); 277 | if (typeof handler === 'undefined') { 278 | this.emitterEventListeners[eventName] = []; 279 | return; 280 | } 281 | if (!this.emitterEventListeners[eventName] || this.emitterEventListeners[eventName].length === 0) return; 282 | for (i = 0; i < this.emitterEventListeners[eventName].length; i++) { 283 | if(this.emitterEventListeners[eventName][i] === handler) this.emitterEventListeners[eventName].splice(i, 1); 284 | } 285 | return; 286 | } 287 | 288 | welle.prototype.once = function(eventName, handler) { 289 | var self = this; 290 | eventName = this.normalizeEventName(eventName); 291 | var _handler = function () { 292 | handler(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]); 293 | self.off(eventName, _handler); 294 | }; 295 | this.on(eventName, _handler); 296 | return; 297 | } 298 | 299 | module.exports = new welle(); -------------------------------------------------------------------------------- /src/welle_const.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Welle Api for developer to create their own gesture controlled applications 3 | * Copyright (C) 2015 - 2017 Maxustech Technologies Inc. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * See www.maxustech.com for more details. 19 | * All requests should be sent to info@maxustech.com. 20 | */ 21 | 22 | module.exports = Object.freeze({ 23 | //------------MSG_TYPE------------- 24 | // Get and Get command response 25 | 'MSG_TYPE' : { 26 | 'wGET' : 0x1001, 27 | 'wGET_RESP' : 0x1002, 28 | // Set and Set command response 29 | 'wSET' : 0x2001, 30 | 'wSET_RESP' : 0x2002, 31 | // Dataflow Start and response 32 | 'wDATAFLOW' : 0x3001, 33 | 'wDATAFLOW_RESP' : 0x3002, 34 | // System command and response 35 | 'wSYSCMD' : 0x4001, 36 | 'wSYSCMD_RESP' : 0x4002, 37 | // Notification for Async Data: Battery, Gesture and letter recognition 38 | 'wNOTIFICATION' : 0x5001, 39 | // reserved for future use 40 | 'wRESERVED' : 0xFFF1, 41 | 'wRESERVED_RESP' : 0xFFF2 42 | }, 43 | 44 | 'SYSTEM_PARA' : { 45 | // GET & SET allowed parameters 46 | // Refresh rate 47 | 'wREFRESH_RATE' : 0x0001, 48 | // Base update parameter 49 | 'wPOWER_STABLE_LENGTH' : 0x0002, 50 | 'wPOWER_STABLE_VAR' : 0x0003, 51 | 'wPEAK_STABLE_LENGTH' : 0x0004, 52 | 'wPEAK_STABLE_VAR' : 0x0005, 53 | // Kalman filter parameter 54 | 'wKALMAN_1D_CV' : 0x0006, 55 | 'wKALMAN_1D_CA' : 0x0007, 56 | 'wKALMAN_2D_CV' : 0x0008, 57 | 'wKALMAN_2D_CA' : 0x0009, 58 | 59 | 'wKALMAN_1D_P_VAR' : 0x0010, 60 | 'wKALMAN_1D_Q_VAR' : 0x0011, 61 | 'wKALMAN_2D_P_VAR' : 0x0012, 62 | 'wKALMAN_2D_Q_VAR' : 0x0013, 63 | // PDAF chi dist gamma 64 | 'wCHIDISTGAMMA' :0x0014, 65 | 'wTRACKER_STATE_FRAMES' : 0x0015, 66 | 'wAVERAGE_FILTER_SIZE' :0x0016, 67 | 68 | // Signal Threshold 69 | 'wTHRESHOLD' : 0x0017, 70 | 'wXYZ_STABLE_SIZE' : 0x0019, 71 | 'wXYZ_STABLE_VAR' : 0x0020, 72 | 73 | // Reconizing algorithm setting 74 | 'wRECOGNIZING' : 0x0021, 75 | 76 | //-------SET allowed parameters--------- 77 | // BLE connection interval time 78 | 'wBLE_CONNECTION_INTERVAL' : 0x0100, 79 | // BLE advertising time 80 | 'wBLE_ADV_INTERVAL' : 0x0101, 81 | // BLE Restart 82 | 'wBLE_RESET' : 0x0102, 83 | // LEDs 84 | 'wLED_1' : 0xFF01, 85 | 'wLED_2' : 0xFF02, 86 | 'wLED_ALL' : 0xFF03, 87 | //-------SET allowed parameters--------- 88 | 89 | //-------GET allowed parameters--------- 90 | 'wDEVICE_INFO' : 0x0200 91 | }, 92 | 93 | 'SYSCMD_PARA' : { 94 | //--------------------------------- 95 | //-----------SYSCMD_PARA----------- 96 | 'wRESET_BOOT' : 0x0001, 97 | 'wRESET_APP' : 0x0002, 98 | 'wRESTART' :0x0004, 99 | 'wRECAL' : 0x0008 100 | //-----------SYSCMD_PARA----------- 101 | //--------------------------------- 102 | }, 103 | 104 | 'DATAFLOW_PARA' : { 105 | //--------------------------------- 106 | //----------DATAFLOW_PARA---------- 107 | //dataflow control byte 108 | 'wSTART' : 0x1000, 109 | 'wSTOP' : 0x2000, 110 | 'wCONFIG' : 0x4000, 111 | //dataflow output to device byte 112 | 'wOUTPUT_BLE' : 0x0100, 113 | 'wOUTPUT_USB' : 0x0200, 114 | //dataflow output type bytes 115 | 'wPEAK_RAW' : 0x0002, 116 | 'wPEAK_FILTERED' : 0x0004, 117 | 'wPOSITION_RAW' : 0x0008, 118 | 'wPOSITION_FILTERED' : 0x0010, 119 | 'wENVELOPE' : 0x0020, 120 | 'wRAW' : 0x0001 121 | // 'wOUTPUT_USB_DEFAULT' : 0x0002 | 0x0004 | 0x0008 | 0x0010 | 0x0020 | 0x0200, 122 | // 'wOUTPUT_BLE_DEFAULT' : 0x0010 | 0x0100 123 | //----------DATAFLOW_PARA---------- 124 | //--------------------------------- 125 | }, 126 | 127 | 'NOTIFICATION_PARA' : { 128 | 'wBATTERY' : 0x0001, 129 | 'wGESTURE' : 0x0002 130 | }, 131 | 132 | 'STATUS' : { 133 | //--------------------------------- 134 | //----------WELLE_STATUS----------- 135 | 'wSUCCESS' : 0x0000, 136 | 'wERR' : 0x0001, // General error 137 | 'wERR_INVALID_PARAMETER' : 0x0002, 138 | 'wERR_OUT_OF_RANGE' : 0x0002, //A provided parameter value was out of its allowed range. 139 | 'wERR_READONLY_PARAMETER' : 0x0003, //General Welle error. 140 | 'wERR_INVALID_DATALENGTH' : 0x0004 //Invalid Datalength 141 | //----------WELLE_STATUS----------- 142 | //--------------------------------- 143 | }, 144 | 145 | 'WELLE_GESTURE' : { 146 | 'wNONE' : 0xFF, 147 | 'wUNKNOWN' : 0xFE, 148 | 'wLEFT_RIGHT' : 0x01, 149 | 'wRIGHT_LEFT' : 0x02, 150 | 'wUP_DOWN' : 0x03, 151 | 'wDOWN_UP' : 0x04, 152 | 'wCLOCKWISE' : 0x05, 153 | 'wANTI_CLOCKWISE' : 0x06, 154 | 'wA' : 0x07, 155 | 'wB' : 0x08, 156 | 'wC' : 0x09, 157 | 'wD' : 0x0A, 158 | 'wE' : 0x0B, 159 | 'wF' : 0x0C, 160 | 'wG' : 0x0D, 161 | 'wH' : 0x0E, 162 | 'wI' : 0x0F, 163 | 'wJ' : 0x10, 164 | 'wK' : 0x11, 165 | 'wL' : 0x12, 166 | 'wM' : 0x13, 167 | 'wN' : 0x14, 168 | 'wO' : 0x15, 169 | 'wP' : 0x16, 170 | 'wQ' : 0x17, 171 | 'wR' : 0x18, 172 | 'wS' : 0x19, 173 | 'wT' : 0x1A, 174 | 'wU' : 0x1B, 175 | 'wV' : 0x1C, 176 | 'wW' : 0x1D, 177 | 'wX' : 0x1E, 178 | 'wY' : 0x1F, 179 | 'wZ' : 0x20, 180 | 'wINVL' : 0x21, 181 | 'wHOLD' : 0x22 182 | }, 183 | 184 | 'BATTERY_STATUS' : { 185 | 'wNOTCHARGING' : 0x00, 186 | 'wCHARGING' : 0x01 187 | }, 188 | 189 | 'LED_MODE' : { 190 | 'wLED_OFF' : 0x00, 191 | 'wLED_ON' : 0x01, 192 | 'wLED_FLICK_SLOW' : 0x02, 193 | 'wLED_FLICK_FAST' : 0x03 194 | }, 195 | 196 | 'BLE_INTERVAL' : { 197 | 'w20MS' : 0x00, 198 | 'w30MS' : 0x01, 199 | 'w50MS' : 0x02, 200 | 'w100MS' : 0x03, 201 | 'w200MS' : 0x04, 202 | 'w300MS' : 0x05, 203 | 'w400MS' : 0x06, 204 | 'w500MS' : 0x07, 205 | 'w1000MS' : 0x08, 206 | 'w1500MS' : 0x09, 207 | 'w2000MS' : 0x0A, 208 | 'w2500MS' : 0x0B, 209 | 'w3000MS' : 0x0C, 210 | 'w4000MS' : 0x0D, 211 | 'w5000MS' : 0x0E 212 | } 213 | }); -------------------------------------------------------------------------------- /src/welle_decoder.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Welle Api for developer to create their own gesture controlled applications 3 | * Copyright (C) 2015 - 2017 Maxustech Technologies Inc. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * See www.maxustech.com for more details. 19 | * All requests should be sent to info@maxustech.com. 20 | */ 21 | 22 | var WELLE_CONST = require('./welle_const.js') 23 | 24 | var defaultSettings = { 25 | int16Bytes : 2, 26 | float32Bytes : 4, 27 | headerLen : 6, 28 | reservedLen : 6, 29 | peakRawLen : 2, 30 | peakFilteredLen : 2, 31 | posRawLen : 3, 32 | posFilteredLen : 3, 33 | signalLen : 1200, 34 | dataHeader : 35, 35 | dataflowLen : 5 36 | }; 37 | 38 | var DECODERSTATE = { 39 | unknown : -1, 40 | header : 1, 41 | dataLength : 2, 42 | message : 3, 43 | dataflow : 4 44 | }; 45 | 46 | var welleDecoder = { 47 | settings : defaultSettings, 48 | decodeState : DECODERSTATE.header, 49 | byteCount : 0, 50 | headerCount : 0, 51 | bufferData : [], 52 | messageLen : 0, 53 | previousDataByte : null 54 | }; 55 | 56 | welleDecoder.resetBuffer = function(){ 57 | this.byteCount = 0; 58 | this.bufferData = []; 59 | }; 60 | 61 | welleDecoder.decode = function(data){ 62 | var ret = null; 63 | for(var i = 0; i < data.length; i++){ 64 | var dataByte = data[i]; 65 | var decodeState = this.decodeHeader(dataByte); 66 | 67 | if(decodeState){ 68 | this.decodeState = decodeState; 69 | continue; 70 | } 71 | 72 | // if(this.decodeState == DECODERSTATE.dataflow){ 73 | // var ret = this.decodeDataflow(dataByte); 74 | // if(ret != undefined){ 75 | // continue; 76 | // } 77 | // } 78 | 79 | if(this.decodeState == DECODERSTATE.dataLength){ 80 | this.decodeDataLength(dataByte); 81 | } 82 | else if(this.decodeState == DECODERSTATE.message){ 83 | ret = this.decodeDataMessage(dataByte); 84 | if(ret != undefined){ 85 | return ret; 86 | } 87 | } 88 | } 89 | return ret; 90 | }; 91 | 92 | welleDecoder.resetDecodeState = function(){ 93 | this.byteCount = 0; 94 | this.bufferData = []; 95 | this.previousDataByte = null; 96 | this.decodeState = DECODERSTATE.header; 97 | }; 98 | 99 | welleDecoder.decodeHeader = function(dataByte){ 100 | var decodeState = null; 101 | if(dataByte == this.settings.dataHeader){ 102 | this.headerCount++; 103 | if(this.headerCount == this.settings.headerLen) { 104 | this.headerCount = 0; 105 | this.resetBuffer(); 106 | decodeState = DECODERSTATE.dataLength; 107 | } 108 | } 109 | else{ 110 | this.headerCount = 0; 111 | } 112 | 113 | // if(this.previousDataByte == 33 && dataByte == 33){ 114 | // decodeState = DECODERSTATE.dataflow; 115 | // this.headerCount = 0; 116 | // } 117 | 118 | this.previousDataByte = dataByte; 119 | return decodeState; 120 | }; 121 | 122 | welleDecoder.decodeDataflow = function(dataByte){ 123 | this.bufferData.push(dataByte); 124 | this.byteCount++; 125 | if(this.byteCount == this.settings.dataflowLen){ 126 | var data_x = this.convert2Int16(this.bufferData, 0); 127 | var data_y = this.convert2Int16(this.bufferData, 3); 128 | 129 | this.resetDecodeState(); 130 | if(Math.abs(data_x) <= 500 && Math.abs(data_y) < 500) 131 | return {x:data_x, y:data_y}; 132 | } 133 | }; 134 | 135 | welleDecoder.decodeDataLength = function(dataByte){ 136 | this.bufferData.push(dataByte); 137 | this.byteCount++; 138 | if(this.byteCount == 2){ 139 | this.messageLen = (this.bufferData[1] << 8) + this.bufferData[0] - 2; 140 | this.byteCount = 0; 141 | this.decodeState = DECODERSTATE.message; 142 | } 143 | }; 144 | 145 | welleDecoder.decodeDataMessage = function(dataByte){ 146 | this.bufferData.push(dataByte); 147 | this.byteCount++; 148 | if(this.byteCount == this.messageLen){ 149 | var response = this.decodePackBodyMessage(this.reverseByte(this.bufferData)); 150 | var message = null; 151 | if(response.param == 'wBATTERY'){ 152 | message = this.decodeBatteryInfo(response.rawDataBytes); 153 | } 154 | else if(response.param == 'wPROFILE'){ 155 | message = this.decodeDeviceProfile(response.rawDataBytes); 156 | } 157 | else if(response.param == 'wDEVICE_INFO'){ 158 | message = this.decodeDeviceInfo(response.rawDataBytes); 159 | } 160 | else if(response.param == 'wGESTURE'){ 161 | message = this.decodeGesture(response.rawDataBytes); 162 | } 163 | this.resetDecodeState(); 164 | return {response : response, message: message}; 165 | } 166 | }; 167 | 168 | welleDecoder.convert2Int16 = function(msg, index){ 169 | var u8array = new Uint8Array([Number(msg[index]), Number(msg[index+1])]); 170 | var view = new DataView(u8array.buffer); 171 | return view.getInt16(0); 172 | }; 173 | 174 | welleDecoder.reverseByte = function(data){ 175 | var data_copy = []; 176 | for(i = 0; i < data.length; i+=2){ 177 | data_copy[i] = data[i+1]; 178 | data_copy[i+1] = data[i]; 179 | } 180 | return data_copy; 181 | }; 182 | 183 | welleDecoder.decodePackBodyMessage = function(msg){ 184 | var decodeMsg = { 185 | dataLen : 0, 186 | msg_type: WELLE_CONST.MSG_TYPE.wRESERVED, 187 | param : WELLE_CONST.SYSTEM_PARA.wREFRESH_RATE, 188 | status : WELLE_CONST.STATUS.wERR, 189 | data : {}, 190 | valid : false, 191 | rawDataBytes : [] 192 | } 193 | var msgLen = (msg[0]<<8) + msg[1]; 194 | if (msgLen == msg.length){ 195 | decodeMsg.valid = true; 196 | } 197 | else{ 198 | return decodeMsg; 199 | } 200 | 201 | decodeMsg.dataLen = (msgLen - 8) / 2; 202 | decodeMsg.msg_type = (msg[2]<<8) + msg[3]; 203 | decodeMsg.param = (msg[4]<<8) + msg[5]; 204 | decodeMsg.status = (msg[6]<<8) + msg[7]; 205 | 206 | if((decodeMsg.msg_type == WELLE_CONST.MSG_TYPE.wGET_RESP || decodeMsg.msg_type == WELLE_CONST.MSG_TYPE.wSET_RESP || decodeMsg.msg_type == WELLE_CONST.MSG_TYPE.wNOTIFICATION) && decodeMsg.dataLen){ 207 | var msg_index = 8; 208 | var temp = []; 209 | for(var i = 0; i < decodeMsg.dataLen; i++){ 210 | decodeMsg.data[i] = this.convert2Int16(msg, msg_index); 211 | msg_index += 2; 212 | } 213 | for(var i = 8; i < msg.length; i++){ 214 | decodeMsg.rawDataBytes.push(msg[i]); 215 | } 216 | } 217 | 218 | if(decodeMsg.msg_type == WELLE_CONST.MSG_TYPE.wDATAFLOW_RESP){ 219 | 220 | if(decodeMsg.dataLen){ 221 | var availableData = { 222 | 'wPEAK_RAW' : {flag : WELLE_CONST.DATAFLOW_PARA.wPEAK_RAW, dataLen : 2}, 223 | 'wPEAK_FILTERED' : {flag : WELLE_CONST.DATAFLOW_PARA.wPEAK_FILTERED, dataLen : 2}, 224 | 'wPOSITION_RAW' : {flag : WELLE_CONST.DATAFLOW_PARA.wPOSITION_RAW, dataLen : 3}, 225 | 'wPOSITION_FILTERED' : {flag : WELLE_CONST.DATAFLOW_PARA.wPOSITION_FILTERED, dataLen : 3}, 226 | 'wENVELOPE' : {flag : WELLE_CONST.DATAFLOW_PARA.wENVELOPE, dataLen : 1200}, 227 | 'wRAW' : {flag : WELLE_CONST.DATAFLOW_PARA.wRAW, dataLen: (1360) * 2} 228 | }; 229 | var msg_index = 8; 230 | for (type in availableData){ 231 | if(decodeMsg.param & availableData[type].flag){ 232 | var temp = []; 233 | for(var i = 0; i < availableData[type].dataLen; i++){ 234 | temp[i] = this.convert2Int16(msg, msg_index); 235 | msg_index += 2; 236 | } 237 | decodeMsg.data[type] = temp; 238 | } 239 | } 240 | 241 | if (decodeMsg.data['wRAW']){ 242 | var rearrangeData = new Array(decodeMsg.data['wRAW'].length); 243 | for (var i = 0; i < decodeMsg.data['wRAW'].length / 2; i++){ 244 | rearrangeData[i] = decodeMsg.data['wRAW'][i * 2]; 245 | rearrangeData[i + decodeMsg.data['wRAW'].length / 2] = decodeMsg.data['wRAW'][i * 2 + 1]; 246 | } 247 | decodeMsg.data['wRAW'] = rearrangeData; 248 | } 249 | } 250 | var paramMsg = ''; 251 | for( param in WELLE_CONST.DATAFLOW_PARA){ 252 | if(decodeMsg.param & WELLE_CONST.DATAFLOW_PARA[param]){ 253 | paramMsg += ' ' + param; 254 | } 255 | } 256 | decodeMsg.param = paramMsg; 257 | } 258 | else if(decodeMsg.msg_type == WELLE_CONST.MSG_TYPE.wGET_RESP || decodeMsg.msg_type == WELLE_CONST.MSG_TYPE.wSET_RESP){ 259 | for( param in WELLE_CONST.SYSTEM_PARA){ 260 | if(decodeMsg.param == WELLE_CONST.SYSTEM_PARA[param]){ 261 | decodeMsg.param = param; 262 | } 263 | } 264 | } 265 | else if(decodeMsg.msg_type == WELLE_CONST.MSG_TYPE.wSYSCMD_RESP){ 266 | for( param in WELLE_CONST.SYSCMD_PARA){ 267 | if(decodeMsg.param == WELLE_CONST.SYSCMD_PARA[param]){ 268 | decodeMsg.param = param; 269 | } 270 | } 271 | } 272 | else if(decodeMsg.msg_type == WELLE_CONST.MSG_TYPE.wNOTIFICATION){ 273 | for( param in WELLE_CONST.NOTIFICATION_PARA){ 274 | if(decodeMsg.param == WELLE_CONST.NOTIFICATION_PARA[param]){ 275 | decodeMsg.param = param; 276 | } 277 | } 278 | } 279 | 280 | // decode response msg type 281 | for( msg_type in WELLE_CONST.MSG_TYPE){ 282 | if(decodeMsg.msg_type == WELLE_CONST.MSG_TYPE[msg_type]){ 283 | decodeMsg.msg_type = msg_type; 284 | } 285 | } 286 | // decode response status 287 | for( status in WELLE_CONST.STATUS){ 288 | if(decodeMsg.status == WELLE_CONST.STATUS[status]){ 289 | decodeMsg.status = status; 290 | } 291 | } 292 | return decodeMsg; 293 | }; 294 | 295 | welleDecoder.decodeBatteryInfo = function(data){ 296 | var charging_ind = data[0]; 297 | var charging_result = ""; 298 | var battery_level = data[1]; 299 | for(item in WELLE_CONST.BATTERY_STATUS){ 300 | if(charging_ind == WELLE_CONST.BATTERY_STATUS[item]){ 301 | charging_result = item; 302 | } 303 | } 304 | 305 | return {status: charging_result, percentage: battery_level}; 306 | 307 | }; 308 | 309 | welleDecoder.decodeDeviceInfo = function(data){ 310 | var temp_UUID = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; 311 | var UUID = temp_UUID.toString(16).toUpperCase(); 312 | if(UUID.length < 8){ 313 | UUID = "00" + UUID; 314 | } 315 | var version = String.fromCharCode(data[4]) + String.fromCharCode(data[5]) + String.fromCharCode(data[6]) + String.fromCharCode(data[7]); 316 | var batteryInfo = this.decodeBatteryInfo(data.slice(8,10)); 317 | var deviceProfile = this.decodeDeviceProfile(data.slice(10)); 318 | return {UUID:UUID, version: version, batteryInfo:batteryInfo, deviceProfile:deviceProfile}; 319 | }; 320 | 321 | welleDecoder.decodeDeviceProfile = function(data){ 322 | var controlled_led_ind = (data[0] << 8) | data[1]; 323 | var controlled_led = ""; 324 | var shortcuts = []; 325 | for(item in WELLE_CONST.SYSTEM_PARA){ 326 | if(controlled_led_ind == WELLE_CONST.SYSTEM_PARA[item]){ 327 | controlled_led = item; 328 | } 329 | } 330 | 331 | for(item in WELLE_CONST.WELLE_GESTURE){ 332 | if(data[2] == WELLE_CONST.WELLE_GESTURE[item]){ 333 | shortcuts[0] = item; 334 | } 335 | 336 | if(data[3] == WELLE_CONST.WELLE_GESTURE[item]){ 337 | shortcuts[1] = item; 338 | } 339 | } 340 | 341 | return {controlled_led : controlled_led, shortcuts: shortcuts}; 342 | }; 343 | 344 | welleDecoder.decodeGesture = function(data){ 345 | var gesture; 346 | var led; 347 | 348 | if (data.length >= 2){ 349 | gesture = data[0] << 8 | data[1]; 350 | if (data.length == 4){ 351 | led = data[2] << 8 | data[3]; 352 | } 353 | } 354 | 355 | for (var item in WELLE_CONST.WELLE_GESTURE){ 356 | if(gesture == WELLE_CONST.WELLE_GESTURE[item]){ 357 | for (var l in WELLE_CONST.SYSTEM_PARA){ 358 | if (led == WELLE_CONST.SYSTEM_PARA[l]){ 359 | return {'gesture_code' : gesture, 'gesture' : item, 'led' : l, 'led_code' : led}; 360 | } 361 | } 362 | return {'gesture_code' : gesture, 'gesture' : item, 'led' : null, 'led_code' : null}; 363 | } 364 | } 365 | } 366 | 367 | welleDecoder.packRequestData = function(ReqDataObj) 368 | { 369 | var msg_type = ReqDataObj.msg_type; 370 | var param = ReqDataObj.param; 371 | var data = ReqDataObj.data; 372 | 373 | var len = 6; 374 | if(typeof(data) == 'object' && data && data.length){ 375 | len = 6 + data.length; 376 | } 377 | else if(typeof(data) == 'number'){ 378 | len = 10; 379 | } 380 | var msgBuf = new Uint8Array(len+6); 381 | for(var i = 0; i < 6; i++){ 382 | msgBuf[i] = 0x23; 383 | } 384 | 385 | msgBuf[6] = (len & 0xFF00)>>8; 386 | msgBuf[7] = len & 0x00FF; 387 | 388 | msgBuf[8] = (msg_type & 0xFF00)>>8; 389 | msgBuf[9] = msg_type & 0x00FF; 390 | 391 | msgBuf[10] = (param & 0xFF00)>>8; 392 | msgBuf[11] = param & 0x00FF; 393 | 394 | if(typeof(data) == 'object' && data &&data.length){ 395 | for(var i = 0; i < data.length; i++){ 396 | msgBuf[12 + i] = data[i]; 397 | } 398 | } 399 | else if(typeof(data) == 'number'){ 400 | 401 | var float32HEX = new Uint8ClampedArray(new Float32Array([data]).buffer); 402 | float32HEX = Array.prototype.slice.call(float32HEX).reverse(); 403 | 404 | for (var i = 0; i < float32HEX.length; i++){ 405 | msgBuf[12 + i] = float32HEX[i]; 406 | } 407 | } 408 | return msgBuf; 409 | } 410 | 411 | module.exports = welleDecoder; -------------------------------------------------------------------------------- /src/welle_serial.js: -------------------------------------------------------------------------------- 1 | /* 2 | * Welle Api for developer to create their own gesture controlled applications 3 | * Copyright (C) 2015 - 2017 Maxustech Technologies Inc. 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | * See www.maxustech.com for more details. 19 | * All requests should be sent to info@maxustech.com. 20 | */ 21 | 22 | var serialport = require('serialport'); 23 | 24 | function welleSerial(decoder, msgCallback, debug){ 25 | this.decoder = decoder || null; 26 | this.msgCallback = msgCallback || null; 27 | this.connectedPort = null; 28 | this.reconnectTask = null; 29 | this.debug = true; 30 | if (debug === false){ 31 | this.debug = false; 32 | } 33 | }; 34 | 35 | welleSerial.prototype.setDebug = function(flag){ 36 | if (flag === true){ 37 | this.debug = true; 38 | } 39 | else if(flag === false){ 40 | this.debug = false; 41 | } 42 | } 43 | 44 | welleSerial.prototype.isConnected = function(){ 45 | if (this.connectedPort){ 46 | return true; 47 | } 48 | else { 49 | return false; 50 | } 51 | } 52 | 53 | welleSerial.prototype.connectToDevice = function(openClb, closeClb, errorClb){ 54 | var self = this; 55 | serialport.list(function (err, ports) { 56 | for (var i = 0; i < ports.length; i++) { 57 | var port = ports[i]; 58 | var portManufacturer = port.manufacturer; 59 | var portName = port.comName; 60 | var vendorId = port.vendorId; 61 | var productId = port.productId; 62 | // console.log(JSON.stringify(port)) 63 | if (portManufacturer && (portManufacturer.indexOf("STMicroelectronics") >= 0 64 | || vendorId.indexOf('0483') >= 0 && productId.indexOf('5740') >= 0)) { 65 | var myPort = new serialport(portName, { 66 | baudrate: 115200, 67 | buffersize: 4096 * 10 68 | }); 69 | self.registerPortFunctionality(myPort, openClb, closeClb, errorClb); 70 | return; 71 | } 72 | } 73 | }); 74 | } 75 | 76 | welleSerial.prototype.registerPortFunctionality = function(port, openClb, closeClb, errorClb){ 77 | var self = this; 78 | this.connectedPort = port; 79 | 80 | clearInterval(this.reconnectTask); 81 | this.reconnectTask = null; 82 | 83 | port.on('data', function(data) { 84 | if (self.debug){ 85 | console.log('Recieving: ', self.buf2hex(data)); 86 | } 87 | var ret = self.decoder.decode(data); 88 | if (ret){ 89 | self.msgCallback && self.msgCallback(ret); 90 | } 91 | }); 92 | 93 | port.on('open', function(){ 94 | self.flush(); 95 | if (openClb){ 96 | openClb() 97 | } 98 | else { 99 | console.log('Port Open!'); 100 | } 101 | }); 102 | port.on('close', function(){ 103 | self.connectedPort = null; 104 | self.periodicConnect(openClb, closeClb, errorClb); 105 | if (closeClb){ 106 | closeClb(); 107 | } 108 | else { 109 | console.log('Port Close!'); 110 | } 111 | }); 112 | port.on('error', function(){ 113 | self.connectedPort = null; 114 | self.periodicConnect(openClb, closeClb, errorClb); 115 | if (errorClb){ 116 | errorClb(); 117 | } 118 | else { 119 | console.log('Port Close!'); 120 | } 121 | }); 122 | 123 | } 124 | 125 | welleSerial.prototype.periodicConnect = function(openClb, closeClb, errorClb){ 126 | var self = this; 127 | if(!this.reconnectTask) { 128 | this.reconnectTask = setInterval(function(){ 129 | self.connectToDevice(openClb, closeClb, errorClb); 130 | console.log("Search Welle COM Ports"); 131 | }, 3000); 132 | } 133 | } 134 | 135 | welleSerial.prototype.flush = function(){ 136 | if (this.connectedPort){ 137 | this.connectedPort.flush(function() { 138 | // console.log('Port flushed!'); 139 | }); 140 | } 141 | else { 142 | console.log('No available port') 143 | } 144 | 145 | } 146 | 147 | welleSerial.prototype.write = function(data){ 148 | var self = this; 149 | if (this.connectedPort){ 150 | this.connectedPort.write(data, function(){ 151 | if (self.debug){ 152 | console.log('Writing: ', self.buf2hex(data)); 153 | } 154 | }) 155 | } 156 | else { 157 | console.log('No available port'); 158 | } 159 | } 160 | 161 | welleSerial.prototype.toArrayBuffer = function(buf) { 162 | var view = new Uint8Array(buf.length); 163 | for (var i = 0; i < buf.length; ++i) { 164 | view[i] = buf[i]; 165 | } 166 | return view; 167 | } 168 | 169 | welleSerial.prototype.buf2hex = function(buffer) { 170 | return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join(''); 171 | } 172 | 173 | module.exports = welleSerial; --------------------------------------------------------------------------------