├── .gitattributes ├── .gitignore ├── COPYING ├── README.md ├── examples ├── WriteInhLabel_Demo │ └── WriteInhLabel_Demo.ino ├── WriteStr_Demo │ └── WriteStr_Demo.ino ├── genieArduino_Demo │ └── genieArduino_Demo.ino └── genieArduino_Demo_MultiScreen │ └── genieArduino_Demo_MultiScreen.ino ├── extras └── genieArduino-WS4-Demo.4DGenie ├── keywords.txt ├── library.properties └── src ├── genieArduino.cpp └── genieArduino.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 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 | ![image](http://www.4dsystems.com.au/downloads/4DLogo.png) 2 | 3 | ViSi-Genie-Arduino-Library (A.K.A genieArduino) 4 | ============================================================== 5 | 6 | Arduino Library for 4D Systems ViSi-Genie Environment 7 | 8 | This library supports the following: 9 | Support for neagative numbers, unsigned longs, unsigned integers with the WriteStr function. 10 | Features enhanced String Writing capability, no longer is a character Array the only viable option. 11 | Support for Workshop4 PRO features. 12 | 2+ displays connected to a single Arduino, and adds a Demo to illustrate how that is achieved. 13 | New Internal and Inherent Widgets. 14 | Much more... 15 | 16 | ## Information 17 | 18 | This library provides high level functions for the Arduino, to ease communication with 4D Systems modules when using the module configured with ViSi-Genie. 19 | Workshop4 PRO adds additional features to ViSi-Genie, allowing the User to write 4DGL code which can be executed at will from ViSi-Genie, enabling many advanced features not previously possible. 20 | Please refer to the 4D Systems website, namingly the Workshop4 Product Page, for documentation regarding Workshop4, and its environments. 21 | 22 | ## Installation 23 | 24 | Library folder should be placed in the C:\Users\(User name)\My Documents\Arduino\Libraries\ folder, or equivalent. (restart the IDE if already open). 25 | 26 | PLEASE ensure that the old library (if installed) has been removed completely so it does not conflict. 27 | 28 | For more information on the installation, please refer to [Installing Additional Arduino Libraries] (http://arduino.cc/en/Guide/Libraries) 29 | 30 | Open the ViSi-Genie project using Workshop4 and download to your display, connect the display to Arduino, reset the Arduino and it should work. 31 | 32 | This library should be discoverable from the Arduino IDE Library Manager too. 33 | 34 | ## Example Sketch 35 | 36 | Inside the library are 4 example sketches, to assist with getting started using this library. Inside is also a ViSi-Genie Workshop4 project, which can be used on a range of 4D Systems displays (designed on a uLCD-32PTU however can be changed via Workshop4 menu). It illustrates how to use some of the commands in the library include Read Object, Write Object, Reported Messages, Write Contrast and Write String. 37 | 38 | ## Tested with 39 | 40 | This library has been tested on the Duemilanove, Uno, Mega 1280, Mega 2560, Leonardo, Chipkit Max32, Due, Intel Galileo, Teensy and Yun (Software Serial only on Yun). 41 | Any problems discovered with this library, please contact technical support so fixes can be put in place, or seek support from our forum. 42 | 43 | ## Compatible 4D Systems Display Modules 44 | 45 | This library will work with all 4D Systems Modules which are capable of using the ViSi-Genie environment. This is therefore all Picaso, Pixxi-28, Pixxi-44 and Diablo16 Display Modules. 46 | The demo included with this library was made for the gen4-uLCD-32DCT-CLB (3.2" Capacitive Touch gen4 module) however can easily be adapted to other size displays. 47 | 48 | ## General Library Discussion 49 | ----------------------------- 50 | 51 | This section serves to give brief discussion about the constructor and functions included in the library. For functional examples on how to use these functions in a project, refer to the examples folder. 52 | 53 | ### Genie() 54 | This is the constructor for the library. It creates a unique instance that can be set to use the desired serial port. 55 | 56 | Genie genie; // Creates a new instance named 'genie' 57 | 58 | ### Begin(Stream &serial) 59 | Creates an instance of ViSi Genie by assigning a *serial* stream 60 | 61 | 62 | | Parameters | Description | 63 | |:----------:| ----------- | 64 | | serial | Stream object that represents the UART hardware | 65 | 66 | Serial.begin(115200); // Open Serial @115200. Can use other Serial UART's (Serial1, Serial2...) depending on your Arduino. 67 | genie.Begin(Serial); // Sets Serial/Serial0 to be used by the Genie instance 'genie' 68 | 69 | ### WriteContrast(uint16_t value) 70 | Sets the display contrast/brightness to a new *value* 71 | 72 | | Parameters | Description | 73 | |:----------:| ----------- | 74 | | value | New brightness/contrast value. The range of this value depends on the 4D display, Typically 0-15 Range | 75 | 76 | genie.WriteContrast(0); // Sets the contrast/brightness value to 0, effectively turning off the backlight 77 | genie.WriteContrast(10); // Sets the contrast/brightness value to 10, about 2/3 max brightness 78 | 79 | ### ReadObject(uint16_t object, uint16_t index) 80 | Sends a request to read the value of the widget specified by *object* (ex: GENIE_OBJ_GAUGE) and *index*. The value will be sent as a GENIE_REPORT_OBJECT command. 81 | A full list of available objects (ex: GENIE_OBJ_GAUGE, GENIE_OBJ_SLIDER etc) can be found at the bottom of this Readme. 82 | 83 | | Parameters | Description | 84 | |:----------:| ----------- | 85 | | object | Type of target widget | 86 | | index | Index number of target widget | 87 | 88 | genie.ReadObject(GENIE_OBJ_GAUGE, 0); // Request a report of the widget Gauge0 89 | 90 | ### WriteObject(uint16_t object, uint16_t index, uint16_t data) 91 | Updates the widget, specified by *object* (ex: GENIE_OBJ_GAUGE) and *index*, to a new value specified by *data* 92 | A full list of available objects (ex: GENIE_OBJ_GAUGE, GENIE_OBJ_SLIDER etc) can be found at the bottom of this Readme. 93 | 94 | | Parameters | Description | 95 | |:----------:| ----------- | 96 | | object | Type of target widget | 97 | | index | Index number of target widget | 98 | | data | New value for the target widget | 99 | 100 | genie.WriteObject(GENIE_OBJ_GAUGE, 0, 50); // Sets Gauge0 to 50 101 | 102 | ### WriteIntLedDigits(uint16_t index, int16_t data) 103 | Updates the Internal LedDigits specified by *index* to a new 16-bit value, specified by *data*. The widget parameter *Format* in ViSi Genie project should be set to Int16. Internal LedDigits are availble for Diablo and Pixxi displays. 104 | 105 | | Parameters | Description | 106 | |:----------:| ----------- | 107 | | index | Index number of target Internal LedDigits | 108 | | data | New 16-bit integer value for the target Internal LedDigits | 109 | 110 | genie.WriteIntLedDigits(0, 50); // Sets ILedDigits0 to 50 111 | 112 | ### WriteIntLedDigits(uint16_t index, float data) 113 | Updates the Internal LedDigits specified by *index* to a new 32-bit float value, specified by *data*. The widget parameter *Format* in ViSi Genie project should be set to any Float option. Internal LedDigits are availble for Diablo and Pixxi displays. 114 | 115 | | Parameters | Description | 116 | |:----------:| ----------- | 117 | | index | Index number of target Internal LedDigits | 118 | | data | New 32-bit float value for the target Internal LedDigits | 119 | 120 | genie.WriteIntLedDigits(0, 3.1416f); // Sets ILedDigits0 to 3.1416 121 | 122 | ### WriteIntLedDigits(uint16_t index, int32_t data) 123 | Updates the Internal LedDigits specified by *index* to a new 32-bit integer value, specified by *data*. The widget parameter *Format* in ViSi Genie project should be set to Int16. Internal LedDigits are availble for Diablo and Pixxi displays. 124 | 125 | | Parameters | Description | 126 | |:----------:| ----------- | 127 | | index | Index number of target Internal LedDigits | 128 | | data | New 32-bit integer value for the target Internal LedDigits | 129 | 130 | genie.WriteIntLedDigits(0, 1000000L); // Sets ILedDigits0 to 1000000 131 | 132 | ### WriteStr(uint16_t index, char * string) 133 | Updates the String widget specified by *index* with a new character string specified by *string* 134 | 135 | | Parameters | Description | 136 | |:----------:| ----------- | 137 | | index | Index number of target String | 138 | | string | Character pointer containing the text to print in the String widget | 139 | 140 | genie.WriteStr(0, "Sample String"); // Set text in String0 to "Sample String" 141 | 142 | ### WriteStr(uint16_t index, const __FlashStringHelper *ifsh) 143 | Updates the String widget specified by *index* with a string stored in program space (flash memory) specified by *ifsh*. This is only available for AVR boards. 144 | 145 | | Parameters | Description | 146 | |:----------:| ----------- | 147 | | index | Index number of target String | 148 | | ifsh | Flash string containing the text to print in the String widget | 149 | 150 | // Writes the string stored in flash memory to String1 151 | genie.WriteStr(1, F("Hello from Flash Memory")); // For AVR Arduinos only 152 | 153 | ### WriteStr(uint16_t index, const String &s) 154 | Updates the String widget specified by *index* with a String widget specified by *s* 155 | 156 | | Parameters | Description | 157 | |:----------:| ----------- | 158 | | index | Index number of target String | 159 | | s | String object containing the text to print in the String widget | 160 | 161 | String str = "This is string class"; 162 | genie.WriteStr(0, Str); // Writes the String class 'str' to String0 163 | 164 | ### WriteStrU(uint16_t index, uint16_t * string) 165 | Updates the String widget specified by *index* with a new Unicode (16-bit) character string specified by *string* 166 | 167 | | Parameters | Description | 168 | |:----------:| ----------- | 169 | | index | Index number of target String | 170 | | string | Character pointer containing the text to print in the String widget | 171 | 172 | uint16_t * unistr = {0x0034, 0x0044, 0x0020, 0x30B7, 0x30B9, 0x30C6, 0x30E0, 0x30BA, 0}; 173 | genie.WriteStr(2, unistr); // Writes the Unicode string "4D システムズ" to String2 174 | 175 | ### WriteStr(uint16_t index, int n) 176 | Updates the String widget specified by *index* with a new integer value *n* with base 10 177 | 178 | | Parameters | Description | 179 | |:----------:| ----------- | 180 | | index | Index number of target String | 181 | | n | Signed short integer value that will be formatted with base 10 to a string and will be printed in the String widget | 182 | 183 | genie.WriteStr(0, 10000); // Writes the value 10000 to String0 184 | 185 | ### WriteStr(uint16_t index, int n, int base) 186 | Updates the String widget specified by *index* with a new integer value *n* with base specified by *base* 187 | 188 | | Parameters | Description | 189 | |:----------:| ----------- | 190 | | index | Index number of target String | 191 | | n | Signed short integer value that will be formatted to a string and will be printed in the String widget | 192 | | base | Custom base to used when formatting the value to a string | 193 | 194 | genie.WriteStr(4, 10000, 16); // Writes the value 10000 to String4 in hexadecimal 195 | 196 | ### WriteStr(uint16_t index, unsigned int n) 197 | Updates the String widget specified by *index* with a new unsigned integer value *n* with base 10 198 | 199 | | Parameters | Description | 200 | |:----------:| ----------- | 201 | | index | Index number of target String | 202 | | n | Unsigned short integer value that will be formatted with base 10 to a string and will be printed in the String widget | 203 | 204 | unsigned int value = 40000; 205 | genie.WriteStr(2, value); // Writes the value 40000 to String2 206 | 207 | ### WriteStr(uint16_t index, unsigned int n, int base) 208 | Updates the String widget specified by *index* with a new unsigned integer value *n* with base specified by *base* 209 | 210 | | Parameters | Description | 211 | |:----------:| ----------- | 212 | | index | Index number of target String | 213 | | n | Unsigned short integer value that will be formatted to a string and will be printed in the String widget | 214 | | base | Custom base to used when formatting the value to a string | 215 | 216 | unsigned int value = 40000; 217 | genie.WriteStr(1, value, 16); // Writes the value 40000 to String1 in hexadecimal 218 | 219 | ### WriteStr(uint16_t index, long n) 220 | Updates the String widget specified by *index* with a new long value *n* with base 10 221 | 222 | | Parameters | Description | 223 | |:----------:| ----------- | 224 | | index | Index number of target String | 225 | | n | Signed long integer value that will be formatted with base 10 to a string and will be printed in the String widget | 226 | 227 | genie.WriteStr(2, 100000L); // Writes the value 100000 to String2 228 | 229 | ### WriteStr(uint16_t index, long n, int base) 230 | Updates the String widget specified by *index* with a new long value *n* with base specified by *base* 231 | 232 | | Parameters | Description | 233 | |:----------:| ----------- | 234 | | index | Index number of target String | 235 | | n | Signed long integer value that will be formatted to a string and will be printed in the String widget | 236 | | base | Custom base to used when formatting the value to a string | 237 | 238 | genie.WriteStr(3, 100000L, 8); // Writes the value 100000 to String3 in octal 239 | 240 | ### WriteStr(uint16_t index, unsigned long n) 241 | Updates the String widget specified by *index* with a new unsigned long value *n* with base 10 242 | 243 | | Parameters | Description | 244 | |:----------:| ----------- | 245 | | index | Index number of target String | 246 | | n | Unsigned long integer value that will be formatted with base 10 to a string and will be printed in the String widget | 247 | 248 | genie.WriteStr(0, 3000000000UL); // Writes the value 3000000000 to String0 249 | 250 | ### WriteStr(uint16_t index, unsigned long n, int base) 251 | Updates the String widget specified by *index* with a new unsigned long value *n* with base specified by *base* 252 | 253 | | Parameters | Description | 254 | |:----------:| ----------- | 255 | | index | Index number of target String | 256 | | n | Unsigned long integer value that will be formatted to a string and will be printed in the String widget | 257 | | base | Custom base to used when formatting the value to a string | 258 | 259 | genie.WriteStr(1, 3000000000UL, 16); // Writes the value 3000000000 to String1 in hexadecimal 260 | 261 | ### WriteStr(uint16_t index, double n) 262 | Updates the String widget specified by *index* with a new 64-bit float value *n* with 2 decimal digits 263 | 264 | | Parameters | Description | 265 | |:----------:| ----------- | 266 | | index | Index number of target String | 267 | | n | Signed 64-bit float value that will be formatted to a string with 2 decimal places (default) and will be printed in the String widget | 268 | 269 | double value = 175.3456; 270 | genie.WriteStr(0, value); // Writes the 64-bit float value 175.3456 to String0 271 | // with 2 decimal places (175.34) 272 | 273 | ### WriteStr(uint16_t index, double n, digits) 274 | Updates the String widget specified by *index* with a new 64-bit float value *n* with the number of decimal digits as specified by *digits* 275 | 276 | | Parameters | Description | 277 | |:----------:| ----------- | 278 | | index | Index number of target String | 279 | | n | Signed 64-bit float value that will be formatted to a string and will be printed in the String widget | 280 | | digits | Number of decimal places to format the value with | 281 | 282 | double value = 175.3456; 283 | genie.WriteStr(0, value, 4); // Writes the 64-bit float value 175.3456 to String0 284 | // with 4 decimal places (175.3456) 285 | 286 | ### WriteInhLabel(uint16_t index) 287 | Updates the Inherent Label widget specified by *index* with the default contents defined in Workshop4 288 | 289 | | Parameters | Description | 290 | |:----------:| ----------- | 291 | | index | Index number of target Inherent Label | 292 | 293 | genie.WriteInhLabel(1); // Set text in ILabelB1 to default String 294 | 295 | ### WriteInhLabel(uint16_t index, char * string) 296 | Updates the Inherent Label widget specified by *index* with a new character string specified by *string* 297 | 298 | | Parameters | Description | 299 | |:----------:| ----------- | 300 | | index | Index number of target Inherent Label | 301 | | string | Character pointer containing the text to print in the Inherent Label widget | 302 | 303 | genie.WriteInhLabel(0, "Sample String"); // Set text in ILabelB0 to "Sample String" 304 | 305 | ### WriteInhLabel(uint16_t index, const __FlashStringHelper *ifsh) 306 | Updates the Inherent Label widget specified by *index* with a string stored in program space (flash memory) specified by *ifsh*. This is only available for AVR boards. 307 | 308 | | Parameters | Description | 309 | |:----------:| ----------- | 310 | | index | Index number of target Inherent Label | 311 | | ifsh | Flash string containing the text to print in the Inherent Label widget | 312 | 313 | // Writes the string stored in flash memory to ILabelB1 314 | genie.WriteInhLabel(1, F("Hello from Flash Memory")); // For AVR Arduinos only 315 | 316 | ### WriteInhLabel(uint16_t index, const String &s) 317 | Updates the Inherent Label widget specified by *index* with a Inherent Label widget specified by *s* 318 | 319 | | Parameters | Description | 320 | |:----------:| ----------- | 321 | | index | Index number of target Inherent Label | 322 | | s | String object containing the text to print in the Inherent Label widget | 323 | 324 | String str = "This is string class"; 325 | genie.WriteInhLabel(0, Str); // Writes the String class 'str' to ILabelB0 326 | 327 | ### WriteInhLabel(uint16_t index, int n) 328 | Updates the Inherent Label widget specified by *index* with a new integer value *n* with base 10 329 | 330 | | Parameters | Description | 331 | |:----------:| ----------- | 332 | | index | Index number of target Inherent Label | 333 | | n | Signed short integer value that will be formatted with base 10 to a string and will be printed in the Inherent Label widget | 334 | 335 | genie.WriteInhLabel(0, 10000); // Writes the value 10000 to ILabelB0 336 | 337 | ### WriteInhLabel(uint16_t index, int n, int base) 338 | Updates the Inherent Label widget specified by *index* with a new integer value *n* with base specified by *base* 339 | 340 | | Parameters | Description | 341 | |:----------:| ----------- | 342 | | index | Index number of target Inherent Label | 343 | | n | Signed short integer value that will be formatted to a string and will be printed in the Inherent Label widget | 344 | | base | Custom base to used when formatting the value to a string | 345 | 346 | // Writes the value 10000 to ILabelB4 in hexadecimal 347 | genie.WriteInhLabel(4, 10000, 16); 348 | 349 | ### WriteInhLabel(uint16_t index, unsigned int n) 350 | Updates the Inherent Label widget specified by *index* with a new unsigned integer value *n* with base 10 351 | 352 | | Parameters | Description | 353 | |:----------:| ----------- | 354 | | index | Index number of target Inherent Label | 355 | | n | Unsigned short integer value that will be formatted with base 10 to a string and will be printed in the Inherent Label widget | 356 | 357 | unsigned int value = 40000; 358 | genie.WriteInhLabel(2, value); // Writes the value 40000 to ILabelB2 359 | 360 | ### WriteInhLabel(uint16_t index, unsigned int n, int base) 361 | Updates the Inherent Label widget specified by *index* with a new unsigned integer value *n* with base specified by *base* 362 | 363 | | Parameters | Description | 364 | |:----------:| ----------- | 365 | | index | Index number of target Inherent Label | 366 | | n | Unsigned short integer value that will be formatted to a string and will be printed in the Inherent Label widget | 367 | | base | Custom base to used when formatting the value to a string | 368 | 369 | unsigned int value = 40000; 370 | // Writes the value 40000 to ILabelB1 in hexadecimal 371 | genie.WriteInhLabel(1, value, 16); 372 | 373 | ### WriteInhLabel(uint16_t index, long n) 374 | Updates the Inherent Label widget specified by *index* with a new long value *n* with base 10 375 | 376 | | Parameters | Description | 377 | |:----------:| ----------- | 378 | | index | Index number of target Inherent Label | 379 | | n | Signed long integer value that will be formatted with base 10 to a string and will be printed in the Inherent Label widget | 380 | 381 | genie.WriteInhLabel(2, 100000L); // Writes the value 100000 to ILabelB2 382 | 383 | ### WriteInhLabel(uint16_t index, long n, int base) 384 | Updates the Inherent Label widget specified by *index* with a new long value *n* with base specified by *base* 385 | 386 | | Parameters | Description | 387 | |:----------:| ----------- | 388 | | index | Index number of target Inherent Label | 389 | | n | Signed long integer value that will be formatted to a string and will be printed in the Inherent Label widget | 390 | | base | Custom base to used when formatting the value to a string | 391 | 392 | // Writes the value 100000 to ILabelB3 in octal 393 | genie.WriteInhLabel(3, 100000L, 8); 394 | 395 | ### WriteInhLabel(uint16_t index, unsigned long n) 396 | Updates the Inherent Label widget specified by *index* with a new unsigned long value *n* with base 10 397 | 398 | | Parameters | Description | 399 | |:----------:| ----------- | 400 | | index | Index number of target Inherent Label | 401 | | n | Unsigned long integer value that will be formatted with base 10 to a string and will be printed in the Inherent Label widget | 402 | 403 | genie.WriteInhLabel(0, 3000000000UL); // Writes the value 3000000000 to ILabelB0 404 | 405 | ### WriteInhLabel(uint16_t index, unsigned long n, int base) 406 | Updates the Inherent Label widget specified by *index* with a new unsigned long value *n* with base specified by *base* 407 | 408 | | Parameters | Description | 409 | |:----------:| ----------- | 410 | | index | Index number of target Inherent Label | 411 | | n | Unsigned long integer value that will be formatted to a string and will be printed in the Inherent Label widget | 412 | | base | Custom base to used when formatting the value to a string | 413 | 414 | // Writes the value 3000000000 to ILabelB1 in hexadecimal 415 | genie.WriteInhLabel(1, 3000000000UL, 16); 416 | 417 | ### WriteInhLabel(uint16_t index, double n) 418 | Updates the Inherent Label widget specified by *index* with a new 64-bit float value *n* with 2 decimal digits 419 | 420 | | Parameters | Description | 421 | |:----------:| ----------- | 422 | | index | Index number of target Inherent Label | 423 | | n | Signed 64-bit float value that will be formatted to a string with 2 decimal places and will be printed in the Inherent Label widget | 424 | 425 | double value = 175.3456; 426 | // Writes the 64-bit float value 175.3456 to ILabelB0 427 | genie.WriteInhLabel(0, value); // with 2 decimal places (175.34) 428 | 429 | ### WriteInhLabel(uint16_t index, double n, digits) 430 | Updates the Inherent Label widget specified by *index* with a new 64-bit float value *n* with the number of decimal digits as specified by *digits* 431 | 432 | | Parameters | Description | 433 | |:----------:| ----------- | 434 | | index | Index number of target Inherent Label | 435 | | n | Signed 64-bit float value that will be formatted to a string and will be printed in the Inherent Label widget | 436 | | digits | Number of decimal places to format the value with | 437 | 438 | double value = 175.3456; 439 | // Writes the 64-bit float value 175.3456 to ILabelB0 440 | genie.WriteInhLabel(0, value, 4); // with 4 decimal places (175.3456) 441 | 442 | ### AttachEventHandler(UserEventHandlerPtr userHandler) 443 | Attach an event handler to handle messages from the display (ex. GENIE_REPORT_EVENT and GENIE_REPORT_OBJECT). Ideally, the handler function doesn't do anything that blocks for a long period since this would cause the command handling to be delayed. 444 | Please refer to the demos provided for more context of what this looks like when implemented. 445 | 446 | | Parameters | Description | 447 | |:-----------:| ----------- | 448 | | userHandler | Pointer to the handler function. The function should follow the format *void userHandler()* | 449 | 450 | - Usage Example 451 | 452 | genie.AttachEventHandler(myGenieEventHandler); // Attach the event handler 453 | // for processing messages 454 | 455 | - Handler Function Example 456 | 457 | void myGenieEventHandler(void) 458 | { 459 | genieFrame Event; // Prepare a genie frame container 460 | genie.DequeueEvent(&Event); // Store next message from display to 'Event' 461 | 462 | // Process event here (quickly), see example below 463 | 464 | // Check if the message stored in 'Event' is a GENIE_REPORT_EVENT from Slider0 465 | if (genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_SLIDER, 0)) 466 | { 467 | // Receive the event data from the Slider0 468 | slider_val = genie.GetEventData(&Event); 469 | // Write Slider0 value to LedDigits0 470 | genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, slider_val); 471 | } 472 | } 473 | 474 | ### DoEvents() 475 | This handles all the receiving of messages from the display and therefore should run as frequent as possible. This also calls the event handlers attached using *AttachEventHandler*, *AttachMagicByteReader* and *AttachMagicDoubleByteReader* 476 | This should be run in your main loop() or in a controlled function which runs as often as possible. 477 | 478 | void loop() 479 | { 480 | static long waitPeriod = millis(); 481 | genie.DoEvents(); // Run as frequently as possible for best experience 482 | 483 | if (millis() >= waitPeriod) 484 | { 485 | // Update the display here 486 | 487 | // Ensure that this code block only runs after ~100ms 488 | waitPeriod = millis() + 100; 489 | } 490 | } 491 | 492 | ### EventIs(genieFrame * e, uint8_t cmd, uint8_t object, uint8_t index) 493 | Returns true if the command stored in genieFrame *e* matches the criteria specified by *cmd*, *object* and *index*. Otherwise, returns false. 494 | 495 | | Parameters | Description | 496 | |:-----------:| ----------- | 497 | | e | Pointer to a genieFrame structure that specifies where the event under evaluation is stored | 498 | | cmd | Specifies the type of command expected of the message | 499 | | object | Specifies the type of widget from which the event is from | 500 | | index | Specifies the index of widget from which the event is from | 501 | 502 | // Check if the message stored in 'Event' is a GENIE_REPORT_EVENT from Slider0 503 | if (genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_SLIDER, 0)) 504 | { 505 | // Receive the event data from the Slider0 506 | slider_val = genie.GetEventData(&Event); 507 | // Write Slider0 value to LedDigits0 508 | genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, slider_val); 509 | } 510 | 511 | ### DequeueEvent(genieFrame * buff) 512 | Remove the next message from the queue and store it to genieFrame *buff*. This function should be used inside the custom event handler. 513 | 514 | | Parameters | Description | 515 | |:-----------:| ----------- | 516 | | buff | Pointer to a genieFrame structure that specifies where the next event should be stored | 517 | 518 | See *AttachEventHandler* for an example. 519 | 520 | ### GetEventData(genieFrame * e) 521 | Retrieves the 16-bit value from genieFrame *e* 522 | 523 | | Parameters | Description | 524 | |:-----------:| ----------- | 525 | | buff | Pointer to a genieFrame structure that specifies where the data to read is from | 526 | 527 | See *AttachEventHandler* for an example. 528 | 529 | ## ViSi Genie Pro Library Discussion 530 | ------------------------------------ 531 | 532 | ### AttachMagicByteReader(UserBytePtr userHandler) 533 | Attach an event handler to handle magic bytes from the display. Magic Bytes needs to be programmed using Magic features (ex. MagicTouch, MagicRelease, etc.) of ViSi Genie. 534 | 535 | It is suggested to store the data and process them later on to prevent a blocking delay. 536 | 537 | | Parameters | Description | 538 | |:-----------:| ----------- | 539 | | userHandler | Pointer to the handler function. The function should follow the format *void UserBytePtr(uint8_t, uint8_t)* | 540 | 541 | - Usage Example 542 | 543 | // Attach the event handler for processing magic bytes 544 | genie.AttachMagicByteReader(myMagicByteHandler); 545 | 546 | - Handler Function Example 547 | 548 | byte buffer0[255]; // Temporary buffer 0 to store the magic bytes 549 | byte buffer1[255]; // Temporary buffer 1 to store the magic bytes 550 | 551 | void myMagicByteHandler(uint8_t index, uint8_t len) 552 | { 553 | // If the magic bytes is coming from MagicObject0 554 | if (index == 0) { 555 | // Store the data to buffer0 556 | for (int i = 0; i < len; i++) { 557 | buffer0[i] = genie.GetNextByte(); 558 | } 559 | } 560 | // If the magic bytes is coming from MagicObject1 561 | if (index == 1) { 562 | // Store the data to buffer1 563 | for (int i = 0; i < len; i++) { 564 | buffer1[i] = genie.GetNextByte(); 565 | } 566 | } 567 | } 568 | 569 | ### AttachMagicDoubleByteReader(UserDoubleBytePtr userHandler) 570 | Attach an event handler to handle Magic Double Bytes from the display. Magic Double Bytes needs to be programmed using Magic features (ex. MagicTouch, MagicRelease, etc.) of ViSi Genie. 571 | 572 | It is suggested to store the data and process them later on to prevent a blocking delay. 573 | 574 | | Parameters | Description | 575 | |:-----------:| ----------- | 576 | | userHandler | Pointer to the handler function. The function should follow the format *void UserBytePtr(uint8_t, uint8_t)* | 577 | 578 | - Usage Example 579 | 580 | // Attach the event handler for processing magic double bytes 581 | genie.AttachMagicDoubleByteReader(myMagicDoubleByteHandler); 582 | 583 | - Handler Function Example 584 | 585 | uint16_t buffer0[255]; // Temporary buffer 0 to store the magic double bytes 586 | uint16_t buffer1[255]; // Temporary buffer 1 to store the magic double bytes 587 | 588 | void myMagicDoubleByteHandler(uint8_t index, uint8_t len) 589 | { 590 | // If the magic double bytes is coming from MagicObject0 591 | if (index == 0) { 592 | // Store the data to buffer0 593 | for (int i = 0; i < len; i++) { 594 | buffer0[i] = genie.GetNextDoubleByte(); 595 | } 596 | } 597 | // If the magic double bytes is coming from MagicObject1 598 | if (index == 1) { 599 | // Store the data to buffer1 600 | for (int i = 0; i < len; i++) { 601 | buffer1[i] = genie.GetNextDoubleByte(); 602 | } 603 | } 604 | } 605 | 606 | ### GetNextByte() 607 | This function can be utilized to receive next incoming byte from the display. This should be used when receiving magic bytes in the user byte handler. 608 | 609 | See *AttachMagicByteReader* for an example. 610 | 611 | ### GetNextDoubleByte() 612 | This function can be utilized to receive next two (2) incoming bytes from the display. This should be used when receiving magic double bytes in the user double byte handler. 613 | 614 | See *AttachMagicDoubleByteReader* for an example. 615 | 616 | ### WriteMagicBytes(uint16_t index, uint8_t *bytes, uint16_t len) 617 | Send magic *bytes* with size *len* to MagicObject specified by *index*. The specified MagicObject should be programmed to handle the magic bytes that will be sent by this function. 618 | 619 | | Parameters | Description | 620 | |:-----------:| ----------- | 621 | | index | Index of MagicObject that is programmed to receive and process the data | 622 | | bytes | Pointer to a byte array that specifies where the data is stored| 623 | | len | Specifies the number of bytes to send | 624 | 625 | uint8_t bytes[] = {0x34, 0x44, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x73}; 626 | genie.WriteMagicBytes(0, bytes, 10); // Writes 10 magic bytes to MagicObject0 627 | 628 | ### WriteMagicDBytes(uint16_t index, uint16_t *dbytes, uint16_t len) 629 | Send magic * bytes* with size *len* to MagicObject specified by *index*. The specified MagicObject should be programmed to handle the magic bytes that will be sent by this function. 630 | 631 | | Parameters | Description | 632 | |:-----------:| ----------- | 633 | | index | Index of MagicObject that is programmed to receive and process the data | 634 | | dbytes | Pointer to a 16-bit array that specifies where the data is stored| 635 | | len | Specifies the number of double bytes to send | 636 | 637 | uint16_t dbytes[] = {0x0034, 0x0044, 0x0020, 0x30B7, 0x30B9, 0x30C6, 0x30E0, 0x30BA}; 638 | genie.WriteMagicDBytes(1, dbytes, 8); // Writes 8 magic double bytes to MagicObject1 639 | 640 | ## Available Library Object Types 641 | --------------------------------- 642 | 643 | This section lists all of the objects/widgets that are available to be used by this library, which represent each of the widgets available to be placed using the Workshop4 IDE. 644 | 645 | These object names are inserted into the ReadObject and WriteObject functions (listed above), and data received back from them presents itself in the AttachEventHandler function. 646 | 647 | For more information on each of the actual Widgets in Workshop4, please refer to the Workshop4 Widgets Reference Manual - available on the Workshop4 Product page of the 4D Systems website. 648 | 649 | | Object Name | Description | 650 | | ----------- | ----------- | 651 | | GENIE_OBJ_DIPSW | Dip Switch Widget | 652 | | GENIE_OBJ_KNOB | Knob Widget | 653 | | GENIE_OBJ_ROCKERSW | Rocker Switch Widget | 654 | | GENIE_OBJ_ROTARYSW | Rotary Switch Widget | 655 | | GENIE_OBJ_SLIDER | Slider Widget | 656 | | GENIE_OBJ_TRACKBAR | Track Bar Widget | 657 | | GENIE_OBJ_WINBUTTON | Winbutton Widget | 658 | | GENIE_OBJ_ANGULAR_METER | Angular Meter Widget | 659 | | GENIE_OBJ_COOL_GAUGE | Cool Gauge Widget | 660 | | GENIE_OBJ_CUSTOM_DIGITS | Custom Digits Widget | 661 | | GENIE_OBJ_FORM | Form Widget | 662 | | GENIE_OBJ_GAUGE | Gauge Widget | 663 | | GENIE_OBJ_IMAGE | Image Widget | 664 | | GENIE_OBJ_KEYBOARD | Keyboard Widget | 665 | | GENIE_OBJ_LED | LED Widget | 666 | | GENIE_OBJ_LED_DIGITS | LED Digits Widget | 667 | | GENIE_OBJ_METER | Meter Widget | 668 | | GENIE_OBJ_STRINGS | String Widget | 669 | | GENIE_OBJ_THERMOMETER | Thermometer Widget | 670 | | GENIE_OBJ_USER_LED | User LED Widget | 671 | | GENIE_OBJ_VIDEO | Video Widget | 672 | | GENIE_OBJ_STATIC_TEXT | Static Text Widget | 673 | | GENIE_OBJ_SOUND | Sound Widget | 674 | | GENIE_OBJ_TIMER | Timer Widget | 675 | | GENIE_OBJ_SPECTRUM | Spectrum Widget | 676 | | GENIE_OBJ_SCOPE | Scope Widget | 677 | | GENIE_OBJ_TANK | Tank Widget | 678 | | GENIE_OBJ_USERIMAGES | User Images Widget | 679 | | GENIE_OBJ_PINOUTPUT | Pin Output Widget | 680 | | GENIE_OBJ_PININPUT | Pin Input Widget | 681 | | GENIE_OBJ_4DBUTTON | 4D Button Widget | 682 | | GENIE_OBJ_ANIBUTTON | Animated Button Widget | 683 | | GENIE_OBJ_COLORPICKER | Colour Picker Widget | 684 | | GENIE_OBJ_USERBUTTON | User Button Widget | 685 | | GENIE_OBJ_SMARTGAUGE | Smart Gauge Widget (PRO Only) | 686 | | GENIE_OBJ_SMARTSLIDER | Smart Slider Widget (PRO Only) | 687 | | GENIE_OBJ_SMARTKNOB | Smart Knob Widget (PRO Only) | 688 | | GENIE_OBJ_ILED_DIGITS_H | Internal LED Digits Widget - High Byte | 689 | | GENIE_OBJ_ILED_DIGITS_L | Internal LED Digits Widget - Low Byte | 690 | | GENIE_OBJ_IANGULAR_METER | Internal Angular Meter Widget | 691 | | GENIE_OBJ_IGAUGE | Internal Gauge Widget | 692 | | GENIE_OBJ_ILED | Internal LED Widget | 693 | | GENIE_OBJ_INEEDLE | Internal Needle Widget | 694 | | GENIE_OBJ_IRULER | Internal Ruler Widget | 695 | | GENIE_OBJ_ILED_DIGIT | Internal LED Digit Widget | 696 | | GENIE_OBJ_ILED_DIGITS | Internal LED Digits Widget | 697 | | GENIE_OBJ_IBUTTOND | Internal Button D Widget | 698 | | GENIE_OBJ_IDIAL | Internal Dial Widget | 699 | | GENIE_OBJ_ISWITCH | Internal Switch Widget | 700 | | GENIE_OBJ_ISLIDERE | Internal Slider E Widget | 701 | | GENIE_OBJ_IBUTTONE | Inherent Button E Widget | 702 | | GENIE_OBJ_ITOGGLE_INPUT | Inherent Toggle Input Widget | 703 | | GENIE_OBJ_ILABELB | Inherent Label B Widget | 704 | | GENIE_OBJ_IUSER_GAUGE | Inherent User Gauge Widget | 705 | | GENIE_OBJ_IMEDIA_BUTTON | Inherent Media Button Widget | 706 | | GENIE_OBJ_IMEDIA_GAUGE | Inherent Media Gauge Widget | 707 | | GENIE_OBJ_IMEDIA_THERMOMETER | Inherent Media Thermometer Widget | 708 | | GENIE_OBJ_IMEDIA_ROTARY | Inherent Media Rotary Widget | 709 | | GENIE_OBJ_IMEDIA_LED | Inherent Media LED Widget | 710 | | GENIE_OBJ_IMEDIA_SLIDER | Inherent Media Slider Widget | 711 | | GENIE_OBJ_IROTARY_INPUT | Inherent Rotary Input Widget | 712 | | GENIE_OBJ_ISWITCHB | Inherent Switch B Widget | 713 | | GENIE_OBJ_ISLIDERH | Inherent Slider H Widget | 714 | | GENIE_OBJ_ISLIDERG | Inherent Slider G Widget | 715 | | GENIE_OBJ_ISLIDERF | Inherent Slider F Widget | 716 | | GENIE_OBJ_ISLIDERD | Inherent Slider D Widget | 717 | | GENIE_OBJ_ISLIDERC | Inherent Slider C Widget | 718 | | GENIE_OBJ_ILINEAR_INPUT | Inherent Linear Input Widget | 719 | 720 | ## Questions/Issues? 721 | 722 | Please sign up for our Forum and ask a question there, or submit a Tech Support Ticket from our website. 723 | http://forum.4dsystems.com.au or http://www.4dsystems.com.au/support 724 | Feel free to add a Github issue if you find a problem, we will do our best to help solve the problem. 725 | -------------------------------------------------------------------------------- /examples/WriteInhLabel_Demo/WriteInhLabel_Demo.ino: -------------------------------------------------------------------------------- 1 | /****************************************************************************************** 2 | * Write Inherent Label (B) Test - Demo application 3 | * This demo simply illustrates the various ways you can now send data to an Inherent Label 4 | * object in ViSi-Genie, from an Arduino. 5 | * 6 | * Demo uses Hardware Serial0 to communicate with the 4D Systems display module. 7 | * Simply create a Workshop4 Genie application for your 4D Systems display module, 8 | * and place a single 'Inherent Label B' object on the display, and download it to your module. 9 | * It will have the ID ILabelB0. This is then populated with data in the demo code below. 10 | * 11 | * PLEASE NOTE: If you are using a non-AVR Arduino, such as a Due, or other variants 12 | * such as a Chipkit or Teensy, then you will need to comment out the Flash String 13 | * line below - Line 62, as it will prevent the demo from compiling. 14 | */ 15 | 16 | #include 17 | 18 | Genie genie; 19 | 20 | #define RESETLINE 4 // Change this if you are not using an Arduino Adaptor Shield Version 2 (see code below) 21 | 22 | // Setup function 23 | void setup() 24 | { 25 | // Use a Serial Begin and serial port of your choice in your code and use the genie.Begin function to send 26 | // it to the Genie library (see this example below) 27 | // max of 200K Baud is good for most Arduinos. Galileo should use 115200 or below. 28 | // Some Arduino variants use Serial1 for the TX/RX pins, as Serial0 is for USB. 29 | Serial.begin(9600); // Serial0 @ 9600 Baud 30 | genie.Begin(Serial); // Use Serial0 for talking to the Genie Library, and to the 4D Systems display 31 | 32 | // Reset the Display (change D4 to D2 if you have original 4D Arduino Adaptor) 33 | // THIS IS IMPORTANT AND CAN PREVENT OUT OF SYNC ISSUES, SLOW SPEED RESPONSE ETC 34 | // If NOT using a 4D Arduino Adaptor, digitalWrites must be reversed as Display Reset is Active Low, and 35 | // the 4D Arduino Adaptors invert this signal so must be Active High. 36 | pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset) 37 | digitalWrite(RESETLINE, 1); // Reset the Display via D4 38 | delay(100); 39 | digitalWrite(RESETLINE, 0); // unReset the Display via D4 40 | 41 | delay (3500); //let the display start up after the reset (This is important) 42 | } 43 | 44 | // Main loop 45 | void loop() 46 | { 47 | //An optional third parameter specifies the base (format) to use; permitted values are BIN (binary, or base 2), OCT (octal, or base 8), DEC (decimal, or base 10), HEX (hexadecimal, or base 16). 48 | //For floating point numbers, this parameter specifies the number of decimal places to use. 49 | int x = -78; 50 | long y = 171; 51 | double z = 175.3456; 52 | int digits = 3; 53 | int temperature1 = 150; 54 | float temperature2 = 12.3; 55 | String Str = "This is string class"; 56 | genie.WriteInhLabel(0, "TEST"); // Write to ILabelB0 Object, with the string "TEST" 57 | delay(1000); 58 | genie.WriteInhLabel(0, z, digits); //3 decimal places 59 | delay(1000); 60 | genie.WriteInhLabel(0, 123.45678, 5); // 5 decimal places 61 | delay(1000); 62 | genie.WriteInhLabel(0, 123.45678); // 2 decimal places by default if no value is given to decimal place. 63 | delay(1000); 64 | genie.WriteInhLabel(0, F("This string will be \n stored in flash memory")); // For AVR Arduinos only - Needs to be commented out for Due, Chipkit, Teensy etc. 65 | delay(1000); 66 | genie.WriteInhLabel(0, " "); // Clear 67 | delay(10); 68 | genie.WriteInhLabel(0, x); //prints negative integer 69 | delay(1000); 70 | genie.WriteInhLabel(0, y); 71 | delay(1000); 72 | genie.WriteInhLabel(0, -x, BIN); //base 2 of 78 73 | delay(1000); 74 | genie.WriteInhLabel(0, y, 16); //base 16 75 | delay(1000); 76 | genie.WriteInhLabel(0, 10); //base 10 by default 77 | delay(1000); 78 | genie.WriteInhLabel(0, 10, 8); //base 8 79 | delay(1000); 80 | genie.WriteInhLabel(0, Str); //prints String Class 81 | delay(1000); 82 | unsigned int zc = 123 ; 83 | genie.WriteInhLabel(0, zc); //prints unsigned ints 84 | delay(1000); 85 | unsigned long e = 1234 ; 86 | genie.WriteInhLabel(0, e); //prints unsigned long 87 | delay(1000); 88 | genie.WriteInhLabel(0); //prints the default information programmed into properties in WS4 89 | delay(1000); 90 | genie.WriteInhLabel(0, (String) temperature1 + (String) "\xB0"); // 150 with degree symbol (Standard Arial ANSI font, not Unicode) 91 | delay(1000); 92 | genie.WriteInhLabel(0, (String) temperature2 + char(176) ); // same as above, done slightly differently 93 | delay(1000); 94 | } 95 | -------------------------------------------------------------------------------- /examples/WriteStr_Demo/WriteStr_Demo.ino: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * Write String Test - Demo application 3 | * This demo simply illustrates the various ways you can now send data to a String 4 | * object in ViSi-Genie, from an Arduino. 5 | * 6 | * Demo uses Hardware Serial0 to communicate with the 4D Systems display module. 7 | * Simply create a Workshop4 Genie application for your 4D Systems display module, 8 | * and place a single 'Strings' object on the display, and download it to your module. 9 | * It will have the ID Strings0. This is then populated with data in the demo code below. 10 | * 11 | * PLEASE NOTE: If you are using a non-AVR Arduino, such as a Due, or other variants 12 | * such as a Chipkit or Teensy, then you will need to comment out the Flash String 13 | * line below - Line 60, as it will prevent the demo from compiling. 14 | */ 15 | 16 | #include 17 | 18 | Genie genie; 19 | 20 | #define RESETLINE 4 // Change this if you are not using an Arduino Adaptor Shield Version 2 (see code below) 21 | 22 | // Setup function 23 | void setup() 24 | { 25 | // Use a Serial Begin and serial port of your choice in your code and use the genie.Begin function to send 26 | // it to the Genie library (see this example below) 27 | // max of 200K Baud is good for most Arduinos. Galileo should use 115200 or below. 28 | // Some Arduino variants use Serial1 for the TX/RX pins, as Serial0 is for USB. 29 | Serial.begin(9600); // Serial0 @ 9600 Baud 30 | genie.Begin(Serial); // Use Serial0 for talking to the Genie Library, and to the 4D Systems display 31 | 32 | // Reset the Display (change D4 to D2 if you have original 4D Arduino Adaptor) 33 | // THIS IS IMPORTANT AND CAN PREVENT OUT OF SYNC ISSUES, SLOW SPEED RESPONSE ETC 34 | // If NOT using a 4D Arduino Adaptor, digitalWrites must be reversed as Display Reset is Active Low, and 35 | // the 4D Arduino Adaptors invert this signal so must be Active High. 36 | pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset) 37 | digitalWrite(RESETLINE, 1); // Reset the Display via D4 38 | delay(100); 39 | digitalWrite(RESETLINE, 0); // unReset the Display via D4 40 | 41 | delay (3500); //let the display start up after the reset (This is important) 42 | } 43 | 44 | // Main loop 45 | void loop() 46 | { 47 | //An optional third parameter specifies the base (format) to use; permitted values are BIN (binary, or base 2), OCT (octal, or base 8), DEC (decimal, or base 10), HEX (hexadecimal, or base 16). 48 | //For floating point numbers, this parameter specifies the number of decimal places to use. 49 | int x = -78; 50 | long y = 171; 51 | double z = 175.3456; 52 | int digits = 3; 53 | int temperature1 = 150; 54 | float temperature2 = 12.3; 55 | String Str = "This is string class"; 56 | genie.WriteStr(0, "TEST"); // Write to String0 Object, with the string "TEST" 57 | delay(1000); 58 | genie.WriteStr(0, z, digits); //3 decimal places 59 | delay(1000); 60 | genie.WriteStr(0, 123.45678, 5); // 5 decimal places 61 | delay(1000); 62 | genie.WriteStr(0, 123.45678); // 2 decimal places by default if no value is given to decimal place. 63 | delay(1000); 64 | genie.WriteStr(0, F("This string will be \n stored in flash memory")); // For AVR Arduinos only - Needs to be commented out for Due, Chipkit, Teensy etc. 65 | delay(1000); 66 | genie.WriteStr(0, " "); // Clear 67 | delay(10); 68 | genie.WriteStr(0, x); //prints negative integer 69 | delay(1000); 70 | genie.WriteStr(0, y); 71 | delay(1000); 72 | genie.WriteStr(0, -x, BIN); //base 2 of 78 73 | delay(1000); 74 | genie.WriteStr(0, y,16); //base 16 75 | delay(1000); 76 | genie.WriteStr(0, 10); //base 10 by default 77 | delay(1000); 78 | genie.WriteStr(0, 10,8); //base 8 79 | delay(1000); 80 | genie.WriteStr(0, Str); //prints String Class 81 | delay(1000); 82 | unsigned int zc = 123 ; 83 | genie.WriteStr(0, zc); //prints unsigned ints 84 | delay(1000); 85 | unsigned long e = 1234 ; 86 | genie.WriteStr(0, e); //prints unsigned long 87 | delay(1000); 88 | genie.WriteStr(0, (String) temperature1 + (String) "\xB0"); // 150 with degree symbol (Standard Arial ANSI font, not Unicode) 89 | delay(1000); 90 | genie.WriteStr(0, (String) temperature2 + char(176) ); // same as above, done slightly differently 91 | delay(1000); 92 | } 93 | 94 | 95 | -------------------------------------------------------------------------------- /examples/genieArduino_Demo/genieArduino_Demo.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // This Demo communicates with a 4D Systems Display, configured with ViSi-Genie, utilising the Genie Arduino Library - https://github.com/4dsystems/ViSi-Genie-Arduino-Library. 4 | // The display has a slider, a cool gauge, an LED Digits, a string box and a User LED. Workshop4 Demo Project is located in the /extras folder 5 | // The program receives messages from the Slider0 object using the Reported Events. This is triggered each time the Slider changes on the display, and an event 6 | // is genereated and sent automatically. Reported Events originate from the On-Changed event from the slider itself, set in the Workshop4 software. 7 | // Coolgauge is written to using Write Object, and the String is updated using the Write String command, showing the version of the library. 8 | // The User LED is updated by the Arduino, by first doing a manual read of the User LED and then toggling it based on the state received back. 9 | 10 | // As the slider changes, it sends its value to the Arduino (Arduino also polls its value using genie.ReadObject, as above), and the Arduino then 11 | // tells the LED Digit to update its value using genie.WriteObject. So the Slider message goes via the Arduino to the LED Digit. 12 | // Coolgauge is updated via simple timer in the Arduino code, and updates the display with its value. 13 | // The User LED is read using genie.ReadObject, and then updated using genie.WriteObject. It is manually read, it does not use an Event. 14 | 15 | // This demo illustrates how to use genie.ReadObject, genie.WriteObject, Reported Messages (Events), genie.WriteStr, genie.WriteContrast, plus supporting functions. 16 | 17 | // Application Notes on the 4D Systems Website that are useful to understand this library are found: https://docs.4dsystems.com.au/app-notes 18 | // Good App Notes to read are: 19 | // ViSi-Genie Connecting a 4D Display to an Arduino Host - https://docs.4dsystems.com.au/app-note/4D-AN-00017/ 20 | // ViSi-Genie Writing to Genie Objects Using an Arduino Host - https://docs.4dsystems.com.au/app-note/4D-AN-00018/ 21 | // ViSi-Genie A Simple Digital Voltmeter Application using an Arduino Host - https://docs.4dsystems.com.au/app-note/4D-AN-00019/ 22 | // ViSi-Genie Connection to an Arduino Host with RGB LED Control - https://docs.4dsystems.com.au/app-note/4D-AN-00010/ 23 | // ViSi-Genie Displaying Temperature values from an Arduino Host - https://docs.4dsystems.com.au/app-note/4D-AN-00015/ 24 | // ViSi-Genie Arduino Danger Shield - https://docs.4dsystems.com.au/app-note/4D-AN-00025 25 | 26 | Genie genie; 27 | #define RESETLINE 4 // Change this if you are not using an Arduino Adaptor Shield Version 2 (see code below) 28 | void setup() 29 | { 30 | // Use a Serial Begin and serial port of your choice in your code and use the 31 | // genie.Begin function to send it to the Genie library (see this example below) 32 | // 200K Baud is good for most Arduinos. Galileo should use 115200. 33 | // Some Arduino variants use Serial1 for the TX/RX pins, as Serial0 is for USB. 34 | Serial.begin(200000); // Serial0 @ 200000 (200K) Baud 35 | genie.Begin(Serial); // Use Serial0 for talking to the Genie Library, and to the 4D Systems display 36 | 37 | genie.AttachEventHandler(myGenieEventHandler); // Attach the user function Event Handler for processing events 38 | 39 | // Reset the Display (change D4 to D2 if you have original 4D Arduino Adaptor) 40 | // THIS IS IMPORTANT AND CAN PREVENT OUT OF SYNC ISSUES, SLOW SPEED RESPONSE ETC 41 | // If NOT using a 4D Arduino Adaptor, digitalWrites must be reversed as Display Reset is Active Low, and 42 | // the 4D Arduino Adaptors invert this signal so must be Active High. 43 | pinMode(RESETLINE, OUTPUT); // Set D4 on Arduino to Output (4D Arduino Adaptor V2 - Display Reset) 44 | digitalWrite(RESETLINE, 1); // Reset the Display via D4 45 | delay(100); 46 | digitalWrite(RESETLINE, 0); // unReset the Display via D4 47 | 48 | // Let the display start up after the reset (This is important) 49 | // Increase to 4500 or 5000 if you have sync problems as your project gets larger. Can depent on microSD init speed. 50 | delay (3500); 51 | 52 | // Set the brightness/Contrast of the Display - (Not needed but illustrates how) 53 | // Most Displays use 0-15 for Brightness Control, where 0 = Display OFF, though to 15 = Max Brightness ON. 54 | // Some displays are more basic, 1 (or higher) = Display ON, 0 = Display OFF. 55 | genie.WriteContrast(10); // About 2/3 Max Brightness 56 | 57 | //Write to String0 on the Display to show the version of the library used 58 | genie.WriteStr(0, GENIE_VERSION); 59 | //OR to illustrate (comment out the above, uncomment the below) 60 | genie.WriteStr(0, (String) "Hello 4D World"); 61 | } 62 | 63 | void loop() 64 | { 65 | static unsigned long waitPeriod = millis(); 66 | static int gaugeAddVal = 1; // Simulation code variable. Value to change the gauge by each loop 67 | static int gaugeVal = 50; // Simulation code variable. Value to start the gauge at when powered on 68 | 69 | genie.DoEvents(); // This calls the library each loop to process the queued responses from the display 70 | 71 | if (millis() >= waitPeriod) 72 | { 73 | // Write to CoolGauge0 with the value in the gaugeVal variable 74 | genie.WriteObject(GENIE_OBJ_COOL_GAUGE, 0, gaugeVal); 75 | 76 | // Simulation code, just to increment and decrement gauge value each loop, for animation 77 | gaugeVal += gaugeAddVal; 78 | if (gaugeVal == 99) gaugeAddVal = -1; 79 | if (gaugeVal == 0) gaugeAddVal = 1; 80 | 81 | // The results of this call will be available to myGenieEventHandler() after the display has responded 82 | genie.ReadObject(GENIE_OBJ_USER_LED, 0); // Do a manual read from the UserLEd0 object 83 | 84 | waitPeriod = millis() + 50; // rerun this code to update Cool Gauge and Slider in another 50ms time. 85 | } 86 | } 87 | 88 | ///////////////////////////////////////////////////////////////////// 89 | // 90 | // This is the user's event handler. It is called by genieDoEvents() 91 | // when the following conditions are true 92 | // 93 | // The link is in an IDLE state, and 94 | // There is an event to handle 95 | // 96 | // The event can be either a REPORT_EVENT frame sent asynchronously 97 | // from the display or a REPORT_OBJ frame sent by the display in 98 | // response to a READ_OBJ (genie.ReadObject) request. 99 | // 100 | 101 | /* COMPACT VERSION HERE, LONGHAND VERSION BELOW WHICH MAY MAKE MORE SENSE 102 | void myGenieEventHandler(void) 103 | { 104 | genieFrame Event; 105 | genie.DequeueEvent(&Event); 106 | 107 | int slider_val = 0; 108 | 109 | //Filter Events from Slider0 (Index = 0) for a Reported Message from Display 110 | if (genie.EventIs(&Event, GENIE_REPORT_EVENT, GENIE_OBJ_SLIDER, 0)) 111 | { 112 | slider_val = genie.GetEventData(&Event); // Receive the event data from the Slider0 113 | genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, slider_val); // Write Slider0 value to LED Digits 0 114 | } 115 | 116 | //Filter Events from UserLed0 (Index = 0) for a Reported Object from Display (triggered from genie.ReadObject in User Code) 117 | if (genie.EventIs(&Event, GENIE_REPORT_OBJ, GENIE_OBJ_USER_LED, 0)) 118 | { 119 | bool UserLed0_val = genie.GetEventData(&Event); // Receive the event data from the UserLed0 120 | UserLed0_val = !UserLed0_val; // Toggle the state of the User LED Variable 121 | genie.WriteObject(GENIE_OBJ_USER_LED, 0, UserLed0_val); // Write UserLed0_val value back to UserLed0 122 | } 123 | } */ 124 | 125 | // LONG HAND VERSION, MAYBE MORE VISIBLE AND MORE LIKE VERSION 1 OF THE LIBRARY 126 | void myGenieEventHandler(void) 127 | { 128 | genieFrame Event; 129 | genie.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below 130 | 131 | int slider_val = 0; 132 | 133 | //If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects) 134 | if (Event.reportObject.cmd == GENIE_REPORT_EVENT) 135 | { 136 | if (Event.reportObject.object == GENIE_OBJ_SLIDER) // If the Reported Message was from a Slider 137 | { 138 | if (Event.reportObject.index == 0) // If Slider0 (Index = 0) 139 | { 140 | slider_val = genie.GetEventData(&Event); // Receive the event data from the Slider0 141 | genie.WriteObject(GENIE_OBJ_LED_DIGITS, 0, slider_val); // Write Slider0 value to LED Digits 0 142 | } 143 | } 144 | } 145 | 146 | //If the cmd received is from a Reported Object, which occurs if a Read Object (genie.ReadOject) is requested in the main code, reply processed here. 147 | if (Event.reportObject.cmd == GENIE_REPORT_OBJ) 148 | { 149 | if (Event.reportObject.object == GENIE_OBJ_USER_LED) // If the Reported Message was from a User LED 150 | { 151 | if (Event.reportObject.index == 0) // If UserLed0 (Index = 0) 152 | { 153 | bool UserLed0_val = genie.GetEventData(&Event); // Receive the event data from the UserLed0 154 | UserLed0_val = !UserLed0_val; // Toggle the state of the User LED Variable 155 | genie.WriteObject(GENIE_OBJ_USER_LED, 0, UserLed0_val); // Write UserLed0_val value back to UserLed0 156 | } 157 | } 158 | } 159 | 160 | /********** This can be expanded as more objects are added that need to be captured ************* 161 | ************************************************************************************************* 162 | Event.reportObject.cmd is used to determine the command of that event, such as an reported event 163 | Event.reportObject.object is used to determine the object type, such as a Slider 164 | Event.reportObject.index is used to determine the index of the object, such as Slider0 165 | genie.GetEventData(&Event) us used to save the data from the Event, into a variable. 166 | *************************************************************************************************/ 167 | } 168 | 169 | -------------------------------------------------------------------------------- /examples/genieArduino_Demo_MultiScreen/genieArduino_Demo_MultiScreen.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // This Demo extends the genieArduino_Demo, by showing how to use more than 1 screen at a time, attached to an Arduino with 2+ Serial Ports. 4 | // This Demo uses the same WS4 Genie program on both displays, in this case, 2x gen4-uLCD-32DCT-CLB's, and an Arduino Mega. 5 | // Workshop4 Demo Project is located in the /extras folder 6 | // NOTE: Both displays must be connected for this demo to function. 7 | 8 | // This Demo communicates with 2 4D Systems Displays, configured with ViSi-Genie, utilising the Genie Arduino Library - https://github.com/4dsystems/ViSi-Genie-Arduino-Library. 9 | // The display demo has a slider, a cool gauge, an LED Digits, a string box and a User LED. 10 | // The program receives messages from the Slider0 object on each display using the Reported Events. This is triggered each time the Slider changes on the display, and an event 11 | // is genereated and sent automatically. Reported Events originate from the On-Changed event from the slider itself, set in the Workshop4 software. 12 | // Coolgauge is written to using Write Object, and the String is updated using the Write String command, showing the version of the library. 13 | // The User LED is updated by the Arduino, by first doing a manual read of the User LED and then toggling it based on the state received back. 14 | 15 | // As the slider changes, it sends its value to the Arduino (Arduino also polls its value using genie.ReadObject, as above), and the Arduino then 16 | // tells the LED Digit to update its value using genie.WriteObject, but of the other displays LED Digit! So the Slider message goes via the Arduino to the LED Digit 17 | // of the other display. 18 | // Coolgauge is updated via simple timer in the Arduino code, and updates the display with its value. 19 | // The User LED is read using genie.ReadObject, and then updated using genie.WriteObject. It is manually read, it does not use an Event. 20 | 21 | // This demo illustrates how to use genie.ReadObject, genie.WriteObject, Reported Messages (Events), genie.WriteStr, genie.WriteContrast, plus supporting functions. 22 | 23 | // Application Notes on the 4D Systems Website that are useful to understand this library are found: https://docs.4dsystems.com.au/app-notes 24 | // Good App Notes to read are: 25 | // ViSi-Genie Connecting a 4D Display to an Arduino Host - https://docs.4dsystems.com.au/app-note/4D-AN-00017/ 26 | // ViSi-Genie Writing to Genie Objects Using an Arduino Host - https://docs.4dsystems.com.au/app-note/4D-AN-00018/ 27 | // ViSi-Genie A Simple Digital Voltmeter Application using an Arduino Host - https://docs.4dsystems.com.au/app-note/4D-AN-00019/ 28 | // ViSi-Genie Connection to an Arduino Host with RGB LED Control - https://docs.4dsystems.com.au/app-note/4D-AN-00010/ 29 | // ViSi-Genie Displaying Temperature values from an Arduino Host - https://docs.4dsystems.com.au/app-note/4D-AN-00015/ 30 | // ViSi-Genie Arduino Danger Shield - https://docs.4dsystems.com.au/app-note/4D-AN-00025 31 | 32 | Genie display1; // Genie Display 1 33 | Genie display2; // Genie Display 2 34 | #define RESETLINE1 4 // Reset pin attached to Display 1 35 | #define RESETLINE2 2 // Reset pin attached to Display 2 36 | 37 | void setup() 38 | { 39 | // Use a Serial Begin and serial port of your choice in your code and use the genie.Begin function to send 40 | // it to the Genie library (see this example below) 41 | // 200K Baud is good for most Arduinos. Galileo should use 115200. 42 | 43 | Serial.begin(200000); // Serial0 @ 200000 (200K) Baud 44 | display1.Begin(Serial); // Use Serial0 for talking to the Genie Library, and to the 4D Systems display #1 45 | 46 | Serial1.begin(200000); // Serial1 @ 200000 (200K) Baud 47 | display2.Begin(Serial1); // Use Serial1 for talking to the Genie Library, and to the 4D Systems display #2 48 | 49 | display1.AttachEventHandler(myGenieEventHandler1); // Attach the user function Event Handler for processing events for display 1 50 | display2.AttachEventHandler(myGenieEventHandler2); // Attach the user function Event Handler for processing events for display 2 51 | 52 | // Reset the Displays 53 | // THIS IS IMPORTANT AND CAN PREVENT OUT OF SYNC ISSUES, SLOW SPEED RESPONSE ETC 54 | pinMode(RESETLINE1, OUTPUT); // Set D4 on Arduino to Output to control the reset line to Display 1 55 | pinMode(RESETLINE2, OUTPUT); // Set D2 on Arduino to Output to control the reset line to Display 2 56 | digitalWrite(RESETLINE1, 1); // Reset Display 1 57 | digitalWrite(RESETLINE2, 1); // Reset Display 2 58 | delay(100); 59 | digitalWrite(RESETLINE1, 0); // unReset Display 1 60 | digitalWrite(RESETLINE2, 0); // unReset Display 2 61 | 62 | // Let the display start up after the reset (This is important) 63 | // Increase to 4500 or 5000 if you have sync problems as your project gets larger. Can depent on microSD init speed. 64 | delay (3500); 65 | 66 | // Set the brightness/Contrast of the Display - (Not needed but illustrates how) 67 | // Most Displays use 0-15 for Brightness Control, where 0 = Display OFF, though to 15 = Max Brightness ON. 68 | // Some displays are more basic, 1 (or higher) = Display ON, 0 = Display OFF. 69 | display1.WriteContrast(10); // Display ON 10/15 brightness 70 | display2.WriteContrast(5); // Display ON 5/15 brightness 71 | 72 | //Write a string to the Display to identify each display 73 | display1.WriteStr(0, "Hello Display 1"); 74 | display2.WriteStr(0, "Hello Display 2"); 75 | } 76 | 77 | void loop() 78 | { 79 | static unsigned long waitPeriod = millis(); // Time now 80 | 81 | static int gaugeAddVal1 = 1; // Set the value at which the Gauge on Display 1 increases by initially 82 | static int gaugeVal1 = 10; // Starting Value for Gauge on Display 1 83 | static int gaugeAddVal2 = 2; // Set the value at which the Gauge on Display 2 increases by initially 84 | static int gaugeVal2 = 50; // Starting Value for Gauge on Display 2 85 | 86 | display1.DoEvents(); // This calls the library each loop to process the queued responses from display 1 87 | display2.DoEvents(); // This calls the library each loop to process the queued responses from display 2 88 | 89 | if (millis() >= waitPeriod) 90 | { 91 | // Write to CoolGauge0 with the value in the gaugeVal variable on Display 1 92 | display1.WriteObject(GENIE_OBJ_COOL_GAUGE, 0, gaugeVal1); 93 | 94 | // Simulation code for Gauge on Display 1, just to increment and decrement gauge value each loop, for animation 95 | gaugeVal1 += gaugeAddVal1; 96 | if (gaugeVal1 >= 99) gaugeAddVal1 = -1; // If the value is > or = to 99, make gauge decrease in value by 1 97 | if (gaugeVal1 <= 0) gaugeAddVal1 = 1; // If the value is < or = to 0, make gauge increase in value by 1 98 | 99 | // The results of this call will be available to myGenieEventHandler() after the display has responded 100 | // Do a manual read from the UserLEd0 object on Display 1 101 | display1.ReadObject(GENIE_OBJ_USER_LED, 0); 102 | 103 | // Write to CoolGauge0 with the value in the gaugeVal variable on Display 2 104 | display2.WriteObject(GENIE_OBJ_COOL_GAUGE, 0, gaugeVal2); 105 | 106 | // Simulation code for Gauge on Display 2, just to increment and decrement gauge value each loop, for animation 107 | gaugeVal2 += gaugeAddVal2; 108 | if (gaugeVal2 >= 99) gaugeAddVal2 = -2; // If the value is > or = to 99, make gauge decrease in value by 2 109 | if (gaugeVal2 <= 0) gaugeAddVal2 = 2; // If the value is < or = to 0, make gauge increase in value by 2 110 | 111 | // The results of this call will be available to myGenieEventHandler() after the display has responded 112 | // Do a manual read from the UserLed0 object on Display 2 113 | display2.ReadObject(GENIE_OBJ_USER_LED, 0); 114 | 115 | waitPeriod = millis() + 50; // rerun this code to update Cool Gauge and Slider in another 50ms time. 116 | } 117 | } 118 | 119 | ///////////////////////////////////////////////////////////////////// 120 | // 121 | // This is the user's event handler. It is called by the DoEvents() 122 | // when the following conditions are true 123 | // 124 | // The link is in an IDLE state, and 125 | // There is an event to handle 126 | // 127 | // The event can be either a REPORT_EVENT frame sent asynchronously 128 | // from the display or a REPORT_OBJ frame sent by the display in 129 | // response to a READ_OBJ (genie.ReadObject) request. 130 | // 131 | 132 | // Event Handler Function for Display 1 133 | void myGenieEventHandler1(void) 134 | { 135 | genieFrame Event; 136 | display1.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below 137 | 138 | //If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects) 139 | if (Event.reportObject.cmd == GENIE_REPORT_EVENT) 140 | { 141 | if (Event.reportObject.object == GENIE_OBJ_SLIDER) // If the Reported Message was from a Slider 142 | { 143 | if (Event.reportObject.index == 0) // If Slider0 (Index = 0) 144 | { 145 | int slider_val = display1.GetEventData(&Event); // Receive the event data from the Slider0 146 | display2.WriteObject(GENIE_OBJ_LED_DIGITS, 0, slider_val); // Write Slider0 value of Display 1 to to LED Digits 0 of Display 2 ! 147 | } 148 | } 149 | } 150 | 151 | //If the cmd received is from a Reported Object, which occurs if a Read Object (genie.ReadOject) is requested in the main code, reply processed here. 152 | if (Event.reportObject.cmd == GENIE_REPORT_OBJ) 153 | { 154 | if (Event.reportObject.object == GENIE_OBJ_USER_LED) // If the Reported Message was from a User LED 155 | { 156 | if (Event.reportObject.index == 0) // If UserLed0 (Index = 0) 157 | { 158 | bool UserLed0_val = display1.GetEventData(&Event); // Receive the event data from the UserLed0 159 | UserLed0_val = !UserLed0_val; // Toggle the state of the User LED Variable 160 | display1.WriteObject(GENIE_OBJ_USER_LED, 0, UserLed0_val); // Write UserLed0_val value back to to UserLed0 161 | } 162 | } 163 | } 164 | } 165 | 166 | // Event Handler Function for Display 2 167 | void myGenieEventHandler2(void) 168 | { 169 | genieFrame Event; 170 | display2.DequeueEvent(&Event); // Remove the next queued event from the buffer, and process it below 171 | 172 | //If the cmd received is from a Reported Event (Events triggered from the Events tab of Workshop4 objects) 173 | if (Event.reportObject.cmd == GENIE_REPORT_EVENT) 174 | { 175 | if (Event.reportObject.object == GENIE_OBJ_SLIDER) // If the Reported Message was from a Slider 176 | { 177 | if (Event.reportObject.index == 0) // If Slider0 (Index = 0) 178 | { 179 | int slider_val = display2.GetEventData(&Event); // Receive the event data from the Slider0 180 | display1.WriteObject(GENIE_OBJ_LED_DIGITS, 0, slider_val); // Write Slider0 value of Display 2 to to LED Digits 0 of Display 1 181 | } 182 | } 183 | } 184 | 185 | //If the cmd received is from a Reported Object, which occurs if a Read Object (genie.ReadOject) is requested in the main code, reply processed here. 186 | if (Event.reportObject.cmd == GENIE_REPORT_OBJ) 187 | { 188 | if (Event.reportObject.object == GENIE_OBJ_USER_LED) // If the Reported Message was from a User LED 189 | { 190 | if (Event.reportObject.index == 0) // If UserLed0 (Index = 0) 191 | { 192 | bool UserLed0_val = display2.GetEventData(&Event); // Receive the event data from the UserLed0 193 | UserLed0_val = !UserLed0_val; // Toggle the state of the User LED Variable 194 | display2.WriteObject(GENIE_OBJ_USER_LED, 0, UserLed0_val); // Write UserLed0_val value back to to UserLed0 195 | } 196 | } 197 | } 198 | 199 | /********** This can be expanded as more objects are added that need to be captured ************* 200 | ************************************************************************************************* 201 | Event.reportObject.cmd is used to determine the command of that event, such as an reported event 202 | Event.reportObject.object is used to determine the object type, such as a Slider 203 | Event.reportObject.index is used to determine the index of the object, such as Slider0 204 | genie.GetEventData(&Event) us used to save the data from the Event, into a variable. 205 | *************************************************************************************************/ 206 | } 207 | -------------------------------------------------------------------------------- /extras/genieArduino-WS4-Demo.4DGenie: -------------------------------------------------------------------------------- 1 | Version 0.0 2 | Platform Gen4-uLCD-32DCT-CLB-LR 3 | PlatRes 240x320 4 | Depends 5 | end 6 | Options 7 | Genie 8 | Speed 200000 9 | Checksum No 10 | ResponseSize 1 11 | Multidrop No 12 | Destination 1 13 | DestBank 0 14 | MainForm 0 15 | SndBuf 2 16 | ButtonDisable No 17 | SignedDigits No 18 | MaxString 75 19 | ComPort 0 20 | ComTX1pinIdx 0 21 | ComRX1pinIdx 0 22 | FileSystem FATfs 23 | FlashEraseOption Optimal 24 | SPIenable 0 25 | SPIsdo 3 26 | SPIsdi 2 27 | SPIsck 1 28 | FlashGT16MB No 29 | end 30 | Form 31 | Name Form0 32 | Alias Form0 33 | Bgtype Color 34 | Color BLACK 35 | Image (None) 36 | Source.Height 0 37 | Source.Left 0 38 | Source.Top 0 39 | Source.Width 0 40 | OnActivate '' 41 | OnCreate '' 42 | OnRepeat '' 43 | OnTouchMoving '' 44 | OnTouchPressed '' 45 | OnTouchReleased '' 46 | end 47 | LedDigits 48 | Name Leddigits0 49 | Alias Leddigits0 50 | Color BLACK 51 | Decimals 0 52 | Digits 2 53 | Height 73 54 | LeadingZero Yes 55 | Left 4 56 | OutlineColor BLACK 57 | Palette.High YELLOW 58 | Palette.Low BLACK 59 | Top 8 60 | Width 105 61 | OnChanged '' 62 | OnTouchMoving '' 63 | OnTouchPressed '' 64 | OnTouchReleased '' 65 | end 66 | Coolgauge 67 | Name Coolgauge0 68 | Alias Coolgauge0 69 | Arc.Color 0xFFEFE0 70 | Arc.Opacity 200 71 | Arc.StartAngle 135 72 | Arc.StopAngle 405 73 | Threshold.Center 25 74 | Threshold.Color 0xFFD0AF 75 | Threshold.EndValue 100 76 | Threshold.Opacity 200 77 | Threshold.Span 25 78 | Threshold.StartAngle 135 79 | Threshold.StartValue 0 80 | Threshold.SweepAngle 270 81 | Threshold.ThresholdKind Angle 82 | Arc.Width 0.03 83 | CircleEndValue 360 84 | CircleStartValue 0 85 | DialText '' 86 | Digit.Alignment Center 87 | Digit.BackGroundColor 0xFFEFE0 88 | Digit.BackGroundOpacity 30 89 | Digit.Color 0x902F00 90 | Digit.Visible Yes 91 | DivisionColor 0x902F00 92 | DivisionCount 10 93 | DivisionWidth 5 94 | EqualDimensions Yes 95 | Font.Color 0x902F00 96 | Font.Effects [] 97 | Font.Name Tahoma 98 | Font.Size 14 99 | Font.Style [] 100 | Height 192 101 | Innercircle.Color 0xFFD0AF 102 | Gloss.Color clWhite 103 | Gloss.Opacity 72 104 | Innercircle.Opacity 150 105 | Left 120 106 | Logarithmic No 107 | LogarithmicBase 10 108 | MaximumValue 100 109 | MinimumValue 0 110 | Needle.Color 0xFFD0AF 111 | Needle.InnerCenterColor 0xFFD0AF 112 | Needle.InnerCenterColorTo 0xFFD0AF 113 | Needle.InnerCenterOpacity 255 114 | Needle.OuterCenterColor 0xFFD0AF 115 | Needle.OuterCenterColorTo clBlue 116 | Needle.OuterCenterOpacity 255 117 | Needle.ShineColor 0xFFEFE0 118 | Needle.ShineColorTo 0xD0D0D0 119 | OuterCircle.Color 0xFFD0AF 120 | OuterCircle.Opacity 100 121 | OuterCircle.Width 0.03 122 | OuterRim.Color 0x908070 123 | OuterRim.Opacity 255 124 | OuterRim.Width 2 125 | ShowValues Yes 126 | SubDivisionColor 0x902F00 127 | SubDivisionCount 3 128 | SubDivisionWidth 2 129 | TextRendering ClearType 130 | Top 0 131 | ValueFont.Color 0x902F00 132 | ValueFont.Effects [] 133 | ValueFont.Name Tahoma 134 | ValueFont.Size 11 135 | ValueFont.Style [] 136 | ValueFormat 0 137 | Width 192 138 | OnChanged '' 139 | end 140 | GSlider 141 | Name Slider0 142 | Alias Slider0 143 | Bevel.BorderColor clBtnFace 144 | Bevel.BorderWidth 0 145 | Bevel.InnerColor BLACK 146 | Bevel.InnerHighlight clBtnHighlight 147 | Bevel.InnerOutline None 148 | Bevel.InnerShadow clBtnShadow 149 | Bevel.InnerSpace 1 150 | Bevel.InnerStyle Lowered 151 | Bevel.Innerwidth 2 152 | Bevel.OuterColor clBtnFace 153 | Bevel.OuterHighlight clBtnHighlight 154 | Bevel.OuterOutline Outer 155 | Bevel.OuterShadow clBtnShadow 156 | Bevel.OuterSpace 0 157 | Bevel.OuterStyle Raised 158 | Bevel.Outerwidth 1 159 | Bevel.Visible Yes 160 | BorderColor clBtnFace 161 | BorderWidth 1 162 | Color BLACK 163 | Height 139 164 | Left 0 165 | Maxvalue 99 166 | Minvalue 0 167 | Orientation Vertical 168 | Palette.High clLime 169 | Palette.Low 0x005100 170 | Spacing 1 171 | SolidFill Yes 172 | TickWidth 1 173 | Top 88 174 | Width 63 175 | OnChanged 'Report Message' 176 | OnChanging '' 177 | end 178 | Strings 179 | Name Strings0 180 | Alias Strings0 181 | Alignment Left 182 | BGcolor AQUA 183 | Height 38 184 | FGcolor BLACK 185 | Font.Bold No 186 | Font.CharSet ANSI 187 | Font.Italic No 188 | Font.Name '4D Font3 (8x12)' 189 | Font.Opaque Yes 190 | Font.Size 12 191 | Font.Strikethrough No 192 | Font.Underline No 193 | Left 120 194 | Strings '' 195 | StringsStyle '' 196 | Top 200 197 | Width 199 198 | OnChanged '' 199 | end 200 | UserLed 201 | Name Userled0 202 | Alias Userled0 203 | Active Yes 204 | Bevel.BorderColor clBtnFace 205 | Bevel.BorderWidth 0 206 | Bevel.InnerColor clBtnFace 207 | Bevel.InnerHighlight clLime 208 | Bevel.InnerOutline None 209 | Bevel.InnerShadow 0x005100 210 | Bevel.InnerSpace 1 211 | Bevel.InnerStyle None 212 | Bevel.Innerwidth 1 213 | Bevel.OuterColor clBtnFace 214 | Bevel.OuterHighlight clBtnHighlight 215 | Bevel.OuterOutline Outer 216 | Bevel.OuterShadow clBtnShadow 217 | Bevel.OuterSpace 0 218 | Bevel.OuterStyle Raised 219 | Bevel.Outerwidth 1 220 | Bevel.Visible Yes 221 | Height 27 222 | Left 72 223 | OutlineColor BLACK 224 | OutlineWidth 0 225 | PaletteEx.High1 0x14EC3F 226 | PaletteEx.High2 0x377B56 227 | PaletteEx.Low1 0x000051 228 | PaletteEx.Low2 BLACK 229 | Top 204 230 | Width 43 231 | OnChanged '' 232 | end 233 | StaticText 234 | Name Statictext0 235 | Alias Statictext0 236 | Alignment Left 237 | AutoSize Yes 238 | Caption UserLED 239 | Color BLACK 240 | Font.Color WHITE 241 | Font.Effects [] 242 | Font.Name Tahoma 243 | Font.Size 9 244 | Font.Style [] 245 | Height 14 246 | Left 72 247 | Top 188 248 | Transparent Yes 249 | Width 45 250 | WordWrap Yes 251 | end 252 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map GenieArduino August 2020 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | Genie KEYWORD1 10 | genieFrame KEYWORD1 11 | EventQueueStruct KEYWORD1 12 | MagicReportHeader KEYWORD1 13 | FrameReportObj KEYWORD1 14 | 15 | ####################################### 16 | # Methods and Functions (KEYWORD2) 17 | ####################################### 18 | 19 | Begin KEYWORD2 20 | ReadObject KEYWORD2 21 | WriteObject KEYWORD2 22 | WriteContrast KEYWORD2 23 | WriteStr KEYWORD2 24 | WriteStrU KEYWORD2 25 | WriteInhLabel KEYWORD2 26 | EventIs KEYWORD2 27 | GetEventData KEYWORD2 28 | DequeueEvent KEYWORD2 29 | DoEvents KEYWORD2 30 | AttachEventHandler KEYWORD2 31 | AttachMagicByteReader KEYWORD2 32 | AttachMagicDoubleByteReader KEYWORD2 33 | WriteMagicBytes KEYWORD2 34 | WriteMagicDBytes KEYWORD2 35 | GetNextByte KEYWORD2 36 | GetNextDoubleByte KEYWORD2 37 | WriteIntLedDigits KEYWORD2 38 | 39 | ###################################### 40 | # Constants (LITERAL1) 41 | ####################################### 42 | 43 | GENIE_READ_OBJ LITERAL1 44 | GENIE_WRITE_OBJ LITERAL1 45 | GENIE_WRITE_STR LITERAL1 46 | GENIE_WRITE_STRU LITERAL1 47 | GENIE_WRITE_CONTRAST LITERAL1 48 | GENIE_REPORT_OBJ LITERAL1 49 | GENIE_REPORT_EVENT LITERAL1 50 | GENIEM_WRITE_BYTES LITERAL1 51 | GENIEM_WRITE_DBYTES LITERAL1 52 | GENIEM_REPORT_BYTES LITERAL1 53 | GENIEM_REPORT_DBYTES LITERAL1 54 | 55 | ###################################### 56 | # Genie ID Constants (LITERAL1) 57 | ####################################### 58 | 59 | GENIE_OBJ_DIPSW LITERAL1 60 | GENIE_OBJ_KNOB LITERAL1 61 | GENIE_OBJ_ROCKERSW LITERAL1 62 | GENIE_OBJ_ROTARYSW LITERAL1 63 | GENIE_OBJ_SLIDER LITERAL1 64 | GENIE_OBJ_TRACKBAR LITERAL1 65 | GENIE_OBJ_WINBUTTON LITERAL1 66 | GENIE_OBJ_ANGULAR_METER LITERAL1 67 | GENIE_OBJ_COOL_GAUGE LITERAL1 68 | GENIE_OBJ_CUSTOM_DIGITS LITERAL1 69 | GENIE_OBJ_FORM LITERAL1 70 | GENIE_OBJ_GAUGE LITERAL1 71 | GENIE_OBJ_IMAGE LITERAL1 72 | GENIE_OBJ_KEYBOARD LITERAL1 73 | GENIE_OBJ_LED LITERAL1 74 | GENIE_OBJ_LED_DIGITS LITERAL1 75 | GENIE_OBJ_METER LITERAL1 76 | GENIE_OBJ_STRINGS LITERAL1 77 | GENIE_OBJ_THERMOMETER LITERAL1 78 | GENIE_OBJ_USER_LED LITERAL1 79 | GENIE_OBJ_VIDEO LITERAL1 80 | GENIE_OBJ_STATIC_TEXT LITERAL1 81 | GENIE_OBJ_SOUND LITERAL1 82 | GENIE_OBJ_TIMER LITERAL1 83 | GENIE_OBJ_SPECTRUM LITERAL1 84 | GENIE_OBJ_SCOPE LITERAL1 85 | GENIE_OBJ_TANK LITERAL1 86 | GENIE_OBJ_USERIMAGES LITERAL1 87 | GENIE_OBJ_PINOUTPUT LITERAL1 88 | GENIE_OBJ_PININPUT LITERAL1 89 | GENIE_OBJ_4DBUTTON LITERAL1 90 | GENIE_OBJ_ANIBUTTON LITERAL1 91 | GENIE_OBJ_COLORPICKER LITERAL1 92 | GENIE_OBJ_USERBUTTON LITERAL1 93 | GENIE_OBJ_SMARTGAUGE LITERAL1 94 | GENIE_OBJ_SMARTSLIDER LITERAL1 95 | GENIE_OBJ_SMARTKNOB LITERAL1 96 | GENIE_OBJ_ISMARTGAUGE LITERAL1 97 | GENIE_OBJ_ISMARTSLIDER LITERAL1 98 | GENIE_OBJ_ISMARTKNOB LITERAL1 99 | GENIE_OBJ_ILED_DIGITS_H LITERAL1 100 | GENIE_OBJ_IANGULAR_METER LITERAL1 101 | GENIE_OBJ_IGAUGE LITERAL1 102 | GENIE_OBJ_ILABELB LITERAL1 103 | GENIE_OBJ_IUSER_GAUGE LITERAL1 104 | GENIE_OBJ_IMEDIA_GAUGE LITERAL1 105 | GENIE_OBJ_IMEDIA_THERMOMETER LITERAL1 106 | GENIE_OBJ_ILED LITERAL1 107 | GENIE_OBJ_IMEDIA_LED LITERAL1 108 | GENIE_OBJ_ILED_DIGITS_L LITERAL1 109 | GENIE_OBJ_ILED_DIGITS LITERAL1 110 | GENIE_OBJ_INEEDLE LITERAL1 111 | GENIE_OBJ_IRULER LITERAL1 112 | GENIE_OBJ_ILED_DIGIT LITERAL1 113 | GENIE_OBJ_IBUTTOND LITERAL1 114 | GENIE_OBJ_IBUTTONE LITERAL1 115 | GENIE_OBJ_IMEDIA_BUTTON LITERAL1 116 | GENIE_OBJ_ITOGGLE_INPUT LITERAL1 117 | GENIE_OBJ_IDIAL LITERAL1 118 | GENIE_OBJ_IMEDIA_ROTARY LITERAL1 119 | GENIE_OBJ_IROTARY_INPUT LITERAL1 120 | GENIE_OBJ_ISWITCH LITERAL1 121 | GENIE_OBJ_ISWITCHB LITERAL1 122 | GENIE_OBJ_ISLIDERE LITERAL1 123 | GENIE_OBJ_IMEDIA_SLIDER LITERAL1 124 | GENIE_OBJ_ISLIDERH LITERAL1 125 | GENIE_OBJ_ISLIDERG LITERAL1 126 | GENIE_OBJ_ISLIDERF LITERAL1 127 | GENIE_OBJ_ISLIDERD LITERAL1 128 | GENIE_OBJ_ISLIDERC LITERAL1 129 | GENIE_OBJ_ILINEAR_INPUT LITERAL1 130 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=genieArduino 2 | version=1.5.3 3 | author=4D Systems Pty Ltd 4 | maintainer=4D Systems Pty Ltd 5 | sentence=4D Systems ViSi-Genie library for Arduino 6 | paragraph=This is a library for the Arduino IDE enables communication to a 4D Systems Intelligent Display Module, programmed with the ViSi-Genie Environment, using a Serial UART 7 | category=Display 8 | url=https://github.com/4dsystems/ViSi-Genie-Arduino-Library 9 | architectures=* 10 | -------------------------------------------------------------------------------- /src/genieArduino.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////// GenieArduino /////////////////////// 2 | // 3 | // Library to utilize the 4D Systems Genie interface to displays 4 | // that have been created using the Visi-Genie creator platform. 5 | // This is intended to be used with the Arduino platform. 6 | // 7 | // Improvements/Updates by 8 | // v1.5.3 4D Systems Engineering, January 2022, www.4dsystems.com.au 9 | // v1.5.2 4D Systems Engineering, May 2021, www.4dsystems.com.au 10 | // v1.5.1 4D Systems Engineering, August 2020, www.4dsystems.com.au 11 | // v1.5.0 4D Systems Engineering, July 2020, www.4dsystems.com.au 12 | // v1.4.5 4D Systems Engineering, August 2017, www.4dsystems.com.au 13 | // v1.4.4 4D Systems Engineering, October 2015, www.4dsystems.com.au 14 | // v1.4.3 4D Systems Engineering, September 2015, www.4dsystems.com.au 15 | // v1.4.2 4D Systems Engineering, August 2015, www.4dsystems.com.au 16 | // v1.4.1 4D Systems Engineering, May 2015, www.4dsystems.com.au 17 | // v1.4.0 Matt Jenkins, March 2015, www.majenko.com 18 | // v1.3.0 Clinton Keith, January 2015, www.clintonkeith.com 19 | // v1.2.0 4D Systems Engineering, July 2014, www.4dsystems.com.au 20 | // v1.1.2 Clinton Keith, March 2014, www.clintonkeith.com 21 | // v1.1.1 Clinton Keith, January 2014, www.clintonkeith.com 22 | // v1.1.0 4D Systems Engineering, January 2014, www.4dsystems.com.au 23 | // v1.0.1 4D Systems Engineering, September 2013, www.4dsystems.com.au 24 | // Written by 25 | // v1.0.0 Rob Gray (GRAYnomad), June 2013, www.robgray.com 26 | // Based on code by 27 | // Gordon Henderson, February 2013, 28 | // 29 | // Copyright (c) 2012-2022 4D Systems Pty Ltd, Sydney, Australia 30 | /********************************************************************* 31 | * This file is part of genieArduino: 32 | * genieArduino is free software: you can redistribute it and/or modify 33 | * it under the terms of the GNU Lesser General Public License as 34 | * published by the Free Software Foundation, either version 3 of the 35 | * License, or (at your option) any later version. 36 | * 37 | * genieArduino is distributed in the hope that it will be useful, 38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 40 | * GNU Lesser General Public License for more details. 41 | * 42 | * You should have received a copy of the GNU Lesser General Public 43 | * License along with genieArduino. 44 | * If not, see . 45 | *********************************************************************/ 46 | //#include 47 | #include "genieArduino.h" 48 | #include 49 | #include 50 | 51 | #define DEC 10 52 | #define HEX 16 53 | #define OCT 8 54 | #define BIN 2 55 | 56 | #if (ARDUINO >= 100) 57 | # include "Arduino.h" // for Arduino 1.0 58 | #else 59 | # include "WProgram.h" // for Arduino 23 60 | #endif 61 | 62 | //int freeRam () { 63 | // extern int __heap_start, *__brkval; 64 | // int v; 65 | // return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 66 | //} 67 | 68 | Genie::Genie() { 69 | // Pointer to the user's event handler function 70 | UserHandler = NULL; 71 | UserByteReader = NULL; 72 | UserDoubleByteReader = NULL; 73 | debugSerial = NULL; 74 | LinkStates[0] = GENIE_LINK_IDLE; 75 | LinkState = &LinkStates[0]; 76 | Timeout = TIMEOUT_PERIOD; 77 | Timeouts = 0; 78 | Error = ERROR_NONE; 79 | rxframe_count = 0; 80 | FatalErrors = 0; 81 | } 82 | 83 | void Genie::assignDebugPort(Stream &port) { 84 | debugSerial = &port; 85 | } 86 | 87 | ////////////////////// GetEventData //////////////////////// 88 | // 89 | // Returns the LSB and MSB of the event's data combined into 90 | // a single uint16 91 | // 92 | // The data is transmitted from the display in big-endian format 93 | // and stored the same so the user can't just access it as an int 94 | // directly from the structure. 95 | // 96 | uint16_t Genie::GetEventData (genieFrame * e) { 97 | return (e->reportObject.data_msb << 8) + e->reportObject.data_lsb; 98 | } 99 | 100 | //////////////////////// GetNextByte /////////////////////////// 101 | // 102 | // Read one byte from the serial device. Blocking. 103 | // 104 | uint8_t Genie::GetNextByte() { 105 | while (deviceSerial->available() < 1) { 106 | continue; 107 | } 108 | return deviceSerial->read(); 109 | } 110 | 111 | //////////////////////// GetNextDoubleByte /////////////////////////// 112 | // 113 | // Reads two bytes from the serial device and joins them into one 114 | // double byte. Blocking. 115 | // 116 | uint16_t Genie::GetNextDoubleByte() { 117 | uint16_t out; 118 | while (deviceSerial->available() < 1) { 119 | continue; 120 | } 121 | out = (deviceSerial->read()) << 8; 122 | out |= deviceSerial->read(); 123 | return out; 124 | } 125 | 126 | //////////////////////// Genie::EventIs /////////////////////////// 127 | // 128 | // Compares the cmd, object and index fields of the event's 129 | // structure. 130 | // 131 | // Returns: TRUE if all the fields match the caller's parms 132 | // FALSE if any of them don't 133 | // 134 | bool Genie::EventIs(genieFrame * e, uint8_t cmd, uint8_t object, uint8_t index) { 135 | return (e->reportObject.cmd == cmd && 136 | e->reportObject.object == object && 137 | e->reportObject.index == index); 138 | } 139 | 140 | ////////////////////// Genie::WaitForIdle //////////////////////// 141 | // 142 | // Wait for the link to become idle or for the timeout period, 143 | // whichever comes first. 144 | // 145 | void Genie::WaitForIdle (void) { 146 | uint16_t do_event_result; 147 | unsigned long timeout = millis() + Timeout; 148 | 149 | for ( ; millis() < timeout;) { 150 | do_event_result = DoEvents(false); 151 | 152 | // if there was a character received from the 153 | // display restart the timeout because doEvents 154 | // is in the process of receiving something 155 | if (do_event_result == GENIE_EVENT_RXCHAR) { 156 | timeout = millis() + Timeout; 157 | } 158 | 159 | if (GetLinkState() == GENIE_LINK_IDLE) { 160 | return; 161 | } 162 | } 163 | 164 | Error = ERROR_TIMEOUT; 165 | handleError(); 166 | return; 167 | } 168 | 169 | ////////////////////// Genie::PushLinkState ////////////////////// 170 | // 171 | // Push a link state onto a FILO stack 172 | // 173 | int linkCount = 0; 174 | void Genie::PushLinkState (uint8_t newstate) { 175 | if (linkCount >= MAX_LINK_STATES) { 176 | Resync(); 177 | } 178 | 179 | linkCount++; 180 | LinkState++; 181 | //if (debugSerial) { *debugSerial << " newstate = " << newstate << " LinkState count = " << linkCount << ", Freemem = " << freeRam() << ", " << (unsigned long)&LinkState[0] << ", rxframe_count = " << rxframe_count << endl; } ; 182 | SetLinkState(newstate); 183 | } 184 | 185 | ////////////////////// Genie::PopLinkState ////////////////////// 186 | // 187 | // Pop a link state from a FILO stack 188 | // 189 | void Genie::PopLinkState (void) { 190 | //if (debugSerial) { *debugSerial << "PopLinkState\n"; } 191 | if (LinkState > &LinkStates[0]) { 192 | *LinkState = 0xFF; 193 | LinkState--; 194 | linkCount--; 195 | } 196 | } 197 | 198 | ///////////////////////// Genie::DoEvents ///////////////////////// 199 | // 200 | // This is the heart of the Genie comms state machine. 201 | // 202 | uint16_t Genie::DoEvents (bool DoHandler) { 203 | uint8_t c; 204 | static uint8_t rx_data[6]; 205 | static uint8_t checksum = 0; 206 | c = Getchar(); 207 | static struct MagicReportHeader magicHeader; 208 | static uint8_t magicByte = 0; 209 | 210 | //if (debugSerial && c != 0xFD) *debugSerial << _HEX(c)<<", "<<"["< 0) && (UserHandler != NULL) && DoHandler) { 218 | (UserHandler)(); 219 | } 220 | 221 | return GENIE_EVENT_NONE; 222 | } 223 | 224 | //if (debugSerial) { *debugSerial << "Freemem = " << freeRam()<< endl; } ; 225 | //return GENIE_EVENT_RXCHAR; // debug 226 | 227 | /////////////////////////////////////////// 228 | // 229 | // Main state machine 230 | // 231 | 232 | switch (GetLinkState()) { 233 | case GENIE_LINK_IDLE: 234 | switch (c) { 235 | case GENIE_REPORT_EVENT: 236 | // event frame out of the blue, set the link state 237 | // and fall through to the frame-accumulate code 238 | // at the end of this function 239 | PushLinkState(GENIE_LINK_RXEVENT); 240 | break; 241 | 242 | case GENIEM_REPORT_BYTES: 243 | magicByte = 0; 244 | PushLinkState(GENIE_LINK_RXMBYTES); 245 | break; 246 | 247 | case GENIEM_REPORT_DBYTES: 248 | magicByte = 0; 249 | PushLinkState(GENIE_LINK_RXMDBYTES); 250 | break; 251 | 252 | default: 253 | // error, bad character, no other character 254 | // is acceptable in this state 255 | return GENIE_EVENT_RXCHAR; 256 | } 257 | 258 | break; 259 | 260 | case GENIE_LINK_WFAN: 261 | switch (c) { 262 | case GENIE_ACK: 263 | PopLinkState(); 264 | return GENIE_EVENT_RXCHAR; 265 | 266 | case GENIE_NAK: 267 | PopLinkState(); 268 | Error = ERROR_NAK; 269 | handleError(); 270 | return GENIE_EVENT_RXCHAR; 271 | 272 | case GENIE_REPORT_EVENT: 273 | // event frame out of the blue while waiting for an ACK 274 | // save/set the link state and fall through to the 275 | // frame-accumulate code at the end of this function 276 | PushLinkState(GENIE_LINK_RXEVENT); 277 | break; 278 | 279 | case GENIEM_REPORT_BYTES: 280 | magicByte = 0; 281 | PushLinkState(GENIE_LINK_RXMBYTES); 282 | break; 283 | 284 | case GENIEM_REPORT_DBYTES: 285 | magicByte = 0; 286 | PushLinkState(GENIE_LINK_RXMDBYTES); 287 | break; 288 | 289 | case GENIE_REPORT_OBJ: 290 | default: 291 | // error, bad character 292 | return GENIE_EVENT_RXCHAR; 293 | } 294 | 295 | break; 296 | 297 | case GENIE_LINK_WF_RXREPORT: // waiting for the first byte of a report 298 | switch (c) { 299 | case GENIE_REPORT_EVENT: 300 | // event frame out of the blue while waiting for the first 301 | // byte of a report frame 302 | // save/set the link state and fall through to the 303 | // frame-accumulate code at the end of this function 304 | PushLinkState(GENIE_LINK_RXEVENT); 305 | break; 306 | 307 | case GENIEM_REPORT_BYTES: 308 | magicByte = 0; 309 | PushLinkState(GENIE_LINK_RXMBYTES); 310 | break; 311 | 312 | case GENIEM_REPORT_DBYTES: 313 | magicByte = 0; 314 | PushLinkState(GENIE_LINK_RXMDBYTES); 315 | break; 316 | 317 | case GENIE_REPORT_OBJ: 318 | // first byte of a report frame 319 | // replace the GENIE_LINK_WF_RXREPORT link state 320 | // with GENIE_LINK_RXREPORT to indicate that we 321 | // are now receiving a report frame 322 | PopLinkState(); 323 | PushLinkState(GENIE_LINK_RXREPORT); 324 | break; 325 | 326 | case GENIE_ACK: 327 | case GENIE_NAK: 328 | default: 329 | // error, bad character 330 | return GENIE_EVENT_RXCHAR; 331 | // break; 332 | } 333 | 334 | case GENIE_LINK_RXREPORT: // already receiving report 335 | case GENIE_LINK_RXEVENT: // already receiving event 336 | case GENIE_LINK_RXMBYTES: // already receiving magic bytes 337 | case GENIE_LINK_RXMDBYTES: // already receiving mahic doublebytes 338 | default: 339 | break; 340 | } 341 | 342 | /////////////////////////////////////////////////////// 343 | // We get here if we are in the process of receiving 344 | // a report or event frame. Accumulate GENIE_FRAME_SIZE 345 | // bytes into a local buffer then queue them as a frame 346 | // into the event queue 347 | // 348 | if (GetLinkState() == GENIE_LINK_RXREPORT || 349 | GetLinkState() == GENIE_LINK_RXEVENT) { 350 | checksum = (rxframe_count == 0) ? c : checksum ^ c; 351 | rx_data[rxframe_count] = c; 352 | 353 | if (rxframe_count == GENIE_FRAME_SIZE - 1) { 354 | // all bytes received, if the CS is good 355 | // queue the frame and restore the link state 356 | if (checksum == 0) { 357 | EnqueueEvent(rx_data); 358 | rxframe_count = 0; 359 | // revert the link state to whatever it was before 360 | // we started accumulating this frame 361 | PopLinkState(); 362 | return GENIE_EVENT_RXCHAR; 363 | } else { 364 | Error = ERROR_BAD_CS; 365 | handleError(); 366 | } 367 | } 368 | 369 | rxframe_count++; 370 | return GENIE_EVENT_RXCHAR; 371 | } 372 | 373 | /////////////////////////////////////////////////////// 374 | // We get here if we are in the process of receiving 375 | // a magic report. When the header has been received 376 | // trigger the byte or double-byte handler to receive 377 | // the rest of the data. 378 | // 379 | if (GetLinkState() == GENIE_LINK_RXMBYTES || 380 | GetLinkState() == GENIE_LINK_RXMDBYTES) { 381 | 382 | switch(magicByte) { 383 | case 0: 384 | magicHeader.cmd = c; 385 | magicByte++; 386 | break; 387 | case 1: 388 | magicHeader.index = c; 389 | magicByte++; 390 | break; 391 | case 2: 392 | magicHeader.length = c; 393 | magicByte++; 394 | if (magicHeader.cmd == GENIEM_REPORT_BYTES) { 395 | if (UserByteReader != NULL) { 396 | UserByteReader(magicHeader.index, magicHeader.length); 397 | } else { 398 | // No handler defined - we need to sink the bytes. 399 | while (--magicHeader.length > 0) { 400 | (void)GetNextByte(); 401 | } 402 | } 403 | } else if (magicHeader.cmd == GENIEM_REPORT_DBYTES) { 404 | if (UserDoubleByteReader != NULL) { 405 | UserDoubleByteReader(magicHeader.index, magicHeader.length); 406 | } else { 407 | // No handler defined - we need to sink the bytes. 408 | while (--magicHeader.length > 0) { 409 | (void)GetNextDoubleByte(); 410 | } 411 | } 412 | } 413 | // Now we want to discard the checksum. We don't yet 414 | // know what has been going on with the data, so we 415 | // can't calculate the checksum. 416 | (void)GetNextByte(); 417 | PopLinkState(); 418 | break; 419 | } 420 | return GENIE_EVENT_RXCHAR; 421 | } 422 | return GENIE_EVENT_RXCHAR; 423 | } 424 | 425 | //////////////////////// Genie::Getchar ////////////////////////// 426 | // 427 | // Get a character from the selected Genie serial port 428 | // 429 | // Returns: ERROR_NOHANDLER if an Rx handler has not 430 | // been defined 431 | // ERROR_NOCHAR if no bytes have beeb received 432 | // The char if there was one to get 433 | // Sets: Error with any errors encountered 434 | // 435 | uint8_t Genie::Getchar() { 436 | Error = ERROR_NONE; 437 | return GetcharSerial(); 438 | } 439 | 440 | /////////////////////////////////////////////////////////////////// 441 | // Serial port 0 (Serial) Rx handler 442 | // Return ERROR_NOCHAR if no character or the char in the lower 443 | // byte if there is. 444 | // 445 | uint16_t Genie::GetcharSerial (void) { 446 | #ifdef SERIAL 447 | 448 | if (deviceSerial->available() == 0) { 449 | Error = ERROR_NOCHAR; 450 | return ERROR_NOCHAR; 451 | } 452 | 453 | return (uint16_t) deviceSerial->read() & 0xFF; 454 | #endif 455 | } 456 | 457 | 458 | /////////////////// Genie::FatalError /////////////////////// 459 | // 460 | void Genie::FatalError(void) { 461 | if (FatalErrors++ > MAX_GENIE_FATALS) { 462 | // *LinkState = GENIE_LINK_SHDN; 463 | // Error = ERROR_NODISPLAY; 464 | } 465 | } 466 | 467 | ///////////////// Genie::FlushSerialInput /////////////////// 468 | // 469 | // Removes and discards all characters from the currently 470 | // used serial port's Rx buffer. 471 | // 472 | void Genie::FlushSerialInput(void) { 473 | while (deviceSerial->read() >= 0); 474 | } 475 | 476 | /////////////////////// Resync ////////////////////////// 477 | // 478 | // This function does nothing for RESYNC_PERIOD to allow the display 479 | // time to stop talking, then it flushes everything so the link 480 | // can start again. 481 | // 482 | // Future improvement work will be required here. 483 | // 484 | void Genie::Resync (void) { 485 | //for (long timeout = millis() + RESYNC_PERIOD ; millis() < timeout;) {}; 486 | FlushSerialInput(); 487 | FlushEventQueue(); 488 | Timeouts = 0; 489 | linkCount = 0; 490 | LinkState = &LinkStates[0]; 491 | *LinkState = GENIE_LINK_IDLE; 492 | } 493 | 494 | ///////////////////////// handleError ///////////////////////// 495 | // 496 | // So far really just a debugging aid, but can be enhanced to 497 | // help recover from errors. 498 | // 499 | void Genie::handleError (void) { 500 | //if (debugSerial) { *debugSerial << "Handle Error Called!\n"; } 501 | } 502 | 503 | ////////////////////// Genie::FlushEventQueue //////////////////// 504 | // 505 | // Reset all the event queue variables and start from scratch. 506 | // 507 | void Genie::FlushEventQueue(void) { 508 | EventQueue.rd_index = 0; 509 | EventQueue.wr_index = 0; 510 | EventQueue.n_events = 0; 511 | } 512 | 513 | ////////////////////// DequeueEvent /////////////////// 514 | // 515 | // Copy the bytes from a queued input event to a buffer supplied 516 | // by the caller. 517 | // 518 | // Parms: genieFrame * buff, a pointer to the user's buffer 519 | // 520 | // Returns: TRUE if there was an event to copy 521 | // FALSE if not 522 | // 523 | bool Genie::DequeueEvent(genieFrame * buff) { 524 | if (EventQueue.n_events > 0) { 525 | memcpy (buff, &EventQueue.frames[EventQueue.rd_index], 526 | GENIE_FRAME_SIZE); 527 | EventQueue.rd_index++; 528 | EventQueue.rd_index &= MAX_GENIE_EVENTS - 1; 529 | EventQueue.n_events--; 530 | return TRUE; 531 | } 532 | 533 | return FALSE; 534 | } 535 | 536 | ////////////////////// Genie::EnqueueEvent /////////////////// 537 | // 538 | // Copy the bytes from a buffer supplied by the caller 539 | // to the input queue 540 | // 541 | // Parms: uint8_t * data, a pointer to the user's data 542 | // 543 | // Returns: TRUE if there was an empty location in the queue 544 | // to copy the data into 545 | // FALSE if not 546 | // Sets: ERROR_REPLY_OVR if there was no room in the queue 547 | // 548 | bool Genie::EnqueueEvent (uint8_t * data) { 549 | if (EventQueue.n_events < MAX_GENIE_EVENTS - 2) { 550 | int i, j ; 551 | bool fnd=false ; 552 | j = EventQueue.wr_index ; 553 | for (i = EventQueue.n_events; i > 0; i--) 554 | { 555 | j-- ; 556 | if (j < 0) 557 | j = MAX_GENIE_EVENTS - 1; 558 | if ( (EventQueue.frames[j].reportObject.cmd == data[0]) 559 | && (EventQueue.frames[j].reportObject.object == data[1]) 560 | && (EventQueue.frames[j].reportObject.index == data[2]) ) 561 | { 562 | EventQueue.frames[j].reportObject.data_msb = data[3] ; 563 | EventQueue.frames[j].reportObject.data_lsb = data[4] ; 564 | fnd = true ; 565 | break ; 566 | } 567 | } 568 | if (!fnd) 569 | { 570 | memcpy (&EventQueue.frames[EventQueue.wr_index], data, 571 | GENIE_FRAME_SIZE); 572 | EventQueue.wr_index++; 573 | EventQueue.wr_index &= MAX_GENIE_EVENTS - 1; 574 | EventQueue.n_events++; 575 | //if (debugSerial) { *debugSerial << "Enque Event " << _HEX(*data) << ", count = " << EventQueue.n_events << endl; } 576 | return TRUE; 577 | } 578 | } else { 579 | Error = ERROR_REPLY_OVR; 580 | handleError(); 581 | return FALSE; 582 | } 583 | return FALSE; 584 | } 585 | 586 | //////////////////////// Genie::ReadObject /////////////////////// 587 | // 588 | // Send a read object command to the Genie display. Note that this 589 | // function does not wait for the reply, that will be read in due 590 | // course by DoEvents() and subsequently by the user's event 591 | // handler. 592 | // 593 | bool Genie::ReadObject (uint16_t object, uint16_t index) { 594 | uint8_t checksum; 595 | // Discard any pending reply frames 596 | //FlushEventQueue(); // Removed due to preventing more than 2 readObjects being queued 597 | WaitForIdle(); 598 | Error = ERROR_NONE; 599 | deviceSerial->write((uint8_t)GENIE_READ_OBJ); 600 | checksum = GENIE_READ_OBJ ; 601 | deviceSerial->write(object); 602 | checksum ^= object ; 603 | deviceSerial->write(index); 604 | checksum ^= index ; 605 | deviceSerial->write(checksum); 606 | PushLinkState(GENIE_LINK_WF_RXREPORT); 607 | return TRUE; 608 | } 609 | 610 | ///////////////////// Genie::SetLinkState //////////////////////// 611 | // 612 | // Set the logical state of the link to the display. 613 | // 614 | // Parms: uint16_t newstate, a value to be written to the 615 | // link's Genie::LinkState variable. Valid values are 616 | // GENIE_LINK_IDLE 0 617 | // GENIE_LINK_WFAN 1 // waiting for Ack or Nak 618 | // GENIE_LINK_WF_RXREPORT 2 // waiting for a report frame 619 | // GENIE_LINK_RXREPORT 3 // receiving a report frame 620 | // GENIE_LINK_RXEVENT 4 // receiving an event frame 621 | // GENIE_LINK_SHDN 5 622 | // 623 | void Genie::SetLinkState (uint16_t newstate) { 624 | *LinkState = newstate; 625 | 626 | if (newstate == GENIE_LINK_RXREPORT || \ 627 | newstate == GENIE_LINK_RXEVENT) { 628 | rxframe_count = 0; 629 | } 630 | } 631 | 632 | /////////////////////// Genie::GetLinkState ////////////////////// 633 | // 634 | // Get the current logical state of the link to the display. 635 | // 636 | uint16_t Genie::GetLinkState (void) { 637 | return *LinkState; 638 | } 639 | 640 | ///////////////////////// WriteObject ////////////////////// 641 | // 642 | // Write data to an object on the display 643 | // 644 | uint16_t Genie::WriteObject (uint16_t object, uint16_t index, uint16_t data) { 645 | uint16_t msb, lsb ; 646 | uint8_t checksum ; 647 | WaitForIdle(); 648 | lsb = lowByte(data); 649 | msb = highByte(data); 650 | Error = ERROR_NONE; 651 | deviceSerial->write(GENIE_WRITE_OBJ) ; 652 | checksum = GENIE_WRITE_OBJ ; 653 | deviceSerial->write(object) ; 654 | checksum ^= object ; 655 | deviceSerial->write(index) ; 656 | checksum ^= index ; 657 | deviceSerial->write(msb) ; 658 | checksum ^= msb; 659 | deviceSerial->write(lsb) ; 660 | checksum ^= lsb; 661 | deviceSerial->write(checksum) ; 662 | /* 663 | if (debugSerial) { 664 | *debugSerial << "WriteObject: " << ", "; 665 | *debugSerial << _HEX(object) << ", "; 666 | *debugSerial << _HEX(index) << ", "; 667 | *debugSerial << _HEX(msb) << ", "; 668 | *debugSerial << _HEX(lsb) << ", "; 669 | *debugSerial << _HEX(checksum) << endl; 670 | *debugSerial << "Freemem = " << freeRam()<< endl; 671 | } 672 | */ 673 | PushLinkState(GENIE_LINK_WFAN); 674 | return FALSE; 675 | } 676 | 677 | /////////////////////// WriteIntLedDigits ////////////////// 678 | // 679 | // Write 16-bit data to Internal LedDigits 680 | // 681 | uint16_t Genie::WriteIntLedDigits (uint16_t index, int16_t data) { 682 | WriteObject(GENIE_OBJ_ILED_DIGITS_L, index, data); 683 | return TRUE; 684 | } 685 | 686 | /////////////////////// WriteIntLedDigits ////////////////// 687 | // 688 | // Write 32-bit float data to Internal LedDigits 689 | // 690 | uint16_t Genie::WriteIntLedDigits (uint16_t index, float data) { 691 | FloatLongFrame frame; 692 | frame.floatValue = data; 693 | WriteObject(GENIE_OBJ_ILED_DIGITS_H, index, frame.wordValue[1]); 694 | WriteObject(GENIE_OBJ_ILED_DIGITS_L, index, frame.wordValue[0]); 695 | return TRUE; 696 | } 697 | 698 | /////////////////////// WriteIntLedDigits ////////////////// 699 | // 700 | // Write 32-bit data to Internal LedDigits 701 | // 702 | uint16_t Genie::WriteIntLedDigits (uint16_t index, int32_t data) { 703 | FloatLongFrame frame; 704 | frame.longValue = data; 705 | WriteObject(GENIE_OBJ_ILED_DIGITS_H, index, frame.wordValue[1]); 706 | WriteObject(GENIE_OBJ_ILED_DIGITS_L, index, frame.wordValue[0]); 707 | return TRUE; 708 | } 709 | 710 | 711 | 712 | /////////////////////// WriteContrast ////////////////////// 713 | // 714 | // Alter the display contrast (backlight) 715 | // 716 | // Parms: uint8_t value: The required contrast setting, only 717 | // values from 0 to 15 are valid. 0 or 1 for most displays 718 | // and 0 to 15 for the uLCD-43, uLCD-70, uLCD-35, uLCD-220RD 719 | // 720 | void Genie::WriteContrast (uint16_t value) { 721 | unsigned int checksum ; 722 | WaitForIdle(); 723 | deviceSerial->write(GENIE_WRITE_CONTRAST) ; 724 | checksum = GENIE_WRITE_CONTRAST ; 725 | deviceSerial->write(value) ; 726 | checksum ^= value ; 727 | deviceSerial->write(checksum) ; 728 | PushLinkState(GENIE_LINK_WFAN); 729 | } 730 | 731 | /////////////////////// WriteStr //////////////////////// 732 | // 733 | // Write a string to the display (ASCII) 734 | // ASCII characters are 1 byte each 735 | // 736 | uint16_t Genie::WriteStr (uint16_t index, char *string) { 737 | char *p; 738 | unsigned int checksum; 739 | int len = strlen (string); 740 | 741 | if (len > 255) { 742 | return -1; 743 | } 744 | 745 | WaitForIdle(); 746 | deviceSerial->write(GENIE_WRITE_STR); 747 | checksum = GENIE_WRITE_STR; 748 | deviceSerial->write(index); 749 | checksum ^= index; 750 | deviceSerial->write((unsigned char)len); 751 | checksum ^= len; 752 | 753 | for (p = string ; *p ; ++p) { 754 | deviceSerial->write(*p); 755 | checksum ^= *p; 756 | } 757 | 758 | deviceSerial->write(checksum); 759 | PushLinkState(GENIE_LINK_WFAN); 760 | return 0; 761 | } 762 | 763 | #ifdef AVR 764 | uint16_t Genie::WriteStr(uint16_t index, const __FlashStringHelper *ifsh){ 765 | PGM_P p = reinterpret_cast(ifsh); 766 | PGM_P p2 = reinterpret_cast(ifsh); 767 | int len = 0; 768 | while (1) { 769 | unsigned char d = pgm_read_byte(p2++); 770 | len++; 771 | if (d == 0) break; 772 | } 773 | 774 | 775 | char arr[len]; 776 | int x = 0; 777 | while (1) { 778 | unsigned char c = pgm_read_byte(p++); 779 | arr[x] = c; 780 | x++; 781 | if (c == 0) break; 782 | } 783 | WriteStr(index, arr); 784 | return 0; 785 | } 786 | #endif 787 | 788 | uint16_t Genie::WriteStr(uint16_t index, const String &s){ 789 | //s.c_str(), s.length() 790 | int len = s.length(); 791 | char arr[len + 1]; 792 | s.toCharArray(arr,len + 1); 793 | WriteStr(index, arr); 794 | return 0; 795 | } 796 | 797 | 798 | uint16_t Genie::WriteStr (uint16_t index, long n) { 799 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 800 | char *str = &buf[sizeof(buf) - 1]; 801 | 802 | long N = n; 803 | n = abs(n); 804 | 805 | *str = '\0'; 806 | 807 | do { 808 | unsigned long m = n; 809 | n /= 10; 810 | char c = m - 10 * n; 811 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 812 | } while(n); 813 | 814 | if (N < 0) { 815 | *--str = '-'; 816 | } 817 | 818 | WriteStr(index, str); 819 | 820 | 821 | 822 | return 0; 823 | } 824 | 825 | uint16_t Genie::WriteStr (uint16_t index, long n, int base) { 826 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 827 | char *str = &buf[sizeof(buf) - 1]; 828 | 829 | long N; 830 | *str = '\0'; 831 | if(n>=0) 832 | { 833 | // prevent crash if called with base == 1 834 | if (base < 2) base = 10; 835 | if(base == 10) 836 | { 837 | N = n; 838 | n = abs(n); 839 | } 840 | 841 | do { 842 | unsigned long m = n; 843 | n /= base; 844 | char c = m - base * n; 845 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 846 | } while(n); 847 | 848 | if(base == 10) 849 | { 850 | if (N < 0) { 851 | *--str = '-'; 852 | } 853 | } 854 | 855 | } 856 | 857 | else if(n<0) 858 | { 859 | unsigned long n2 = (unsigned long)n; 860 | uint8_t base2 = base; 861 | do { 862 | unsigned long m = n2; 863 | n2 /= base2; 864 | char c = m - base2 * n2; 865 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 866 | } while(n2); 867 | 868 | } 869 | 870 | 871 | WriteStr(index, str); 872 | return 0; 873 | } 874 | 875 | uint16_t Genie::WriteStr (uint16_t index, int n) { 876 | WriteStr (index, (long) n); 877 | return 0; 878 | } 879 | 880 | uint16_t Genie::WriteStr (uint16_t index, int n, int base) { 881 | WriteStr (index, (long) n, base); 882 | return 0; 883 | } 884 | 885 | uint16_t Genie::WriteStr (uint16_t index, unsigned long n) { 886 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 887 | char *str = &buf[sizeof(buf) - 1]; 888 | 889 | *str = '\0'; 890 | 891 | do { 892 | unsigned long m = n; 893 | n /= 10; 894 | char c = m - 10 * n; 895 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 896 | } while(n); 897 | 898 | WriteStr(index, str); 899 | return 0; 900 | } 901 | 902 | uint16_t Genie::WriteStr (uint16_t index, unsigned long n, int base) { 903 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 904 | char *str = &buf[sizeof(buf) - 1]; 905 | 906 | *str = '\0'; 907 | 908 | // prevent crash if called with base == 1 909 | if (base < 2) base = 10; 910 | do { 911 | unsigned long m = n; 912 | n /= base; 913 | char c = m - base * n; 914 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 915 | } while(n); 916 | 917 | WriteStr(index, str); 918 | return 0; 919 | } 920 | 921 | uint16_t Genie::WriteStr (uint16_t index, unsigned int n) { 922 | WriteStr (index, (unsigned long) n); 923 | return 0; 924 | } 925 | 926 | uint16_t Genie::WriteStr (uint16_t index, unsigned n, int base) { 927 | WriteStr (index, (unsigned long) n, base); 928 | return 0; 929 | } 930 | 931 | 932 | uint16_t Genie::WriteStr (uint16_t index, double number, int digits) { 933 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 934 | char *str = &buf[sizeof(buf) - 1]; 935 | *str = '\0'; 936 | 937 | double number2 = number; 938 | if (number < 0.0) 939 | { 940 | number = -number; 941 | } 942 | 943 | // Round correctly so that print(1.999, 2) prints as "2.00" 944 | double rounding = 0.5; 945 | for (int i=0; i 0) 957 | { 958 | remainder *= 10.0; 959 | int toPrint = int(remainder); 960 | char c = toPrint + 48; 961 | *str++ = c; 962 | remainder -= toPrint; 963 | } 964 | str = &buf[sizeof(buf) - 1 - digits]; 965 | if (digits > 0) { 966 | *--str = '.'; 967 | } 968 | // Extract the integer part of the number and print it 969 | do { 970 | unsigned long m = int_part; 971 | int_part /= 10; 972 | char c = m - 10 * int_part; 973 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 974 | } while(int_part); 975 | 976 | // Handle negative numbers 977 | if (number2 < 0.0) 978 | { 979 | *--str = '-'; 980 | } 981 | 982 | WriteStr(index, str); 983 | 984 | return 0; 985 | } 986 | 987 | uint16_t Genie::WriteStr (uint16_t index, double n){ 988 | WriteStr(index, n, 2); 989 | return 0; 990 | 991 | } 992 | 993 | /////////////////////// WriteStrU //////////////////////// 994 | // 995 | // Write a string to the display (Unicode) 996 | // Unicode characters are 2 bytes each 997 | // 998 | uint16_t Genie::WriteStrU (uint16_t index, uint16_t *string) { 999 | uint16_t *p; 1000 | unsigned int checksum; 1001 | int len = 0; 1002 | p = string; 1003 | 1004 | while (*p++) { 1005 | len++; 1006 | } 1007 | 1008 | if (len > 255) { 1009 | return -1; 1010 | } 1011 | 1012 | WaitForIdle(); 1013 | deviceSerial->write(GENIE_WRITE_STRU); 1014 | checksum = GENIE_WRITE_STRU; 1015 | deviceSerial->write(index); 1016 | checksum ^= index; 1017 | deviceSerial->write((unsigned char)(len)); 1018 | checksum ^= (len); 1019 | p = string; 1020 | 1021 | while (*p) { 1022 | deviceSerial->write (*p >> 8); 1023 | checksum ^= *p >> 8; 1024 | deviceSerial->write (*p); 1025 | checksum ^= *p++ & 0xff; 1026 | } 1027 | 1028 | deviceSerial->write(checksum); 1029 | PushLinkState(GENIE_LINK_WFAN); 1030 | return 0; 1031 | } 1032 | 1033 | /////////////////////// WriteInhLabel //////////////////////// 1034 | // 1035 | // Write a string to the display's Inherent Labeld 1036 | // ASCII characters are 1 byte each 1037 | // 1038 | uint16_t Genie::WriteInhLabel (uint16_t index) { 1039 | WriteObject(GENIE_OBJ_ILABELB, index, -1); 1040 | return 0; 1041 | } 1042 | 1043 | uint16_t Genie::WriteInhLabel (uint16_t index, char *string) { 1044 | char *p; 1045 | unsigned int checksum; 1046 | int len = strlen (string); 1047 | 1048 | if (len > 255) { 1049 | return -1; 1050 | } 1051 | 1052 | WaitForIdle(); 1053 | deviceSerial->write(GENIE_WRITE_INH_LABEL); 1054 | checksum = GENIE_WRITE_INH_LABEL; 1055 | deviceSerial->write(index); 1056 | checksum ^= index; 1057 | deviceSerial->write((unsigned char)len); 1058 | checksum ^= len; 1059 | 1060 | for (p = string ; *p ; ++p) { 1061 | deviceSerial->write(*p); 1062 | checksum ^= *p; 1063 | } 1064 | 1065 | deviceSerial->write(checksum); 1066 | PushLinkState(GENIE_LINK_WFAN); 1067 | return 0; 1068 | } 1069 | 1070 | #ifdef AVR 1071 | uint16_t Genie::WriteInhLabel(uint16_t index, const __FlashStringHelper *ifsh){ 1072 | PGM_P p = reinterpret_cast(ifsh); 1073 | PGM_P p2 = reinterpret_cast(ifsh); 1074 | int len = 0; 1075 | while (1) { 1076 | unsigned char d = pgm_read_byte(p2++); 1077 | len++; 1078 | if (d == 0) break; 1079 | } 1080 | 1081 | char arr[len]; 1082 | int x = 0; 1083 | while (1) { 1084 | unsigned char c = pgm_read_byte(p++); 1085 | arr[x] = c; 1086 | x++; 1087 | if (c == 0) break; 1088 | } 1089 | WriteInhLabel(index, arr); 1090 | return 0; 1091 | } 1092 | #endif 1093 | 1094 | uint16_t Genie::WriteInhLabel(uint16_t index, const String &s){ 1095 | //s.c_str(), s.length() 1096 | int len = s.length(); 1097 | char arr[len + 1]; 1098 | s.toCharArray(arr,len + 1); 1099 | WriteInhLabel(index, arr); 1100 | return 0; 1101 | } 1102 | 1103 | 1104 | uint16_t Genie::WriteInhLabel (uint16_t index, long n) { 1105 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 1106 | char *str = &buf[sizeof(buf) - 1]; 1107 | 1108 | long N = n; 1109 | n = abs(n); 1110 | 1111 | *str = '\0'; 1112 | 1113 | do { 1114 | unsigned long m = n; 1115 | n /= 10; 1116 | char c = m - 10 * n; 1117 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 1118 | } while(n); 1119 | 1120 | if (N < 0) { 1121 | *--str = '-'; 1122 | } 1123 | 1124 | WriteInhLabel(index, str); 1125 | 1126 | return 0; 1127 | } 1128 | 1129 | uint16_t Genie::WriteInhLabel (uint16_t index, long n, int base) { 1130 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 1131 | char *str = &buf[sizeof(buf) - 1]; 1132 | 1133 | long N; 1134 | *str = '\0'; 1135 | if(n>=0) 1136 | { 1137 | // prevent crash if called with base == 1 1138 | if (base < 2) base = 10; 1139 | if(base == 10) 1140 | { 1141 | N = n; 1142 | n = abs(n); 1143 | } 1144 | 1145 | do { 1146 | unsigned long m = n; 1147 | n /= base; 1148 | char c = m - base * n; 1149 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 1150 | } while(n); 1151 | 1152 | if(base == 10) 1153 | { 1154 | if (N < 0) { 1155 | *--str = '-'; 1156 | } 1157 | } 1158 | 1159 | } 1160 | 1161 | else if(n<0) 1162 | { 1163 | unsigned long n2 = (unsigned long)n; 1164 | uint8_t base2 = base; 1165 | do { 1166 | unsigned long m = n2; 1167 | n2 /= base2; 1168 | char c = m - base2 * n2; 1169 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 1170 | } while(n2); 1171 | 1172 | } 1173 | 1174 | WriteInhLabel(index, str); 1175 | return 0; 1176 | } 1177 | 1178 | uint16_t Genie::WriteInhLabel (uint16_t index, int n) { 1179 | WriteInhLabel (index, (long) n); 1180 | return 0; 1181 | } 1182 | 1183 | uint16_t Genie::WriteInhLabel (uint16_t index, int n, int base) { 1184 | WriteInhLabel (index, (long) n, base); 1185 | return 0; 1186 | } 1187 | 1188 | uint16_t Genie::WriteInhLabel (uint16_t index, unsigned long n) { 1189 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 1190 | char *str = &buf[sizeof(buf) - 1]; 1191 | 1192 | *str = '\0'; 1193 | 1194 | do { 1195 | unsigned long m = n; 1196 | n /= 10; 1197 | char c = m - 10 * n; 1198 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 1199 | } while(n); 1200 | 1201 | WriteInhLabel(index, str); 1202 | return 0; 1203 | } 1204 | 1205 | uint16_t Genie::WriteInhLabel (uint16_t index, unsigned long n, int base) { 1206 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 1207 | char *str = &buf[sizeof(buf) - 1]; 1208 | 1209 | *str = '\0'; 1210 | 1211 | // prevent crash if called with base == 1 1212 | if (base < 2) base = 10; 1213 | do { 1214 | unsigned long m = n; 1215 | n /= base; 1216 | char c = m - base * n; 1217 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 1218 | } while(n); 1219 | 1220 | WriteInhLabel(index, str); 1221 | return 0; 1222 | } 1223 | 1224 | uint16_t Genie::WriteInhLabel (uint16_t index, unsigned int n) { 1225 | WriteInhLabel (index, (unsigned long) n); 1226 | return 0; 1227 | } 1228 | 1229 | uint16_t Genie::WriteInhLabel (uint16_t index, unsigned n, int base) { 1230 | WriteInhLabel (index, (unsigned long) n, base); 1231 | return 0; 1232 | } 1233 | 1234 | 1235 | uint16_t Genie::WriteInhLabel (uint16_t index, double number, int digits) { 1236 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte. 1237 | char *str = &buf[sizeof(buf) - 1]; 1238 | *str = '\0'; 1239 | 1240 | double number2 = number; 1241 | if (number < 0.0) 1242 | { 1243 | number = -number; 1244 | } 1245 | 1246 | // Round correctly so that print(1.999, 2) prints as "2.00" 1247 | double rounding = 0.5; 1248 | for (int i=0; i 0) 1260 | { 1261 | remainder *= 10.0; 1262 | int toPrint = int(remainder); 1263 | char c = toPrint + 48; 1264 | *str++ = c; 1265 | remainder -= toPrint; 1266 | } 1267 | str = &buf[sizeof(buf) - 1 - digits]; 1268 | if (digits > 0) { 1269 | *--str = '.'; 1270 | } 1271 | // Extract the integer part of the number and print it 1272 | do { 1273 | unsigned long m = int_part; 1274 | int_part /= 10; 1275 | char c = m - 10 * int_part; 1276 | *--str = c < 10 ? c + '0' : c + 'A' - 10; 1277 | } while(int_part); 1278 | 1279 | // Handle negative numbers 1280 | if (number2 < 0.0) 1281 | { 1282 | *--str = '-'; 1283 | } 1284 | 1285 | WriteInhLabel(index, str); 1286 | 1287 | return 0; 1288 | } 1289 | 1290 | uint16_t Genie::WriteInhLabel (uint16_t index, double n){ 1291 | WriteInhLabel(index, n, 2); 1292 | return 0; 1293 | } 1294 | 1295 | /////////////////// AttachEventHandler ////////////////////// 1296 | // 1297 | // "Attaches" a pointer to the users event handler by writing 1298 | // the pointer into the variable used by doEVents() 1299 | // 1300 | void Genie::AttachEventHandler (UserEventHandlerPtr handler) { 1301 | UserHandler = handler; 1302 | } 1303 | 1304 | /////////////////// AttachMagicByteReader ////////////////////// 1305 | // 1306 | // "Attaches" a pointer to a user's function for receiving 1307 | // GenieMagic byte reports. 1308 | // 1309 | void Genie::AttachMagicByteReader(UserBytePtr handler) { 1310 | UserByteReader = handler; 1311 | } 1312 | 1313 | /////////////////// AttachMagicDoubleByteReader////////////////////// 1314 | // 1315 | // "Attaches" a pointer to a user's function for receiving 1316 | // GenieMagic doublebyte reports. 1317 | // 1318 | void Genie::AttachMagicDoubleByteReader(UserDoubleBytePtr handler) { 1319 | UserDoubleByteReader = handler; 1320 | } 1321 | 1322 | //////////////////////// deviceSerial->read ////////////////////////// 1323 | // 1324 | // Get a character from the selected Genie serial port 1325 | // 1326 | // Returns: ERROR_NOHANDLER if an Rx handler has not 1327 | // been defined 1328 | // ERROR_NOCHAR if no bytes have beeb received 1329 | // The char if there was one to get 1330 | // Sets: Error with any errors encountered 1331 | // 1332 | 1333 | 1334 | //////////////////////////////////// Setup ///////////////////////////////////////// 1335 | // 1336 | // Send a reference to a hardware serial port directly 1337 | // void Begin (Stream &serial) 1338 | // 1339 | 1340 | void Genie::Begin (Stream &serial) { 1341 | deviceSerial = &serial; 1342 | PushLinkState(GENIE_LINK_IDLE); 1343 | FlushEventQueue(); 1344 | } 1345 | 1346 | /////////////////////// WriteMagicBytes //////////////////////// 1347 | // 1348 | // Write an array of bytes to a Magic object 1349 | // 1350 | uint16_t Genie::WriteMagicBytes (uint16_t index, uint8_t *bytes, uint16_t len) { 1351 | unsigned int checksum; 1352 | 1353 | if (len > 255) { 1354 | return -1; 1355 | } 1356 | 1357 | WaitForIdle(); 1358 | deviceSerial->write(GENIEM_WRITE_BYTES); 1359 | checksum = GENIEM_WRITE_BYTES; 1360 | deviceSerial->write(index); 1361 | checksum ^= index; 1362 | deviceSerial->write((unsigned char)len); 1363 | checksum ^= len; 1364 | 1365 | for (uint16_t i = 0; i < len; i++) { 1366 | deviceSerial->write(bytes[i]); 1367 | checksum ^= bytes[i]; 1368 | } 1369 | 1370 | deviceSerial->write(checksum); 1371 | PushLinkState(GENIE_LINK_WFAN); 1372 | return 0; 1373 | } 1374 | 1375 | /////////////////////// WriteMagicDBytes //////////////////////// 1376 | // 1377 | // Write an array of 16-bit short values to a Magic object 1378 | // 1379 | uint16_t Genie::WriteMagicDBytes (uint16_t index, uint16_t *shorts, uint16_t len) { 1380 | unsigned int checksum; 1381 | 1382 | if (len > 255) { 1383 | return -1; 1384 | } 1385 | 1386 | WaitForIdle(); 1387 | deviceSerial->write(GENIEM_WRITE_DBYTES); 1388 | checksum = GENIEM_WRITE_DBYTES; 1389 | deviceSerial->write(index); 1390 | checksum ^= index; 1391 | deviceSerial->write((unsigned char)(len)); 1392 | checksum ^= (len); 1393 | 1394 | for (uint16_t i = 0; i < len; i++) { 1395 | deviceSerial->write (shorts[i] >> 8); 1396 | checksum ^= shorts[i] >> 8; 1397 | deviceSerial->write (shorts[i] & 0xFF); 1398 | checksum ^= shorts[i] & 0xff; 1399 | } 1400 | 1401 | deviceSerial->write(checksum); 1402 | PushLinkState(GENIE_LINK_WFAN); 1403 | return 0; 1404 | } 1405 | 1406 | -------------------------------------------------------------------------------- /src/genieArduino.h: -------------------------------------------------------------------------------- 1 | /////////////////////// GenieArduino /////////////////////// 2 | // 3 | // Library to utilize the 4D Systems Genie interface to displays 4 | // that have been created using the Visi-Genie creator platform. 5 | // This is intended to be used with the Arduino platform. 6 | // 7 | // Improvements/Updates by 8 | // v1.5.3 4D Systems Engineering, January 2022, www.4dsystems.com.au 9 | // v1.5.2 4D Systems Engineering, May 2021, www.4dsystems.com.au 10 | // v1.5.1 4D Systems Engineering, August 2020, www.4dsystems.com.au 11 | // v1.5.0 4D Systems Engineering, July 2020, www.4dsystems.com.au 12 | // v1.4.5 4D Systems Engineering, August 2017, www.4dsystems.com.au 13 | // v1.4.4 4D Systems Engineering, October 2015, www.4dsystems.com.au 14 | // v1.4.3 4D Systems Engineering, September 2015, www.4dsystems.com.au 15 | // v1.4.2 4D Systems Engineering, August 2015, www.4dsystems.com.au 16 | // v1.4.1 4D Systems Engineering, May 2015, www.4dsystems.com.au 17 | // v1.4.0 Matt Jenkins, March 2015, www.majenko.com 18 | // v1.3.0 Clinton Keith, January 2015, www.clintonkeith.com 19 | // v1.2.0 4D Systems Engineering, July 2014, www.4dsystems.com.au 20 | // v1.1.2 Clinton Keith, March 2014, www.clintonkeith.com 21 | // v1.1.1 Clinton Keith, January 2014, www.clintonkeith.com 22 | // v1.1.0 4D Systems Engineering, January 2014, www.4dsystems.com.au 23 | // v1.0.1 4D Systems Engineering, September 2013, www.4dsystems.com.au 24 | // Written by 25 | // v1.0.0 Rob Gray (GRAYnomad), June 2013, www.robgray.com 26 | // Based on code by 27 | // Gordon Henderson, February 2013, 28 | // 29 | // Copyright (c) 2012-2022 4D Systems Pty Ltd, Sydney, Australia 30 | /********************************************************************* 31 | * This file is part of genieArduino: 32 | * genieArduino is free software: you can redistribute it and/or modify 33 | * it under the terms of the GNU Lesser General Public License as 34 | * published by the Free Software Foundation, either version 3 of the 35 | * License, or (at your option) any later version. 36 | * 37 | * genieArduino is distributed in the hope that it will be useful, 38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 40 | * GNU Lesser General Public License for more details. 41 | * 42 | * You should have received a copy of the GNU Lesser General Public 43 | * License along with genieArduino. 44 | * If not, see . 45 | *********************************************************************/ 46 | #if defined(ARDUINO) && ARDUINO >= 100 47 | #include "Arduino.h" 48 | #else 49 | #include "WProgram.h" 50 | #endif 51 | 52 | #include 53 | 54 | #include 55 | 56 | #ifndef genieArduino_h 57 | #define genieArduino_h 58 | 59 | #undef GENIE_DEBUG 60 | 61 | #define GENIE_VERSION (String)"v1.5.3 - 26-01-2022" // DD-MM-YYYY 62 | 63 | // Genie commands & replys: 64 | 65 | #define GENIE_ACK 0x06 66 | #define GENIE_NAK 0x15 67 | 68 | #define TIMEOUT_PERIOD 1000 69 | #define RESYNC_PERIOD 100 70 | 71 | #define GENIE_READ_OBJ 0 72 | #define GENIE_WRITE_OBJ 1 73 | #define GENIE_WRITE_STR 2 74 | #define GENIE_WRITE_STRU 3 75 | #define GENIE_WRITE_CONTRAST 4 76 | #define GENIE_REPORT_OBJ 5 77 | #define GENIE_REPORT_EVENT 7 78 | #define GENIEM_WRITE_BYTES 8 79 | #define GENIEM_WRITE_DBYTES 9 80 | #define GENIEM_REPORT_BYTES 10 81 | #define GENIEM_REPORT_DBYTES 11 82 | #define GENIE_WRITE_INH_LABEL 12 83 | 84 | 85 | // Objects 86 | // the manual says: 87 | // Note: Object IDs may change with future releases; it is not 88 | // advisable to code their values as constants. 89 | 90 | #define GENIE_OBJ_DIPSW 0 91 | #define GENIE_OBJ_KNOB 1 92 | #define GENIE_OBJ_ROCKERSW 2 93 | #define GENIE_OBJ_ROTARYSW 3 94 | #define GENIE_OBJ_SLIDER 4 95 | #define GENIE_OBJ_TRACKBAR 5 96 | #define GENIE_OBJ_WINBUTTON 6 97 | #define GENIE_OBJ_ANGULAR_METER 7 98 | #define GENIE_OBJ_COOL_GAUGE 8 99 | #define GENIE_OBJ_CUSTOM_DIGITS 9 100 | #define GENIE_OBJ_FORM 10 101 | #define GENIE_OBJ_GAUGE 11 102 | #define GENIE_OBJ_IMAGE 12 103 | #define GENIE_OBJ_KEYBOARD 13 104 | #define GENIE_OBJ_LED 14 105 | #define GENIE_OBJ_LED_DIGITS 15 106 | #define GENIE_OBJ_METER 16 107 | #define GENIE_OBJ_STRINGS 17 108 | #define GENIE_OBJ_THERMOMETER 18 109 | #define GENIE_OBJ_USER_LED 19 110 | #define GENIE_OBJ_VIDEO 20 111 | #define GENIE_OBJ_STATIC_TEXT 21 112 | #define GENIE_OBJ_SOUND 22 113 | #define GENIE_OBJ_TIMER 23 114 | #define GENIE_OBJ_SPECTRUM 24 115 | #define GENIE_OBJ_SCOPE 25 116 | #define GENIE_OBJ_TANK 26 117 | #define GENIE_OBJ_USERIMAGES 27 118 | #define GENIE_OBJ_PINOUTPUT 28 119 | #define GENIE_OBJ_PININPUT 29 120 | #define GENIE_OBJ_4DBUTTON 30 121 | #define GENIE_OBJ_ANIBUTTON 31 122 | #define GENIE_OBJ_COLORPICKER 32 123 | #define GENIE_OBJ_USERBUTTON 33 124 | // reserved for magic functions 34 125 | #define GENIE_OBJ_SMARTGAUGE 35 126 | #define GENIE_OBJ_SMARTSLIDER 36 127 | #define GENIE_OBJ_SMARTKNOB 37 128 | // Not advisable to use the below 3, use the above 3 instead. 129 | #define GENIE_OBJ_ISMARTGAUGE 35 // Retained for backwards compatibility, however Users should use SMARTGAUGE instead of ISMARTGAUGE 130 | #define GENIE_OBJ_ISMARTSLIDER 36 // Retained for backwards compatibility, however Users should use SMARTSLIDER instead of ISMARTSLIDER 131 | #define GENIE_OBJ_ISMARTKNOB 37 // Retained for backwards compatibility, however Users should use SMARTKNOB instead of ISMARTKNOB 132 | // Comment end 133 | #define GENIE_OBJ_ILED_DIGITS_H 38 134 | #define GENIE_OBJ_IANGULAR_METER 39 135 | #define GENIE_OBJ_IGAUGE 40 136 | #define GENIE_OBJ_ILABELB 41 137 | #define GENIE_OBJ_IUSER_GAUGE 42 138 | #define GENIE_OBJ_IMEDIA_GAUGE 43 139 | #define GENIE_OBJ_IMEDIA_THERMOMETER 44 140 | #define GENIE_OBJ_ILED 45 141 | #define GENIE_OBJ_IMEDIA_LED 46 142 | #define GENIE_OBJ_ILED_DIGITS_L 47 143 | #define GENIE_OBJ_ILED_DIGITS 47 144 | #define GENIE_OBJ_INEEDLE 48 145 | #define GENIE_OBJ_IRULER 49 146 | #define GENIE_OBJ_ILED_DIGIT 50 147 | #define GENIE_OBJ_IBUTTOND 51 148 | #define GENIE_OBJ_IBUTTONE 52 149 | #define GENIE_OBJ_IMEDIA_BUTTON 53 150 | #define GENIE_OBJ_ITOGGLE_INPUT 54 151 | #define GENIE_OBJ_IDIAL 55 152 | #define GENIE_OBJ_IMEDIA_ROTARY 56 153 | #define GENIE_OBJ_IROTARY_INPUT 57 154 | #define GENIE_OBJ_ISWITCH 58 155 | #define GENIE_OBJ_ISWITCHB 59 156 | #define GENIE_OBJ_ISLIDERE 60 157 | #define GENIE_OBJ_IMEDIA_SLIDER 61 158 | #define GENIE_OBJ_ISLIDERH 62 159 | #define GENIE_OBJ_ISLIDERG 63 160 | #define GENIE_OBJ_ISLIDERF 64 161 | #define GENIE_OBJ_ISLIDERD 65 162 | #define GENIE_OBJ_ISLIDERC 66 163 | #define GENIE_OBJ_ILINEAR_INPUT 67 164 | 165 | // Structure to store replys returned from a display 166 | 167 | #define GENIE_FRAME_SIZE 6 168 | 169 | struct FrameReportObj { 170 | uint8_t cmd; 171 | uint8_t object; 172 | uint8_t index; 173 | uint8_t data_msb; 174 | uint8_t data_lsb; 175 | }; 176 | 177 | struct MagicReportHeader { 178 | uint8_t cmd; 179 | uint8_t index; 180 | uint8_t length; 181 | }; 182 | 183 | union FloatLongFrame { 184 | float floatValue; 185 | int32_t longValue; 186 | uint32_t ulongValue; 187 | int16_t wordValue[2]; 188 | }; 189 | 190 | ///////////////////////////////////////////////////////////////////// 191 | // The Genie frame definition 192 | // 193 | // The union allows the data to be referenced as an array of uint8_t 194 | // or a structure of type FrameReportObj, eg 195 | // 196 | // genieFrame f; 197 | // f.bytes[4]; 198 | // f.reportObject.data_lsb 199 | // 200 | // both methods get the same byte 201 | // 202 | union genieFrame { 203 | uint8_t bytes[GENIE_FRAME_SIZE]; 204 | FrameReportObj reportObject; 205 | }; 206 | 207 | #define MAX_GENIE_EVENTS 16 // MUST be a power of 2 208 | #define MAX_GENIE_FATALS 10 209 | #define MAX_LINK_STATES 20 210 | 211 | struct EventQueueStruct { 212 | genieFrame frames[MAX_GENIE_EVENTS]; 213 | uint8_t rd_index; 214 | uint8_t wr_index; 215 | uint8_t n_events; 216 | }; 217 | 218 | typedef void (*UserEventHandlerPtr) (void); 219 | typedef void (*UserBytePtr)(uint8_t, uint8_t); 220 | typedef void (*UserDoubleBytePtr)(uint8_t, uint8_t); 221 | 222 | ///////////////////////////////////////////////////////////////////// 223 | // User API functions 224 | // These function prototypes are the user API to the library 225 | // 226 | class Genie { 227 | 228 | public: 229 | Genie(); 230 | void Begin (Stream &serial); 231 | bool ReadObject (uint16_t object, uint16_t index); 232 | uint16_t WriteObject (uint16_t object, uint16_t index, uint16_t data); 233 | uint16_t WriteIntLedDigits (uint16_t index, int16_t data); 234 | uint16_t WriteIntLedDigits (uint16_t index, float data); 235 | uint16_t WriteIntLedDigits (uint16_t index, int32_t data); 236 | void WriteContrast (uint16_t value); 237 | uint16_t WriteStr (uint16_t index, char *string); 238 | uint16_t WriteStr (uint16_t index, long n) ; 239 | uint16_t WriteStr (uint16_t index, long n, int base) ; 240 | uint16_t WriteStr (uint16_t index, unsigned long n) ; 241 | uint16_t WriteStr (uint16_t index, unsigned long n, int base) ; 242 | uint16_t WriteStr (uint16_t index, int n) ; 243 | uint16_t WriteStr (uint16_t index, int n, int base) ; 244 | uint16_t WriteStr (uint16_t index, unsigned int n) ; 245 | uint16_t WriteStr (uint16_t index, unsigned int n, int base) ; 246 | uint16_t WriteStr (uint16_t index, const String &s); 247 | #ifdef AVR 248 | uint16_t WriteStr (uint16_t index, const __FlashStringHelper *ifsh); 249 | #endif 250 | uint16_t WriteStr (uint16_t index, double n, int digits); 251 | uint16_t WriteStr (uint16_t index, double n); 252 | uint16_t WriteStrU (uint16_t index, uint16_t *string); 253 | 254 | uint16_t WriteInhLabel (uint16_t index); 255 | uint16_t WriteInhLabel (uint16_t index, char *string); 256 | uint16_t WriteInhLabel (uint16_t index, long n) ; 257 | uint16_t WriteInhLabel (uint16_t index, long n, int base) ; 258 | uint16_t WriteInhLabel (uint16_t index, unsigned long n) ; 259 | uint16_t WriteInhLabel (uint16_t index, unsigned long n, int base) ; 260 | uint16_t WriteInhLabel (uint16_t index, int n) ; 261 | uint16_t WriteInhLabel (uint16_t index, int n, int base) ; 262 | uint16_t WriteInhLabel (uint16_t index, unsigned int n) ; 263 | uint16_t WriteInhLabel (uint16_t index, unsigned int n, int base) ; 264 | uint16_t WriteInhLabel (uint16_t index, const String &s); 265 | #ifdef AVR 266 | uint16_t WriteInhLabel (uint16_t index, const __FlashStringHelper *ifsh); 267 | #endif 268 | uint16_t WriteInhLabel (uint16_t index, double n, int digits); 269 | uint16_t WriteInhLabel (uint16_t index, double n); 270 | 271 | bool EventIs (genieFrame * e, uint8_t cmd, uint8_t object, uint8_t index); 272 | uint16_t GetEventData (genieFrame * e); 273 | bool DequeueEvent (genieFrame * buff); 274 | uint16_t DoEvents (bool DoHandler = true); 275 | void AttachEventHandler (UserEventHandlerPtr userHandler); 276 | void AttachMagicByteReader (UserBytePtr userHandler); 277 | void AttachMagicDoubleByteReader (UserDoubleBytePtr userHandler); 278 | void pulse (int pin); 279 | void assignDebugPort (Stream &port); 280 | 281 | // Genie Magic functions (ViSi-Genie Pro Only) 282 | 283 | uint16_t WriteMagicBytes (uint16_t index, uint8_t *bytes, uint16_t len); 284 | uint16_t WriteMagicDBytes (uint16_t index, uint16_t *bytes, uint16_t len); 285 | 286 | uint8_t GetNextByte (void); 287 | uint16_t GetNextDoubleByte (void); 288 | 289 | private: 290 | void FlushEventQueue (void); 291 | void handleError (void); 292 | void SetLinkState (uint16_t newstate); 293 | uint16_t GetLinkState (void); 294 | bool EnqueueEvent (uint8_t * data); 295 | uint8_t Getchar (void); 296 | uint16_t GetcharSerial (void); 297 | void WaitForIdle (void); 298 | void PushLinkState (uint8_t newstate); 299 | void PopLinkState (void); 300 | void FatalError (void); 301 | void FlushSerialInput (void); 302 | void Resync (void); 303 | 304 | 305 | ////////////////////////////////////////////////////////////// 306 | // A structure to hold up to MAX_GENIE_EVENTS events receive 307 | // from the display 308 | // 309 | EventQueueStruct EventQueue; 310 | 311 | ////////////////////////////////////////////////////////////// 312 | // Simple 5-deep stack for the link state, this allows 313 | // DoEvents() to save the current state, receive a frame, 314 | // then restore the state 315 | // 316 | uint8_t LinkStates[MAX_LINK_STATES]; 317 | // 318 | // Stack pointer 319 | // 320 | uint8_t *LinkState; 321 | 322 | ////////////////////////////////////////////////////////////// 323 | // Number of mS the GetChar() function will wait before 324 | // giving up on the display 325 | int Timeout; 326 | 327 | ////////////////////////////////////////////////////////////// 328 | // Number of times we have had a timeout 329 | int Timeouts; 330 | 331 | ////////////////////////////////////////////////////////////// 332 | // Global error variable 333 | int Error; 334 | 335 | 336 | uint8_t rxframe_count; 337 | 338 | ////////////////////////////////////////////////////////////// 339 | // Number of fatal errors encountered 340 | int FatalErrors; 341 | 342 | Stream* deviceSerial; 343 | Stream* debugSerial; 344 | 345 | UserEventHandlerPtr UserHandler; 346 | UserBytePtr UserByteReader; 347 | UserDoubleBytePtr UserDoubleByteReader; 348 | 349 | }; 350 | 351 | #ifndef TRUE 352 | #define TRUE (1==1) 353 | #define FALSE (!TRUE) 354 | #endif 355 | 356 | #define ERROR_NONE 0 357 | #define ERROR_TIMEOUT -1 // 255 0xFF 358 | #define ERROR_NOHANDLER -2 // 254 0xFE 359 | #define ERROR_NOCHAR -3 // 253 0xFD 360 | #define ERROR_NAK -4 // 252 0xFC 361 | #define ERROR_REPLY_OVR -5 // 251 0xFB 362 | #define ERROR_RESYNC -6 // 250 0xFA 363 | #define ERROR_NODISPLAY -7 // 249 0xF9 364 | #define ERROR_BAD_CS -8 // 248 0xF8 365 | 366 | #define GENIE_LINK_IDLE 0 367 | #define GENIE_LINK_WFAN 1 // waiting for Ack or Nak 368 | #define GENIE_LINK_WF_RXREPORT 2 // waiting for a report frame 369 | #define GENIE_LINK_RXREPORT 3 // receiving a report frame 370 | #define GENIE_LINK_RXEVENT 4 // receiving an event frame 371 | #define GENIE_LINK_SHDN 5 372 | #define GENIE_LINK_RXMBYTES 6 // receiving magic bytes 373 | #define GENIE_LINK_RXMDBYTES 7 // receiving magic dbytes 374 | 375 | #define GENIE_EVENT_NONE 0 376 | #define GENIE_EVENT_RXCHAR 1 377 | 378 | #endif 379 | --------------------------------------------------------------------------------