├── .gitignore ├── LICENSE ├── README.md ├── color.go ├── dac.go ├── draw.go ├── examples ├── circle │ └── circle.go ├── connect │ └── connect.go ├── cycloid │ └── cycloid.go ├── lissajous │ └── lissa.go ├── ln1 │ └── ln1.go ├── ln2 │ └── ln2.go ├── parallel_lines │ └── lines.go ├── spiral │ └── spiral.go └── square │ └── square.go ├── point.go └── status.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | 26 | # tmp files 27 | .*.swp 28 | *~ 29 | debug 30 | .vscode 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GPL v3 2 | 3 | Copyright (c) 2016 Tim Greiser 4 | 5 | GNU GENERAL PUBLIC LICENSE 6 | Version 3, 29 June 2007 7 | 8 | Copyright (C) 2007 Free Software Foundation, Inc. 9 | Everyone is permitted to copy and distribute verbatim copies 10 | of this license document, but changing it is not allowed. 11 | 12 | Preamble 13 | 14 | The GNU General Public License is a free, copyleft license for 15 | software and other kinds of works. 16 | 17 | The licenses for most software and other practical works are designed 18 | to take away your freedom to share and change the works. By contrast, 19 | the GNU General Public License is intended to guarantee your freedom to 20 | share and change all versions of a program--to make sure it remains free 21 | software for all its users. We, the Free Software Foundation, use the 22 | GNU General Public License for most of our software; it applies also to 23 | any other work released this way by its authors. You can apply it to 24 | your programs, too. 25 | 26 | When we speak of free software, we are referring to freedom, not 27 | price. Our General Public Licenses are designed to make sure that you 28 | have the freedom to distribute copies of free software (and charge for 29 | them if you wish), that you receive source code or can get it if you 30 | want it, that you can change the software or use pieces of it in new 31 | free programs, and that you know you can do these things. 32 | 33 | To protect your rights, we need to prevent others from denying you 34 | these rights or asking you to surrender the rights. Therefore, you have 35 | certain responsibilities if you distribute copies of the software, or if 36 | you modify it: responsibilities to respect the freedom of others. 37 | 38 | For example, if you distribute copies of such a program, whether 39 | gratis or for a fee, you must pass on to the recipients the same 40 | freedoms that you received. You must make sure that they, too, receive 41 | or can get the source code. And you must show them these terms so they 42 | know their rights. 43 | 44 | Developers that use the GNU GPL protect your rights with two steps: 45 | (1) assert copyright on the software, and (2) offer you this License 46 | giving you legal permission to copy, distribute and/or modify it. 47 | 48 | For the developers' and authors' protection, the GPL clearly explains 49 | that there is no warranty for this free software. For both users' and 50 | authors' sake, the GPL requires that modified versions be marked as 51 | changed, so that their problems will not be attributed erroneously to 52 | authors of previous versions. 53 | 54 | Some devices are designed to deny users access to install or run 55 | modified versions of the software inside them, although the manufacturer 56 | can do so. This is fundamentally incompatible with the aim of 57 | protecting users' freedom to change the software. The systematic 58 | pattern of such abuse occurs in the area of products for individuals to 59 | use, which is precisely where it is most unacceptable. Therefore, we 60 | have designed this version of the GPL to prohibit the practice for those 61 | products. If such problems arise substantially in other domains, we 62 | stand ready to extend this provision to those domains in future versions 63 | of the GPL, as needed to protect the freedom of users. 64 | 65 | Finally, every program is threatened constantly by software patents. 66 | States should not allow patents to restrict development and use of 67 | software on general-purpose computers, but in those that do, we wish to 68 | avoid the special danger that patents applied to a free program could 69 | make it effectively proprietary. To prevent this, the GPL assures that 70 | patents cannot be used to render the program non-free. 71 | 72 | The precise terms and conditions for copying, distribution and 73 | modification follow. 74 | 75 | TERMS AND CONDITIONS 76 | 77 | 0. Definitions. 78 | 79 | "This License" refers to version 3 of the GNU General Public License. 80 | 81 | "Copyright" also means copyright-like laws that apply to other kinds of 82 | works, such as semiconductor masks. 83 | 84 | "The Program" refers to any copyrightable work licensed under this 85 | License. Each licensee is addressed as "you". "Licensees" and 86 | "recipients" may be individuals or organizations. 87 | 88 | To "modify" a work means to copy from or adapt all or part of the work 89 | in a fashion requiring copyright permission, other than the making of an 90 | exact copy. The resulting work is called a "modified version" of the 91 | earlier work or a work "based on" the earlier work. 92 | 93 | A "covered work" means either the unmodified Program or a work based 94 | on the Program. 95 | 96 | To "propagate" a work means to do anything with it that, without 97 | permission, would make you directly or secondarily liable for 98 | infringement under applicable copyright law, except executing it on a 99 | computer or modifying a private copy. Propagation includes copying, 100 | distribution (with or without modification), making available to the 101 | public, and in some countries other activities as well. 102 | 103 | To "convey" a work means any kind of propagation that enables other 104 | parties to make or receive copies. Mere interaction with a user through 105 | a computer network, with no transfer of a copy, is not conveying. 106 | 107 | An interactive user interface displays "Appropriate Legal Notices" 108 | to the extent that it includes a convenient and prominently visible 109 | feature that (1) displays an appropriate copyright notice, and (2) 110 | tells the user that there is no warranty for the work (except to the 111 | extent that warranties are provided), that licensees may convey the 112 | work under this License, and how to view a copy of this License. If 113 | the interface presents a list of user commands or options, such as a 114 | menu, a prominent item in the list meets this criterion. 115 | 116 | 1. Source Code. 117 | 118 | The "source code" for a work means the preferred form of the work 119 | for making modifications to it. "Object code" means any non-source 120 | form of a work. 121 | 122 | A "Standard Interface" means an interface that either is an official 123 | standard defined by a recognized standards body, or, in the case of 124 | interfaces specified for a particular programming language, one that 125 | is widely used among developers working in that language. 126 | 127 | The "System Libraries" of an executable work include anything, other 128 | than the work as a whole, that (a) is included in the normal form of 129 | packaging a Major Component, but which is not part of that Major 130 | Component, and (b) serves only to enable use of the work with that 131 | Major Component, or to implement a Standard Interface for which an 132 | implementation is available to the public in source code form. A 133 | "Major Component", in this context, means a major essential component 134 | (kernel, window system, and so on) of the specific operating system 135 | (if any) on which the executable work runs, or a compiler used to 136 | produce the work, or an object code interpreter used to run it. 137 | 138 | The "Corresponding Source" for a work in object code form means all 139 | the source code needed to generate, install, and (for an executable 140 | work) run the object code and to modify the work, including scripts to 141 | control those activities. However, it does not include the work's 142 | System Libraries, or general-purpose tools or generally available free 143 | programs which are used unmodified in performing those activities but 144 | which are not part of the work. For example, Corresponding Source 145 | includes interface definition files associated with source files for 146 | the work, and the source code for shared libraries and dynamically 147 | linked subprograms that the work is specifically designed to require, 148 | such as by intimate data communication or control flow between those 149 | subprograms and other parts of the work. 150 | 151 | The Corresponding Source need not include anything that users 152 | can regenerate automatically from other parts of the Corresponding 153 | Source. 154 | 155 | The Corresponding Source for a work in source code form is that 156 | same work. 157 | 158 | 2. Basic Permissions. 159 | 160 | All rights granted under this License are granted for the term of 161 | copyright on the Program, and are irrevocable provided the stated 162 | conditions are met. This License explicitly affirms your unlimited 163 | permission to run the unmodified Program. The output from running a 164 | covered work is covered by this License only if the output, given its 165 | content, constitutes a covered work. This License acknowledges your 166 | rights of fair use or other equivalent, as provided by copyright law. 167 | 168 | You may make, run and propagate covered works that you do not 169 | convey, without conditions so long as your license otherwise remains 170 | in force. You may convey covered works to others for the sole purpose 171 | of having them make modifications exclusively for you, or provide you 172 | with facilities for running those works, provided that you comply with 173 | the terms of this License in conveying all material for which you do 174 | not control copyright. Those thus making or running the covered works 175 | for you must do so exclusively on your behalf, under your direction 176 | and control, on terms that prohibit them from making any copies of 177 | your copyrighted material outside their relationship with you. 178 | 179 | Conveying under any other circumstances is permitted solely under 180 | the conditions stated below. Sublicensing is not allowed; section 10 181 | makes it unnecessary. 182 | 183 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 184 | 185 | No covered work shall be deemed part of an effective technological 186 | measure under any applicable law fulfilling obligations under article 187 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 188 | similar laws prohibiting or restricting circumvention of such 189 | measures. 190 | 191 | When you convey a covered work, you waive any legal power to forbid 192 | circumvention of technological measures to the extent such circumvention 193 | is effected by exercising rights under this License with respect to 194 | the covered work, and you disclaim any intention to limit operation or 195 | modification of the work as a means of enforcing, against the work's 196 | users, your or third parties' legal rights to forbid circumvention of 197 | technological measures. 198 | 199 | 4. Conveying Verbatim Copies. 200 | 201 | You may convey verbatim copies of the Program's source code as you 202 | receive it, in any medium, provided that you conspicuously and 203 | appropriately publish on each copy an appropriate copyright notice; 204 | keep intact all notices stating that this License and any 205 | non-permissive terms added in accord with section 7 apply to the code; 206 | keep intact all notices of the absence of any warranty; and give all 207 | recipients a copy of this License along with the Program. 208 | 209 | You may charge any price or no price for each copy that you convey, 210 | and you may offer support or warranty protection for a fee. 211 | 212 | 5. Conveying Modified Source Versions. 213 | 214 | You may convey a work based on the Program, or the modifications to 215 | produce it from the Program, in the form of source code under the 216 | terms of section 4, provided that you also meet all of these conditions: 217 | 218 | a) The work must carry prominent notices stating that you modified 219 | it, and giving a relevant date. 220 | 221 | b) The work must carry prominent notices stating that it is 222 | released under this License and any conditions added under section 223 | 7. This requirement modifies the requirement in section 4 to 224 | "keep intact all notices". 225 | 226 | c) You must license the entire work, as a whole, under this 227 | License to anyone who comes into possession of a copy. This 228 | License will therefore apply, along with any applicable section 7 229 | additional terms, to the whole of the work, and all its parts, 230 | regardless of how they are packaged. This License gives no 231 | permission to license the work in any other way, but it does not 232 | invalidate such permission if you have separately received it. 233 | 234 | d) If the work has interactive user interfaces, each must display 235 | Appropriate Legal Notices; however, if the Program has interactive 236 | interfaces that do not display Appropriate Legal Notices, your 237 | work need not make them do so. 238 | 239 | A compilation of a covered work with other separate and independent 240 | works, which are not by their nature extensions of the covered work, 241 | and which are not combined with it such as to form a larger program, 242 | in or on a volume of a storage or distribution medium, is called an 243 | "aggregate" if the compilation and its resulting copyright are not 244 | used to limit the access or legal rights of the compilation's users 245 | beyond what the individual works permit. Inclusion of a covered work 246 | in an aggregate does not cause this License to apply to the other 247 | parts of the aggregate. 248 | 249 | 6. Conveying Non-Source Forms. 250 | 251 | You may convey a covered work in object code form under the terms 252 | of sections 4 and 5, provided that you also convey the 253 | machine-readable Corresponding Source under the terms of this License, 254 | in one of these ways: 255 | 256 | a) Convey the object code in, or embodied in, a physical product 257 | (including a physical distribution medium), accompanied by the 258 | Corresponding Source fixed on a durable physical medium 259 | customarily used for software interchange. 260 | 261 | b) Convey the object code in, or embodied in, a physical product 262 | (including a physical distribution medium), accompanied by a 263 | written offer, valid for at least three years and valid for as 264 | long as you offer spare parts or customer support for that product 265 | model, to give anyone who possesses the object code either (1) a 266 | copy of the Corresponding Source for all the software in the 267 | product that is covered by this License, on a durable physical 268 | medium customarily used for software interchange, for a price no 269 | more than your reasonable cost of physically performing this 270 | conveying of source, or (2) access to copy the 271 | Corresponding Source from a network server at no charge. 272 | 273 | c) Convey individual copies of the object code with a copy of the 274 | written offer to provide the Corresponding Source. This 275 | alternative is allowed only occasionally and noncommercially, and 276 | only if you received the object code with such an offer, in accord 277 | with subsection 6b. 278 | 279 | d) Convey the object code by offering access from a designated 280 | place (gratis or for a charge), and offer equivalent access to the 281 | Corresponding Source in the same way through the same place at no 282 | further charge. You need not require recipients to copy the 283 | Corresponding Source along with the object code. If the place to 284 | copy the object code is a network server, the Corresponding Source 285 | may be on a different server (operated by you or a third party) 286 | that supports equivalent copying facilities, provided you maintain 287 | clear directions next to the object code saying where to find the 288 | Corresponding Source. Regardless of what server hosts the 289 | Corresponding Source, you remain obligated to ensure that it is 290 | available for as long as needed to satisfy these requirements. 291 | 292 | e) Convey the object code using peer-to-peer transmission, provided 293 | you inform other peers where the object code and Corresponding 294 | Source of the work are being offered to the general public at no 295 | charge under subsection 6d. 296 | 297 | A separable portion of the object code, whose source code is excluded 298 | from the Corresponding Source as a System Library, need not be 299 | included in conveying the object code work. 300 | 301 | A "User Product" is either (1) a "consumer product", which means any 302 | tangible personal property which is normally used for personal, family, 303 | or household purposes, or (2) anything designed or sold for incorporation 304 | into a dwelling. In determining whether a product is a consumer product, 305 | doubtful cases shall be resolved in favor of coverage. For a particular 306 | product received by a particular user, "normally used" refers to a 307 | typical or common use of that class of product, regardless of the status 308 | of the particular user or of the way in which the particular user 309 | actually uses, or expects or is expected to use, the product. A product 310 | is a consumer product regardless of whether the product has substantial 311 | commercial, industrial or non-consumer uses, unless such uses represent 312 | the only significant mode of use of the product. 313 | 314 | "Installation Information" for a User Product means any methods, 315 | procedures, authorization keys, or other information required to install 316 | and execute modified versions of a covered work in that User Product from 317 | a modified version of its Corresponding Source. The information must 318 | suffice to ensure that the continued functioning of the modified object 319 | code is in no case prevented or interfered with solely because 320 | modification has been made. 321 | 322 | If you convey an object code work under this section in, or with, or 323 | specifically for use in, a User Product, and the conveying occurs as 324 | part of a transaction in which the right of possession and use of the 325 | User Product is transferred to the recipient in perpetuity or for a 326 | fixed term (regardless of how the transaction is characterized), the 327 | Corresponding Source conveyed under this section must be accompanied 328 | by the Installation Information. But this requirement does not apply 329 | if neither you nor any third party retains the ability to install 330 | modified object code on the User Product (for example, the work has 331 | been installed in ROM). 332 | 333 | The requirement to provide Installation Information does not include a 334 | requirement to continue to provide support service, warranty, or updates 335 | for a work that has been modified or installed by the recipient, or for 336 | the User Product in which it has been modified or installed. Access to a 337 | network may be denied when the modification itself materially and 338 | adversely affects the operation of the network or violates the rules and 339 | protocols for communication across the network. 340 | 341 | Corresponding Source conveyed, and Installation Information provided, 342 | in accord with this section must be in a format that is publicly 343 | documented (and with an implementation available to the public in 344 | source code form), and must require no special password or key for 345 | unpacking, reading or copying. 346 | 347 | 7. Additional Terms. 348 | 349 | "Additional permissions" are terms that supplement the terms of this 350 | License by making exceptions from one or more of its conditions. 351 | Additional permissions that are applicable to the entire Program shall 352 | be treated as though they were included in this License, to the extent 353 | that they are valid under applicable law. If additional permissions 354 | apply only to part of the Program, that part may be used separately 355 | under those permissions, but the entire Program remains governed by 356 | this License without regard to the additional permissions. 357 | 358 | When you convey a copy of a covered work, you may at your option 359 | remove any additional permissions from that copy, or from any part of 360 | it. (Additional permissions may be written to require their own 361 | removal in certain cases when you modify the work.) You may place 362 | additional permissions on material, added by you to a covered work, 363 | for which you have or can give appropriate copyright permission. 364 | 365 | Notwithstanding any other provision of this License, for material you 366 | add to a covered work, you may (if authorized by the copyright holders of 367 | that material) supplement the terms of this License with terms: 368 | 369 | a) Disclaiming warranty or limiting liability differently from the 370 | terms of sections 15 and 16 of this License; or 371 | 372 | b) Requiring preservation of specified reasonable legal notices or 373 | author attributions in that material or in the Appropriate Legal 374 | Notices displayed by works containing it; or 375 | 376 | c) Prohibiting misrepresentation of the origin of that material, or 377 | requiring that modified versions of such material be marked in 378 | reasonable ways as different from the original version; or 379 | 380 | d) Limiting the use for publicity purposes of names of licensors or 381 | authors of the material; or 382 | 383 | e) Declining to grant rights under trademark law for use of some 384 | trade names, trademarks, or service marks; or 385 | 386 | f) Requiring indemnification of licensors and authors of that 387 | material by anyone who conveys the material (or modified versions of 388 | it) with contractual assumptions of liability to the recipient, for 389 | any liability that these contractual assumptions directly impose on 390 | those licensors and authors. 391 | 392 | All other non-permissive additional terms are considered "further 393 | restrictions" within the meaning of section 10. If the Program as you 394 | received it, or any part of it, contains a notice stating that it is 395 | governed by this License along with a term that is a further 396 | restriction, you may remove that term. If a license document contains 397 | a further restriction but permits relicensing or conveying under this 398 | License, you may add to a covered work material governed by the terms 399 | of that license document, provided that the further restriction does 400 | not survive such relicensing or conveying. 401 | 402 | If you add terms to a covered work in accord with this section, you 403 | must place, in the relevant source files, a statement of the 404 | additional terms that apply to those files, or a notice indicating 405 | where to find the applicable terms. 406 | 407 | Additional terms, permissive or non-permissive, may be stated in the 408 | form of a separately written license, or stated as exceptions; 409 | the above requirements apply either way. 410 | 411 | 8. Termination. 412 | 413 | You may not propagate or modify a covered work except as expressly 414 | provided under this License. Any attempt otherwise to propagate or 415 | modify it is void, and will automatically terminate your rights under 416 | this License (including any patent licenses granted under the third 417 | paragraph of section 11). 418 | 419 | However, if you cease all violation of this License, then your 420 | license from a particular copyright holder is reinstated (a) 421 | provisionally, unless and until the copyright holder explicitly and 422 | finally terminates your license, and (b) permanently, if the copyright 423 | holder fails to notify you of the violation by some reasonable means 424 | prior to 60 days after the cessation. 425 | 426 | Moreover, your license from a particular copyright holder is 427 | reinstated permanently if the copyright holder notifies you of the 428 | violation by some reasonable means, this is the first time you have 429 | received notice of violation of this License (for any work) from that 430 | copyright holder, and you cure the violation prior to 30 days after 431 | your receipt of the notice. 432 | 433 | Termination of your rights under this section does not terminate the 434 | licenses of parties who have received copies or rights from you under 435 | this License. If your rights have been terminated and not permanently 436 | reinstated, you do not qualify to receive new licenses for the same 437 | material under section 10. 438 | 439 | 9. Acceptance Not Required for Having Copies. 440 | 441 | You are not required to accept this License in order to receive or 442 | run a copy of the Program. Ancillary propagation of a covered work 443 | occurring solely as a consequence of using peer-to-peer transmission 444 | to receive a copy likewise does not require acceptance. However, 445 | nothing other than this License grants you permission to propagate or 446 | modify any covered work. These actions infringe copyright if you do 447 | not accept this License. Therefore, by modifying or propagating a 448 | covered work, you indicate your acceptance of this License to do so. 449 | 450 | 10. Automatic Licensing of Downstream Recipients. 451 | 452 | Each time you convey a covered work, the recipient automatically 453 | receives a license from the original licensors, to run, modify and 454 | propagate that work, subject to this License. You are not responsible 455 | for enforcing compliance by third parties with this License. 456 | 457 | An "entity transaction" is a transaction transferring control of an 458 | organization, or substantially all assets of one, or subdividing an 459 | organization, or merging organizations. If propagation of a covered 460 | work results from an entity transaction, each party to that 461 | transaction who receives a copy of the work also receives whatever 462 | licenses to the work the party's predecessor in interest had or could 463 | give under the previous paragraph, plus a right to possession of the 464 | Corresponding Source of the work from the predecessor in interest, if 465 | the predecessor has it or can get it with reasonable efforts. 466 | 467 | You may not impose any further restrictions on the exercise of the 468 | rights granted or affirmed under this License. For example, you may 469 | not impose a license fee, royalty, or other charge for exercise of 470 | rights granted under this License, and you may not initiate litigation 471 | (including a cross-claim or counterclaim in a lawsuit) alleging that 472 | any patent claim is infringed by making, using, selling, offering for 473 | sale, or importing the Program or any portion of it. 474 | 475 | 11. Patents. 476 | 477 | A "contributor" is a copyright holder who authorizes use under this 478 | License of the Program or a work on which the Program is based. The 479 | work thus licensed is called the contributor's "contributor version". 480 | 481 | A contributor's "essential patent claims" are all patent claims 482 | owned or controlled by the contributor, whether already acquired or 483 | hereafter acquired, that would be infringed by some manner, permitted 484 | by this License, of making, using, or selling its contributor version, 485 | but do not include claims that would be infringed only as a 486 | consequence of further modification of the contributor version. For 487 | purposes of this definition, "control" includes the right to grant 488 | patent sublicenses in a manner consistent with the requirements of 489 | this License. 490 | 491 | Each contributor grants you a non-exclusive, worldwide, royalty-free 492 | patent license under the contributor's essential patent claims, to 493 | make, use, sell, offer for sale, import and otherwise run, modify and 494 | propagate the contents of its contributor version. 495 | 496 | In the following three paragraphs, a "patent license" is any express 497 | agreement or commitment, however denominated, not to enforce a patent 498 | (such as an express permission to practice a patent or covenant not to 499 | sue for patent infringement). To "grant" such a patent license to a 500 | party means to make such an agreement or commitment not to enforce a 501 | patent against the party. 502 | 503 | If you convey a covered work, knowingly relying on a patent license, 504 | and the Corresponding Source of the work is not available for anyone 505 | to copy, free of charge and under the terms of this License, through a 506 | publicly available network server or other readily accessible means, 507 | then you must either (1) cause the Corresponding Source to be so 508 | available, or (2) arrange to deprive yourself of the benefit of the 509 | patent license for this particular work, or (3) arrange, in a manner 510 | consistent with the requirements of this License, to extend the patent 511 | license to downstream recipients. "Knowingly relying" means you have 512 | actual knowledge that, but for the patent license, your conveying the 513 | covered work in a country, or your recipient's use of the covered work 514 | in a country, would infringe one or more identifiable patents in that 515 | country that you have reason to believe are valid. 516 | 517 | If, pursuant to or in connection with a single transaction or 518 | arrangement, you convey, or propagate by procuring conveyance of, a 519 | covered work, and grant a patent license to some of the parties 520 | receiving the covered work authorizing them to use, propagate, modify 521 | or convey a specific copy of the covered work, then the patent license 522 | you grant is automatically extended to all recipients of the covered 523 | work and works based on it. 524 | 525 | A patent license is "discriminatory" if it does not include within 526 | the scope of its coverage, prohibits the exercise of, or is 527 | conditioned on the non-exercise of one or more of the rights that are 528 | specifically granted under this License. You may not convey a covered 529 | work if you are a party to an arrangement with a third party that is 530 | in the business of distributing software, under which you make payment 531 | to the third party based on the extent of your activity of conveying 532 | the work, and under which the third party grants, to any of the 533 | parties who would receive the covered work from you, a discriminatory 534 | patent license (a) in connection with copies of the covered work 535 | conveyed by you (or copies made from those copies), or (b) primarily 536 | for and in connection with specific products or compilations that 537 | contain the covered work, unless you entered into that arrangement, 538 | or that patent license was granted, prior to 28 March 2007. 539 | 540 | Nothing in this License shall be construed as excluding or limiting 541 | any implied license or other defenses to infringement that may 542 | otherwise be available to you under applicable patent law. 543 | 544 | 12. No Surrender of Others' Freedom. 545 | 546 | If conditions are imposed on you (whether by court order, agreement or 547 | otherwise) that contradict the conditions of this License, they do not 548 | excuse you from the conditions of this License. If you cannot convey a 549 | covered work so as to satisfy simultaneously your obligations under this 550 | License and any other pertinent obligations, then as a consequence you may 551 | not convey it at all. For example, if you agree to terms that obligate you 552 | to collect a royalty for further conveying from those to whom you convey 553 | the Program, the only way you could satisfy both those terms and this 554 | License would be to refrain entirely from conveying the Program. 555 | 556 | 13. Use with the GNU Affero General Public License. 557 | 558 | Notwithstanding any other provision of this License, you have 559 | permission to link or combine any covered work with a work licensed 560 | under version 3 of the GNU Affero General Public License into a single 561 | combined work, and to convey the resulting work. The terms of this 562 | License will continue to apply to the part which is the covered work, 563 | but the special requirements of the GNU Affero General Public License, 564 | section 13, concerning interaction through a network will apply to the 565 | combination as such. 566 | 567 | 14. Revised Versions of this License. 568 | 569 | The Free Software Foundation may publish revised and/or new versions of 570 | the GNU General Public License from time to time. Such new versions will 571 | be similar in spirit to the present version, but may differ in detail to 572 | address new problems or concerns. 573 | 574 | Each version is given a distinguishing version number. If the 575 | Program specifies that a certain numbered version of the GNU General 576 | Public License "or any later version" applies to it, you have the 577 | option of following the terms and conditions either of that numbered 578 | version or of any later version published by the Free Software 579 | Foundation. If the Program does not specify a version number of the 580 | GNU General Public License, you may choose any version ever published 581 | by the Free Software Foundation. 582 | 583 | If the Program specifies that a proxy can decide which future 584 | versions of the GNU General Public License can be used, that proxy's 585 | public statement of acceptance of a version permanently authorizes you 586 | to choose that version for the Program. 587 | 588 | Later license versions may give you additional or different 589 | permissions. However, no additional obligations are imposed on any 590 | author or copyright holder as a result of your choosing to follow a 591 | later version. 592 | 593 | 15. Disclaimer of Warranty. 594 | 595 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 596 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 597 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 598 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 599 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 600 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 601 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 602 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 603 | 604 | 16. Limitation of Liability. 605 | 606 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 607 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 608 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 609 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 610 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 611 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 612 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 613 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 614 | SUCH DAMAGES. 615 | 616 | 17. Interpretation of Sections 15 and 16. 617 | 618 | If the disclaimer of warranty and limitation of liability provided 619 | above cannot be given local legal effect according to their terms, 620 | reviewing courts shall apply local law that most closely approximates 621 | an absolute waiver of all civil liability in connection with the 622 | Program, unless a warranty or assumption of liability accompanies a 623 | copy of the Program in return for a fee. 624 | 625 | END OF TERMS AND CONDITIONS 626 | 627 | How to Apply These Terms to Your New Programs 628 | 629 | If you develop a new program, and you want it to be of the greatest 630 | possible use to the public, the best way to achieve this is to make it 631 | free software which everyone can redistribute and change under these terms. 632 | 633 | To do so, attach the following notices to the program. It is safest 634 | to attach them to the start of each source file to most effectively 635 | state the exclusion of warranty; and each file should have at least 636 | the "copyright" line and a pointer to where the full notice is found. 637 | 638 | 639 | Copyright (C) 640 | 641 | This program is free software: you can redistribute it and/or modify 642 | it under the terms of the GNU General Public License as published by 643 | the Free Software Foundation, either version 3 of the License, or 644 | (at your option) any later version. 645 | 646 | This program is distributed in the hope that it will be useful, 647 | but WITHOUT ANY WARRANTY; without even the implied warranty of 648 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 649 | GNU General Public License for more details. 650 | 651 | You should have received a copy of the GNU General Public License 652 | along with this program. If not, see . 653 | 654 | Also add information on how to contact you by electronic and paper mail. 655 | 656 | If the program does terminal interaction, make it output a short 657 | notice like this when it starts in an interactive mode: 658 | 659 | Copyright (C) 660 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 661 | This is free software, and you are welcome to redistribute it 662 | under certain conditions; type `show c' for details. 663 | 664 | The hypothetical commands `show w' and `show c' should show the appropriate 665 | parts of the General Public License. Of course, your program's commands 666 | might be different; for a GUI interface, you would use an "about box". 667 | 668 | You should also get your employer (if you work as a programmer) or school, 669 | if any, to sign a "copyright disclaimer" for the program, if necessary. 670 | For more information on this, and how to apply and follow the GNU GPL, see 671 | . 672 | 673 | The GNU General Public License does not permit incorporating your program 674 | into proprietary programs. If your program is a subroutine library, you 675 | may consider it more useful to permit linking proprietary applications with 676 | the library. If this is what you want to do, use the GNU Lesser General 677 | Public License instead of this License. But first, please read 678 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Go Ether Dream 2 | 3 | Go language interface to the Ether Dream laser DAC. Current features: blanking, basic path optimization, quality (trade resolution for frame rate) and 3D scene rendering via [ln](https://github.com/tgreiser/ln). For an introduction to laser projectors and programming, see: [Laser Hack 101 presentation slides](https://github.com/tgreiser/etherdream-touch-designer/blob/master/laser_hack_101.pdf). 4 | 5 | Based on the work of [j4cbo](https://github.com/j4cbo/j4cDAC/), [echelon](https://github.com/echelon) and [fogleman](https://github.com/fogleman) 6 | 7 | ![Spiral](http://prim8.net/art/spiral.jpg) 8 | 9 | ## Terminology 10 | 11 | - projector/scanner - An ILDA compatible laser projector aka laser scanner. 2 (or more) mirrors, 2 galvos, some laser diodes and electronics. Not to be confused with the other kind of laser projector. 12 | - DAC - Digital to Analog Converter. An electronic box that translates digital signals from a computer into analog signals that control the galvos via an IDLA cable. There are proprietary and open source DACs, as well as modified sound cards used as DACs. In this context, it means your Ether Dream(s). 13 | 14 | ## Setup 15 | 16 | This assumes you are plugged in to your ether dream via ethernet cable. You 17 | may need to set up some rules for your firewall. Inbound communications 18 | are needed for the initial broadcast signal and handshake, if you don't 19 | need to Find a DAC, you can use outbound only. 20 | 21 | - Outbound rule: TCP port 7765 22 | - Inbound rule: UDP port 7654 23 | 24 | The simplest setup involves one DAC and one projector, but there are many options. 25 | 26 | - Multiple projectors chained off one DAC signal 27 | - Multiple projectors chained off one DAC signal, including use of a cross-over ILDA cable to mirror left/right on one side of the room. 28 | - Multiple projectors each with their own DAC. This offers independent control over each projector. If calibrated in a stack, can be used to create complex imagery. 29 | 30 | ## Install 31 | 32 | If you don't have Go installed, start here: 33 | [https://golang.org/doc/install](https://golang.org/doc/install) 34 | 35 | Once Go is installed with your environment updated, just: 36 | 37 | go get github.com/tgreiser/etherdream 38 | cd $GOPATH/src/github.com/tgreiser/etherdream 39 | 40 | You can run any of the examples like: 41 | 42 | go run examples/square/square.go 43 | # if you aren't blocking the network ports, and your Ether Dream 44 | # is connected to an ILDA laser, it should project a square 45 | 46 | 47 | ## Connecting 48 | 49 | If you have opened the necessary ports, the Ether Dream will broadcast it's identity on the network. Once you have connected, you can provide a PointStream to play. 50 | 51 | func main() { 52 | log.Printf("Listening...\n") 53 | addr, bp, err := etherdream.FindFirstDAC() 54 | if err != nil { 55 | log.Fatalf("Network error: %v", err) 56 | } 57 | 58 | log.Printf("Found DAC at %v\n", addr) 59 | log.Printf("BP: %v\n\n", bp) 60 | 61 | dac, err := etherdream.NewDAC(addr.IP.String()) 62 | if err != nil { 63 | log.Fatal(err) 64 | } 65 | defer dac.Close() 66 | log.Printf("Initialized: %v\n\n", dac.LastStatus) 67 | log.Printf("Firmware String: %v\n\n", dac.FirmwareString) 68 | } 69 | 70 | ## Point Streams 71 | 72 | type PointStream func(w io.WriteCloser) 73 | 74 | Point streams should contain an infinite loop that will use the [WriteCloser](https://golang.org/pkg/io/#WriteCloser) interface to output encoded points to the DAC sequentially. In Ether Dream, a point has 2D vector information and a color (see: [image/color](https://golang.org/pkg/image/color/#Color)). 75 | 76 | // make a red point at X=0, Y=300 77 | pt := etherdream.NewPoint(0, 300, color.RGBA{0xff, 0x00, 0x00, 0xff}) 78 | 79 | // Encode the point to bytes 80 | by := pt.Encode() 81 | 82 | // Stream the encoded points to the DAC 83 | w.Write(by) 84 | 85 | From examples\square\square.go: 86 | 87 | func main() { 88 | ... 89 | 90 | debug := false 91 | dac.Play(squarePointStream, debug) 92 | } 93 | func squarePointStream(w io.WriteCloser) { 94 | defer w.Close() 95 | pmax := 15600 96 | pstep := 100 97 | for { 98 | for _, x := range xrange(-pmax, pmax, pstep) { 99 | w.Write(etherdream.NewPoint(x, pmax, color.RGBA{0xff, 0x00, 0x00, 0xff}).Encode()) 100 | } 101 | for _, y := range xrange(pmax, -pmax, -pstep) { 102 | w.Write(etherdream.NewPoint(pmax, y, color.RGBA{0x00, 0xff, 0x00, 0xff}).Encode()) 103 | } 104 | for _, x := range xrange(pmax, -pmax, -pstep) { 105 | w.Write(etherdream.NewPoint(x, -pmax, color.RGBA{0x00, 0x00, 0xff, 0xff}).Encode()) 106 | } 107 | for _, y := range xrange(-pmax, pmax, pstep) { 108 | w.Write(etherdream.NewPoint(-pmax, y, color.RGBA{0xff, 0xff, 0xff, 0xff}).Encode()) 109 | } 110 | } 111 | } 112 | 113 | func xrange(min, max, step int) []int { 114 | rng := max - min 115 | ret := make([]int, rng/step+1) 116 | iY := 0 117 | for iX := min; rlogic(min, max, iX); iX += step { 118 | ret[iY] = iX 119 | iY++ 120 | } 121 | return ret 122 | } 123 | 124 | func rlogic(min, max, iX int) bool { 125 | if min < max { 126 | return iX <= max 127 | } 128 | return iX >= max 129 | } 130 | 131 | ## Flags 132 | 133 | Etherdream library will intialize the following flags - use -help for more info: 134 | 135 | -blank-count int 136 | How many samples to wait after drawing a blanking line. (default 20) 137 | -debug 138 | Enable debug output. 139 | -draw-speed float 140 | Draw speed (25-100). Lower is more precision but slower. (default 50) 141 | -scan-rate int 142 | Number of points per second to play back. (default 24000) 143 | 144 | ## Blanking and Paths 145 | 146 | Here we introduce the use of [tgreiser/ln](https://github.com/tgreiser/ln), a fork of Fogleman's excellent [ln](https://github.com/fogleman/ln) 3D vector library. Blanking is used to reposition the laser to a new location, it involves turning off the beam, repositioning and then a pause. The exact pause necessary to clean up an image can vary from projector to projector so this can be easily configured. I am using the methodology outlined in [Accurate and Efficient Drawing Method for Laser Projection](http://www.art-science.org/journal/v7n4/v7n4pp155/artsci-v7n4pp155.pdf) 147 | 148 | If you just want to configure your projector, use examples\parallel_lines\lines.go 149 | 150 | go run examples\parallel_lines\lines.go -blank-count=5 151 | # Without sufficient post-blank-count, it produce diagonal lines that cut across most of the image. 152 | 153 | ![Not blanking](http://prim8.net/art/lines_unblanked.jpg) 154 | 155 | go run examples\parallel_lines\lines.go -blank-count=17 156 | # These settings look pretty good on my 30 KPPS projectors. You can still see a small flaw at 17. 157 | 158 | ![Blanking](http://prim8.net/art/lines_blanked.jpg) 159 | 160 | // declare some ln Paths 161 | p := ln.Path{ln.Vector{0, 0, 0}, ln.Vector{0, 500, 0}} 162 | p2 := ln.Path{ln.Vector{10000, 0, 0}, ln.Vector{10000, 500, 0}} 163 | // draw speed 0 will use defaults 164 | speed := 0 165 | 166 | // in the draw loop 167 | for { 168 | // draw the first path 169 | etherdream.DrawPath(w, p, c, speed) 170 | // use ln Vector.Distance to see if a blank is necessary 171 | if p2[0].Distance(p[1]) > 0 { 172 | // blank from p endpoint to p2 startpoint 173 | etherdream.BlankPath(w, ln.Path{p[1], p2[0]}) 174 | } 175 | // draw p2 176 | etherdream.DrawPath(w, p2, c, speed) 177 | if p2[1].Distance(p[0]) > 0 { 178 | blank from p2 endbpoint back to original start 179 | etherdream.BlankPath(w, ln.Path{p2[1], p[0]}) 180 | } 181 | } 182 | 183 | ## Frames 184 | 185 | If you are interested in animations, the driver is more precise when you 186 | signal the end of a frame in your pointStream. This will flush the buffer 187 | and send the frame to the Ether Dream. Currently this is controlled via 188 | NextFrame(), but this portion is in active development. 189 | 190 | func pointStream(w io.WriteCloser) { 191 | defer w.Close() 192 | for { 193 | // write all the points in a frame 194 | // count how many, and save the last point 195 | 196 | frameCount := etherdream.NextFrame(w, pointCount, lastPoint) 197 | } 198 | 199 | Using this we can draw a scene. See: https://github.com/tgreiser/simpartdream 200 | 201 | [![Laser Particles](http://img.youtube.com/vi/sJ83l9APE3A/0.jpg)](http://www.youtube.com/watch?v=sJ83l9APE3A "Laser Particles") 202 | 203 | ## 3D Rendering 204 | 205 | ![Cube](http://prim8.net/art/laser-cube.jpg) 206 | 207 | ln can also help you with 3D rendering and transformation. You can position 3D primitives within a scene, render those to paths, optimize the order of the paths and then send the result to the projector. See examples\ln1\ln1.go. Aside from the base ln functionality, the one thing to be aware of here is paths.Optimize - without it the ln output creates many unnessesary blank lines. 208 | 209 | // render our scene to paths 210 | paths := scene.Render(eye, center, up, width, height, fovy, znear, zfar, step) 211 | // reorder the paths for optimized output 212 | paths.Optimize() 213 | 214 | // now we can draw all our paths with the laser 215 | 216 | ## Draw Speed 217 | 218 | When a frame takes too long to draw you will see the output flicker. We can adjust the amount of time we take to draw a path to trade precision for frame rate. This gives you a little more control over the perceived quality of your laser output. 219 | 220 | go run examples\ln2\ln2.go 221 | # the default draw speed 50 doesn't look very good. Severe flicker. 222 | 223 | go run examples\ln2\ln2.go -draw-speed 80 224 | # when I increase the draw speed some distortion appears on the corners, but flicker is almost entirely eliminated. 225 | 226 | ## TODO 227 | 228 | - Instead of draw speed, render a frame from vectors according with optimum sample count. 229 | - Optimization - slow down prior to to sharp angles of movement. 230 | - Import of SVG/ILDA files. 231 | 232 | ## Resources 233 | 234 | - [Library Documentation](https://godoc.org/github.com/tgreiser/etherdream) 235 | - [Ether Dream](http://ether-dream.com) 236 | -------------------------------------------------------------------------------- /color.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, version 3. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | */ 16 | 17 | package etherdream 18 | 19 | import "image/color" 20 | 21 | // ColorMax is the maximum color/intensity value 22 | const ColorMax = 65535 23 | 24 | // BlankColor is a zeroed out color used for blanking segments 25 | var BlankColor = color.Black 26 | -------------------------------------------------------------------------------- /dac.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | # Based on work by Jacob Potter, some comments are from his 4 | # protocol documents 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | */ 18 | 19 | package etherdream 20 | 21 | import ( 22 | "bytes" 23 | "encoding/binary" 24 | "flag" 25 | "fmt" 26 | "io" 27 | "net" 28 | "os" 29 | "runtime" 30 | "strings" 31 | "sync" 32 | "time" 33 | ) 34 | 35 | var mut = &sync.Mutex{} 36 | 37 | // ScanRate controls the playback speed of the ether dream 38 | var ScanRate = flag.Int("scan-rate", 24000, "Number of points per second to play back.") 39 | 40 | // Assuming the ether dream scans 30 times per second 41 | var frameRate = 30 42 | 43 | // Count frames 44 | var frameCount = 0 45 | 46 | var bufferSize = 1799 47 | 48 | // PointSize is the number of bytes in a point struct 49 | const PointSize uint16 = 18 50 | 51 | func whenToPlay() int { 52 | return bufferSize - FramePoints() 53 | } 54 | 55 | // ProtocolError indicates a protocol level error. I've 56 | // never seen one, but maybe you will. 57 | type ProtocolError struct { 58 | Msg string 59 | } 60 | 61 | func (e *ProtocolError) Error() string { 62 | return e.Msg 63 | } 64 | 65 | // DAC is the interface to the Ether Dream Digital to 66 | // Analog Converter that turns network signals into 67 | // ILDA control singnals for a laser scanner. 68 | type DAC struct { 69 | Host string 70 | Port string 71 | FirmwareString string 72 | LastStatus *DACStatus 73 | Reader io.Reader 74 | Writer io.WriteCloser 75 | PointsPlayed int 76 | buf bytes.Buffer 77 | conn net.Conn 78 | } 79 | 80 | // NewDAC will connect to an Ether Dream device over TCP 81 | // or it will return an error 82 | func NewDAC(host string) (*DAC, error) { 83 | if !flag.Parsed() { 84 | flag.Parse() 85 | } 86 | // connect to the DAC over TCP 87 | r, w := io.Pipe() 88 | dac := &DAC{Host: host, Port: "7765", Reader: r, Writer: w} 89 | err := dac.init() 90 | return dac, err 91 | } 92 | 93 | // Close the network connection, you should. -- Yoda 94 | func (d *DAC) Close() { 95 | d.conn.Close() 96 | } 97 | 98 | func (d *DAC) init() error { 99 | if *Debug { 100 | fmt.Println("Connecting to TCP") 101 | } 102 | c, err := net.DialTimeout("tcp", d.Host+":"+d.Port, time.Second*15) 103 | if err != nil { 104 | return err 105 | } 106 | d.conn = c 107 | 108 | if _, err = d.ReadResponse("?"); err != nil { 109 | return err 110 | } 111 | 112 | if err = d.Send([]byte("v")); err != nil { 113 | return err 114 | } 115 | 116 | by, err := d.Read(32) 117 | if err != nil { 118 | return err 119 | } 120 | 121 | d.FirmwareString = strings.TrimSpace(strings.Replace(string(by), "\x00", " ", -1)) 122 | if *Debug { 123 | fmt.Printf("Firmware: %v\n", d.FirmwareString) 124 | } 125 | 126 | return nil 127 | } 128 | 129 | func (d *DAC) Read(l int) ([]byte, error) { 130 | if l > d.buf.Len() { 131 | // read more bytes into the buffer 132 | _, err := io.CopyN(&d.buf, d.conn, int64(l)) 133 | if err != nil { 134 | return []byte{}, err 135 | } 136 | } 137 | ret := make([]byte, l) 138 | _, err := d.buf.Read(ret) 139 | return ret, err 140 | } 141 | 142 | // ReadResponse reads the ACK/NACK response to a command 143 | func (d *DAC) ReadResponse(cmd string) (*DACStatus, error) { 144 | data, err := d.Read(22) 145 | if err != nil { 146 | fmt.Printf("Error: %v\n", err) 147 | return nil, err 148 | } 149 | 150 | resp := data[0] 151 | cmdR := data[1] 152 | status := NewDACStatus(data[2:]) 153 | //fmt.Printf("\nRead response: Resp=%s Cmd=%s Status=%s\n", string(resp), string(cmdR), status.String()) 154 | 155 | if cmdR != []byte(cmd)[0] { 156 | return nil, &ProtocolError{fmt.Sprintf("Expected resp for %s, got %s", cmd, string(cmdR))} 157 | } 158 | if resp != []byte("a")[0] { 159 | return nil, &ProtocolError{fmt.Sprintf("Expected ACK, got %s Resp=%s\n%s", string(cmdR), string(resp), status.String())} 160 | } 161 | d.LastStatus = status 162 | return status, nil 163 | } 164 | 165 | // Send a command to the DAC 166 | func (d DAC) Send(cmd []byte) error { 167 | _, err := d.conn.Write(cmd) 168 | return err 169 | } 170 | 171 | // BeginCmd starts playback 172 | const BeginCmd = 0x62 173 | 174 | // Begin Playback 175 | // This causes the DAC to begin producing output. lwm is 176 | // currently unused. rate is the number of points per second 177 | // to be read from the buffer. If the playback system was 178 | // Prepared and there was data in the buffer, then the DAC 179 | // will reply with ACK; otherwise, it replies with NAK - Invalid. 180 | func (d *DAC) Begin(lwm uint16, rate uint32) (*DACStatus, error) { 181 | var cmd = make([]byte, 7) 182 | cmd[0] = BeginCmd 183 | binary.LittleEndian.PutUint16(cmd[1:3], lwm) 184 | binary.LittleEndian.PutUint32(cmd[3:7], rate) 185 | 186 | if err := d.Send(cmd); err != nil { 187 | return nil, err 188 | } 189 | 190 | s, err := d.ReadResponse(string(BeginCmd)) 191 | fmt.Printf("Begin: %v\n\n", s) 192 | return s, err 193 | } 194 | 195 | // Update should not exist? 196 | // Maybe this is the 'q' command now. 197 | func (d *DAC) Update(lwm uint16, rate uint32) (*DACStatus, error) { 198 | var cmd = make([]byte, 7) 199 | cmd[0] = 'u' 200 | binary.LittleEndian.PutUint16(cmd[1:3], lwm) 201 | binary.LittleEndian.PutUint32(cmd[3:7], rate) 202 | 203 | if err := d.Send(cmd); err != nil { 204 | return nil, err 205 | } 206 | 207 | return d.ReadResponse("u") 208 | } 209 | 210 | func (d *DAC) Write(b []byte) (*DACStatus, error) { 211 | l := uint16(len(b)) 212 | cmd := make([]byte, l+3) 213 | cmd[0] = 'd' 214 | binary.LittleEndian.PutUint16(cmd[1:3], l/PointSize) 215 | copy(cmd[3:], b) 216 | if *Debug { 217 | fmt.Printf("DAC Write %v points\n", l/PointSize) 218 | } 219 | 220 | if err := d.Send(cmd); err != nil { 221 | return nil, err 222 | } 223 | 224 | return d.ReadResponse("d") 225 | } 226 | 227 | // Prepare command 228 | func (d *DAC) Prepare() (*DACStatus, error) { 229 | if err := d.Send([]byte("p")); err != nil { 230 | return nil, err 231 | } 232 | 233 | return d.ReadResponse("p") 234 | } 235 | 236 | // Stop command 237 | func (d *DAC) Stop() (*DACStatus, error) { 238 | if err := d.Send([]byte("s")); err != nil { 239 | return nil, err 240 | } 241 | 242 | return d.ReadResponse("s") 243 | } 244 | 245 | // EmergencyStop command causes the light engine to 246 | // enter the E-Stop state, regardless of its previous 247 | // state. It is always ACKed. 248 | func (d *DAC) EmergencyStop() (*DACStatus, error) { 249 | if err := d.Send([]byte("\xFF")); err != nil { 250 | return nil, err 251 | } 252 | 253 | return d.ReadResponse("\xFF") 254 | } 255 | 256 | // ClearEmergencyStop command. If the light engine was in 257 | // E-Stop state due to an emergency stop command (either from 258 | // a local stop condition or over the network), then this 259 | // command resets it to be Ready. It is ACKed if the DAC was 260 | // previously in E-Stop; otherwise it is replied to with a NAK - 261 | // Invalid. If the condition that caused the emergency stop is 262 | // still active (E-Stop input still asserted, temperature still 263 | // out of bounds, etc.), then a NAK - Stop Condition is sent. 264 | func (d *DAC) ClearEmergencyStop() (*DACStatus, error) { 265 | if err := d.Send([]byte("c")); err != nil { 266 | return nil, err 267 | } 268 | 269 | return d.ReadResponse("c") 270 | } 271 | 272 | // Ping command 273 | func (d *DAC) Ping() (*DACStatus, error) { 274 | if err := d.Send([]byte("?")); err != nil { 275 | return nil, err 276 | } 277 | 278 | return d.ReadResponse("?") 279 | } 280 | 281 | // ShouldPrepare or not? State 1 and 2 are good. Some Flags 282 | // need prepare to reset an invalid state. 283 | func (d DAC) ShouldPrepare() bool { 284 | return d.LastStatus.PlaybackState == 0 || 285 | d.LastStatus.PlaybackFlags&2 == 2 || 286 | d.LastStatus.PlaybackFlags&4 == 4 287 | } 288 | 289 | // Measure how long it takes to play 10,000 points 290 | func (d *DAC) Measure(stream PointStream) { 291 | *Debug = true 292 | t0 := time.Now() 293 | 294 | go d.Play(stream) 295 | 296 | for { 297 | if d.PointsPlayed >= 100000 { 298 | t1 := time.Now() 299 | fmt.Printf("%v took %v\n", d.PointsPlayed, t1.Sub(t0).String()) 300 | os.Exit(0) 301 | } 302 | runtime.Gosched() 303 | } 304 | } 305 | 306 | // Play a stream generator and begin sending output to the laser 307 | func (d *DAC) Play(stream PointStream) { 308 | // First, prepare the stream 309 | if d.LastStatus.PlaybackState == 2 { 310 | if *Debug { 311 | fmt.Printf("Error: Already playing?!") 312 | } 313 | } else if d.ShouldPrepare() { 314 | st, err := d.Prepare() 315 | if err != nil { 316 | fmt.Printf("ERROR: Failed to prepare: %v\n\n", err) 317 | } 318 | if *Debug { 319 | fmt.Printf("DAC prepared: %v\n\n", st) 320 | } 321 | } 322 | 323 | started := 0 324 | // Start stream 325 | go stream(d.Writer) 326 | 327 | OuterLoop: 328 | for { 329 | // Read calls from the pipe 330 | cap := 1799 - d.LastStatus.BufferFullness 331 | by := make([]byte, FramePoints()*int(PointSize)) 332 | idx := 0 333 | when := whenToPlay() 334 | 335 | if *Debug { 336 | fmt.Printf("Buffer capacity: %v is lessThan: %v\n", cap, when) 337 | } 338 | 339 | if int(cap) <= when { 340 | time.Sleep(time.Millisecond * 5) 341 | d.Ping() 342 | continue 343 | } 344 | 345 | fp := FramePoints() 346 | for idx < fp { 347 | bdx := idx * int(PointSize) 348 | _, err := d.Reader.Read(by[bdx:]) 349 | if err != nil { 350 | if err == io.EOF { 351 | break OuterLoop 352 | } 353 | fmt.Printf("Error playing stream: %v", err) 354 | break 355 | } 356 | idx++ 357 | } 358 | 359 | mut.Lock() 360 | st, err := d.Write(by) 361 | if err != nil { 362 | fmt.Printf("ERROR: %v\n", err) 363 | } 364 | 365 | d.PointsPlayed += len(by) / int(PointSize) 366 | if *Debug { 367 | fmt.Printf("Points: %v\nStatus: %v\n", d.PointsPlayed, st) 368 | } 369 | 370 | if started == 0 { 371 | st, err := d.Begin(0, uint32(*ScanRate)) 372 | if err != nil { 373 | fmt.Printf("ERROR on Begin: %v\n\n", err) 374 | } 375 | started = 1 376 | if *Debug { 377 | fmt.Printf("\nBegin executed: %v\n", st) 378 | } 379 | } 380 | 381 | mut.Unlock() 382 | runtime.Gosched() 383 | } 384 | } 385 | 386 | // FindFirstDAC starts a UDP server to listen for broadcast packets on your network. Return the UDPAddr 387 | // of the first Ether Dream DAC located 388 | func FindFirstDAC() (*net.UDPAddr, *BroadcastPacket, error) { 389 | // listen for broadcast packets 390 | sock, err := net.ListenUDP("udp4", &net.UDPAddr{ 391 | IP: net.IPv4(0, 0, 0, 0), 392 | Port: 7654, 393 | }) 394 | if err != nil { 395 | return nil, nil, err 396 | } 397 | 398 | var data [36]byte 399 | _, addr, err := sock.ReadFromUDP(data[0:]) 400 | if err != nil { 401 | return nil, nil, err 402 | } 403 | 404 | bp := NewBroadcastPacket(data) 405 | return addr, bp, nil 406 | } 407 | -------------------------------------------------------------------------------- /draw.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, version 3. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | */ 16 | 17 | package etherdream 18 | 19 | import ( 20 | "flag" 21 | "fmt" 22 | "image/color" 23 | "io" 24 | "log" 25 | "math" 26 | "time" 27 | 28 | "github.com/tgreiser/ln/ln" 29 | ) 30 | 31 | // BlankCount is the number of blank samples to insert after moving 32 | var BlankCount = flag.Int("blank-count", 20, "How many samples to wait after drawing a blanking line.") 33 | 34 | // DrawSpeed affects how many points will be sampled on your lines. Lower is 35 | // more precise, but is more likely to flicker. Higher values will give smoother 36 | // playback, but there may be gaps around corners. Try values 25-100. 37 | var DrawSpeed = flag.Float64("draw-speed", 50.0, "Draw speed (25-100). Lower is more precision but slower.") 38 | 39 | // Debug mode 40 | var Debug = flag.Bool("debug", false, "Enable debug output.") 41 | 42 | // Dump will output the point stream coordinates 43 | var Dump = flag.Bool("dump", false, "Dump point stream to stdout.") 44 | 45 | var tf0 = time.Now() 46 | 47 | // FramePoints is the number of points in one frame - 24k / 30 = 800 48 | func FramePoints() int { 49 | return (*ScanRate) / frameRate 50 | } 51 | 52 | // NextFrame advances playback ... add some blank points 53 | func NextFrame(w io.WriteCloser, pointsPlayed int, last Point) int { 54 | times := FramePoints() - pointsPlayed 55 | by := NewPoint(int(last.X), int(last.Y), BlankColor).Encode() 56 | for iX := 0; iX < times; iX++ { 57 | w.Write(by) 58 | } 59 | if *Debug { 60 | tf1 := time.Now() 61 | log.Printf("%v - Frame %v added %v empty points", tf1.Sub(tf0), frameCount, times) 62 | tf0 = tf1 63 | } 64 | if *Dump { 65 | fmt.Printf("---- %v x %v\t%v\t%v\t%v\t%v\n", times, last.X, last.Y, 0, 0, 0) 66 | } 67 | frameCount++ 68 | return frameCount 69 | } 70 | 71 | // NumberOfSegments to use when interpolating the path 72 | func NumberOfSegments(p ln.Path, drawSpeed float64) float64 { 73 | return p[0].Distance(p[1]) / drawSpeed 74 | } 75 | 76 | // DrawPath will use linear interpolation to draw fn+1 points along the path (fn segments) 77 | // qual will override the LineQuality (see above). 78 | func DrawPath(w io.WriteCloser, p ln.Path, c color.Color, drawSpeed float64) { 79 | if drawSpeed == 0.0 { 80 | drawSpeed = *DrawSpeed 81 | } 82 | dist := p[1].Sub(p[0]) 83 | 84 | fn := NumberOfSegments(p, drawSpeed) 85 | for iX := 0.0; iX < fn; iX++ { 86 | x := dist.X * (iX / fn) 87 | y := dist.Y * (iX / fn) 88 | np := p[0].Add(ln.Vector{x, y, 0}) 89 | w.Write(NewPoint(int(np.X), int(np.Y), c).Encode()) 90 | } 91 | w.Write(NewPoint(int(p[1].X), int(p[1].Y), c).Encode()) 92 | } 93 | 94 | // BlankPath will add the necessary pause to effectively blank a path 95 | func BlankPath(w io.WriteCloser, p ln.Path) *Point { 96 | var pt *Point 97 | for i := 1; i <= *BlankCount; i++ { 98 | pt = NewPoint(int(p[1].X), int(p[1].Y), BlankColor) 99 | w.Write(pt.Encode()) 100 | } 101 | return pt 102 | } 103 | 104 | // Osc is an oscillator value - send it frame counts / point counts 105 | func Osc(cur, max int, amplitude, frequency, offset float64) float64 { 106 | rad := float64(cur+1) / float64(max) * 2.0 * math.Pi 107 | return math.Sin(rad*frequency)*amplitude + offset 108 | } 109 | -------------------------------------------------------------------------------- /examples/circle/circle.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | # Based on work by Jacob Potter, some comments are from his 4 | # protocol documents. Example code from Brandon Thomas. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | */ 18 | 19 | package main 20 | 21 | import ( 22 | "io" 23 | "log" 24 | 25 | "math" 26 | 27 | "image/color" 28 | 29 | "github.com/tgreiser/etherdream" 30 | ) 31 | 32 | func main() { 33 | log.Printf("Listening...\n") 34 | addr, _, err := etherdream.FindFirstDAC() 35 | if err != nil { 36 | log.Fatalf("Network error: %v", err) 37 | } 38 | 39 | log.Printf("Found DAC at %v\n", addr) 40 | 41 | dac, err := etherdream.NewDAC(addr.IP.String()) 42 | if err != nil { 43 | log.Fatal(err) 44 | } 45 | defer dac.Close() 46 | 47 | dac.Play(pointStream) 48 | } 49 | 50 | func pointStream(w io.WriteCloser) { 51 | defer w.Close() 52 | 53 | // Don't use a low # of steps, 30 and below can damage galvos 54 | // We'll use the number of points in a frame for optimal sampling 55 | pstep := etherdream.FramePoints() 56 | c := color.RGBA{0x66, 0x33, 0x00, 0xFF} 57 | maxrad := 10260 58 | rad := maxrad 59 | grow := false 60 | 61 | for { 62 | if rad <= 1 { 63 | grow = true 64 | } else if rad >= maxrad { 65 | grow = false 66 | } 67 | if grow { 68 | rad += 100 69 | } else { 70 | rad -= 100 71 | } 72 | var pt *etherdream.Point 73 | for i := 0; i < pstep; i++ { 74 | f := float64(i) / float64(pstep) * 2.0 * math.Pi 75 | x := int(math.Cos(f) * float64(rad)) 76 | y := int(math.Sin(f) * float64(rad)) 77 | pt = etherdream.NewPoint(x, y, c) 78 | w.Write(pt.Encode()) 79 | } 80 | 81 | _ = etherdream.NextFrame(w, pstep, *pt) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /examples/connect/connect.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | # Based on work by Jacob Potter, some comments are from his 4 | # protocol documents 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | */ 18 | 19 | package main 20 | 21 | import ( 22 | "log" 23 | 24 | "github.com/tgreiser/etherdream" 25 | ) 26 | 27 | func main() { 28 | log.Printf("Listening...\n") 29 | addr, bp, err := etherdream.FindFirstDAC() 30 | if err != nil { 31 | log.Printf("Network error: %v", err) 32 | } 33 | 34 | log.Printf("Found DAC at %v\n", addr) 35 | 36 | log.Printf("BP:\n%v\n", bp) 37 | log.Printf("Status:\n%v\n", bp.Status) 38 | 39 | dac, err := etherdream.NewDAC(addr.IP.String()) 40 | if err != nil { 41 | log.Fatal(err) 42 | } 43 | defer dac.Close() 44 | log.Printf("Initialized %v\n", dac.LastStatus) 45 | log.Printf("Firmware String: %v\n", dac.FirmwareString) 46 | 47 | st, err := dac.Ping() 48 | if err != nil { 49 | log.Fatal(err) 50 | } 51 | log.Printf("Ping status: %v", st) 52 | } 53 | -------------------------------------------------------------------------------- /examples/cycloid/cycloid.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, version 3. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "image/color" 21 | "io" 22 | "log" 23 | "math" 24 | 25 | "flag" 26 | 27 | "github.com/tgreiser/etherdream" 28 | ) 29 | 30 | func main() { 31 | log.Printf("Listening...\n") 32 | addr, bp, err := etherdream.FindFirstDAC() 33 | if err != nil { 34 | log.Fatalf("Network error: %v", err) 35 | } 36 | 37 | log.Printf("Found DAC at %v\n", addr) 38 | log.Printf("BP: %v\n\n", bp) 39 | 40 | dac, err := etherdream.NewDAC(addr.IP.String()) 41 | if err != nil { 42 | log.Fatal(err) 43 | } 44 | defer dac.Close() 45 | log.Printf("Initialized: %v\n\n", dac.LastStatus) 46 | log.Printf("Firmware String: %v\n\n", dac.FirmwareString) 47 | 48 | dac.Play(pointStream) 49 | } 50 | 51 | var max = flag.Int("speed", 500, "Speed to run the oscillation (1-20000)") 52 | var ratio = flag.Float64("ratio", 3.0, "Ratio of inner to outer") 53 | var amax = flag.Float64("max-diam", 12000.0, "Maximum diameter of the outer circle (a)") 54 | var amin = flag.Float64("min-diam", 500.0, "Minimum diameter of the outer circle (b)") 55 | var h = flag.Float64("point-dist", 4000.0, "Distance from the draw point to the center of the inner circle (h)") 56 | 57 | func pointStream(w io.WriteCloser) { 58 | defer w.Close() 59 | pcount := 380 60 | //etherdream.FramePoints() - *etherdream.BlankCount 61 | log.Printf("PCount %v\n", pcount) 62 | grow := true 63 | 64 | //var pt *etherdream.Point 65 | a := *amin 66 | b := a / *ratio 67 | //pt := etherdream.NewPoint(0,0, color.Black) 68 | for { 69 | for iY := 1; iY < 3; iY++ { 70 | for iX := 0; iX < pcount; iX++ { 71 | graph(w, pcount, iX, iY, a/float64(iY), b/float64(iY), *h/float64(iY)) 72 | } 73 | } 74 | //etherdream.NextFrame(w, pcount, *pt) 75 | if grow { 76 | a = a / .9 77 | } else { 78 | a = a * .9 79 | } 80 | b = a / *ratio 81 | if a < *amin { 82 | grow = true 83 | } 84 | if a > *amax { 85 | grow = false 86 | } 87 | } 88 | } 89 | 90 | var xyMin = -5600 91 | var xyMax = 5600 92 | var xyRange = xyMax - xyMin 93 | 94 | func graph(w io.WriteCloser, max, cur, rep int, a, b, h float64) *etherdream.Point { 95 | th := float64(cur) / 10.0 96 | x := (a-b)*math.Cos(th) + h*math.Cos((a-b)/b*th) 97 | y := (a-b)*math.Sin(th) - h*math.Sin((a-b)/b*th) 98 | 99 | pt := etherdream.NewPoint(int(x), int(y), colorOsc(cur, rep)) 100 | w.Write(pt.Encode()) 101 | return pt 102 | } 103 | 104 | func colorOsc(cur, rep int) color.Color { 105 | // blank the beginning of the frame also 106 | if cur < *etherdream.BlankCount { 107 | return etherdream.BlankColor 108 | } 109 | if rep == 2 { 110 | return color.RGBA{0x00, 0x55, 0x55, 0x77} 111 | } 112 | return color.RGBA{0x33, 0x00, 0x55, 0xff} 113 | } 114 | -------------------------------------------------------------------------------- /examples/lissajous/lissa.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, version 3. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | */ 16 | 17 | package main 18 | 19 | import ( 20 | "image/color" 21 | "io" 22 | "log" 23 | "math" 24 | 25 | "flag" 26 | 27 | "github.com/tgreiser/etherdream" 28 | "github.com/tgreiser/ln/ln" 29 | ) 30 | 31 | func main() { 32 | log.Printf("Listening...\n") 33 | addr, bp, err := etherdream.FindFirstDAC() 34 | if err != nil { 35 | log.Fatalf("Network error: %v", err) 36 | } 37 | 38 | log.Printf("Found DAC at %v\n", addr) 39 | log.Printf("BP: %v\n\n", bp) 40 | 41 | dac, err := etherdream.NewDAC(addr.IP.String()) 42 | if err != nil { 43 | log.Fatal(err) 44 | } 45 | defer dac.Close() 46 | log.Printf("Initialized: %v\n\n", dac.LastStatus) 47 | log.Printf("Firmware String: %v\n\n", dac.FirmwareString) 48 | 49 | dac.Play(pointStream) 50 | } 51 | 52 | var max = flag.Int("speed", 500, "Speed to run the oscillation (1-20000)") 53 | var xAmp = flag.Float64("x-amp", 20.0, "X amplitude (1.0 - 50.0)") 54 | var yAmp = flag.Float64("y-amp", 5.0, "Y amplitude (1.0 - 50.0)") 55 | 56 | func pointStream(w io.WriteCloser) { 57 | defer w.Close() 58 | pcount := etherdream.FramePoints() - *etherdream.BlankCount 59 | xx := 0 60 | xy := 0 61 | 62 | var pt *etherdream.Point 63 | for { 64 | xRate := etherdream.Osc(xx%*max, *max, *xAmp, 1, 2.5) 65 | yRate := etherdream.Osc(xy%*max, *max, *yAmp, 1, 2.5) 66 | xx++ 67 | xy++ 68 | for iX := 0; iX < pcount; iX++ { 69 | if iX == 0 && pt != nil { 70 | nextPt := graph(w, pcount, iX, xRate, yRate) 71 | blank := ln.Path{pt.ToVector(), nextPt.ToVector()} 72 | etherdream.BlankPath(w, blank) 73 | pt = nextPt 74 | } else { 75 | pt = graph(w, pcount, iX, xRate, yRate) 76 | } 77 | } 78 | } 79 | } 80 | 81 | var xyMin = -5600 82 | var xyMax = 5600 83 | var xyRange = xyMax - xyMin 84 | 85 | func graph(w io.WriteCloser, max, cur int, xRate, yRate float64) *etherdream.Point { 86 | // 0 - max = 0 - 2 radians 87 | rad := float64(cur+1) / float64(max) * 2.0 * math.Pi 88 | x := math.Sin(rad*xRate)*float64(xyRange) + float64(xyMin) 89 | y := math.Sin(rad*yRate)*float64(xyRange) + float64(xyMin) 90 | 91 | pt := etherdream.NewPoint(int(x), int(y), colorOsc(max, cur)) 92 | w.Write(pt.Encode()) 93 | return pt 94 | } 95 | 96 | func colorOsc(max, cur int) color.Color { 97 | return color.RGBA{0x00, 0x00, 0x55, 0xff} 98 | } 99 | -------------------------------------------------------------------------------- /examples/ln1/ln1.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | # Based on work by Jacob Potter, some comments are from his 4 | # protocol documents. Example code based on work from Michael 5 | # Fogleman. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, version 3. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | */ 19 | 20 | package main 21 | 22 | import ( 23 | "io" 24 | "log" 25 | 26 | "image/color" 27 | 28 | "github.com/tgreiser/etherdream" 29 | "github.com/tgreiser/ln/ln" 30 | ) 31 | 32 | func main() { 33 | log.Printf("Listening...\n") 34 | addr, _, err := etherdream.FindFirstDAC() 35 | if err != nil { 36 | log.Fatalf("Network error: %v", err) 37 | } 38 | 39 | log.Printf("Found DAC at %v\n", addr) 40 | 41 | dac, err := etherdream.NewDAC(addr.IP.String()) 42 | if err != nil { 43 | log.Fatal(err) 44 | } 45 | defer dac.Close() 46 | 47 | dac.Play(pointStream) 48 | } 49 | 50 | func pointStream(w io.WriteCloser) { 51 | defer w.Close() 52 | 53 | // create a scene and add a single cube 54 | scene := ln.Scene{} 55 | scene.Add(ln.NewCube(ln.Vector{-1, -1, -1}, ln.Vector{1, 1, 1})) 56 | 57 | // define camera parameters 58 | eye := ln.Vector{4, 3, 2} // camera position 59 | center := ln.Vector{0, 0, 0} // camera looks at 60 | up := ln.Vector{0, 0, 1} // up direction 61 | 62 | // define rendering parameters 63 | width := 10240.0 // rendered width 64 | height := 10240.0 // rendered height 65 | fovy := 50.0 // vertical field of view, degrees 66 | znear := 0.1 // near z plane 67 | zfar := 10.0 // far z plane 68 | step := 0.01 // how finely to chop the paths for visibility testing 69 | speed := 50.0 // Ether Dream rendering quality, lower is more points/slower. 70 | 71 | c := color.RGBA{0x88, 0x00, 0x00, 0xFF} 72 | frame := 0 73 | 74 | for { 75 | 76 | // compute 2D paths that depict the 3D scene 77 | paths := scene.Render(eye, center, up, width, height, fovy, znear, zfar, step) 78 | paths.Optimize() 79 | 80 | lp := len(paths) 81 | for iX := 0; iX < lp; iX++ { 82 | p := paths[iX] 83 | p2 := paths[0] 84 | if iX+1 < lp { 85 | p2 = paths[iX+1] 86 | } 87 | 88 | etherdream.DrawPath(w, p, c, speed) 89 | if p2[0].Distance(p[1]) > 0 { 90 | etherdream.BlankPath(w, ln.Path{p[1], p2[0]}) 91 | } 92 | } 93 | 94 | frame++ 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /examples/ln2/ln2.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | # Based on work by Jacob Potter, some comments are from his 4 | # protocol documents. This example incorporates the work of 5 | # Michael Fogleman. 6 | 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation, version 3. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | */ 19 | 20 | package main 21 | 22 | import ( 23 | "io" 24 | "log" 25 | "math/rand" 26 | 27 | "image/color" 28 | 29 | "flag" 30 | 31 | "github.com/tgreiser/etherdream" 32 | "github.com/tgreiser/ln/ln" 33 | ) 34 | 35 | func main() { 36 | flag.Parse() 37 | log.Printf("Listening...\n") 38 | addr, _, err := etherdream.FindFirstDAC() 39 | if err != nil { 40 | log.Fatalf("Network error: %v", err) 41 | } 42 | 43 | log.Printf("Found DAC at %v\n", addr) 44 | 45 | dac, err := etherdream.NewDAC(addr.IP.String()) 46 | if err != nil { 47 | log.Fatal(err) 48 | } 49 | defer dac.Close() 50 | 51 | dac.Play(pointStream) 52 | } 53 | 54 | func cube(x, y, z float64) ln.Shape { 55 | size := 0.5 56 | v := ln.Vector{x, y, z} 57 | return ln.NewCube(v.SubScalar(size), v.AddScalar(size)) 58 | } 59 | 60 | func pointStream(w io.WriteCloser) { 61 | defer w.Close() 62 | 63 | scene := ln.Scene{} 64 | for x := -1; x <= 1; x++ { 65 | for y := -1; y <= 1; y++ { 66 | z := rand.Float64() 67 | scene.Add(cube(float64(x), float64(y), z)) 68 | } 69 | } 70 | eye := ln.Vector{6, 5, 3} 71 | center := ln.Vector{0, 0, 0} 72 | up := ln.Vector{0, 0, 1} 73 | width := 10000.0 74 | height := 10000.0 75 | fovy := 30.0 76 | 77 | c := color.RGBA{0x77, 0x00, 0x00, 0xFF} 78 | frame := 0 79 | 80 | for { 81 | 82 | // compute 2D paths that depict the 3D scene 83 | paths := scene.Render(eye, center, up, width, height, fovy, 0.1, 100, 0.01) 84 | paths.Optimize() 85 | 86 | lp := len(paths) 87 | for iX := 0; iX < lp; iX++ { 88 | p := paths[iX] 89 | p2 := paths[0] 90 | if iX+1 < lp { 91 | p2 = paths[iX+1] 92 | } 93 | etherdream.DrawPath(w, p, c, 0.0) 94 | if p2[0].Distance(p[1]) > 0 { 95 | etherdream.BlankPath(w, ln.Path{p[1], p2[0]}) 96 | } 97 | } 98 | 99 | frame++ 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /examples/parallel_lines/lines.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | # Based on work by Jacob Potter, some comments are from his 4 | # protocol documents. Example code from Brandon Thomas. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | */ 18 | 19 | package main 20 | 21 | import ( 22 | "io" 23 | "log" 24 | 25 | "image/color" 26 | 27 | "github.com/tgreiser/etherdream" 28 | "github.com/tgreiser/ln/ln" 29 | ) 30 | 31 | func main() { 32 | log.Printf("Listening...\n") 33 | addr, _, err := etherdream.FindFirstDAC() 34 | if err != nil { 35 | log.Fatalf("Network error: %v", err) 36 | } 37 | 38 | log.Printf("Found DAC at %v\n", addr) 39 | 40 | dac, err := etherdream.NewDAC(addr.IP.String()) 41 | if err != nil { 42 | log.Fatal(err) 43 | } 44 | defer dac.Close() 45 | 46 | dac.Play(pointStream) 47 | } 48 | 49 | func line(x, y, z, x2, y2, z2 float64) ln.Path { 50 | return ln.Path{ln.Vector{x, y, z}, ln.Vector{x2, y2, z2}} 51 | } 52 | 53 | func pointStream(w io.WriteCloser) { 54 | defer w.Close() 55 | 56 | c1 := color.RGBA{0x88, 0x00, 0x77, 0xFF} 57 | c2 := color.RGBA{0x00, 0x88, 0x00, 0xFF} 58 | frame := 0 59 | 60 | for { 61 | 62 | // compute 2D paths that depict the 3D scene 63 | paths := ln.Paths{ 64 | line(0, 0, 0, 0, 5000, 0), 65 | line(5000, 0, 0, 5000, 5000, 0), 66 | line(10000, 0, 0, 10000, 5000, 0), 67 | line(12000, 0, 0, 12000, 5000, 0), 68 | line(14000, 0, 0, 14000, 5000, 0), 69 | line(14000, 5000, 0, 0, 5000, 0), 70 | line(0, 0, 0, 14000, 0, 0), 71 | } 72 | 73 | lp := len(paths) 74 | for iX := 0; iX < lp; iX++ { 75 | p := paths[iX] 76 | p2 := paths[0] 77 | if iX+1 < lp { 78 | p2 = paths[iX+1] 79 | } 80 | 81 | c := c1 82 | if iX%2 == 0 { 83 | c = c2 84 | } 85 | etherdream.DrawPath(w, p, c, 0.0) 86 | if p2[0].Distance(p[1]) > 0 { 87 | etherdream.BlankPath(w, ln.Path{p[1], p2[0]}) 88 | } 89 | } 90 | 91 | frame++ 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /examples/spiral/spiral.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | # Based on work by Jacob Potter, some comments are from his 4 | # protocol documents. Example code from Brandon Thomas. 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | */ 18 | 19 | package main 20 | 21 | import ( 22 | "io" 23 | "log" 24 | 25 | "math" 26 | 27 | "image/color" 28 | 29 | "github.com/tgreiser/etherdream" 30 | "github.com/tgreiser/ln/ln" 31 | ) 32 | 33 | func main() { 34 | log.Printf("Listening...\n") 35 | addr, _, err := etherdream.FindFirstDAC() 36 | if err != nil { 37 | log.Fatalf("Network error: %v", err) 38 | } 39 | 40 | log.Printf("Found DAC at %v\n", addr) 41 | 42 | dac, err := etherdream.NewDAC(addr.IP.String()) 43 | if err != nil { 44 | log.Fatal(err) 45 | } 46 | defer dac.Close() 47 | 48 | dac.Play(pointStream) 49 | } 50 | 51 | func pointStream(w io.WriteCloser) { 52 | defer w.Close() 53 | 54 | c := color.RGBA{0x88, 0x00, 0x55, 0xFF} 55 | maxrad := 22600 56 | rad := int(maxrad / 100) 57 | var spiralgrowth float64 = 14 58 | 59 | for { 60 | var j float64 61 | 62 | to := etherdream.FramePoints() - *etherdream.BlankCount 63 | for _, i := range xrange(0, to, 1) { 64 | f := float64(i) / 1000.0 * 2.0 * math.Pi * spiralgrowth 65 | j = f 66 | x := int(j * math.Cos(f) * float64(rad)) 67 | y := int(j * math.Sin(f) * float64(rad)) 68 | w.Write(etherdream.NewPoint(x, y, c).Encode()) 69 | } 70 | 71 | // blank and return to origin 72 | f := 1000.0 / 1000.0 * 2.0 * math.Pi * spiralgrowth 73 | j = f 74 | x := j * math.Cos(f) * float64(rad) 75 | y := j * math.Sin(f) * float64(rad) 76 | p := ln.Path{ln.Vector{x, y, 0}, ln.Vector{0, 0, 0}} 77 | pt := etherdream.BlankPath(w, p) 78 | 79 | _ = etherdream.NextFrame(w, etherdream.FramePoints(), *pt) 80 | } 81 | } 82 | 83 | func xrange(min, max, step int) []int { 84 | rng := max - min 85 | ret := make([]int, rng/step+1) 86 | iY := 0 87 | for iX := min; rlogic(min, max, iX); iX += step { 88 | ret[iY] = iX 89 | iY++ 90 | } 91 | return ret 92 | } 93 | 94 | func rlogic(min, max, iX int) bool { 95 | if min < max { 96 | return iX <= max 97 | } 98 | return iX >= max 99 | } 100 | -------------------------------------------------------------------------------- /examples/square/square.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | # Based on work by Jacob Potter, some comments are from his 4 | # protocol documents. Example code from Brandon Thomas. 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | */ 18 | 19 | package main 20 | 21 | import ( 22 | "io" 23 | "log" 24 | "math" 25 | 26 | "image/color" 27 | 28 | "github.com/tgreiser/etherdream" 29 | ) 30 | 31 | func main() { 32 | log.Printf("Listening...\n") 33 | addr, bp, err := etherdream.FindFirstDAC() 34 | if err != nil { 35 | log.Fatalf("Network error: %v", err) 36 | } 37 | 38 | log.Printf("Found DAC at %v\n", addr) 39 | log.Printf("BP: %v\n\n", bp) 40 | 41 | dac, err := etherdream.NewDAC(addr.IP.String()) 42 | if err != nil { 43 | log.Fatal(err) 44 | } 45 | defer dac.Close() 46 | log.Printf("Initialized: %v\n\n", dac.LastStatus) 47 | log.Printf("Firmware String: %v\n\n", dac.FirmwareString) 48 | 49 | dac.Play(squarePointStream) 50 | } 51 | 52 | func squareFrame(w io.WriteCloser, pmax, pstep int) *etherdream.Point { 53 | for _, x := range xrange(-pmax, pmax, pstep) { 54 | w.Write(etherdream.NewPoint(x, pmax, color.RGBA{0xff, 0x00, 0x00, 0xff}).Encode()) 55 | } 56 | for _, y := range xrange(pmax, -pmax, -pstep) { 57 | w.Write(etherdream.NewPoint(pmax, y, color.RGBA{0x00, 0xff, 0x00, 0xff}).Encode()) 58 | } 59 | for _, x := range xrange(pmax, -pmax, -pstep) { 60 | w.Write(etherdream.NewPoint(x, -pmax, color.RGBA{0x00, 0x00, 0xff, 0xff}).Encode()) 61 | } 62 | var pt *etherdream.Point 63 | for _, y := range xrange(-pmax, pmax, pstep) { 64 | pt = etherdream.NewPoint(-pmax, y, color.RGBA{0xff, 0xff, 0xff, 0xff}) 65 | w.Write(pt.Encode()) 66 | } 67 | return pt 68 | } 69 | 70 | func squarePointStream(w io.WriteCloser) { 71 | defer w.Close() 72 | pmax := 5600 73 | pstep := 112 74 | pct := pmax / pstep * 4 75 | for { 76 | var pt *etherdream.Point 77 | ct := pct 78 | times := int(math.Floor(float64(etherdream.FramePoints() / ct))) 79 | ct = 0 80 | 81 | // This approach gives flicker free draw, when 82 | // repeated 4x 83 | for i := 0; i < times; i++ { 84 | pt = squareFrame(w, pmax, pstep) 85 | ct += pct 86 | } 87 | 88 | etherdream.NextFrame(w, ct, *pt) 89 | } 90 | } 91 | 92 | func xrange(min, max, step int) []int { 93 | rng := max - min 94 | ret := make([]int, rng/step+1) 95 | iY := 0 96 | for iX := min; rlogic(min, max, iX); iX += step { 97 | ret[iY] = iX 98 | iY++ 99 | } 100 | return ret 101 | } 102 | 103 | func rlogic(min, max, iX int) bool { 104 | if min < max { 105 | return iX <= max 106 | } 107 | return iX >= max 108 | } 109 | -------------------------------------------------------------------------------- /point.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, version 3. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program. If not, see . 15 | */ 16 | 17 | package etherdream 18 | 19 | import ( 20 | "encoding/binary" 21 | "fmt" 22 | "image/color" 23 | "io" 24 | 25 | "github.com/tgreiser/ln/ln" 26 | ) 27 | 28 | // PointStream is the interface clients should implement to 29 | // generate points 30 | type PointStream func(w io.WriteCloser) 31 | 32 | // Point is a step in the laser stream, X, Y, RGB, Intensity and 33 | // some other fields. 34 | type Point struct { 35 | X int16 36 | Y int16 37 | R uint16 38 | G uint16 39 | B uint16 40 | I uint16 41 | U1 uint16 42 | U2 uint16 43 | Flags uint16 44 | } 45 | 46 | // NewPoint wil instantiate a point from the basic attributes. 47 | func NewPoint(x, y int, c color.Color) *Point { 48 | r, g, b, a := c.RGBA() 49 | return &Point{ 50 | X: int16(x), 51 | Y: int16(y), 52 | R: uint16(r), 53 | G: uint16(g), 54 | B: uint16(b), 55 | I: uint16(a), 56 | } 57 | } 58 | 59 | // Encode color values into a 18 byte struct Point 60 | // 61 | // Values must be specified for x, y, r, g, and b. If a value is not 62 | // passed in for the other fields, i will default to max(r, g, b); the 63 | // rest default to zero. 64 | func (p Point) Encode() []byte { 65 | mut.Lock() 66 | if p.I <= 0 { 67 | p.I = p.R 68 | if p.G > p.I { 69 | p.I = p.G 70 | } 71 | if p.B > p.I { 72 | p.I = p.B 73 | } 74 | } 75 | var enc = make([]byte, 18) 76 | 77 | binary.LittleEndian.PutUint16(enc[0:2], p.Flags) 78 | // X and Y are actualy int16 79 | binary.LittleEndian.PutUint16(enc[2:4], uint16(p.X)) 80 | binary.LittleEndian.PutUint16(enc[4:6], uint16(p.Y)) 81 | 82 | binary.LittleEndian.PutUint16(enc[6:8], p.R) 83 | binary.LittleEndian.PutUint16(enc[8:10], p.G) 84 | binary.LittleEndian.PutUint16(enc[10:12], p.B) 85 | binary.LittleEndian.PutUint16(enc[12:14], p.I) 86 | binary.LittleEndian.PutUint16(enc[14:16], p.U1) 87 | binary.LittleEndian.PutUint16(enc[16:18], p.U2) 88 | 89 | if *Dump { 90 | fmt.Printf("%v\t%v\t%v\t%v\t%v\n", p.X, p.Y, p.R, p.G, p.B) 91 | } 92 | 93 | mut.Unlock() 94 | return enc 95 | } 96 | 97 | func (p Point) ToVector() ln.Vector { 98 | return ln.Vector{float64(p.X), float64(p.Y), 0.0} 99 | } 100 | 101 | // Points - Point list 102 | type Points struct { 103 | Points []Point 104 | } 105 | -------------------------------------------------------------------------------- /status.go: -------------------------------------------------------------------------------- 1 | /* 2 | # Copyright 2016 Tim Greiser 3 | # Based on work by Jacob Potter, some comments are from his 4 | # protocol documents 5 | 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation, version 3. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | */ 18 | 19 | package etherdream 20 | 21 | import ( 22 | "encoding/binary" 23 | "fmt" 24 | ) 25 | 26 | // DACStatus is a struct of status informaion sent by the etherdream DAC 27 | type DACStatus struct { 28 | Protocol uint8 29 | LightEngineState uint8 30 | PlaybackState uint8 31 | Source uint8 32 | LightEngineFlags uint16 33 | PlaybackFlags uint16 34 | SourceFlags uint16 35 | BufferFullness uint16 36 | PointRate uint32 37 | PointCount uint32 38 | } 39 | 40 | func NewDACStatus(b []byte) *DACStatus { 41 | return &DACStatus{ 42 | Protocol: b[0], 43 | LightEngineState: b[1], 44 | PlaybackState: b[2], 45 | Source: b[3], 46 | LightEngineFlags: binary.LittleEndian.Uint16(b[4:6]), 47 | PlaybackFlags: binary.LittleEndian.Uint16(b[6:8]), 48 | SourceFlags: binary.LittleEndian.Uint16(b[8:10]), 49 | BufferFullness: binary.LittleEndian.Uint16(b[10:12]), 50 | PointRate: binary.LittleEndian.Uint32(b[12:16]), 51 | PointCount: binary.LittleEndian.Uint32(b[16:20]), 52 | } 53 | } 54 | func (st DACStatus) String() string { 55 | return fmt.Sprintf("Light engine: state %d, flags 0x%x\n", st.LightEngineState, st.LightEngineFlags) + 56 | fmt.Sprintf("Playback: state %d, flags 0x%x\n", st.PlaybackState, st.PlaybackFlags) + 57 | fmt.Sprintf("Buffer: %d points\n", st.BufferFullness) + 58 | fmt.Sprintf("Playback: %d pps, %d points played", st.PointRate, st.PointCount) + 59 | fmt.Sprintf("Source: %d, flags 0x%x", st.Source, st.SourceFlags) 60 | } 61 | 62 | // BroadcastPacket is the various capabilities advertised by the DAC 63 | type BroadcastPacket struct { 64 | MAC []uint8 65 | HWRev uint16 66 | SWRev uint16 67 | BufferCapacity uint16 68 | MaxPointRate uint32 69 | Status *DACStatus 70 | } 71 | 72 | // NewBroadcastPacket is assembled from 36 bytes of data 73 | func NewBroadcastPacket(b [36]byte) *BroadcastPacket { 74 | return &BroadcastPacket{ 75 | MAC: b[0:6], 76 | HWRev: binary.LittleEndian.Uint16(b[6:8]), 77 | SWRev: binary.LittleEndian.Uint16(b[8:10]), 78 | BufferCapacity: binary.LittleEndian.Uint16(b[10:12]), 79 | MaxPointRate: binary.LittleEndian.Uint32(b[12:16]), 80 | Status: NewDACStatus(b[16:36]), 81 | } 82 | } 83 | 84 | func (bp BroadcastPacket) String() string { 85 | return fmt.Sprintf("MAC: %02x %02x %02x %02x %02x %02x\n", bp.MAC[0], bp.MAC[1], bp.MAC[2], bp.MAC[3], bp.MAC[4], bp.MAC[5]) + 86 | fmt.Sprintf("HW %d, SW %d\n", bp.HWRev, bp.SWRev) + 87 | fmt.Sprintf("Capabilities: max %d points, %d kpps", bp.BufferCapacity, bp.MaxPointRate) 88 | } 89 | --------------------------------------------------------------------------------