├── LICENSE ├── MillControl ├── BrewTimer.cpp ├── BrewTimer.h ├── BrewlessState.cpp ├── BrewlessState.h ├── Button.cpp ├── Button.h ├── CMakeLists.txt ├── CalibrationPrompt.cpp ├── CalibrationPrompt.h ├── CharEditor.cpp ├── CharEditor.h ├── DataEditor.cpp ├── DataEditor.h ├── DataEditorData.h ├── DirectRun.cpp ├── DirectRun.h ├── Editor.cpp ├── Editor.h ├── FlatModeSelector.cpp ├── FlatModeSelector.h ├── HoldRun.cpp ├── HoldRun.h ├── MillControl.cpp ├── MillControl.h ├── MillControl.ino ├── Mode.cpp ├── Mode.h ├── ModeSelector.cpp ├── ModeSelector.h ├── MultiModeSelector.cpp ├── MultiModeSelector.h ├── MultiTimer1.cpp ├── MultiTimer1.h ├── Prompt.cpp ├── Prompt.h ├── RotatingButtons.cpp ├── RotatingButtons.h ├── RotatingEncoder.cpp ├── RotatingEncoder.h ├── Rotator.h ├── Run.cpp ├── Run.h ├── Scale.cpp ├── Scale.h ├── ScaleTarePrompt.cpp ├── ScaleTarePrompt.h ├── State.cpp ├── State.h ├── Timed.h ├── TimedRun.cpp ├── TimedRun.h ├── UI.cpp ├── UI.h ├── WeightCalibrationRun.cpp ├── WeightCalibrationRun.h ├── WeightRun.cpp ├── WeightRun.h ├── cmake │ ├── ArduinoToolchain.cmake │ ├── ArduinoToolchain.cmake~ │ └── Platform │ │ └── Arduino.cmake ├── fonts │ ├── bdffont.py │ └── fub20b.bdf ├── fub20bn.h ├── helvB10s.h ├── helvB14r.h ├── helvR14n.h └── images │ ├── bean.xbm │ ├── bean20.xbm │ ├── cup.png │ ├── cupS.xbm │ ├── hand.xbm │ └── hand20.xbm └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | -------------------------------------------------------------------------------- /MillControl/BrewTimer.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by roman on 03.12.15. 3 | // 4 | 5 | 6 | #include 7 | #include "BrewTimer.h" 8 | #include "MillControl.h" 9 | 10 | #ifdef BREW_BUTTON 11 | 12 | //Initialize the timer 13 | bool BrewTimer::open() { 14 | if (UI::brewButton.isPressed()) { 15 | DEBUG_PRINTLN("opened: BrewTimer"); 16 | updateTime = 0; 17 | startTime = millis(); 18 | return true; 19 | } 20 | return false; 21 | } 22 | 23 | //Return to the brew timer, will only start if it is alive 24 | bool BrewTimer::start() { 25 | return isRunning(); 26 | } 27 | 28 | //Checks if the Brew Timer is alive 29 | bool BrewTimer::isRunning(){ 30 | if (startTime > 0 && !UI::brewButton.isPressed()) { 31 | startTime = 0; 32 | } 33 | return startTime > 0; 34 | } 35 | 36 | //Update Display & stop if timer died 37 | void BrewTimer::loop() { 38 | if(!isRunning()) 39 | close(); 40 | else if (millis() > (updateTime + 250)) { 41 | updateTime = millis(); 42 | redraw(); 43 | } 44 | } 45 | 46 | //Pass through the mill click 47 | void BrewTimer::millClick(unsigned char i) { 48 | //Forward the click to the state below 49 | previousState->millClick(i); 50 | } 51 | 52 | //Get start to previous state 53 | void BrewTimer::encoderChanged(int encoderPos) { 54 | encoderClick(); 55 | } 56 | 57 | //Start to previous state 58 | void BrewTimer::encoderClick() { 59 | MillControl::start(*previousState); 60 | } 61 | 62 | //simple for now 63 | void BrewTimer::draw() { 64 | UI::u8g.setFont(UI::FONT_REGULAR); 65 | #ifdef PORTRAIT_DISPLAY 66 | UI::u8g.drawStr270(UI::LINE_HEIGHT, UI::u8g.getStrWidth(UI::BREW_TITLE), UI::BREW_TITLE); 67 | UI::BREW_SYMBOL.draw(&UI::u8g, UI::DISPLAY_WIDTH - UI::BREW_SYMBOL.width, UI::BREW_SYMBOL.height); 68 | const char x= UI::DISPLAY_WIDTH - UI::SMALL_LINE_HEIGHT; 69 | const char y= UI::DISPLAY_HEIGHT - UI::BORDER_WIDTH - 1; //Bottom 70 | #else 71 | UI::u8g.drawStr(0, UI::LINE_HEIGHT, UI::BREW_TITLE); 72 | UI::BREW_SYMBOL.draw(&UI::u8g, 0, UI::DISPLAY_HEIGHT - UI::BREW_SYMBOL.height/2); 73 | const char x = UI::DISPLAY_WIDTH - UI::LINE_HEIGHT - 1; //89 74 | const char y = UI::DISPLAY_HEIGHT - 3 * UI::BORDER_WIDTH - 1;//57; 75 | #endif 76 | UI::drawRunTime(x, y, (millis() - startTime) / 1000); 77 | } 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /MillControl/BrewTimer.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_BREWTIMER_H 2 | #define MILLCONTROL_BREWTIMER_H 3 | 4 | #include "State.h" 5 | 6 | #ifdef BREW_BUTTON 7 | 8 | class BrewTimer : public State { 9 | unsigned long startTime = 0; 10 | unsigned long updateTime = 0; 11 | protected: 12 | virtual void draw() override; 13 | 14 | public: 15 | virtual void loop() override; 16 | 17 | virtual bool start() override; 18 | 19 | virtual void millClick(unsigned char i) override; 20 | virtual void encoderClick() override; 21 | 22 | virtual void encoderChanged(int encoderPos) override; 23 | 24 | bool isRunning(); 25 | 26 | virtual bool open() override; 27 | 28 | #ifdef DEBUG 29 | virtual char* getClassName() {return (char *) "BrewTimer"; } 30 | #endif 31 | }; 32 | 33 | #endif 34 | 35 | #endif //MILLCONTROL_BREWTIMER_H -------------------------------------------------------------------------------- /MillControl/BrewlessState.cpp: -------------------------------------------------------------------------------- 1 | #include "BrewlessState.h" 2 | #include "MillControl.h" 3 | 4 | #ifdef BREW_BUTTON 5 | //No brew timer here 6 | void BrewlessState::brewClick() { 7 | MillControl::openInBackground(MillControl::BREW_TIMER); 8 | } 9 | #endif -------------------------------------------------------------------------------- /MillControl/BrewlessState.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_BREWLESSSTATE_H 2 | #define MILLCONTROL_BREWLESSSTATE_H 3 | 4 | #include "State.h" 5 | 6 | class BrewlessState : public State { 7 | #ifdef BREW_BUTTON 8 | public: 9 | virtual void brewClick() override; 10 | #endif 11 | }; 12 | 13 | #endif //MILLCONTROL_BREWLESSSTATE_H 14 | -------------------------------------------------------------------------------- /MillControl/Button.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Partly based on raron's (raronzen@gmail.com) clickbutton library. 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; either version 3 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software Foundation, 16 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | #include "Button.h" 21 | 22 | Button::Button(unsigned char pin, bool multiClick) : pin(pin), multiClick(multiClick) { 23 | //Set pin to input 24 | pinMode(pin, INPUT_PULLUP); 25 | 26 | MultiTimer1::add(this); 27 | } 28 | 29 | //Update clicks 30 | void Button::run() { 31 | long now = (long) millis(); // get current time 32 | bool btnState = !digitalRead(pin); // current appearant button state 33 | 34 | // If the switch changed, due to noise or a button press, reset the debounce timer 35 | if (btnState != lastState) lastBounceTime = now; 36 | 37 | // debounce the button (Check if a stable, changed state has occured) 38 | const long delta = now - lastBounceTime; 39 | 40 | if (btnState != stableState && delta > DEBOUNCE_TIME) { 41 | stableState = btnState; 42 | //if the button was pressed then this is one more click 43 | if (stableState) 44 | clickCount++; 45 | } 46 | 47 | if (multiClick) { 48 | // If the button is released and the pause was long enough then report the number of clicks and restart 49 | if (!stableState && delta > CLICK_TIME_MULTI) { 50 | // positive count for released buttons 51 | clicks = clickCount; 52 | clickCount = 0; 53 | } 54 | 55 | // Check for "long click" 56 | if (stableState && (delta > CLICK_TIME_LONG)) { 57 | // negative count for long clicks 58 | clicks = -clickCount; 59 | clickCount = 0; 60 | } 61 | 62 | } else if (clickCount) { 63 | //immedeately propagate the click 64 | clicks = clickCount; 65 | clickCount = 0; 66 | } 67 | 68 | lastState = btnState; 69 | } 70 | 71 | //Pulls clicks - resets the counter 72 | char Button::getClicks() { 73 | const char c = clicks; 74 | clicks = 0; 75 | return c; 76 | } 77 | 78 | //Sets the button to allow multiple clicks and long clicks 79 | void Button::setMultiClick(bool _multiClick) { 80 | multiClick = _multiClick; 81 | } 82 | 83 | // Is the button pressed? 84 | bool Button::isPressed() { 85 | return stableState; 86 | } 87 | -------------------------------------------------------------------------------- /MillControl/Button.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_BUTTON_H 2 | #define MILLCONTROL_BUTTON_H 3 | 4 | #include "MultiTimer1.h" 5 | 6 | class Button : public Timed { 7 | char clicks = 0; //clicks if any since the last getClicks(); 8 | 9 | //Can handle up to four buttons - change to allow for more 10 | static const int DEBOUNCE_TIME = 30; //Milliseconds to wait for a stable state 11 | static const int CLICK_TIME_MULTI = 500; 12 | static const int CLICK_TIME_LONG = 1000; 13 | 14 | unsigned char pin; // Arduino pin connected to the button 15 | bool multiClick; // Is this a multi-click button? 16 | 17 | bool lastState = false; // previous button reading 18 | bool stableState = false;// the currently debounced button (press) state 19 | 20 | char clickCount = 0; // Number of button clicks within a CLICK_TIME_MULTI 21 | long lastBounceTime = 0; // the last time the button input pin was toggled, due to noise or a press 22 | public: 23 | static const bool SINGLE_CLICK = false; 24 | static const bool MULTI_CLICK = true; 25 | 26 | Button(unsigned char, bool = SINGLE_CLICK); 27 | 28 | void setMultiClick(bool _multiClick); 29 | 30 | void run() override; 31 | 32 | char getClicks(); 33 | 34 | bool isPressed(); 35 | }; 36 | 37 | #endif //MILLCONTROL_BUTTON_H 38 | -------------------------------------------------------------------------------- /MillControl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8.4) 2 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") 3 | set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/ArduinoToolchain.cmake) 4 | 5 | 6 | set(PROJECT_NAME MillControl) 7 | project(${PROJECT_NAME}) 8 | 9 | link_directories(/home/roman/sketchbook/libraries/U8glib) 10 | set(U8glib_RECURSE True) 11 | link_directories(/home/roman/sketchbook/libraries/Queuetue_HX711_Library/src) 12 | #set(U8glib_RECURSE True) 13 | link_directories(/home/roman/sketchbook/libraries/) 14 | 15 | 16 | set(${CMAKE_PROJECT_NAME}_SKETCH MillControl.ino) 17 | 18 | set(${CMAKE_PROJECT_NAME}_BOARD pro5v328) 19 | set(${CMAKE_PROJECT_NAME}_PORT /dev/ttyUSB0) 20 | set(${CMAKE_PROJECT_NAME}_SERIAL picocom @SERIAL_PORT@ -b 9600 -l) 21 | 22 | 23 | generate_arduino_firmware(${CMAKE_PROJECT_NAME}) 24 | -------------------------------------------------------------------------------- /MillControl/CalibrationPrompt.cpp: -------------------------------------------------------------------------------- 1 | #include "CalibrationPrompt.h" 2 | #include "MillControl.h" 3 | 4 | CalibrationPrompt::CalibrationPrompt() : Prompt(2, 3) { 5 | #ifndef PORTRAIT_DISPLAY 6 | prompt_position = 2; 7 | #endif 8 | } 9 | 10 | bool CalibrationPrompt::open() { 11 | position = 2; 12 | MillControl::open(MillControl::CALIBRATION_TIME_EDITOR); 13 | return true; 14 | } 15 | 16 | void CalibrationPrompt::encoderClick() { 17 | Prompt::encoderClick(); 18 | 19 | if (position == 2) 20 | MillControl::open(MillControl::CALIBRATION_TIME_EDITOR); 21 | } 22 | 23 | void CalibrationPrompt::draw() { 24 | Prompt::draw(); 25 | draw(false); 26 | } 27 | 28 | 29 | void CalibrationPrompt::draw(bool editor) { 30 | Prompt::draw(); 31 | 32 | UI::drawSubtitle(UI::CALIBRATION_TITLE); 33 | UI::drawRunWeightLine(weight, position == 2 ? (editor ? 1 : 2) : 0); 34 | } 35 | 36 | void CalibrationPrompt::drawEditor() { 37 | draw(true); 38 | } 39 | 40 | int *CalibrationPrompt::getData() { 41 | return &weight; 42 | } 43 | 44 | void CalibrationPrompt::cancel() { 45 | weight = 0; 46 | Prompt::cancel(); 47 | } 48 | -------------------------------------------------------------------------------- /MillControl/CalibrationPrompt.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_CALIBRATIONPROMPT_H 2 | #define MILLCONTROL_CALIBRATIONPROMPT_H 3 | 4 | #include "Prompt.h" 5 | #include "DataEditorData.h" 6 | 7 | class CalibrationPrompt : public Prompt, public DataEditorData { 8 | protected: 9 | void draw(bool editor); 10 | 11 | public: 12 | CalibrationPrompt(); 13 | 14 | virtual bool open() override; 15 | 16 | virtual int *getData() override; 17 | 18 | int weight = 70; 19 | private: 20 | virtual void drawEditor() override; 21 | 22 | virtual void encoderClick() override; 23 | 24 | virtual void draw() override; 25 | 26 | protected: 27 | 28 | 29 | public: 30 | virtual void cancel() override; 31 | 32 | #ifdef DEBUG 33 | virtual char* getClassName() {return (char *) "CalibrationPrompt"; } 34 | #endif 35 | }; 36 | 37 | #endif //MILLCONTROL_CALIBRATIONPROMPT_H -------------------------------------------------------------------------------- /MillControl/CharEditor.cpp: -------------------------------------------------------------------------------- 1 | #include "CharEditor.h" 2 | #include "MillControl.h" 3 | 4 | //const char CharEditor::CHARACTERS[]= " ABCDEFGHIJLKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890/-+*&!?:#'()[]"; 5 | //const unsigned char CharEditor::CHARACTERS_COUNT = sizeof(CharEditor::CHARACTERS) - 1; 6 | 7 | bool CharEditor::start() { 8 | c = MillControl::EDITOR.getChar(); 9 | int encoderPosition = *c - UI::CHAR_BEGIN + 1; 10 | setEncoderMode(UI::CHAR_END - UI::CHAR_BEGIN + 1, encoderPosition); 11 | return true; 12 | } 13 | 14 | void CharEditor::encoderClick() { 15 | close(); 16 | } 17 | 18 | void CharEditor::encoderChanged(int encoderPos) { 19 | (*c) = encoderPos + UI::CHAR_BEGIN; 20 | redraw(); 21 | } 22 | 23 | void CharEditor::draw() { 24 | MillControl::EDITOR.drawEditor(); 25 | } 26 | -------------------------------------------------------------------------------- /MillControl/CharEditor.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_CHAREDITOR_H 2 | #define MILLCONTROL_CHAREDITOR_H 3 | 4 | #include "State.h" 5 | 6 | class CharEditor : public State { 7 | char *c; 8 | public: 9 | 10 | virtual bool start() override; 11 | 12 | virtual void encoderClick() override; 13 | 14 | virtual void draw() override; 15 | 16 | virtual void encoderChanged(int encoderPos) override; 17 | 18 | #ifdef DEBUG 19 | virtual char* getClassName() {return (char *) "CharEditor"; } 20 | #endif 21 | }; 22 | 23 | #endif //MILLCONTROL_CHAREDITOR_H -------------------------------------------------------------------------------- /MillControl/DataEditor.cpp: -------------------------------------------------------------------------------- 1 | #include "DataEditor.h" 2 | 3 | bool DataEditor::start() { 4 | time = editor->getData(); 5 | setEncoderMode(1901, *time < 1000 ? *time : 1000 + (*time - 1000) / 10) ; 6 | return true; 7 | } 8 | 9 | void DataEditor::encoderClick() { 10 | close(); 11 | } 12 | 13 | void DataEditor::encoderChanged(int encoderPos) { 14 | (*time) = encoderPos < 1000 ? encoderPos : 1000 + (encoderPos - 1000) * 10; 15 | redraw(); 16 | } 17 | 18 | void DataEditor::draw() { 19 | editor->drawEditor(); 20 | } 21 | -------------------------------------------------------------------------------- /MillControl/DataEditor.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_DATAEDITOR_H 2 | #define MILLCONTROL_DATAEDITOR_H 3 | 4 | #include "State.h" 5 | #include "DataEditorData.h" 6 | 7 | class DataEditor : public State { 8 | protected: 9 | int *time; 10 | DataEditorData *editor; 11 | public: 12 | DataEditor(DataEditorData *editor) : editor(editor) { } 13 | 14 | virtual bool start() override; 15 | 16 | virtual void encoderClick() override; 17 | 18 | virtual void draw() override; 19 | 20 | virtual void encoderChanged(int encoderPos) override; 21 | 22 | #ifdef DEBUG 23 | virtual char* getClassName() {return (char *) "DataEditor"; } 24 | #endif 25 | }; 26 | 27 | #endif //MILLCONTROL_DATAEDITOR_H -------------------------------------------------------------------------------- /MillControl/DataEditorData.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_DATAEDITORDATA_H 2 | #define MILLCONTROL_DATAEDITORDATA_H 3 | 4 | class DataEditorData { 5 | public: 6 | virtual void drawEditor(); 7 | 8 | virtual int *getData(); 9 | }; 10 | 11 | #endif //MILLCONTROL_DATAEDITORDATA_H 12 | -------------------------------------------------------------------------------- /MillControl/DirectRun.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by roman on 05.02.16. 3 | // 4 | 5 | #include "DirectRun.h" 6 | 7 | bool DirectRun::start() { 8 | startTime = millis(); 9 | return Run::start(); 10 | } 11 | 12 | void DirectRun::millClick(unsigned char i) { 13 | close(); 14 | } 15 | 16 | void DirectRun::draw() { 17 | Run::draw(); 18 | int seconds = max(0, ((millis() + 500) - startTime) / 1000); 19 | 20 | #ifdef PORTRAIT_DISPLAY 21 | const char x = UI::DISPLAY_WIDTH - UI::LINE_HEIGHT; 22 | const char y = UI::DISPLAY_HEIGHT - 12 * UI::BORDER_WIDTH; 23 | #else 24 | const char x = UI::DISPLAY_WIDTH - UI::LINE_HEIGHT; //115; 25 | const char y = UI::DISPLAY_HEIGHT - 6 * UI::BORDER_WIDTH; //53; 26 | #endif 27 | UI::drawRunTime(x, y, seconds); 28 | } 29 | -------------------------------------------------------------------------------- /MillControl/DirectRun.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by roman on 05.02.16. 3 | // 4 | 5 | #ifndef MILLCONTROL_DIRECTRUN_H 6 | #define MILLCONTROL_DIRECTRUN_H 7 | 8 | 9 | #include "Run.h" 10 | 11 | class DirectRun : public Run { 12 | unsigned long startTime; 13 | public: 14 | DirectRun(const unsigned char run_icon, const int run_data) : Run(run_icon, run_data) { } 15 | 16 | virtual bool start() override; 17 | 18 | virtual void millClick(unsigned char i) override; 19 | 20 | virtual void draw() override; 21 | }; 22 | 23 | 24 | #endif //MILLCONTROL_DIRECTRUN_H 25 | -------------------------------------------------------------------------------- /MillControl/Editor.cpp: -------------------------------------------------------------------------------- 1 | #include "MillControl.h" 2 | 3 | bool Editor::start() { 4 | //get the current mode 5 | timeMode = &MillControl::TIME_MODE_SELECTOR.getMode(); 6 | //get all time modes - needed for adding and deleting 7 | timeModes = &MillControl::TIME_MODE_SELECTOR.timeModes; 8 | 9 | firstChar = (unsigned char) (Mode::DATA_PER_MODE + (timeMode->mode == Mode::WEIGHT_MODE ? 1 : 0)); 10 | 11 | const int size = timeModes->size; 12 | 13 | back = firstChar++; 14 | 15 | if (!deleteMode) 16 | gram = firstChar++; 17 | else 18 | gram = 0; 19 | 20 | if (size < ModeList::MAX_MODES && !deleteMode) 21 | add = firstChar++; 22 | else 23 | add = 0; 24 | 25 | del = firstChar++; 26 | 27 | if (size > 2 && !deleteMode) { 28 | left = firstChar++; 29 | right = firstChar++; 30 | } else { 31 | left = 0; 32 | right = 0; 33 | } 34 | 35 | if (deleteMode) 36 | setEncoderMode(2, 0); 37 | else 38 | setEncoderMode(firstChar + Mode::MAX_CHARS, position); 39 | 40 | DEBUG_PRINTLN("editor set up"); 41 | //if there is no mill button i need a multi click button in the gram editor 42 | #ifndef MILL_BUTTON 43 | //Multi click if not in timed mode (for calibration menus) 44 | UI::encoderButton.setMultiClick(timeMode->mode != Mode::TIME_MODE); 45 | #endif 46 | return true; 47 | } 48 | 49 | void Editor::stop() { 50 | } 51 | 52 | int *Editor::getData() { 53 | if (timeMode->mode == Mode::WEIGHT_MODE) { 54 | if (position == 0) 55 | return &timeMode->calibration_data; 56 | else 57 | return &timeMode->data[position - 1]; 58 | } 59 | else 60 | return &timeMode->data[position]; 61 | } 62 | 63 | char *Editor::getChar() { 64 | return &timeMode->name[position - firstChar]; 65 | } 66 | 67 | 68 | void Editor::encoderClick() { 69 | if (position < back) { 70 | MillControl::open(MillControl::TIME_EDITOR); 71 | return; 72 | } else if (position == back) { 73 | if (deleteMode) { 74 | deleteMode = false; 75 | } else { 76 | timeModes->eepromWrite(); 77 | close(); 78 | return; 79 | } 80 | position = 0; 81 | } else if (position == gram) { 82 | unsigned char new_mode; 83 | switch (timeMode->mode) { 84 | case Mode::TIME_MODE: 85 | new_mode = Mode::WEIGHT_MODE; 86 | break; 87 | #ifdef SCALE 88 | case Mode::WEIGHT_MODE: 89 | new_mode = Mode::SCALE_MODE; 90 | break; 91 | #endif 92 | default: 93 | new_mode = Mode::TIME_MODE; 94 | } 95 | timeMode->setMode(new_mode); 96 | position = 0; 97 | } else if (position == add) { 98 | MillControl::TIME_MODE_SELECTOR.setMode(&timeModes->insertAfer(*timeMode)); 99 | position = 0; 100 | } else if (position == left) { 101 | MillControl::TIME_MODE_SELECTOR.setMode(&timeModes->moveLeft(*timeMode)); 102 | position = back; 103 | } else if (position == right) { 104 | MillControl::TIME_MODE_SELECTOR.setMode(&timeModes->moveRight(*timeMode)); 105 | position = back; 106 | } else if (position == del) { 107 | if (deleteMode) { 108 | MillControl::TIME_MODE_SELECTOR.setMode(&timeModes->del(*timeMode)); 109 | position = 0; 110 | deleteMode = false; 111 | close(); 112 | return; 113 | } else { 114 | position = back; 115 | deleteMode = true; 116 | } 117 | } else if (position >= firstChar) { 118 | MillControl::open(MillControl::CHAR_EDITOR); 119 | return; 120 | } 121 | start(); 122 | redraw(); 123 | } 124 | 125 | //In Weight Mode rotator click starts the calibration mode 126 | void Editor::millClick(unsigned char i) { 127 | if (timeMode->mode == Mode::WEIGHT_MODE) 128 | MillControl::open(MillControl::WEIGHT_CALIBRATOR); 129 | #ifdef SCALE 130 | else if (timeMode->mode == Mode::SCALE_MODE) 131 | MillControl::open(MillControl::SCALE_CALIBRATOR); 132 | #endif 133 | #ifndef MILL_BUTTON 134 | else 135 | encoderClick(); 136 | #endif 137 | } 138 | 139 | 140 | void Editor::encoderChanged(int encoderPos) { 141 | position = (deleteMode ? back : 0) + encoderPos; 142 | redraw(); 143 | } 144 | 145 | 146 | void Editor::draw() { 147 | draw(false); 148 | } 149 | 150 | void Editor::drawEditor() { 151 | draw(true); 152 | } 153 | 154 | void Editor::draw(bool editor) { 155 | State::draw(); 156 | unsigned char weightMode = timeMode->mode == Mode::WEIGHT_MODE ? 1 : 0; 157 | for (char t = -weightMode; t < Mode::DATA_PER_MODE; t++) { 158 | 159 | const char pos = t + weightMode; 160 | 161 | #ifdef PORTRAIT_DISPLAY 162 | unsigned char x = 0; 163 | #ifdef MILL_BUTTON 164 | const bool small = false; 165 | unsigned char y = weightMode ? (UI::LINE_HEIGHT + UI::SMALL_LINE_HEIGHT + ((UI::DISPLAY_HEIGHT - UI::LINE_HEIGHT - (UI::SMALL_LINE_HEIGHT * 5)) * 2 / 10) + (((UI::DISPLAY_HEIGHT - UI::LINE_HEIGHT - (UI::SMALL_LINE_HEIGHT * 5)) * 2 / 10) + UI::SMALL_LINE_HEIGHT) * pos) 166 | : (UI::LINE_HEIGHT * 2 + ((UI::DISPLAY_HEIGHT - UI::SMALL_LINE_HEIGHT - (UI::LINE_HEIGHT * 5)) * 3 / 8) + (((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 5)) * 2 / 8) + UI::LINE_HEIGHT) * pos ); //52 + line*32#endif 167 | #else 168 | const bool small = false; 169 | unsigned char y = UI::LINE_HEIGHT *2 + ((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 5)) * 3 / 8) + (((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 5)) * 2 / 8) + UI::LINE_HEIGHT) * pos; //52 + line*32#endif 170 | #endif 171 | #else 172 | unsigned char x = UI::LINE_HEIGHT * 2; 173 | #ifdef MILL_BUTTON 174 | const bool small = weightMode; 175 | const unsigned char y = weightMode ? (((UI::DISPLAY_HEIGHT - (UI::SMALL_LINE_HEIGHT * 4)) / 8) + 176 | UI::SMALL_LINE_HEIGHT + 177 | (((UI::DISPLAY_HEIGHT - (UI::SMALL_LINE_HEIGHT * 4)) / 4) + 178 | UI::SMALL_LINE_HEIGHT) * pos) : 179 | (((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 3)) / 6) + UI::LINE_HEIGHT + 180 | (((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 3)) / 3) + UI::LINE_HEIGHT) * 181 | pos); //small ? (13 + pos * 16) : (16 + t * 22); 182 | #else 183 | const bool small = false; 184 | const unsigned char y = weightMode ? (((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 3)) / 6) + UI::LINE_HEIGHT + (((UI::DISPLAY_HEIGHT- (UI::LINE_HEIGHT *3)) / 3) + UI::LINE_HEIGHT ) * pos) : 185 | (((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 2)) / 4) + UI::LINE_HEIGHT + (((UI::DISPLAY_HEIGHT- (UI::LINE_HEIGHT *2)) / 2) + UI::LINE_HEIGHT ) * pos); // y = weightMode ? (15 + pos * 22) : (23 + pos * 32); 186 | #endif 187 | #endif 188 | const int data = (t == -1) ? timeMode->calibration_data : timeMode->data[t]; 189 | 190 | UI::drawTimeLine(t, data, y, x, timeMode->mode != Mode::TIME_MODE, small, position == pos, editor); 191 | } 192 | 193 | UI::u8g.setFont(UI::FONT_SMALL); 194 | 195 | drawEditPoint(0, back, UI::BACK_SYMBOL); 196 | 197 | if (gram) 198 | drawEditPoint(1, gram, weightMode ? 'g' : (timeMode->mode == Mode::SCALE_MODE ? UI::SCALE_SYMBOL : 's')); 199 | 200 | if (add) 201 | drawEditPoint(2, add, UI::ADD_STRING); 202 | 203 | if (del) 204 | drawEditPoint(3, del, UI::DEL_STRING); 205 | 206 | if (left) 207 | drawEditPoint(4, left, UI::MOVE_LEFT_STRING); 208 | 209 | if (right) 210 | drawEditPoint(5, right, UI::MOVE_RIGHT_STRING); 211 | 212 | if (position >= firstChar) { 213 | UI::u8g.setFont(UI::FONT_REGULAR); 214 | char charBuf[Mode::MAX_CHARS + 1]; 215 | 216 | const int i = position - firstChar; 217 | memcpy(charBuf, &timeMode->name, i + 1); 218 | charBuf[i + 1] = 0; 219 | 220 | unsigned char w = UI::u8g.getStrWidth(&charBuf[i]); 221 | 222 | charBuf[i] = 0; 223 | unsigned char x = UI::u8g.getStrWidth(charBuf); 224 | 225 | #ifdef PORTRAIT_DISPLAY 226 | UI::u8g.drawHLine(x, UI::LINE_HEIGHT + UI::BORDER_WIDTH, w); 227 | if (editor) 228 | UI::u8g.drawHLine(x, UI::LINE_HEIGHT + UI::BORDER_WIDTH + 2, w); 229 | #else 230 | UI::u8g.drawVLine(UI::LINE_HEIGHT + UI::BORDER_WIDTH, UI::DISPLAY_HEIGHT - x - w, w); 231 | if (editor) 232 | UI::u8g.drawVLine(UI::LINE_HEIGHT + UI::BORDER_WIDTH + 2, UI::DISPLAY_HEIGHT - x - w, w); 233 | #endif 234 | } 235 | } 236 | 237 | void Editor::drawEditPoint(const unsigned char p, const unsigned char pos, const unsigned char symbol) const { 238 | UI::drawEditPoint(p, pos == position, symbol); 239 | }; 240 | -------------------------------------------------------------------------------- /MillControl/Editor.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_EDITOR_H 2 | #define MILLCONTROL_EDITOR_H 3 | 4 | #include "State.h" 5 | #include "DataEditorData.h" 6 | 7 | class MultiModeSelector; 8 | 9 | class Editor : public State, public DataEditorData { 10 | int position = 0; 11 | 12 | unsigned char back = 0; 13 | unsigned char gram = 0; 14 | unsigned char add = 0; 15 | unsigned char del = 0; 16 | unsigned char left = 0; 17 | unsigned char right = 0; 18 | unsigned char firstChar = 0; 19 | 20 | bool deleteMode = false; 21 | 22 | Mode *timeMode; 23 | ModeList *timeModes; 24 | public: 25 | virtual bool start() override; 26 | virtual void stop() override; 27 | 28 | void encoderClick(); 29 | virtual void millClick(unsigned char i) override; 30 | virtual void encoderChanged(int encoderPos) override; 31 | 32 | virtual void draw(); 33 | 34 | char *getChar(); 35 | 36 | virtual int *getData() override; 37 | 38 | virtual void drawEditor() override; 39 | 40 | private: 41 | 42 | void drawEditPoint(const unsigned char p, const unsigned char pos, const unsigned char symbol) const; 43 | 44 | void draw(bool editor); 45 | 46 | #ifdef DEBUG 47 | virtual char* getClassName() {return (char *) "Editor"; } 48 | #endif 49 | }; 50 | 51 | 52 | #endif //MILLCONTROL_EDITOR_H -------------------------------------------------------------------------------- /MillControl/FlatModeSelector.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by roman on 24.11.15. 3 | // 4 | 5 | #include 6 | #include "FlatModeSelector.h" 7 | #include "MillControl.h" 8 | #include "TimedRun.h" 9 | #include "HoldRun.h" 10 | 11 | #ifdef SCALE 12 | #include "WeightRun.h" 13 | #include "ScaleTarePrompt.h" 14 | #endif 15 | 16 | EEMEM unsigned char eeprom_time; 17 | 18 | FlatModeSelector::FlatModeSelector() { 19 | selectedTime = eeprom_read_byte(&eeprom_time); 20 | if (selectedTime > 1) { 21 | selectedTime = 0; 22 | } 23 | } 24 | 25 | bool FlatModeSelector::start() { 26 | const int modes = findTimePos(timeModes.size - 1, Mode::DATA_PER_MODE); 27 | const int mode = findTimePos(selectedMode, selectedTime); 28 | setEncoderMode(modes, mode); 29 | 30 | return ModeSelector::start(); 31 | } 32 | 33 | int FlatModeSelector::findTimePos(const int mode, const int time) { 34 | int modes = 0; 35 | for (unsigned char m = 0; m <= mode; m++) { 36 | for (unsigned char t = 0; t < (m == mode ? time : Mode::DATA_PER_MODE); t++) { 37 | if (timeModes.timeModes[m].data[t] != 0) 38 | modes++; 39 | } 40 | } 41 | return modes; 42 | } 43 | 44 | 45 | void FlatModeSelector::encoderClick() { 46 | MillControl::open(MillControl::EDITOR); 47 | } 48 | 49 | void FlatModeSelector::millClick(unsigned char clickType) { 50 | unsigned char run_index = (clickType == MillControl::DOUBLE_CLICK) ? MillControl::DOUBLE_CLICK : selectedTime; 51 | Mode &mode = getMode(); 52 | const int data = mode.getDeciSeconds(run_index); 53 | 54 | if (data) { 55 | Run *run; 56 | 57 | if (data == Mode::SPECIAL_DATA) { 58 | if (clickType == MillControl::LONG_CLICK) 59 | run = new HoldRun(MillControl::LONG_CLICK, data); 60 | else 61 | run = new DirectRun(MillControl::LONG_CLICK, data); 62 | } else { 63 | #ifdef SCALE 64 | if (mode.mode == Mode::SCALE_MODE) 65 | run = new WeightRun(run_index, data, &mode); 66 | else 67 | #endif 68 | run = new TimedRun(run_index, data); 69 | } 70 | 71 | MillControl::open(*run); 72 | } 73 | } 74 | 75 | void FlatModeSelector::encoderChanged(int encoderPos) { 76 | int mode = 0; 77 | for (unsigned char m = 0; m < timeModes.size; m++) { 78 | for (unsigned char t = 0; t < Mode::DATA_PER_MODE; t++) { 79 | if (timeModes.timeModes[m].data[t] != 0) { 80 | if (mode == encoderPos) { 81 | //Found! 82 | selectedMode = m; 83 | selectedTime = t; 84 | redraw(); 85 | eepromWriteTime(); 86 | return; 87 | } 88 | mode++; 89 | } 90 | } 91 | } 92 | } 93 | 94 | void FlatModeSelector::draw() { 95 | State::draw(); 96 | 97 | const Mode &mode = timeModes.timeModes[selectedMode]; 98 | int time = mode.data[selectedTime]; 99 | 100 | //Symbol - same as in run 101 | char c_t[5] = ""; 102 | #ifdef PORTRAIT_DISPLAY 103 | int x = 0; 104 | int y = UI::LINE_HEIGHT + (UI::DISPLAY_HEIGHT / 3) + (UI::LARGE_LINE_HEIGHT / 2); 105 | #else 106 | int x = UI::LINE_HEIGHT * 2 + (UI::LARGE_LINE_HEIGHT / 2) + UI::BORDER_WIDTH * 2; //42 107 | int y = UI::LARGE_LINE_HEIGHT + UI::BORDER_WIDTH * 2 + UI::BORDER_WIDTH * 5; //29 108 | #endif 109 | 110 | UI::u8g.setFont(UI::FONT_LARGE_NUMERIC); 111 | UI::drawLargeSymbol(x, y, (time == Mode::SPECIAL_DATA ? 2 : selectedTime)); 112 | 113 | 114 | #ifdef PORTRAIT_DISPLAY 115 | x = UI::DISPLAY_WIDTH - UI::SMALL_LINE_HEIGHT; 116 | y = UI::LINE_HEIGHT + (2 * UI::DISPLAY_HEIGHT / 3) + (UI::LINE_HEIGHT / 2); 117 | #else 118 | x = UI::DISPLAY_WIDTH - UI::SMALL_LINE_HEIGHT; //115; 119 | y = UI::DISPLAY_HEIGHT - 6 * UI::BORDER_WIDTH; //53; 120 | #endif 121 | if (time == Mode::SPECIAL_DATA) { 122 | UI::u8g.setFont(UI::FONT_REGULAR); 123 | char *const text = UI::SPECIAL_TIME_START_NAME; 124 | UI::u8g.drawStr(UI::DISPLAY_WIDTH - UI::u8g.getStrWidth(text), y, text); 125 | } else { 126 | UI::u8g.setFont(UI::FONT_NUMERIC); 127 | 128 | UI::printData(c_t, time); 129 | UI::u8g.drawStr(x - UI::u8g.getStrWidth(c_t), y, c_t); 130 | 131 | UI::u8g.setFont(UI::FONT_SMALL); 132 | UI::u8g.drawStr(x, y, mode.isWeightMode() ? "g" : "s"); 133 | } 134 | 135 | } 136 | 137 | /* write settings to EEPROM */ 138 | void FlatModeSelector::eepromWriteTime() { 139 | eeprom_write_byte(&eeprom_time, selectedTime); 140 | eepromWrite(); 141 | } -------------------------------------------------------------------------------- /MillControl/FlatModeSelector.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_FLATMODESELECTOR_H 2 | #define MILLCONTROL_FLATMODESELECTOR_H 3 | 4 | #include "State.h" 5 | #include "ModeSelector.h" 6 | 7 | class FlatModeSelector : public ModeSelector { 8 | unsigned char selectedTime = 0; 9 | 10 | public: 11 | FlatModeSelector(); 12 | 13 | private: 14 | void eepromWriteTime(); 15 | 16 | int findTimePos(int mode, int time); 17 | 18 | public: 19 | virtual bool start() override; 20 | 21 | virtual void draw() override; 22 | 23 | virtual void encoderClick() override; 24 | 25 | virtual void millClick(unsigned char clickType) override; 26 | 27 | virtual void encoderChanged(int encoderPos) override; 28 | 29 | #ifdef DEBUG 30 | virtual char* getClassName() {return (char *) "FlatModeSelector"; } 31 | #endif 32 | }; 33 | 34 | #endif //MILLCONTROL_FLATMODESELECTOR_H -------------------------------------------------------------------------------- /MillControl/HoldRun.cpp: -------------------------------------------------------------------------------- 1 | #include "HoldRun.h" 2 | 3 | void HoldRun::loop() { 4 | #ifdef MILL_BUTTON 5 | if (!UI::millButton.isPressed()) 6 | close(); 7 | else 8 | DirectRun::loop(); 9 | #endif 10 | } -------------------------------------------------------------------------------- /MillControl/HoldRun.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_HOLDRUN_H 2 | #define MILLCONTROL_HOLDRUN_H 3 | 4 | 5 | #include "DirectRun.h" 6 | 7 | class HoldRun : public DirectRun { 8 | 9 | public: 10 | HoldRun(const unsigned char run_icon, const int run_data) : DirectRun(run_icon, run_data) { } 11 | 12 | virtual void loop() override; 13 | }; 14 | 15 | 16 | #endif //MILLCONTROL_HOLDRUN_H 17 | -------------------------------------------------------------------------------- /MillControl/MillControl.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by roman on 26.11.15. 3 | // 4 | #include "MillControl.h" 5 | 6 | #ifdef FLAT_MODE 7 | 8 | FlatModeSelector MillControl::TIME_MODE_SELECTOR; 9 | #else 10 | MultiModeSelector MillControl::TIME_MODE_SELECTOR; 11 | #endif 12 | 13 | Editor MillControl::EDITOR; 14 | DataEditor MillControl::TIME_EDITOR(&MillControl::EDITOR); 15 | CharEditor MillControl::CHAR_EDITOR; 16 | WeightCalibrationRun MillControl::WEIGHT_CALIBRATOR; 17 | CalibrationPrompt MillControl::CALIBRATION_PROMPT; 18 | DataEditor MillControl::CALIBRATION_TIME_EDITOR(&MillControl::CALIBRATION_PROMPT); 19 | 20 | #ifdef BREW_BUTTON 21 | BrewTimer MillControl::BREW_TIMER; 22 | #endif 23 | 24 | #ifdef SCALE 25 | ScaleTarePrompt MillControl::SCALE_CALIBRATOR; 26 | #endif 27 | 28 | 29 | State *MillControl::state = &TIME_MODE_SELECTOR; 30 | 31 | void MillControl::setup() { 32 | state->open(); 33 | state->redraw(); 34 | } 35 | 36 | #ifdef aDEBUG 37 | #define STACK() {\ 38 | DEBUG_PRINTLN("Stack:");\ 39 | State *s = state; \ 40 | while (s != NULL){\ 41 | DEBUG_PRINT("# "); \ 42 | DEBUG_PRINTLN(s->getClassName());\ 43 | s= s->previousState;\ 44 | }\ 45 | } 46 | #else 47 | #define STACK() 48 | #endif 49 | 50 | //start the previous state and remove from stack if possible 51 | void MillControl::close(State *closeState) { 52 | DEBUG_PRINT("close: "); 53 | DEBUG_PRINTLN(closeState->getClassName()); 54 | 55 | closeState->stop(); 56 | if (remove(closeState) != NULL) { 57 | if (state->start()) { 58 | UI::u8g.begin(); 59 | state->redraw(); 60 | } 61 | else 62 | close(state); 63 | }; 64 | STACK(); 65 | } 66 | 67 | State *MillControl::remove(State *find) { 68 | DEBUG_PRINT("remove: "); 69 | DEBUG_PRINTLN(find->getClassName()); 70 | 71 | if (find == state) { 72 | state = find->previousState; 73 | return state; 74 | } else { 75 | State *before = state; 76 | while (before != NULL && before->previousState != find) 77 | before = before->previousState; 78 | if (before != NULL) 79 | before->previousState = find->previousState; 80 | return NULL; 81 | } 82 | } 83 | 84 | void MillControl::open(State &newState) { 85 | start(newState, true); 86 | } 87 | 88 | void MillControl::openInBackground(State &newState) { 89 | DEBUG_PRINT("openInBackground: "); 90 | DEBUG_PRINTLN(newState.getClassName()); 91 | bool opened = newState.open(); 92 | if (opened) { 93 | //Insert state behind top 94 | remove(&newState); 95 | newState.previousState = state->previousState; 96 | state->previousState = &newState; 97 | STACK(); 98 | } 99 | } 100 | 101 | void MillControl::start(State &newState, bool open) { 102 | DEBUG_PRINT("start: "); 103 | DEBUG_PRINTLN(newState.getClassName()); 104 | 105 | //Stop the old state 106 | state->stop(); 107 | 108 | //Pull it from the stack 109 | remove(&newState); 110 | 111 | //put it on top of the stack 112 | newState.previousState = state; 113 | state = &newState; 114 | 115 | bool started; 116 | if (!open) { 117 | started = newState.start(); 118 | } else { 119 | started = newState.open(); 120 | } 121 | 122 | //Do I need this Idea of a state not starting? 123 | if (started) { 124 | //redraw 125 | UI::u8g.begin(); 126 | state->redraw(); 127 | } else { 128 | //restart the old state 129 | state = newState.previousState; 130 | state->start(); 131 | }; 132 | STACK(); 133 | } 134 | 135 | 136 | //Handle user input 137 | void MillControl::loop() { 138 | 139 | #ifdef BREW_BUTTON 140 | const char brewClicks = UI::brewButton.getClicks(); 141 | #endif 142 | 143 | #ifdef MILL_BUTTON 144 | const char millClicks = UI::millButton.getClicks(); 145 | #ifdef MILL_BUTTON_2 146 | const char mill2Clicks = UI::millButton2.getClicks(); 147 | #endif 148 | #else 149 | const char millClicks = UI::encoderButton.getClicks(); 150 | #endif 151 | 152 | if (millClicks != 0) { 153 | DEBUG_PRINTLN(millClicks); 154 | #ifdef MILL_BUTTON 155 | state->millClick(millClicks > 0 ? (millClicks == 1 ? CLICK : DOUBLE_CLICK) : LONG_CLICK); 156 | } 157 | #ifdef MILL_BUTTON_2 158 | else if (mill2Clicks != 0) { 159 | state->millClick(mill2Clicks > 0 ? DOUBLE_CLICK : LONG_CLICK); 160 | } 161 | #endif 162 | else if (UI::encoderButton.getClicks() != 0) { 163 | state->encoderClick(); 164 | } 165 | #else 166 | if(state == &TIME_MODE_SELECTOR){ 167 | if(millClicks <= 0) 168 | state->encoderClick(); 169 | else 170 | state->millClick(millClicks == 1 ? CLICK : DOUBLE_CLICK); 171 | } else if(state == &EDITOR){ 172 | if(millClicks < 0) 173 | state->millClick(CLICK); 174 | else 175 | state->encoderClick(); 176 | } else { 177 | state->encoderClick(); 178 | } 179 | } 180 | #endif 181 | #ifdef BREW_BUTTON 182 | // Only the long click is used 183 | else if (brewClicks != 0) { 184 | DEBUG_PRINTLN("loop::brewClick()"); 185 | state->brewClick(); 186 | } 187 | #endif 188 | else if (UI::rotator->updated()) { 189 | state->encoderChanged(UI::rotator->getPosition()); 190 | } else 191 | state->loop(); 192 | 193 | } 194 | 195 | 196 | -------------------------------------------------------------------------------- /MillControl/MillControl.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_MILLCONTROL_H 2 | #define MILLCONTROL_MILLCONTROL_H 3 | 4 | /* 5 | * App Class 6 | * Here everything is static. 7 | */ 8 | #include "State.h" 9 | #include "ModeSelector.h" 10 | #include "Editor.h" 11 | #include "DataEditor.h" 12 | #include "CharEditor.h" 13 | #include "Run.h" 14 | #include "WeightCalibrationRun.h" 15 | #include "CalibrationPrompt.h" 16 | 17 | #ifdef FLAT_MODE 18 | #include "FlatModeSelector.h" 19 | #else 20 | #include "MultiModeSelector.h" 21 | #endif 22 | 23 | #ifdef BREW_BUTTON 24 | #include "BrewTimer.h" 25 | #endif 26 | 27 | #ifdef SCALE 28 | #include "ScaleTarePrompt.h" 29 | #endif 30 | 31 | class MillControl{ 32 | static State* state; 33 | 34 | public: 35 | static const unsigned char CLICK = 0; 36 | static const unsigned char DOUBLE_CLICK = 1; 37 | static const unsigned char LONG_CLICK = 2; 38 | 39 | #ifdef FLAT_MODE 40 | static FlatModeSelector TIME_MODE_SELECTOR; 41 | #else 42 | static MultiModeSelector TIME_MODE_SELECTOR; 43 | #endif 44 | static Editor EDITOR; 45 | static DataEditor TIME_EDITOR; 46 | static CharEditor CHAR_EDITOR; 47 | static WeightCalibrationRun WEIGHT_CALIBRATOR; 48 | static CalibrationPrompt CALIBRATION_PROMPT; 49 | static DataEditor CALIBRATION_TIME_EDITOR; 50 | 51 | #ifdef SCALE 52 | static ScaleTarePrompt SCALE_CALIBRATOR; 53 | #endif 54 | 55 | #ifdef BREW_BUTTON 56 | static BrewTimer BREW_TIMER; 57 | #endif 58 | 59 | static void setup(); 60 | static void loop(); 61 | 62 | static void open(State &newState); 63 | static void start(State &newState, bool open = false); 64 | 65 | static void close(State *closeState); 66 | 67 | static State *remove(State *state); 68 | 69 | static void openInBackground(State &newState); 70 | }; 71 | 72 | #endif //MILLCONTROL_MILLCONTROL_H -------------------------------------------------------------------------------- /MillControl/MillControl.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * Mill Control 3 | * Timer Control for Coffee Mills 4 | * 5 | * Runs on Arduino Pro Mini & similar systems (needs 20k of storage space). 6 | * 7 | * Needs an encoder with a switch and an optional second switch. 8 | * If you only have one switch comment out the define in UI.h 9 | * 10 | * Output is to a 128*64 graphics display, comment out the orientation 11 | * define in UI.h 12 | * 13 | * Dependencies: 14 | * - Encoder (v1.4) - http://www.pjrc.com/teensy/td_libs_Encoder.html 15 | * - TimerOne (v1.1) - https://github.com/PaulStoffregen/TimerOne 16 | * - U8Glib - https://github.com/olikraus/u8glib 17 | * 18 | * (c) 2015 by Roman Seidl 19 | * The bean and hand symbols (c) by @mamu - www.kaffee-netz.de 20 | * 21 | * This program is free software; you can redistribute it and/or modify 22 | * it under the terms of the GNU General Public License as published by 23 | * the Free Software Foundation; either version 3 of the License, or 24 | * (at your option) any later version. 25 | * 26 | * This program is distributed in the hope that it will be useful, 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | * GNU General Public License for more details. 30 | * 31 | * You should have received a copy of the GNU General Public License 32 | * along with this program; if not, write to the Free Software Foundation, 33 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 34 | */ 35 | 36 | #include "MillControl.h" 37 | #include 38 | 39 | #include "helvB14r.h" 40 | #include "helvB10s.h" 41 | #include "helvR14n.h" 42 | #include "fub20bn.h" 43 | 44 | //================================================= 45 | // ENCODER - has two pins 46 | // only change pins if necessary, som pins have hardware interrupts and are thus faster 47 | // on most platforms do NOT use pin 13 (led pin) 48 | 49 | // Pins with HW-interrupts for different boards (s. http://www.pjrc.com/teensy/td_libs_Encoder.html) 50 | // Teensy 3.0 All Digital Pins 51 | // Teensy 2.0 5, 6, 7, 8 11 52 | // Teensy 1.0 0, 1, 2, 3, 4, 6, 7, 16 53 | // Teensy++ 2.0 0, 1, 2, 3, 18, 19, 36, 37 6 54 | // Teensy++ 1.0 0, 1, 2, 3, 18, 19, 36, 37 55 | // Arduino Due All Digital Pins 56 | // Arduino Uno 2, 3 57 | // Arduino Leonardo 0, 1, 2, 3 58 | // Arduino Mega 2, 3, 18, 19, 20, 21 59 | // Sanguino 2, 10, 11 60 | 61 | //Default for Ardiuno Pro Micro and Uno 62 | Rotator *UI::rotator = new RotatingEncoder(2, 3); 63 | 64 | //Default for Ardiuno Pro Micro and Uno when using spi (they are on pin 2 & 3) 65 | //Rotator* UI::rotator = new RotatingEncoder(0, 1); 66 | 67 | //Button Encoder - up and down button 68 | //Rotator *UI::rotator = new RotatingButtons(2, 3); 69 | 70 | 71 | #define ENCODER_BUTTON 4 72 | 73 | //================================================= 74 | // BUTTONS 75 | 76 | //Buttons are in UI.h 77 | 78 | //================================================= 79 | // SCALE 80 | // to activate the scale uncomment the SCALE define in UI.h 81 | // Setup is scale(data_pin, clock_pin, power_pin) 82 | 83 | #ifdef SCALE 84 | Scale UI::scale(A1, A2, A3); 85 | #endif 86 | 87 | //================================================= 88 | // Pause time 89 | // when stopping a timedrun by pressing the button the mill will wait for 90 | // the given amount of seconds to allow for a restart 91 | const unsigned char UI::PAUSE_TIME = 5; 92 | 93 | //================================================= 94 | // Brew timer Timeout 95 | // when in the main selector (time mode selector) and the brew timer is active 96 | // after the given amount of milliseconds until the brew timer is shown again if it was interrupted 97 | #ifdef BREW_TIMER 98 | const long UI::BREW_TIMER_TIMEOUT = 3000; 99 | #endif 100 | 101 | //================================================= 102 | // Display 103 | 104 | // Orientation of the display can be changed in UI.h 105 | 106 | // SPI - Bus (only applies if you use a SPI Display 107 | // These are sensible defaults for Arduino Mini pro. If you use different Hardware and use Hardware SPI you might need to adapt them 108 | // Somehow HArdware SPI with MISO on pin 12 was not working even though this is the default according to the arduino.cc. 109 | // SPI is hell because there is only a very weak norm on how the connectors are called. Producers seem keep inventing new names... 110 | #define OLED_RESET 8 // also called: RES, RST 111 | #define OLED_CS 10 // also called: SS, ST, CE 112 | #define OLED_MOSI 11 // also called: SDA, SID, Din 113 | #define OLED_MISO 9 // also called: a0, D/C, DC, RS 114 | #define OLED_SCK 13 // also called: CLK, SCL, SCLK 115 | 116 | // Pro Micro settings: 117 | /*#define OLED_RESET 8 // also called: RES, RST 118 | #define OLED_CS 10 // also called: SS, ST, CE 119 | #define OLED_MOSI 16 // also called: SDA, SID, Din 120 | #define OLED_MISO 9 // also called: a0, D/C, DC, RS 121 | #define OLED_SCK 15 // also called: CLK, SCL, SCLK 122 | */ 123 | //================================================= 124 | // SSD 1306 Display 125 | 126 | // Uncomment this if you are using the SSD1306 127 | #define DISPLAY_128x64 128 | 129 | // You can either connect a SPI or a I2C display. SPI is much faster but may be a bit annoying to find th right pinout 130 | 131 | // i2c 132 | //U8GLIB UI::u8g = *new U8GLIB_SSD1306_128X64_2X(U8G_I2C_OPT_NO_ACK); 133 | 134 | // Software SPI 135 | //U8GLIB UI::u8g = *new U8GLIB_SSD1306_128X64_2X(OLED_SCK, OLED_MOSI, OLED_CS, OLED_MISO, OLED_RESET); 136 | 137 | // Hardware SPI (recommended, if not working try software spi) 138 | U8GLIB UI::u8g = *new U8GLIB_SSD1306_128X64_2X(OLED_CS, OLED_MISO, OLED_RESET); 139 | 140 | //================================================= 141 | // PCD 8544 Display 142 | // PCD IS NOT WORKING AT THE MOMENT! 143 | 144 | // Uncomment this if you are using the PCD 8544 145 | //U8GLIB UI::u8g = U8GLIB_PCD8544(OLED_SCK, OLED_MOSI, OLED_CS, OLED_MISO, OLED_RESET); 146 | 147 | #ifdef DISPLAY_128x64 148 | #ifdef PORTRAIT_DISPLAY 149 | const unsigned char UI::DISPLAY_WIDTH = 64; 150 | const unsigned char UI::DISPLAY_HEIGHT = 128; 151 | #else 152 | const unsigned char UI::DISPLAY_WIDTH = 128; 153 | const unsigned char UI::DISPLAY_HEIGHT = 64; 154 | #endif 155 | const u8g_fntpgm_uint8_t *UI::FONT_SMALL{helvB10s}; 156 | const u8g_fntpgm_uint8_t *UI::FONT_NUMERIC{helvR14n}; 157 | const u8g_fntpgm_uint8_t *UI::FONT_REGULAR{helvB14r}; 158 | //const u8g_fntpgm_uint8_t* UI::FONT_REGULAR{helvB10s}; 159 | const u8g_fntpgm_uint8_t *UI::FONT_LARGE_NUMERIC{fub20bn}; 160 | //const u8g_fntpgm_uint8_t* UI::FONT_LARGE_NUMERIC{helvR14n}; 161 | const unsigned char UI::BORDER_WIDTH = 2; 162 | 163 | const unsigned char UI::LINE_HEIGHT = 14; 164 | const unsigned char UI::SMALL_LINE_HEIGHT = 10; 165 | const unsigned char UI::LARGE_LINE_HEIGHT = 20; 166 | #else 167 | #ifdef PORTRAIT_DISPLAY 168 | const unsigned char UI::DISPLAY_WIDTH = 48; 169 | const unsigned char UI::DISPLAY_HEIGHT = 84; 170 | #else 171 | const unsigned char UI::DISPLAY_WIDTH = 84; 172 | const unsigned char UI::DISPLAY_HEIGHT = 48; 173 | #endif 174 | const u8g_fntpgm_uint8_t* UI::FONT_SMALL{u8g_font_6x12r}; 175 | const u8g_fntpgm_uint8_t* UI::FONT_NUMERIC{u8g_font_helvR08n}; 176 | const u8g_fntpgm_uint8_t* UI::FONT_REGULAR{u8g_font_helvB08r}; 177 | const u8g_fntpgm_uint8_t* UI::FONT_LARGE_NUMERIC{u8g_font_helvB14n}; 178 | const unsigned char UI::LINE_HEIGHT = 8; 179 | const unsigned char UI::SMALL_LINE_HEIGHT = 6; 180 | const unsigned char UI::LARGE_LINE_HEIGHT = 14; 181 | const unsigned char UI::BORDER_WIDTH = 1; 182 | #endif 183 | 184 | //This will change the button settings - do not change 185 | Button UI::encoderButton(ENCODER_BUTTON, Button::SINGLE_CLICK); 186 | #ifdef MILL_BUTTON 187 | Button UI::millButton(MILL_BUTTON, Button::MULTI_CLICK); 188 | #ifdef MILL_BUTTON_2 189 | Button UI::millButton2(MILL_BUTTON_2, Button::MULTI_CLICK); 190 | #endif 191 | #endif 192 | 193 | #ifdef BREW_BUTTON 194 | Button UI::brewButton(BREW_BUTTON, Button::SINGLE_CLICK); 195 | #endif 196 | 197 | void setup() { 198 | #ifdef PORTRAIT_DISPLAY 199 | //Rotate the screen 200 | UI::u8g.setRot90(); 201 | #endif 202 | 203 | #ifdef DEBUG 204 | Serial.begin(9600); 205 | #endif 206 | MultiTimer1::start(); 207 | MillControl::setup(); 208 | DEBUG_PRINTLN("Setup completed"); 209 | } 210 | 211 | void loop() { 212 | //DEBUG_PRINT("."); 213 | MillControl::loop(); 214 | } 215 | 216 | -------------------------------------------------------------------------------- /MillControl/Mode.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "Mode.h" 4 | 5 | int Mode::secondsForGrams(int grams) const { 6 | return min(MAX_DATA, (((long) grams * (long) calibration_data) / 100l)); 7 | } 8 | 9 | int Mode::gramsForSeconds(int seconds) const { 10 | //deciseconds to decigrams 11 | //Reconsider rounding problems! 12 | return min(MAX_DATA, ((long) seconds * 100l) / (long) calibration_data); 13 | } 14 | 15 | //converts to another mode 16 | void Mode::setMode(char newMode) { 17 | if (mode != newMode) { 18 | int (Mode::*converter)(int) const = NULL; 19 | 20 | if (calibration_data < 0) 21 | calibration_data = 70; 22 | 23 | //Conversion needed? 24 | if (newMode == TIME_MODE) { 25 | converter = &Mode::secondsForGrams; 26 | } else if (mode == TIME_MODE) { 27 | converter = &Mode::gramsForSeconds; 28 | } 29 | 30 | if (converter != NULL) { 31 | for (unsigned char c = 0; c < DATA_PER_MODE; c++) { 32 | //special data is not converted 33 | if (data[c] != SPECIAL_DATA) { 34 | data[c] = (*this.*converter)(data[c]); 35 | } 36 | } 37 | } 38 | 39 | if (newMode == SCALE_MODE) 40 | calibration_data = 0; 41 | mode = newMode; 42 | } 43 | } 44 | 45 | //Returns the seonds for the data 46 | int Mode::getDeciSeconds(unsigned char time) { 47 | if (mode == WEIGHT_MODE) { 48 | //data is decigrams -> deciseconds 49 | return secondsForGrams(data[time]); 50 | } 51 | else 52 | //data is in seconds -> deciseconds 53 | return data[time]; 54 | } 55 | 56 | //---------------------------------------------------------------------------------- 57 | //Time Mode List 58 | 59 | EEMEM unsigned char eeprom_eeprom_version; 60 | 61 | //The number of modes 62 | EEMEM unsigned char eeprom_time_modes; 63 | 64 | //names 65 | EEMEM char eeprom_time_mode_names[ModeList::MAX_MODES][Mode::MAX_CHARS + 1]; 66 | 67 | EEMEM int eeprom_time_mode_times[ModeList::MAX_MODES][Mode::DATA_PER_MODE]; 68 | EEMEM unsigned char eeprom_time_mode_weight_modes[ModeList::MAX_MODES]; 69 | EEMEM int eeprom_time_mode_centi_seconds_per_grams[ModeList::MAX_MODES]; 70 | 71 | constexpr char *ModeList::INIT_NAMES[4]; 72 | constexpr char ModeList::INIT_WEIGHT_MODES[4]; 73 | constexpr int ModeList::INIT_TIMES[4][3]; 74 | 75 | ModeList::ModeList() { 76 | eepromRead(); 77 | } 78 | 79 | //clones a time mode and inserts it after the one 80 | Mode &ModeList::insertAfer(Mode &mode) { 81 | //find the position 82 | const unsigned char newPos = pos(mode) + 1U; 83 | //add a new mode there 84 | Mode &newMode = add(newPos); 85 | 86 | //Clone data 87 | newMode.mode = mode.mode; 88 | newMode.calibration_data = mode.calibration_data; 89 | for (unsigned char c = 0; c < Mode::DATA_PER_MODE; c++) 90 | newMode.data[c] = mode.data[c]; 91 | strcpy(newMode.name, mode.name); 92 | 93 | //Add marker 94 | unsigned char pos = Mode::MAX_CHARS - 1; 95 | while (newMode.name[pos] == ' ' && pos > 0) 96 | pos--; 97 | newMode.name[pos + 1] = '*'; 98 | 99 | return newMode; 100 | } 101 | 102 | Mode &ModeList::add(unsigned char pos) { 103 | //move time modes to the right 104 | for (unsigned char p = pos; p < size; p++) { 105 | timeModes[p + 1] = timeModes[p]; 106 | } 107 | 108 | //construct new mode 109 | timeModes[pos] = *new Mode(); 110 | DEBUG_PRINTLN("pos") 111 | DEBUG_PRINTLN(pos) 112 | DEBUG_PRINTLN(size) 113 | //Is there a template? 114 | if (size < INIT_TEMPLATES) { 115 | DEBUG_PRINTLN("t") 116 | //Initialize the name 117 | strcpy(timeModes[pos].name, INIT_NAMES[size]); 118 | 119 | for (unsigned char c = strlen(timeModes[pos].name); c < Mode::MAX_CHARS; c++) 120 | timeModes[pos].name[c] = '@'; 121 | timeModes[pos].name[Mode::MAX_CHARS] = 0; 122 | 123 | //initialize the data 124 | for (unsigned char c = 0; c < Mode::DATA_PER_MODE; c++) 125 | timeModes[pos].data[c] = INIT_TIMES[size][c]; 126 | 127 | timeModes[pos].mode = INIT_WEIGHT_MODES[size]; 128 | timeModes[pos].calibration_data = timeModes[pos].mode == Mode::SCALE_MODE ? 0 : 70; 129 | } 130 | 131 | size++; 132 | return timeModes[pos]; 133 | } 134 | 135 | //--------------------------------------------- 136 | // Moving 137 | 138 | void ModeList::swap(unsigned char from, unsigned char to) { 139 | Mode save = timeModes[from]; 140 | timeModes[from] = timeModes[to]; 141 | timeModes[to] = save; 142 | } 143 | 144 | Mode &ModeList::moveLeft(Mode &mode) { 145 | const unsigned char p = pos(mode); 146 | const unsigned char p_ex = p > 0 ? p - 1 : size - 1; 147 | swap(p, p_ex); 148 | return timeModes[p_ex]; 149 | } 150 | 151 | Mode &ModeList::moveRight(Mode &mode) { 152 | const unsigned char p = pos(mode); 153 | const unsigned char p_ex = p < size - 1 ? p + 1 : 0; 154 | swap(p, p_ex); 155 | return timeModes[p_ex]; 156 | } 157 | 158 | //------------------------------------------- 159 | // Deleting 160 | 161 | Mode &ModeList::del(Mode &tm_del) { 162 | //if this is the last mode do a reset 163 | if (size > 1) { 164 | unsigned char del = pos(tm_del); 165 | //Move to the right 166 | for (unsigned char m = del; m < size; m++) { 167 | timeModes[m] = timeModes[m + 1]; 168 | } 169 | size--; 170 | return timeModes[(del == size ? (del - 1) : del)]; 171 | } else { 172 | reset(); 173 | return timeModes[0]; 174 | } 175 | } 176 | 177 | //Find mode 178 | unsigned char ModeList::pos(Mode &tm) { 179 | unsigned char p = 0; 180 | while (p < size && &timeModes[p] != &tm) 181 | p++; 182 | return p; 183 | } 184 | 185 | void ModeList::reset() { 186 | size = 0; 187 | for (unsigned char c = 0; c < INIT_TEMPLATES; c++) { 188 | add(size); 189 | } 190 | eepromWrite(); 191 | } 192 | 193 | void ModeList::eepromRead() { 194 | #ifdef RESET_MODE 195 | if (false) { 196 | #else 197 | if (EEPROM_VERSION == eeprom_read_byte(&eeprom_eeprom_version)) { 198 | #endif 199 | eeprom_read_block(&size, &eeprom_time_modes, sizeof(unsigned char)); 200 | for (unsigned char c = 0; c < size; c++) { 201 | timeModes[c].mode = eeprom_read_byte(&eeprom_time_mode_weight_modes[c]); 202 | eeprom_read_block(&timeModes[c].calibration_data, &eeprom_time_mode_centi_seconds_per_grams[c], 203 | sizeof(int)); 204 | eeprom_read_block(timeModes[c].name, eeprom_time_mode_names[c], Mode::MAX_CHARS + 1); 205 | eeprom_read_block(timeModes[c].data, eeprom_time_mode_times[c], Mode::DATA_PER_MODE * sizeof(int)); 206 | } 207 | } else { 208 | reset(); 209 | eeprom_write_byte(&eeprom_eeprom_version, EEPROM_VERSION); 210 | } 211 | //I had strange race conditions here - adding a delay seemed to save the machine 212 | _delay_ms(10); 213 | } 214 | 215 | /* write settings to EEPROM */ 216 | void ModeList::eepromWrite() { 217 | eeprom_update_block(&size, &eeprom_time_modes, sizeof(unsigned char)); 218 | 219 | for (unsigned char c = 0; c < size; c++) { 220 | eeprom_write_byte(&eeprom_time_mode_weight_modes[c], timeModes[c].mode); 221 | eeprom_update_block(&timeModes[c].calibration_data, &eeprom_time_mode_centi_seconds_per_grams[c], 222 | sizeof(int)); 223 | eeprom_update_block(timeModes[c].name, &eeprom_time_mode_names[c], Mode::MAX_CHARS + 1); 224 | eeprom_update_block(timeModes[c].data, eeprom_time_mode_times[c], Mode::DATA_PER_MODE * sizeof(int)); 225 | } 226 | } 227 | 228 | 229 | bool Mode::isWeightMode() const { 230 | return !mode == TIME_MODE; 231 | } 232 | -------------------------------------------------------------------------------- /MillControl/Mode.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_MODE_H 2 | #define MILLCONTROL_MODE_H 3 | 4 | #include "UI.h" 5 | 6 | class Mode { 7 | int secondsForGrams(int grams) const; 8 | 9 | int gramsForSeconds(int seconds) const; 10 | 11 | public: 12 | static const int SPECIAL_DATA = 10000; 13 | static const int MAX_DATA = 9990; 14 | static const unsigned char MAX_CHARS = 10; 15 | 16 | static const char TIME_MODE = 0; 17 | static const char WEIGHT_MODE = 1; 18 | static const char SCALE_MODE = 2; 19 | 20 | #ifdef MILL_BUTTON 21 | #ifdef FLAT_MODE 22 | static const unsigned char DATA_PER_MODE = 2; 23 | #else 24 | static const unsigned char PROGMEM DATA_PER_MODE = 3; 25 | #endif 26 | #else 27 | static const unsigned char DATA_PER_MODE = 2; 28 | #endif 29 | 30 | char name[MAX_CHARS + 1]; 31 | int data[DATA_PER_MODE]; 32 | 33 | char mode = TIME_MODE; 34 | int calibration_data; 35 | 36 | int getDeciSeconds(unsigned char time); 37 | 38 | void setMode(char newMode); 39 | 40 | bool isWeightMode() const; 41 | 42 | }; 43 | 44 | //-------------------------------------------------------------------------------------------- 45 | // ModeList 46 | 47 | class ModeList { 48 | static const unsigned char EEPROM_VERSION = 5; 49 | 50 | #ifdef SCALE 51 | static const unsigned char INIT_TEMPLATES = 4; 52 | #else 53 | static const unsigned char INIT_TEMPLATES = 3; 54 | #endif 55 | 56 | static constexpr char *INIT_NAMES[4] = {(char *const) "Direct", 57 | (char *const) "Time", 58 | (char *const) "Weight", 59 | (char *const) "Scale"}; 60 | static constexpr char INIT_WEIGHT_MODES[4] = {Mode::TIME_MODE, Mode::TIME_MODE, Mode::WEIGHT_MODE, 61 | Mode::SCALE_MODE}; 62 | static constexpr int INIT_TIMES[4][3] = {{Mode::SPECIAL_DATA, 0, Mode::SPECIAL_DATA}, 63 | {50, 100, 150}, 64 | {70, 140, 160}, 65 | {70, 140, 160}}; 66 | 67 | public: 68 | static const unsigned char PROGMEM MAX_MODES = 20; 69 | unsigned char size = 0; 70 | private: 71 | 72 | void swap(unsigned char from, unsigned char to); 73 | 74 | Mode &add(unsigned char pos); 75 | public: 76 | ModeList(); 77 | 78 | void reset(); 79 | 80 | Mode timeModes[MAX_MODES]; 81 | 82 | Mode &insertAfer(Mode &); 83 | 84 | unsigned char pos(Mode &); 85 | 86 | Mode &moveLeft(Mode &); 87 | 88 | Mode &moveRight(Mode &); 89 | 90 | Mode &del(Mode &); 91 | 92 | void eepromRead(); 93 | 94 | void eepromWrite(); 95 | 96 | }; 97 | 98 | #endif //MILLCONTROL_MODE_H 99 | -------------------------------------------------------------------------------- /MillControl/ModeSelector.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by roman on 06.01.16. 3 | // 4 | 5 | #include 6 | #include "MultiModeSelector.h" 7 | #include "MillControl.h" 8 | 9 | EEMEM unsigned char eeprom_time_mode; 10 | 11 | Mode &ModeSelector::getMode() { 12 | return timeModes.timeModes[selectedMode]; 13 | } 14 | 15 | ModeSelector::ModeSelector() { 16 | selectedMode = eeprom_read_byte(&eeprom_time_mode); 17 | if (selectedMode > (timeModes.size - 1)) { 18 | selectedMode = 0; 19 | } 20 | } 21 | 22 | bool ModeSelector::start() { 23 | //If there is only one button ensure it is multi-click 24 | #ifndef MILL_BUTTON 25 | UI::encoderButton.setMultiClick(true); 26 | #endif 27 | updateTime = millis(); 28 | return true; 29 | } 30 | 31 | void ModeSelector::setMode(Mode *mode) { 32 | selectedMode = timeModes.pos(*mode); 33 | eepromWrite(); 34 | updateTime = millis(); 35 | redraw(); 36 | } 37 | 38 | #ifdef BREW_BUTTON 39 | 40 | void ModeSelector::loop() { 41 | //re-show the bre timer after a timeout if its running 42 | if (millis() - updateTime > UI::BREW_TIMER_TIMEOUT && MillControl::BREW_TIMER.isRunning()) { 43 | MillControl::start(MillControl::BREW_TIMER); 44 | } 45 | } 46 | 47 | #endif 48 | 49 | /* write settings to EEPROM */ 50 | void ModeSelector::eepromWrite() { 51 | eeprom_write_byte(&eeprom_time_mode, (uint8_t) selectedMode); 52 | } 53 | -------------------------------------------------------------------------------- /MillControl/ModeSelector.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_MODESELECTOR_H 2 | #define MILLCONTROL_MODESELECTOR_H 3 | 4 | #include "State.h" 5 | #include "Mode.h" 6 | 7 | class ModeSelector : public State { 8 | unsigned long updateTime; 9 | public: 10 | ModeList timeModes; 11 | 12 | void setMode(Mode *mode); 13 | 14 | Mode &getMode(); 15 | 16 | ModeSelector(); 17 | 18 | protected: 19 | 20 | void eepromWrite(); 21 | 22 | int selectedMode; 23 | 24 | virtual bool start() override; 25 | 26 | 27 | public: 28 | 29 | #ifdef BREW_BUTTON 30 | virtual void loop() override; 31 | #endif 32 | 33 | #ifdef DEBUG 34 | virtual char* getClassName() {return (char *) "ModeSelector"; } 35 | #endif 36 | }; 37 | 38 | #endif //MILLCONTROL_MODESELECTOR_H -------------------------------------------------------------------------------- /MillControl/MultiModeSelector.cpp: -------------------------------------------------------------------------------- 1 | #include "MultiModeSelector.h" 2 | #include "MillControl.h" 3 | #include "TimedRun.h" 4 | #include "DirectRun.h" 5 | #include "HoldRun.h" 6 | 7 | #ifdef SCALE 8 | #include "WeightRun.h" 9 | #endif 10 | 11 | bool MultiModeSelector::start() { 12 | setEncoderMode(timeModes.size, selectedMode); 13 | return ModeSelector::start(); 14 | } 15 | 16 | void MultiModeSelector::encoderClick() { 17 | MillControl::open(MillControl::EDITOR); 18 | } 19 | 20 | void MultiModeSelector::millClick(unsigned char clickType) { 21 | Mode &mode = getMode(); 22 | const int data = mode.getDeciSeconds(clickType); 23 | if (data) { 24 | Run *run; 25 | 26 | if (data == Mode::SPECIAL_DATA) { 27 | if (clickType == MillControl::LONG_CLICK) 28 | run = new HoldRun(clickType, data); 29 | else 30 | run = new DirectRun(clickType, data); 31 | } else { 32 | #ifdef SCALE 33 | if (mode.mode == Mode::SCALE_MODE) 34 | run = new WeightRun(clickType, data, &mode); 35 | else 36 | #endif 37 | run = new TimedRun(clickType, data); 38 | } 39 | 40 | MillControl::open(*run); 41 | } 42 | } 43 | 44 | void MultiModeSelector::encoderChanged(int encoderPos) { 45 | if (encoderPos != selectedMode) { 46 | selectedMode = encoderPos; 47 | eepromWrite(); 48 | redraw(); 49 | } 50 | } 51 | 52 | void MultiModeSelector::draw() { 53 | State::draw(); 54 | UI::u8g.setFont(UI::FONT_SMALL); 55 | 56 | #ifndef PORTRAIT_DISPLAY 57 | unsigned char lines = 0; 58 | for (unsigned char t = 0; t < Mode::DATA_PER_MODE; t++) { 59 | if (timeModes.timeModes[selectedMode].data[t] > 0) 60 | lines++; 61 | } 62 | #endif 63 | 64 | unsigned char line = 0; 65 | for (unsigned char t = 0; t < Mode::DATA_PER_MODE; t++) { 66 | const Mode &mode = timeModes.timeModes[selectedMode]; 67 | int time = mode.data[t]; 68 | if (time > 0) { 69 | #ifdef PORTRAIT_DISPLAY 70 | unsigned char x = 0; 71 | unsigned char y = UI::LINE_HEIGHT * 2 + ((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 4)) * 3 / 8) + 72 | (((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 4)) * 2 / 8) + UI::LINE_HEIGHT) * 73 | line; //52 + line*32 74 | #else 75 | unsigned char x = (UI::DISPLAY_WIDTH - UI::DISPLAY_HEIGHT - UI::LINE_HEIGHT) / 2 + UI::LINE_HEIGHT; 76 | unsigned char y = lines > 2 ? ((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 3)) / 6) + UI::LINE_HEIGHT + 77 | (((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 3)) / 3) + UI::LINE_HEIGHT) * line 78 | : 79 | ((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 2)) / 4) + UI::LINE_HEIGHT + 80 | (((UI::DISPLAY_HEIGHT - (UI::LINE_HEIGHT * 2)) / 2) + UI::LINE_HEIGHT) * 81 | line; //lines > 2 ? 16 + line * 22 : 23 + line * 32; //16 + line * 22 : 23 + line * 32 - 82 | #endif 83 | UI::drawTimeLine(t, time, y, x, mode.mode, false, false, false); 84 | line++; 85 | } 86 | } 87 | } 88 | 89 | 90 | -------------------------------------------------------------------------------- /MillControl/MultiModeSelector.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_MULTIMODESELECTOR_H 2 | #define MILLCONTROL_MULTIMODESELECTOR_H 3 | 4 | #include "ModeSelector.h" 5 | 6 | class MultiModeSelector : public ModeSelector { 7 | 8 | public: 9 | virtual bool start() override; 10 | 11 | virtual void draw() override; 12 | 13 | virtual void encoderClick() override; 14 | 15 | virtual void millClick(unsigned char clickType) override; 16 | 17 | virtual void encoderChanged(int encoderPos) override; 18 | 19 | #ifdef DEBUG 20 | virtual char* getClassName() {return (char *) "MultiModeSelector"; } 21 | #endif 22 | }; 23 | 24 | #endif //MILLCONTROL_MULTIMODESELECTOR_H -------------------------------------------------------------------------------- /MillControl/MultiTimer1.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by roman on 15.01.16. 3 | // 4 | 5 | #include 6 | #include "MultiTimer1.h" 7 | #include "UI.h" 8 | 9 | unsigned char MultiTimer1::n_timers = 0; 10 | Timed *MultiTimer1::timers[MAX_TIMERS]; 11 | 12 | //Trigger all events 13 | void MultiTimer1::update() { 14 | //DEBUG_PRINTLN(n_timers) 15 | for (unsigned char b = 0; b < n_timers; b++) 16 | MultiTimer1::timers[b]->run(); 17 | } 18 | 19 | void MultiTimer1::add(Timed *timed) { 20 | DEBUG_PRINTLN("MultiTimer1::add()") 21 | DEBUG_PRINTLN(n_timers); 22 | // Register Button 23 | MultiTimer1::timers[n_timers] = timed; 24 | n_timers++; 25 | } 26 | 27 | 28 | void MultiTimer1::start() { 29 | //Microseconds 30 | Timer1.initialize(INTERVAL); 31 | Timer1.attachInterrupt(MultiTimer1::update); 32 | } 33 | -------------------------------------------------------------------------------- /MillControl/MultiTimer1.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_MULTITIMER1_H 2 | #define MILLCONTROL_MULTITIMER1_H 3 | 4 | #include "Timed.h" 5 | 6 | class MultiTimer1 { 7 | static const unsigned char MAX_TIMERS = 10; 8 | static const long INTERVAL = 10l * 1000l; 9 | public: 10 | static Timed *timers[]; 11 | 12 | static unsigned char n_timers; 13 | static unsigned char interval; 14 | 15 | static void update(); 16 | 17 | static void add(Timed *timed); 18 | 19 | static void start(); 20 | }; 21 | 22 | #endif //MILLCONTROL_MULTITIMER1_H -------------------------------------------------------------------------------- /MillControl/Prompt.cpp: -------------------------------------------------------------------------------- 1 | #include "Prompt.h" 2 | 3 | void Prompt::encoderClick() { 4 | switch (position) { 5 | case 0: 6 | ok(); 7 | break; 8 | case 1: 9 | cancel(); 10 | break; 11 | } 12 | } 13 | 14 | void Prompt::encoderChanged(int encoderPos) { 15 | position = encoderPos; 16 | redraw(); 17 | } 18 | 19 | void Prompt::draw() { 20 | State::draw(); 21 | 22 | UI::u8g.setFont(UI::FONT_SMALL); 23 | UI::drawEditPoint(prompt_position, position == 0, UI::OK_SYMBOL); 24 | UI::drawEditPoint(prompt_position + 1, position == 1, 'x'); 25 | } 26 | 27 | void Prompt::cancel() { 28 | close(); 29 | } 30 | 31 | void Prompt::ok() { 32 | close(); 33 | } 34 | 35 | Prompt::Prompt(const int start_position, const int positions) : start_position(start_position), positions(positions) { 36 | 37 | } 38 | 39 | Prompt::Prompt() : start_position(0), positions(2) { 40 | } 41 | 42 | bool Prompt::start() { 43 | setEncoderMode(positions, start_position); 44 | return true; 45 | } 46 | 47 | #ifdef BREW_BUTTON 48 | #endif -------------------------------------------------------------------------------- /MillControl/Prompt.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_PROMPT_H 2 | #define MILLCONTROL_PROMPT_H 3 | 4 | #include "BrewlessState.h" 5 | 6 | class Prompt : public BrewlessState { 7 | const int start_position; 8 | const int positions; 9 | public: 10 | Prompt(); 11 | 12 | Prompt(const int start_position, const int positions); 13 | 14 | virtual void encoderClick() override; 15 | 16 | virtual void encoderChanged(int encoderPos) override; 17 | 18 | virtual bool start() override; 19 | 20 | virtual void ok(); 21 | 22 | virtual void cancel(); 23 | 24 | protected: 25 | int position = 0; 26 | unsigned char prompt_position = 0; 27 | 28 | virtual void draw() override; 29 | }; 30 | 31 | #endif //MILLCONTROL_PROMPT_H -------------------------------------------------------------------------------- /MillControl/RotatingButtons.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Created by roman on 15.01.16. 3 | // 4 | 5 | #include "RotatingButtons.h" 6 | 7 | RotatingButtons::RotatingButtons(unsigned char pin1, unsigned char pin2) { 8 | MultiTimer1::add(this); 9 | button1 = new Button(pin1); 10 | button2 = new Button(pin2); 11 | } 12 | 13 | int RotatingButtons::getPosition() { 14 | return pos; 15 | } 16 | 17 | bool RotatingButtons::updated() { 18 | if (pos_updated) { 19 | pos_updated = false; 20 | return true; 21 | } else 22 | return false; 23 | } 24 | 25 | void RotatingButtons::setPosititon(int p) { 26 | pos = p; 27 | } 28 | 29 | void RotatingButtons::setMode(int _ticks, int _pos) { 30 | pos = _pos; 31 | ticks = _ticks; 32 | } 33 | 34 | void RotatingButtons::run() { 35 | if (button1->getClicks()) { 36 | pos = pos > 0 ? pos - 1 : pos = ticks - 1; 37 | pos_updated = true; 38 | // DEBUG_PRINTLN("<") 39 | } 40 | else if (button2->getClicks()) { 41 | pos = pos < ticks - 1 ? pos + 1 : 0; 42 | pos_updated = true; 43 | // DEBUG_PRINTLN(">") 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /MillControl/RotatingButtons.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_ROTATINGBUTTONS_H 2 | #define MILLCONTROL_ROTATINGBUTTONS_H 3 | 4 | #include "Rotator.h" 5 | #include "Button.h" 6 | #include "Timed.h" 7 | 8 | class RotatingButtons : public Rotator, Timed { 9 | 10 | Button *button1; 11 | Button *button2; 12 | int ticks; 13 | int pos; 14 | bool pos_updated = false; 15 | 16 | public: 17 | RotatingButtons(unsigned char pin1, unsigned char pin2); 18 | 19 | private: 20 | virtual void run() override; 21 | 22 | virtual int getPosition() override; 23 | 24 | virtual bool updated() override; 25 | 26 | virtual void setPosititon(int i) override; 27 | 28 | virtual void setMode(int ticks, int pos) override; 29 | 30 | }; 31 | 32 | #endif //MILLCONTROL_ROTATINGBUTTONS_H -------------------------------------------------------------------------------- /MillControl/RotatingEncoder.cpp: -------------------------------------------------------------------------------- 1 | #include "RotatingEncoder.h" 2 | 3 | RotatingEncoder::RotatingEncoder(unsigned char pin1, unsigned char pin2) { 4 | encoder = new Encoder(pin1, pin2); 5 | } 6 | 7 | int RotatingEncoder::getPosition() { 8 | const int p = (((*RotatingEncoder::encoder).read() / 4) + RotatingEncoder::startticks) % RotatingEncoder::ticks; 9 | return p >= 0 ? p : RotatingEncoder::ticks + p; 10 | } 11 | 12 | bool RotatingEncoder::updated() { 13 | int newpos = getPosition(); 14 | bool change = RotatingEncoder::pos != newpos; 15 | RotatingEncoder::pos = newpos; 16 | return change; 17 | } 18 | 19 | void RotatingEncoder::setPosititon(int _startticks) { 20 | RotatingEncoder::startticks = _startticks; 21 | (*RotatingEncoder::encoder).write(0); 22 | } 23 | 24 | void RotatingEncoder::setMode(int _ticks, int _startticks) { 25 | RotatingEncoder::ticks = _ticks; 26 | setPosititon(_startticks); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /MillControl/RotatingEncoder.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_ROTATINGENCODER_H 2 | #define MILLCONTROL_ROTATINGENCODER_H 3 | 4 | #include 5 | #include "Rotator.h" 6 | 7 | class RotatingEncoder : public Rotator { 8 | Encoder *encoder; 9 | int ticks; 10 | int startticks; 11 | int pos; 12 | 13 | public: 14 | RotatingEncoder(unsigned char, unsigned char); 15 | 16 | virtual int getPosition() override; 17 | 18 | virtual bool updated() override; 19 | 20 | virtual void setPosititon(int i) override; 21 | 22 | virtual void setMode(int ticks, int pos) override; 23 | }; 24 | 25 | #endif //MILLCONTROL_ROTATINGENCODER_H -------------------------------------------------------------------------------- /MillControl/Rotator.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_ROTATOR_H 2 | #define MILLCONTROL_ROTATOR_H 3 | 4 | class Rotator { 5 | 6 | public: 7 | virtual int getPosition(); 8 | 9 | virtual bool updated(); 10 | 11 | virtual void setPosititon(int); 12 | 13 | virtual void setMode(int, int); 14 | }; 15 | 16 | #endif //MILLCONTROL_ROTATOR_H -------------------------------------------------------------------------------- /MillControl/Run.cpp: -------------------------------------------------------------------------------- 1 | #include "Run.h" 2 | #include "MillControl.h" 3 | 4 | Run::Run(unsigned char run_icon, int run_data) : run_data(run_data), run_icon(run_icon) { 5 | //Init Relay 6 | pinMode(UI::RELAY_PIN, OUTPUT); 7 | digitalWrite(UI::RELAY_PIN, HIGH); 8 | } 9 | 10 | bool Run::start() { 11 | #ifdef MILL_BUTTON 12 | UI::millButton.setMultiClick(false); 13 | #else 14 | UI::encoderButton.setMultiClick(false); 15 | #endif 16 | startMill(); 17 | UI::u8g.begin(); //resetting display - might help if there is interferences with the mill switch 18 | return true; 19 | } 20 | 21 | void Run::stop() { 22 | stopMill(); 23 | #ifdef MILL_BUTTON 24 | UI::millButton.setMultiClick(true); 25 | #else 26 | UI::encoderButton.setMultiClick(true); 27 | #endif 28 | UI::u8g.begin(); //resetting display - might help if there is interferences with the mill switch 29 | } 30 | 31 | 32 | void Run::loop() { 33 | if (millis() > (update_time + 250)) { 34 | update_time = millis(); 35 | redraw(); 36 | } 37 | } 38 | 39 | void Run::startMill() { digitalWrite(UI::RELAY_PIN, LOW); } 40 | 41 | void Run::stopMill() { digitalWrite(UI::RELAY_PIN, HIGH); } 42 | 43 | 44 | void Run::encoderClick() { 45 | millClick(MillControl::CLICK); 46 | } 47 | 48 | 49 | void Run::draw() { 50 | State::draw(); 51 | 52 | #ifdef PORTRAIT_DISPLAY 53 | unsigned char x = 0; 54 | unsigned char y = UI::LINE_HEIGHT + (UI::DISPLAY_HEIGHT / 3) + (UI::LARGE_LINE_HEIGHT / 2); 55 | #else 56 | unsigned char x = UI::LINE_HEIGHT * 2 + UI::BORDER_WIDTH; //42 57 | unsigned char y = UI::LARGE_LINE_HEIGHT + UI::BORDER_WIDTH * 2 + UI::BORDER_WIDTH; //29 58 | #endif 59 | 60 | UI::u8g.setFont(UI::FONT_LARGE_NUMERIC); 61 | UI::drawLargeSymbol(x, y, run_icon); 62 | 63 | } 64 | 65 | bool Run::close() { 66 | if (BrewlessState::close()) 67 | delete this; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /MillControl/Run.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_RUN_H 2 | #define MILLCONTROL_RUN_H 3 | 4 | #include "Mode.h" 5 | #include "BrewlessState.h" 6 | 7 | class Run : public BrewlessState { 8 | unsigned long update_time = 0; 9 | 10 | const unsigned char run_icon; 11 | protected: 12 | int run_data; 13 | public: 14 | Run(const unsigned char run_icon, const int run_data); 15 | 16 | static void stopMill(); 17 | 18 | static void startMill(); 19 | 20 | virtual bool start() override; 21 | 22 | virtual void stop() override; 23 | 24 | virtual void encoderClick() override; 25 | 26 | #ifdef DEBUG 27 | virtual char* getClassName() {return (char *) "Run"; } 28 | #endif 29 | 30 | virtual void loop() override; 31 | 32 | virtual void draw() override; 33 | 34 | protected: 35 | virtual bool close() override; 36 | }; 37 | 38 | #endif //MILLCONTROL_RUN_H -------------------------------------------------------------------------------- /MillControl/Scale.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * HX 711 based scale 3 | * (c) 2016 by Roman Seidl 4 | * code partly based on code by @mamu at kaffee-netz.de and on the 5 | * Q2HX711 library by Scott Russell 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, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * This program is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with this program. If not, see . 19 | */ 20 | 21 | #include "Scale.h" 22 | 23 | #include 24 | #include 25 | 26 | 27 | EEMEM unsigned char eeprom_version; 28 | EEMEM int eeprom_noise; 29 | EEMEM long eeprom_offset; 30 | EEMEM double eeprom_factor; 31 | 32 | Scale::Scale(unsigned char data_pin, unsigned char clock_pin, unsigned char power_pin) : data_pin(data_pin), 33 | clock_pin(clock_pin), 34 | power_pin(power_pin) { 35 | pinMode(data_pin, INPUT); 36 | pinMode(clock_pin, OUTPUT); 37 | pinMode(power_pin, OUTPUT); 38 | digitalWrite(power_pin, HIGH); 39 | reset_floating_weight(); 40 | eeprom_read(); 41 | }; 42 | 43 | 44 | long Scale::read() { 45 | while (digitalRead(data_pin)); 46 | 47 | noInterrupts(); 48 | 49 | //read data 50 | byte data[3]; 51 | for (byte j = 3; j--;) { 52 | data[j] = shiftIn(data_pin, clock_pin, MSBFIRST); 53 | } 54 | 55 | //Will produce GAIN 128 56 | digitalWrite(clock_pin, HIGH); 57 | digitalWrite(clock_pin, LOW); 58 | 59 | interrupts(); 60 | 61 | data[2] ^= 0x80; 62 | //merge to long 63 | return ((uint32_t) data[2] << 16) | ((uint32_t) data[1] << 8) | (uint32_t) data[0]; 64 | } 65 | 66 | long lround(double value) { 67 | return round(value); 68 | } 69 | 70 | //Returns the average of n raw weight measurements 71 | long Scale::read(unsigned char times) { 72 | long sum = 0; 73 | for (unsigned char i = 0; i < times; i++) { 74 | sum += read(); 75 | } 76 | return lround((double) sum / (double) times); 77 | } 78 | 79 | long Scale::toWeight(long value) { 80 | return lround(value * factor); 81 | } 82 | 83 | //Returns an average weight of n meassurements - only works if calibrated els -1 84 | long Scale::get_weight(unsigned char times) { 85 | return toWeight(read(times) - offset); 86 | } 87 | 88 | //Calibrates the scale with measurement 89 | void Scale::set_weight(long weight, unsigned char times) { 90 | long data = read(times) - offset; 91 | factor = (double) weight / (double) (data); 92 | eeprom_write(); 93 | } 94 | 95 | //Initializes the floating weight buffer 96 | void Scale::reset_floating_weight() { 97 | buffer_pos = 0; 98 | buffer_sum = 0; 99 | for (unsigned char p = 0; p < BUFFER_SIZE; p++) 100 | weight_buffer[p] = 0; 101 | } 102 | 103 | //Reads a number of bytes, adds them to the buffer and returns the current average 104 | long Scale::get_floating_weight(unsigned char updates) { 105 | for (unsigned char u = 0; u < updates; u++) { 106 | buffer_sum -= weight_buffer[buffer_pos]; 107 | 108 | const long data = (read() - offset); 109 | weight_buffer[buffer_pos] = data; 110 | buffer_sum += data; 111 | 112 | buffer_pos = (buffer_pos + 1) % BUFFER_SIZE; 113 | } 114 | return toWeight(((double) buffer_sum / (double) BUFFER_SIZE)); 115 | } 116 | 117 | long Scale::get_stable_weight(unsigned char times) { 118 | return toWeight(stable_read(times) - offset); 119 | } 120 | 121 | //meassures the noise level the scale has by running a series of measurements on the scale 122 | void Scale::calibrate_noise(unsigned char times) { 123 | long value = read(); 124 | for (unsigned char i = 0; i < times; i++) { 125 | long next_value = read(); 126 | long delta = abs(next_value - value); 127 | if (noise < delta) { 128 | noise = delta; 129 | } 130 | value = next_value; 131 | } 132 | eeprom_write(); 133 | } 134 | 135 | //reads a value if the scale is stable 136 | long Scale::stable_read(unsigned char times) { 137 | if (!noise) 138 | calibrate_noise(100); 139 | 140 | long value; 141 | unsigned char counter = 0; 142 | long sum = 0; 143 | do { 144 | long next_value = read(); 145 | if (abs(value - next_value) > noise) { 146 | //restart the process as there was instability 147 | sum = counter = 0; 148 | } else { 149 | //add result 150 | sum += next_value; 151 | counter++; 152 | } 153 | value = next_value; 154 | } while (counter < times); 155 | 156 | //calculate average 157 | return sum / times; 158 | } 159 | 160 | 161 | //tare the scale 162 | void Scale::tare(unsigned char times) { 163 | offset = stable_read(times); 164 | reset_floating_weight(); 165 | } 166 | 167 | //Power down the Sensor and the power pin 168 | void Scale::power_down() { 169 | digitalWrite(power_pin, HIGH); 170 | digitalWrite(clock_pin, LOW); 171 | digitalWrite(clock_pin, HIGH); 172 | } 173 | 174 | //Power up the Sensor and the power pin 175 | void Scale::power_up() { 176 | digitalWrite(power_pin, LOW); 177 | digitalWrite(clock_pin, LOW); 178 | } 179 | 180 | //Read calibration data from eeprom 181 | void Scale::eeprom_read() { 182 | if (EEPROM_VERSION == eeprom_read_byte(&eeprom_version)) { 183 | eeprom_read_block(&noise, &eeprom_noise, sizeof(int)); 184 | eeprom_read_block(&offset, &eeprom_offset, sizeof(long)); 185 | eeprom_read_block(&factor, &eeprom_factor, sizeof(double)); 186 | } 187 | } 188 | 189 | //Write calibration data to eeprom 190 | void Scale::eeprom_write() { 191 | eeprom_write_byte(&eeprom_version, EEPROM_VERSION); 192 | eeprom_update_block(&noise, &eeprom_noise, sizeof(int)); 193 | eeprom_update_block(&offset, &eeprom_offset, sizeof(long)); 194 | eeprom_update_block(&factor, &eeprom_factor, sizeof(double)); 195 | } 196 | -------------------------------------------------------------------------------- /MillControl/Scale.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_SCALE_H 2 | #define MILLCONTROL_SCALE_H 3 | 4 | /** 5 | * HX 711 based scale 6 | * (c) 2016 by Roman Seidl 7 | * code partly based on code by @mamu at kaffee-netz.de and on the 8 | * Q2HX711 library by Scott Russell 9 | * 10 | * This program is free software: you can redistribute it and/or modify 11 | * it under the terms of the GNU General Public License as published by 12 | * the Free Software Foundation, either version 3 of the License, or 13 | * (at your option) any later version. 14 | * 15 | * This program is distributed in the hope that it will be useful, 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | * GNU General Public License for more details. 19 | * 20 | * You should have received a copy of the GNU General Public License 21 | * along with this program. If not, see . 22 | */ 23 | 24 | class Scale { 25 | public: 26 | static const unsigned char BUFFER_SIZE = 32; 27 | 28 | private: 29 | static const unsigned char EEPROM_VERSION = 4; 30 | 31 | //The hx711 pinout 32 | const unsigned char data_pin; 33 | const unsigned char clock_pin; 34 | 35 | //needed for power up & down 36 | const unsigned char power_pin; 37 | 38 | //Tare offest 39 | long offset; 40 | //Noise level 41 | int noise = 0; 42 | //Calibration factor 43 | double factor = -1; 44 | 45 | //Weight buffer - gives a floating average of measurements 46 | long weight_buffer[BUFFER_SIZE]; 47 | long buffer_sum; 48 | unsigned char buffer_pos; 49 | 50 | void eeprom_read(); 51 | 52 | void eeprom_write(); 53 | 54 | public: 55 | Scale(unsigned char data_pin, unsigned char clock_pin, unsigned char power_pin); 56 | 57 | void power_down(); 58 | 59 | void power_up(); 60 | 61 | long read(); 62 | 63 | long read(unsigned char times); 64 | 65 | long stable_read(unsigned char times = 20); 66 | 67 | void tare(unsigned char times = 20); 68 | 69 | long get_weight(unsigned char times = 10); 70 | 71 | long get_stable_weight(unsigned char times = 20); 72 | 73 | //calibration 74 | void set_weight(long weight, unsigned char times = 100); 75 | 76 | //noise calibration 77 | void calibrate_noise(unsigned char times = 100); 78 | 79 | void reset_floating_weight(); 80 | 81 | //returns the floating average - must be initialized first 82 | long get_floating_weight(unsigned char updates = 1); 83 | 84 | long toWeight(long value); 85 | }; 86 | 87 | #endif //MILLCONTROL_SCALE_H 88 | -------------------------------------------------------------------------------- /MillControl/ScaleTarePrompt.cpp: -------------------------------------------------------------------------------- 1 | #include "ScaleTarePrompt.h" 2 | #include "MillControl.h" 3 | 4 | #ifdef SCALE 5 | 6 | bool ScaleTarePrompt::open() { 7 | UI::scale.power_up(); 8 | UI::u8g.begin(); 9 | //Need to wait for the scale to boot up 10 | delay(2500); 11 | UI::scale.calibrate_noise(); 12 | UI::scale.reset_floating_weight(); 13 | return Prompt::start(); 14 | } 15 | 16 | 17 | //this is called when a fallback happens! 18 | bool ScaleTarePrompt::start() { 19 | //Convention is: Calibrator returns 0 if cancel occured 20 | int weight = *MillControl::CALIBRATION_PROMPT.getData(); 21 | if (weight) 22 | UI::scale.set_weight(weight); 23 | return close(); 24 | } 25 | 26 | bool ScaleTarePrompt::close() { 27 | UI::scale.power_down(); 28 | UI::u8g.begin(); 29 | return State::close(); 30 | } 31 | 32 | void ScaleTarePrompt::loop() { 33 | weight = UI::scale.get_floating_weight(); 34 | if (millis() > (updateTime + 250)) { 35 | updateTime = millis(); 36 | redraw(); 37 | } 38 | } 39 | 40 | void ScaleTarePrompt::ok() { 41 | UI::scale.tare(); 42 | *MillControl::CALIBRATION_PROMPT.getData() = 500; 43 | MillControl::open(MillControl::CALIBRATION_PROMPT); 44 | } 45 | 46 | void ScaleTarePrompt::draw() { 47 | Prompt::draw(); 48 | UI::drawSubtitle(UI::TARE_TITLE); 49 | UI::drawRunWeightLine(weight, 0); 50 | } 51 | 52 | #endif -------------------------------------------------------------------------------- /MillControl/ScaleTarePrompt.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_SCALETAREPROMPT_H 2 | #define MILLCONTROL_SCALETAREPROMPT_H 3 | 4 | #include "Prompt.h" 5 | 6 | class ScaleTarePrompt : public Prompt { 7 | long updateTime; 8 | long weight; 9 | 10 | public: 11 | virtual bool open() override; 12 | 13 | virtual void loop() override; 14 | 15 | virtual void draw() override; 16 | 17 | #ifdef DEBUG 18 | virtual char* getClassName() {return (char *) "ScaleTarePrompt"; } 19 | #endif 20 | 21 | virtual void ok() override; 22 | 23 | virtual bool start() override; 24 | 25 | protected: 26 | virtual bool close() override; 27 | }; 28 | 29 | #endif -------------------------------------------------------------------------------- /MillControl/State.cpp: -------------------------------------------------------------------------------- 1 | #include "State.h" 2 | #include "MillControl.h" 3 | 4 | void State::redraw() { 5 | DEBUG_PRINTLN("redraw()"); 6 | UI::u8g.firstPage(); 7 | do { 8 | draw(); 9 | } while (UI::u8g.nextPage()); 10 | } 11 | 12 | void State::setEncoderMode(int positions, int position) { 13 | UI::rotator->setMode(positions, position); 14 | } 15 | 16 | void State::millClick(unsigned char clickType) { 17 | } 18 | 19 | #ifdef BREW_BUTTON 20 | //Will open the brew timer 21 | void State::brewClick() { 22 | DEBUG_PRINTLN("State::brewClick()"); 23 | MillControl::open(MillControl::BREW_TIMER); 24 | } 25 | #endif 26 | 27 | // Called when ste state is stopped 28 | void State::stop() { 29 | } 30 | 31 | // Called when the state is opened, defaults to doing the same as when started 32 | bool State::open() { 33 | return start(); 34 | } 35 | 36 | // Is called when the State is started 37 | bool State::start() { 38 | return true; 39 | } 40 | 41 | void State::loop() { 42 | } 43 | 44 | void State::encoderChanged(int encoderPos) { 45 | } 46 | 47 | void State::encoderClick() { 48 | } 49 | 50 | void State::draw() { 51 | UI::drawTitle(MillControl::TIME_MODE_SELECTOR.getMode().name); 52 | } 53 | 54 | //go start to the previous state 55 | bool State::close() { 56 | if (!previousState == NULL) { 57 | MillControl::close(this); 58 | return true; 59 | } else 60 | return false; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /MillControl/State.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_STATE_H 2 | #define MILLCONTROL_STATE_H 3 | 4 | #include "UI.h" 5 | #include 6 | 7 | class State { 8 | protected: 9 | void setEncoderMode(int, int); 10 | 11 | virtual bool close(); 12 | 13 | public: 14 | State* previousState = NULL; 15 | void redraw(); 16 | 17 | virtual bool open(); 18 | 19 | virtual bool start(); 20 | virtual void stop(); 21 | 22 | //Draws the UI - title only for the master state 23 | virtual void draw(); 24 | 25 | //UI functions 26 | virtual void millClick(unsigned char); 27 | 28 | virtual void encoderClick(); 29 | 30 | virtual void encoderChanged(int encoderPos); 31 | 32 | #ifdef BREW_BUTTON 33 | virtual void brewClick(); 34 | #endif 35 | 36 | //Delegating loop function - false will exit a sub-mode (if there is one) 37 | virtual void loop(); 38 | 39 | #ifdef DEBUG 40 | virtual char* getClassName() {return (char *) "State"; } 41 | #endif 42 | }; 43 | 44 | #endif //MILLCONTROL_STATE_H -------------------------------------------------------------------------------- /MillControl/Timed.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_TIMED_H 2 | #define MILLCONTROL_TIMED_H 3 | 4 | class Timed { 5 | public: 6 | virtual void run(); 7 | }; 8 | 9 | #endif //MILLCONTROL_TIMED_H -------------------------------------------------------------------------------- /MillControl/TimedRun.cpp: -------------------------------------------------------------------------------- 1 | #include "TimedRun.h" 2 | 3 | 4 | bool TimedRun::start() { 5 | pauseTime = 0; 6 | 7 | stopTime = millis(); 8 | lastEncoderPos = run_data / 10; 9 | setEncoderMode(10000, lastEncoderPos); 10 | stopTime += (long) run_data * 100l; 11 | 12 | return Run::start(); 13 | } 14 | 15 | //watches if the run should be stopped and updates display 16 | void TimedRun::loop() { 17 | /* //Hold Run only exists if there is a mill button 18 | #ifdef MILL_BUTTON 19 | || (run_type == HOLD_RUN && !UI::millButton.isPressed()) 20 | #endif 21 | ) */ 22 | if (millis() > stopTime) 23 | close(); 24 | else 25 | Run::loop(); 26 | } 27 | 28 | //If this is a timed tun this will only stop 29 | void TimedRun::millClick(unsigned char clickType) { 30 | if (!pauseTime) { 31 | pauseTime = stopTime - millis(); 32 | //Will time out 33 | stopTime = millis() + UI::PAUSE_TIME * 1000; 34 | stopMill(); 35 | } else { 36 | stopTime = millis() + pauseTime; 37 | startMill(); 38 | pauseTime = 0; 39 | } 40 | } 41 | 42 | void TimedRun::draw() { 43 | Run::draw(); 44 | 45 | long remainingMillis = max(0, pauseTime ? pauseTime : stopTime - millis()); 46 | int remainingSeconds = remainingMillis / 1000 + 1; 47 | 48 | #ifdef PORTRAIT_DISPLAY 49 | const char x = UI::DISPLAY_WIDTH - UI::LINE_HEIGHT; 50 | const char y = UI::DISPLAY_HEIGHT - 12 * UI::BORDER_WIDTH; 51 | #else 52 | const char x = UI::DISPLAY_WIDTH - UI::LINE_HEIGHT; //115; 53 | const char y = UI::DISPLAY_HEIGHT - 6 * UI::BORDER_WIDTH; //53; 54 | #endif 55 | 56 | if (!pauseTime || (millis() / 500) % 2) { 57 | UI::drawRunTime(x, y, remainingSeconds, pauseTime); 58 | } 59 | 60 | UI::drawProgressBar(1.0 - double(remainingMillis) / double(100l * (long) run_data)); 61 | } 62 | 63 | void TimedRun::encoderChanged(int encoderPos) { 64 | const int encoderDiff = encoderPos - lastEncoderPos; 65 | //Adapt time and data 66 | stopTime += encoderDiff * 1000l; 67 | run_data += encoderDiff * 10; 68 | lastEncoderPos = encoderPos; 69 | lastEncoderPos = encoderPos; 70 | } -------------------------------------------------------------------------------- /MillControl/TimedRun.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_TIMEDRUN_H 2 | #define MILLCONTROL_TIMEDRUN_H 3 | 4 | 5 | #include "Run.h" 6 | 7 | class TimedRun : public Run { 8 | private: 9 | unsigned long stopTime; 10 | unsigned long pauseTime; 11 | int lastEncoderPos; 12 | protected: 13 | virtual void loop() override; 14 | 15 | virtual void draw() override; 16 | 17 | public: 18 | TimedRun(const unsigned char run_icon, const int run_data) : Run(run_icon, run_data) { } 19 | 20 | virtual void millClick(unsigned char i) override; 21 | 22 | virtual void encoderChanged(int encoderPos) override; 23 | 24 | virtual bool start() override; 25 | }; 26 | 27 | 28 | #endif //MILLCONTROL_TIMEDRUN_H 29 | -------------------------------------------------------------------------------- /MillControl/UI.cpp: -------------------------------------------------------------------------------- 1 | #include "TimedRun.h" 2 | 3 | 4 | void UI::drawSubtitle(const char *text) { 5 | #ifdef PORTRAIT_DISPLAY 6 | UI::u8g.setFont(UI::FONT_SMALL); 7 | const char x = UI::DISPLAY_WIDTH - 1; 8 | const char y = UI::DISPLAY_HEIGHT - UI::BORDER_WIDTH - 1; 9 | UI::u8g.drawStr270(x, y, text); 10 | #else 11 | u8g.setFont(FONT_REGULAR); 12 | u8g.drawStr(LINE_HEIGHT * 2, LINE_HEIGHT, text); 13 | #endif 14 | } 15 | 16 | void UI::drawTitle(const char *title) { 17 | u8g.setFont(FONT_REGULAR); 18 | #ifdef PORTRAIT_DISPLAY 19 | UI::u8g.drawStr(0, UI::LINE_HEIGHT, title); 20 | #else 21 | u8g.drawStr270(LINE_HEIGHT, DISPLAY_HEIGHT - 1, title); 22 | #endif 23 | 24 | #ifdef DEBUG 25 | //Memory display 26 | // UI::u8g.setFont(u8g_font_u8glib_4); 27 | char mem_str[5]; 28 | 29 | extern int __heap_start, *__brkval; 30 | int v; 31 | const int mem = (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 32 | Serial.begin(9600); 33 | Serial.println(mem); 34 | Serial.flush(); 35 | // sprintf(mem_str, "%i", mem); 36 | // UI::u8g.drawStr(20, 20, mem_str); 37 | #endif 38 | } 39 | 40 | void UI::drawTimeLine(char line, const int data, unsigned char y, unsigned char x, bool grams, 41 | const bool small, bool selected, bool editor) { 42 | char c_t[6] = ""; 43 | const bool weightLine = line == -1; 44 | 45 | if (small) 46 | u8g.setFont(FONT_SMALL); 47 | else 48 | u8g.setFont(FONT_REGULAR); 49 | 50 | if (!weightLine) 51 | drawSymbol(x, y, line, small ? SMALL_LINE_HEIGHT : LINE_HEIGHT); 52 | 53 | #ifdef PORTRAIT_DISPLAY 54 | const unsigned char line_w = UI::DISPLAY_WIDTH; 55 | #else 56 | const unsigned char line_w = DISPLAY_HEIGHT; 57 | #endif 58 | 59 | //Seconds 60 | 61 | u8g.setColorIndex(1); 62 | const bool special_line = line != -1 && data == Mode::SPECIAL_DATA; 63 | const char *text = special_line ? 64 | (line == 2 ? SPECIAL_TIME_HOLD_NAME : SPECIAL_TIME_START_NAME) 65 | : (weightLine ? "s/g" : (grams ? "g" : "s")); 66 | 67 | 68 | //Maybe one should use consts on that? 69 | u8g.setFont(FONT_SMALL); 70 | const unsigned char text_w = u8g.getStrWidth(text); 71 | const unsigned char text_x = special_line ? (x + 2 * LINE_HEIGHT + 2 * BORDER_WIDTH) : (x + line_w - text_w); 72 | u8g.drawStr(text_x, y - (special_line ? 1 : 0), text); 73 | 74 | //draw time 75 | if (!special_line) { 76 | if (!small) 77 | u8g.setFont(FONT_NUMERIC); 78 | 79 | printData(c_t, data, weightLine); 80 | 81 | const unsigned char data_w = u8g.getStrWidth(c_t); 82 | const unsigned char data_x = text_x - data_w; 83 | 84 | u8g.drawStr(data_x, y, c_t); 85 | if (selected && editor) 86 | u8g.drawHLine(data_x, y + BORDER_WIDTH, data_w); 87 | } else { 88 | if (selected && editor) 89 | u8g.drawHLine(text_x, y + BORDER_WIDTH, text_w); 90 | } 91 | 92 | if (selected && !editor) { 93 | #if defined(MILL_BUTTON) && !defined(PORTRAIT_DISPLAY) 94 | const unsigned char d = BORDER_WIDTH; 95 | #else 96 | const unsigned char d = UI::BORDER_WIDTH * 2; 97 | #endif 98 | u8g.drawHLine(x, y + d, line_w); 99 | } 100 | } 101 | 102 | void UI::printData(char *c_t, const int data, const bool weightLine) { 103 | if (weightLine) { 104 | if (data < 1000) 105 | sprintf(c_t, "%i.%02i", data / 100, data % 100); 106 | else 107 | sprintf(c_t, "%i.%i", data / 100, data / 10 % 10); 108 | } else { 109 | if (data < 1000) 110 | sprintf(c_t, "%i.%i", data / 10, data % 10); 111 | else 112 | sprintf(c_t, "%i", data / 10); 113 | } 114 | } 115 | 116 | void UI::drawDirectionSymbol(const unsigned char x, const unsigned char y, const unsigned char height, 117 | const bool back, const unsigned char weight) { 118 | const unsigned char h = height - 2 * BORDER_WIDTH; 119 | const unsigned char w0 = back ? (h / 2) : 0; 120 | const unsigned char w1 = back ? 0 : (h / 2); 121 | const unsigned char w = h / 2; 122 | const unsigned char x0 = x - h / 4 - weight * BORDER_WIDTH; 123 | const unsigned char y0 = y - BORDER_WIDTH; 124 | for (unsigned char l = 0; l < 2; l++) { 125 | for (unsigned char c = 0; c < BORDER_WIDTH * weight; c++) { 126 | const unsigned char x1 = x0 + c + l * (BORDER_WIDTH * weight * 2); 127 | u8g.drawLine(x1 + w0, y0, x1 + w1, y0 - w); 128 | u8g.drawLine(x1 + w0, y0 - h, x1 + w1, y0 - w); 129 | } 130 | } 131 | } 132 | 133 | void UI::drawSymbol(const unsigned char x, const unsigned char y, const unsigned char symbol, 134 | const unsigned char line_height, const unsigned char border, const unsigned char weight) { 135 | u8g.setColorIndex(1); 136 | 137 | const unsigned char r = (line_height / 2) + border; 138 | u8g.drawDisc(x + r, y - (line_height / 2), r); 139 | 140 | u8g.setColorIndex(0); 141 | if (symbol < 2) { 142 | const char *s = symbol ? "2" : "1"; 143 | u8g.drawStr(x + r - (u8g.getStrWidth(s) / 2) + (line_height < 18 ? 1 : 0), y, s); 144 | } else { 145 | drawDirectionSymbol(x + r, y, line_height, false, weight); 146 | } 147 | u8g.setColorIndex(1); 148 | } 149 | 150 | void UI::drawLargeSymbol(const unsigned char x, const unsigned char y, const unsigned char symbol) { 151 | #ifdef MODE_SYMBOLS 152 | SYMBOLS[symbol].draw(&u8g, x, y - UI::LARGE_LINE_HEIGHT / 2); 153 | #else 154 | drawSymbol(x, y, symbol, UI::LARGE_LINE_HEIGHT, 4, 2); 155 | #endif 156 | 157 | } 158 | 159 | void UI::drawRunWeight(const unsigned char x, const unsigned char y, int weight, bool small, unsigned char line) { 160 | 161 | char c_t[6] = ""; 162 | if (weight < 1000) 163 | sprintf(c_t, "%i.%i", weight / 10, weight % 10); 164 | else 165 | sprintf(c_t, "%i", weight / 10); 166 | 167 | u8g.setFont(small ? UI::FONT_REGULAR : FONT_LARGE_NUMERIC); 168 | u8g.drawStr(x - u8g.getStrWidth(c_t), y, c_t); 169 | 170 | if (line) { 171 | const char w = UI::u8g.getStrWidth(c_t); 172 | 173 | if (line == 1) 174 | UI::u8g.drawHLine(x - w, y + UI::BORDER_WIDTH, w); 175 | else 176 | UI::u8g.drawHLine(x - w, y + UI::BORDER_WIDTH, w + UI::SMALL_LINE_HEIGHT); 177 | } 178 | 179 | u8g.setFont(FONT_REGULAR); 180 | u8g.drawStr(x, y, "g"); 181 | } 182 | 183 | void UI::drawRunTime(const unsigned char x, const unsigned char y, int seconds, bool small) { 184 | char c_t[6] = ""; 185 | sprintf(c_t, "%i", seconds); 186 | u8g.setFont(small ? UI::FONT_REGULAR : FONT_LARGE_NUMERIC); 187 | u8g.drawStr(x - u8g.getStrWidth(c_t), y, c_t); 188 | 189 | u8g.setFont(FONT_REGULAR); 190 | u8g.drawStr(x, y, "s"); 191 | } 192 | 193 | void UI::drawEditPoint(const unsigned char p, const bool active, const unsigned char symbol) { 194 | // UI::u8g.setFont(UI::FONT_SMALL); 195 | #ifdef PORTRAIT_DISPLAY 196 | char c[2]; 197 | c[0] = UI::MOVE_RIGHT_STRING; 198 | c[1] = 0; 199 | const unsigned char x = 200 | (DISPLAY_WIDTH / 6) * p + (p > 0 ? ((DISPLAY_WIDTH / 6) - u8g.getStrWidth(c)) : 0); 201 | const unsigned char y = DISPLAY_HEIGHT - 2 * BORDER_WIDTH; 202 | #else 203 | const unsigned char x = UI::DISPLAY_WIDTH - (p == 0 ? (2 * UI::SMALL_LINE_HEIGHT + UI::BORDER_WIDTH * 4) : 204 | (UI::SMALL_LINE_HEIGHT + UI::BORDER_WIDTH * 2)); 205 | const unsigned char y = p > 1 ? ((p - 1) * (UI::DISPLAY_HEIGHT - 2 * UI::SMALL_LINE_HEIGHT - 2 * UI::BORDER_WIDTH - 1) / 3 + 206 | UI::SMALL_LINE_HEIGHT) : UI::SMALL_LINE_HEIGHT; 207 | #endif 208 | 209 | char s[2]; 210 | s[0] = symbol; 211 | s[1] = 0; 212 | u8g.drawStr(x, y, s); 213 | 214 | if (active) { 215 | u8g.drawHLine(x, (u8g_uint_t) (y + 1), u8g.getStrWidth(s)); 216 | } 217 | } 218 | 219 | void UI::drawProgressBar(const double progress) { 220 | #ifdef PORTRAIT_DISPLAY 221 | const unsigned char w = UI::DISPLAY_WIDTH * progress; 222 | u8g.drawBox(0, UI::DISPLAY_HEIGHT - UI::BORDER_WIDTH * 2 - 1, w, UI::BORDER_WIDTH * 2); 223 | #else 224 | const unsigned char w = (UI::DISPLAY_WIDTH - UI::LINE_HEIGHT * 2) * progress; 225 | u8g.drawBox(UI::LINE_HEIGHT * 2, UI::DISPLAY_HEIGHT - UI::BORDER_WIDTH * 2 - 1, w, UI::BORDER_WIDTH * 2); 226 | #endif 227 | } 228 | 229 | void UI::drawRunWeightLine(long weight, const unsigned char line) { 230 | weight = max(0, min(9999, weight)); 231 | 232 | #ifdef PORTRAIT_DISPLAY 233 | const char x = UI::DISPLAY_WIDTH - UI::SMALL_LINE_HEIGHT - UI::LINE_HEIGHT - UI::BORDER_WIDTH; 234 | const char y = UI::DISPLAY_HEIGHT - 2 * UI::SMALL_LINE_HEIGHT - 1; 235 | drawRunWeight(x, y, weight, true, line); 236 | #else 237 | const char x = UI::DISPLAY_WIDTH - UI::LINE_HEIGHT - 1; //89 238 | const char y = UI::DISPLAY_HEIGHT - 3 * UI::BORDER_WIDTH - 1;//57; 239 | drawRunWeight(x, y, weight, false, line); 240 | #endif 241 | } 242 | 243 | 244 | //------------------------------------------ 245 | // Symbols 246 | 247 | void Symbol::draw(U8GLIB *_display, const unsigned char x, const unsigned char y) { 248 | for (unsigned char m = 0; m < multiple; m++) 249 | _display->drawXBMP((u8g_uint_t) (x + m * (width + 2 * UI::BORDER_WIDTH)), (u8g_uint_t) (y - (height / 2)), 250 | width, height, 251 | bits); 252 | } 253 | 254 | 255 | #ifdef BREW_BUTTON 256 | 257 | #ifdef DISPLAY_128x64 258 | static const u8g_pgm_uint8_t BREW_BITS[] U8G_PROGMEM = { 259 | 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 260 | 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 261 | 0xff, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 262 | 0xff, 0xff, 0xff, 0xff, 0xff, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 263 | 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0x8f, 0x3f, 264 | 0xff, 0xff, 0xff, 0xff, 0x0f, 0x7c, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x7c, 265 | 0xfe, 0xff, 0xff, 0xff, 0x0f, 0x78, 0xfe, 0xff, 0xff, 0xff, 0x0f, 0x78, 266 | 0xfe, 0xff, 0xff, 0xff, 0x0f, 0x78, 0xfe, 0xff, 0xff, 0xff, 0x07, 0x7c, 267 | 0xfe, 0xff, 0xff, 0xff, 0x07, 0x3c, 0xfe, 0xff, 0xff, 0xff, 0x07, 0x3e, 268 | 0xfe, 0xff, 0xff, 0xff, 0x07, 0x3e, 0xfc, 0xff, 0xff, 0xff, 0x07, 0x1f, 269 | 0xfc, 0xff, 0xff, 0xff, 0x87, 0x0f, 0xfc, 0xff, 0xff, 0xff, 0xc7, 0x0f, 270 | 0xfc, 0xff, 0xff, 0xff, 0xe3, 0x07, 0xf8, 0xff, 0xff, 0xff, 0xf3, 0x03, 271 | 0xf8, 0xff, 0xff, 0xff, 0xfb, 0x01, 0xf8, 0xff, 0xff, 0xff, 0xff, 0x00, 272 | 0xf8, 0xff, 0xff, 0xff, 0x7f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x1f, 0x00, 273 | 0xf0, 0xff, 0xff, 0xff, 0x0f, 0x00, 0xf0, 0xff, 0xff, 0xff, 0x07, 0x00, 274 | 0xf0, 0xff, 0xff, 0xff, 0x01, 0x00, 0xe0, 0xff, 0xff, 0xff, 0x00, 0x00, 275 | 0xe0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0xc0, 0xff, 0xff, 0x7f, 0x00, 0x00, 276 | 0xc0, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x80, 0xff, 0xff, 0x3f, 0x00, 0x00, 277 | 0x80, 0xff, 0xff, 0x3f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x1f, 0x00, 0x00, 278 | 0x00, 0xff, 0xff, 0x0f, 0x00, 0x00, 0x00, 0xfe, 0xff, 0x0f, 0x00, 0x00 279 | }; 280 | Symbol UI::BREW_SYMBOL(47, 40, BREW_BITS); 281 | #else 282 | static const u8g_pgm_uint8_t BREW_BITS[] U8G_PROGMEM = { 283 | 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x00, 284 | 0x00, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 285 | 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0xff, 0xff, 0x07, 286 | 0xff, 0xff, 0x07, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 287 | 0xff, 0xff, 0xc3, 0xff, 0xff, 0xc3, 0xfe, 0xff, 0xe3, 0xfe, 0xff, 0x63, 288 | 0xfe, 0xff, 0x73, 0xfe, 0xff, 0x39, 0xfe, 0xff, 0x1f, 0xfc, 0xff, 0x07, 289 | 0xfc, 0xff, 0x03, 0xfc, 0xff, 0x01, 0xf8, 0xff, 0x00, 0xf8, 0x7f, 0x00, 290 | 0xf0, 0x7f, 0x00, 0xf0, 0x3f, 0x00 291 | }; 292 | Symbol UI::BREW_SYMBOL(24, 30, BREW_BITS); 293 | #endif 294 | #endif 295 | 296 | 297 | #ifdef MODE_SYMBOLS 298 | //Converted with GIMP 299 | 300 | //Large Symbols not used for now 301 | #ifdef LARGE_SYMBOLS 302 | static const u8g_pgm_uint8_t HAND_BITS[] U8G_PROGMEM = { 303 | 0x00, 0xe0, 0x0f, 0x00, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0xff, 304 | 0xff, 0x01, 0x00, 0x80, 0x1f, 0xf0, 0x07, 0x00, 0xe0, 0x07, 0xc0, 0x0f, 305 | 0x00, 0xe0, 0x01, 0x00, 0x1f, 0x00, 0xf0, 0x00, 0x00, 0x3e, 0x00, 0x78, 306 | 0x00, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x00, 0x78, 0x00, 0x3c, 0x00, 0x00, 307 | 0x70, 0x00, 0x1e, 0x00, 0x00, 0xf0, 0x00, 0x0e, 0x00, 0x00, 0xe0, 0x00, 308 | 0x0e, 0x00, 0x00, 0xe0, 0x01, 0x0e, 0x80, 0x03, 0xc0, 0x01, 0x0f, 0xc0, 309 | 0x07, 0xc0, 0x01, 0x07, 0xc0, 0x07, 0xc0, 0x01, 0x07, 0xe0, 0x0f, 0xc0, 310 | 0x01, 0x07, 0xe0, 0x0f, 0xc0, 0x01, 0x0e, 0xe0, 0x0f, 0xc0, 0x01, 0x0e, 311 | 0xe0, 0x0f, 0xc0, 0x01, 0x0e, 0xe0, 0x0f, 0xe0, 0x00, 0x0e, 0xe0, 0x0f, 312 | 0xe0, 0x00, 0x1e, 0xe0, 0x0f, 0xf0, 0x00, 0x1c, 0xe0, 0x0f, 0x00, 0x00, 313 | 0x3c, 0xe0, 0x0f, 0x00, 0x00, 0x78, 0xe0, 0x0f, 0x00, 0x00, 0xf0, 0xe0, 314 | 0x4f, 0x00, 0x00, 0xf0, 0xe1, 0xef, 0x01, 0x00, 0xe0, 0xe3, 0xff, 0x03, 315 | 0x00, 0x80, 0xe3, 0xff, 0x03, 0x00, 0x00, 0xe3, 0xff, 0xf7, 0x00, 0x00, 316 | 0xe0, 0xff, 0xff, 0x01, 0x00, 0xe0, 0xff, 0xff, 0x01, 0x00, 0xe0, 0xff, 317 | 0xff, 0x39, 0x00, 0xe0, 0xff, 0xff, 0x7d, 0x00, 0xe0, 0xff, 0xff, 0x7f, 318 | 0x00, 0xe0, 0xff, 0xff, 0x7f, 0x00, 0xe0, 0xff, 0xff, 0x7f, 0xf0, 0xe0, 319 | 0xff, 0xff, 0x7f, 0xf8, 0xe1, 0xff, 0xff, 0x7f, 0xf8, 0xe3, 0xff, 0xff, 320 | 0x7f, 0xf8, 0xe7, 0xff, 0xff, 0x7f, 0xf8, 0xe7, 0xff, 0xff, 0x7f, 0xf0, 321 | 0xef, 0xff, 0xff, 0x7f, 0xe0, 0xff, 0xff, 0xff, 0x7f, 0xc0, 0xff, 0xff, 322 | 0xff, 0x7f, 0xc0, 0xff, 0xff, 0xff, 0x7f, 0x80, 0xff, 0xff, 0xff, 0x7f, 323 | 0x00, 0xff, 0xff, 0xff, 0x7f, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0x00, 0xfc, 324 | 0xff, 0xff, 0x7f, 0x00, 0xf8, 0xff, 0xff, 0x7f, 0x00, 0xe0, 0xff, 0xff, 325 | 0x3f 326 | 327 | }; 328 | 329 | static const u8g_pgm_uint8_t BEAN_BITS[] U8G_PROGMEM = { 330 | 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 331 | 0xff, 0xff, 0x07, 0x00, 0xc0, 0xff, 0xff, 0x0f, 0x00, 0xe0, 0xff, 0xff, 332 | 0x01, 0x00, 0xf0, 0xff, 0x3f, 0x30, 0x00, 0xf8, 0xff, 0x0f, 0x3c, 0x00, 333 | 0xfe, 0xff, 0x07, 0x7f, 0x00, 0xff, 0xff, 0xc1, 0x7f, 0x80, 0xff, 0xff, 334 | 0xe0, 0x7f, 0x80, 0xff, 0x7f, 0xf0, 0x7f, 0xc0, 0xff, 0x3f, 0xf8, 0x7f, 335 | 0xe0, 0xff, 0x1f, 0xfc, 0x7f, 0xf0, 0xff, 0x0f, 0xfe, 0x7f, 0xf0, 0xff, 336 | 0x0f, 0xff, 0x7f, 0xf8, 0xff, 0x87, 0xff, 0x7f, 0xf8, 0xff, 0x87, 0xff, 337 | 0x7f, 0xfc, 0xff, 0xc7, 0xff, 0x7f, 0xfc, 0xff, 0xc3, 0xff, 0x3f, 0xfe, 338 | 0xff, 0xc3, 0xff, 0x3f, 0xfe, 0xff, 0xe3, 0xff, 0x3f, 0xfe, 0xff, 0xe1, 339 | 0xff, 0x1f, 0xfe, 0xff, 0xe1, 0xff, 0x1f, 0xff, 0xff, 0xf0, 0xff, 0x0f, 340 | 0xff, 0x7f, 0xf0, 0xff, 0x0f, 0xff, 0x7f, 0xf8, 0xff, 0x07, 0xff, 0x3f, 341 | 0xfc, 0xff, 0x03, 0xff, 0x1f, 0xfc, 0xff, 0x03, 0xff, 0x0f, 0xff, 0xff, 342 | 0x01, 0xff, 0x07, 0xff, 0xff, 0x00, 0xfe, 0xc1, 0xff, 0x7f, 0x00, 0xfe, 343 | 0xe0, 0xff, 0x3f, 0x00, 0x3c, 0xfc, 0xff, 0x1f, 0x00, 0x0c, 0xfe, 0xff, 344 | 0x0f, 0x00, 0xe0, 0xff, 0xff, 0x03, 0x00, 0xf0, 0xff, 0xff, 0x01, 0x00, 345 | 0xe0, 0xff, 0x7f, 0x00, 0x00, 0xc0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0xff, 346 | 0x03, 0x00, 0x00 347 | }; 348 | 349 | Symbol UI::SYMBOLS[]{Symbol(39, 39, BEAN_BITS), Symbol(39, 39, BEAN_BITS, 2), Symbol(39, 53, HAND_BITS)}; 350 | #else 351 | static const u8g_pgm_uint8_t HAND_BITS[] U8G_PROGMEM = { 352 | 0x80, 0x07, 0x00, 0xf0, 0x1f, 0x00, 0x38, 0x70, 0x00, 0x0c, 0xe0, 0x00, 353 | 0x06, 0x80, 0x01, 0x06, 0x80, 0x01, 0x02, 0x00, 0x03, 0x03, 0x03, 0x03, 354 | 0x83, 0x07, 0x03, 0x82, 0x07, 0x03, 0x82, 0x07, 0x03, 0x82, 0x07, 0x01, 355 | 0x86, 0x07, 0x00, 0x8c, 0x07, 0x00, 0x9c, 0x1f, 0x00, 0x90, 0x3f, 0x00, 356 | 0x80, 0xff, 0x03, 0x80, 0xff, 0x0b, 0x80, 0xff, 0x1f, 0x80, 0xff, 0x1f 357 | }; 358 | 359 | static const u8g_pgm_uint8_t BEAN_BITS[] U8G_PROGMEM = { 360 | 0x00, 0xf8, 0x00, 0x00, 0xff, 0x03, 0x80, 0xff, 0x01, 0xc0, 0x3f, 0x06, 361 | 0xf0, 0x9f, 0x0f, 0xf0, 0xcf, 0x0f, 0xf8, 0xe7, 0x0f, 0xfc, 0xf3, 0x0f, 362 | 0xfc, 0xf3, 0x0f, 0xfe, 0xf9, 0x07, 0xfe, 0xf9, 0x07, 0xfe, 0xf9, 0x07, 363 | 0xff, 0xfc, 0x03, 0x7f, 0xfe, 0x01, 0x3f, 0xff, 0x01, 0x9e, 0xff, 0x00, 364 | 0xe6, 0x7f, 0x00, 0xf8, 0x1f, 0x00, 0xf8, 0x0f, 0x00, 0xf0, 0x01, 0x00 365 | }; 366 | 367 | Symbol UI::SYMBOLS[]{Symbol(20, 20, BEAN_BITS), Symbol(20, 20, BEAN_BITS, 2), Symbol(21, 20, HAND_BITS)}; 368 | 369 | #endif 370 | 371 | #endif 372 | 373 | 374 | -------------------------------------------------------------------------------- /MillControl/UI.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_UI_H 2 | #define MILLCONTROL_UI_H 3 | 4 | #include "RotatingEncoder.h" 5 | #include "RotatingButtons.h" 6 | #include "Button.h" 7 | #include "Scale.h" 8 | #include 9 | 10 | #include "helvB10s.h" 11 | #include "helvB14r.h" 12 | 13 | //================================================= 14 | // DEBUG 15 | // If uncommented this will print debug messages to the serial port 16 | 17 | //#define DEBUG 18 | #ifdef DEBUG 19 | #include 20 | #define DEBUG_PRINTLN(message) {Serial.println(message);Serial.flush();} 21 | #define DEBUG_PRINT(message) {Serial.print(message);Serial.flush();} 22 | #else 23 | #define DEBUG_PRINTLN(message) 24 | #define DEBUG_PRINT(message) 25 | #endif 26 | 27 | //================================================= 28 | // BUTTONS 29 | 30 | // Comment out this line if there is no mill button 31 | // Change the Pin if you want it to be somewhere else 32 | #define MILL_BUTTON 5 33 | 34 | // Comment out this line if there is no second mill button 35 | // Change the Pin if you want it to be somewhere else 36 | #define MILL_BUTTON_2 6 37 | 38 | // Comment out this line if there is no brew button 39 | // Change the Pin if you want it to be somewhere else 40 | //#define BREW_BUTTON A0 41 | 42 | 43 | //================================================= 44 | // SCREEN ORIENTATION 45 | 46 | // Uncomment this to change the orientation to portrait mode 47 | #define PORTRAIT_DISPLAY 48 | 49 | //================================================= 50 | // FLAT MODE 51 | // In flat mode only one time per page is shown in the time mode selector. 52 | //#define FLAT_MODE 53 | 54 | //================================================= 55 | // RESET MODE 56 | // Set this and flash once to reset data - don't forget to comment it out again! 57 | // You can usually also reset all data by deteling all pages 58 | 59 | //#define RESET_MODE 60 | 61 | 62 | //================================================= 63 | // SCALE MODE 64 | 65 | //#define SCALE 66 | 67 | //================================================= 68 | // SYMBOLS 69 | // If you want to use symbols for run mode and flat mode - symbols are defined in UI.cpp 70 | //#define MODE_SYMBOLS 71 | #ifdef FLAT_MODE 72 | #define MODE_SYMBOLS 73 | #endif 74 | 75 | class Symbol { 76 | const u8g_pgm_uint8_t *bits; 77 | const unsigned char multiple; 78 | public: 79 | Symbol(const unsigned char width, const unsigned char height, const u8g_pgm_uint8_t *bits, 80 | unsigned char multiple = 1) 81 | : width(width), height(height), bits(bits), multiple(multiple) { } 82 | 83 | void draw(U8GLIB *_display, const unsigned char x, const unsigned char y); 84 | 85 | const unsigned char width; 86 | const unsigned char height; 87 | }; 88 | 89 | class UI { 90 | protected: 91 | #ifdef MODE_SYMBOLS 92 | static Symbol SYMBOLS[]; 93 | #endif 94 | public: 95 | //================================================= 96 | // Titles - change these titles if you would like to have different titles - be aware that size matters... 97 | static constexpr char *SPECIAL_TIME_START_NAME PROGMEM = (char *const) "start"; 98 | static constexpr char *SPECIAL_TIME_HOLD_NAME PROGMEM = (char *const) "hold"; 99 | 100 | static constexpr char *BREW_TITLE PROGMEM = (char *const) "Brewing"; 101 | static constexpr char *CALIBRATION_TITLE PROGMEM = (char *const) "Calibration"; 102 | static constexpr char *TARE_TITLE PROGMEM = (char *const) "Tare"; 103 | 104 | static const unsigned char DEL_STRING PROGMEM = 'x'; 105 | static const unsigned char ADD_STRING PROGMEM = '+'; 106 | static const unsigned char MOVE_LEFT_STRING PROGMEM = '<'; 107 | static const unsigned char MOVE_RIGHT_STRING PROGMEM = '>'; 108 | //================================================= 109 | // Relay Pin - change the pin if you want it to be somewhere else 110 | static const unsigned char RELAY_PIN = 7; 111 | 112 | static const unsigned char PAUSE_TIME; 113 | 114 | #ifdef BREW_BUTTON 115 | static const long BREW_TIMER_TIMEOUT = 1000; 116 | #endif 117 | 118 | static const u8g_fntpgm_uint8_t *FONT_SMALL; 119 | static const u8g_fntpgm_uint8_t *FONT_NUMERIC; 120 | static const u8g_fntpgm_uint8_t *FONT_REGULAR; 121 | static const u8g_fntpgm_uint8_t *FONT_LARGE_NUMERIC; 122 | 123 | static Button encoderButton; 124 | #ifdef MILL_BUTTON 125 | static Button millButton; 126 | #endif 127 | #ifdef MILL_BUTTON_2 128 | static Button millButton2; 129 | #endif 130 | #ifdef BREW_BUTTON 131 | static Button brewButton; 132 | static Symbol BREW_SYMBOL; 133 | #endif 134 | static Rotator *rotator; 135 | 136 | #ifdef SCALE 137 | static Scale scale; 138 | #endif 139 | 140 | //Display object - defined below 141 | static U8GLIB u8g; 142 | 143 | //Display & Font settings 144 | static const unsigned char DISPLAY_WIDTH; 145 | static const unsigned char DISPLAY_HEIGHT; 146 | static const unsigned char BORDER_WIDTH; 147 | static const unsigned char LINE_HEIGHT; 148 | static const unsigned char SMALL_LINE_HEIGHT; 149 | static const unsigned char LARGE_LINE_HEIGHT; 150 | 151 | //Menu Symbols 152 | static const unsigned char SCALE_SYMBOL = SYMBOL_SCALE; 153 | static const unsigned char BACK_SYMBOL = SYMBOL_BACK; 154 | static const unsigned char OK_SYMBOL = SYMBOL_OK; 155 | 156 | //Menu Symbols 157 | static const unsigned char CHAR_BEGIN = REGULAR_BEGIN; 158 | static const unsigned char CHAR_END = REGULAR_END; 159 | 160 | //Draw Routines 161 | static void drawSubtitle(const char *text); 162 | 163 | static void drawTitle(const char *title); 164 | 165 | static void drawDirectionSymbol(const unsigned char x, const unsigned char y, const unsigned char height, 166 | const bool back, const unsigned char weight = 1); 167 | 168 | static void drawSymbol(unsigned char x, unsigned char y, unsigned char symbol, unsigned char line_height, 169 | const unsigned char border = 2, const unsigned char weight = 1); 170 | 171 | static void drawLargeSymbol(const unsigned char x, const unsigned char y, const unsigned char symbol); 172 | 173 | static void drawTimeLine(char line, const int data, unsigned char y, unsigned char x, bool grams, const bool small, 174 | bool selected, bool editor); 175 | 176 | static void drawRunTime(const unsigned char x, const unsigned char y, int seconds, bool small = false); 177 | 178 | static void drawRunWeight(const unsigned char x, const unsigned char y, int weight, bool small = false, 179 | unsigned char line = 0); 180 | 181 | static void drawEditPoint(const unsigned char p, const bool active, const unsigned char symbol); 182 | 183 | static void printData(char *c_t, const int data, const bool weightLine = false); 184 | 185 | static void drawProgressBar(const double progress); 186 | 187 | static void drawRunWeightLine(long weight, const unsigned char line); 188 | }; 189 | 190 | #endif //MILLCONTROL_UI_H -------------------------------------------------------------------------------- /MillControl/WeightCalibrationRun.cpp: -------------------------------------------------------------------------------- 1 | #include "WeightCalibrationRun.h" 2 | #include "MillControl.h" 3 | 4 | bool WeightCalibrationRun::open() { 5 | updateTime = 0; 6 | startTime = millis(); 7 | Run::startMill(); 8 | return true; 9 | } 10 | 11 | void WeightCalibrationRun::loop() { 12 | #ifdef MILL_BUTTON 13 | if (!UI::millButton.isPressed()) 14 | encoderClick(); 15 | #endif 16 | 17 | if (millis() > (updateTime + 250)) { 18 | updateTime = millis(); 19 | redraw(); 20 | } 21 | } 22 | 23 | //this is called when a fallback happens! 24 | bool WeightCalibrationRun::start() { 25 | //Convention is: Calibrator returns 0 if cancel occured 26 | int deciGrams = *MillControl::CALIBRATION_PROMPT.getData(); 27 | if (deciGrams) { 28 | long centiSecondsPerGram = getRunMillis() / MillControl::CALIBRATION_PROMPT.weight; 29 | if (centiSecondsPerGram > Mode::SPECIAL_DATA) 30 | centiSecondsPerGram = Mode::SPECIAL_DATA; 31 | MillControl::TIME_MODE_SELECTOR.getMode().calibration_data = centiSecondsPerGram; 32 | } 33 | return close(); 34 | } 35 | 36 | void WeightCalibrationRun::stop() { 37 | stopTime = millis(); 38 | Run::stopMill(); 39 | } 40 | 41 | void WeightCalibrationRun::millClick(unsigned char i) { 42 | encoderClick(); 43 | } 44 | 45 | 46 | void WeightCalibrationRun::encoderClick() { 47 | *MillControl::CALIBRATION_PROMPT.getData() = 70; 48 | MillControl::open(MillControl::CALIBRATION_PROMPT); 49 | } 50 | 51 | void WeightCalibrationRun::draw() { 52 | State::draw(); 53 | UI::drawSubtitle(UI::CALIBRATION_TITLE); 54 | 55 | #ifdef PORTRAIT_DISPLAY 56 | const char x= UI::DISPLAY_WIDTH - UI::SMALL_LINE_HEIGHT - UI::LINE_HEIGHT - UI::BORDER_WIDTH; 57 | const char y= UI::DISPLAY_HEIGHT - UI::BORDER_WIDTH - 1; 58 | #else 59 | const char x = UI::DISPLAY_WIDTH - UI::LINE_HEIGHT - 1; //89 60 | const char y = UI::DISPLAY_HEIGHT - 3 * UI::BORDER_WIDTH - 1;//57; 61 | #endif 62 | 63 | UI::drawRunTime(x, y, (millis() - startTime) / 1000); 64 | } 65 | 66 | unsigned long WeightCalibrationRun::getRunMillis() { 67 | return stopTime - startTime; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /MillControl/WeightCalibrationRun.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_WEIGHTCALIBRATONRUN_H 2 | #define MILLCONTROL_WEIGHTCALIBRATONRUN_H 3 | 4 | #include "BrewlessState.h" 5 | 6 | class WeightCalibrationRun : public BrewlessState { 7 | unsigned long startTime = 0; 8 | unsigned long stopTime = 0; 9 | unsigned long updateTime = 0; 10 | 11 | public: 12 | virtual bool open() override; 13 | virtual bool start() override; 14 | virtual void stop() override; 15 | 16 | virtual void loop() override; 17 | 18 | virtual void millClick(unsigned char i) override; 19 | virtual void encoderClick() override; 20 | 21 | virtual void draw() override; 22 | 23 | unsigned long getRunMillis(); 24 | 25 | #ifdef DEBUG 26 | virtual char* getClassName() {return (char *) "WeightCalibrationRun"; } 27 | #endif 28 | }; 29 | 30 | #endif //MILLCONTROL_WEIGHTCALIBRATONRUN_H -------------------------------------------------------------------------------- /MillControl/WeightRun.cpp: -------------------------------------------------------------------------------- 1 | #include "WeightRun.h" 2 | #include "MillControl.h" 3 | 4 | #ifdef SCALE 5 | 6 | bool WeightRun::start() { 7 | calibration_data = &mode->calibration_data; 8 | 9 | UI::scale.power_up(); 10 | UI::scale.tare(50); 11 | 12 | start_time = millis(); 13 | return Run::start(); 14 | } 15 | 16 | void WeightRun::loop() { 17 | if (millis() - start_time > STARTUP_DELAY) 18 | weight = max(0, UI::scale.get_floating_weight()); 19 | 20 | if (weight > (run_data + *calibration_data)) { 21 | //Stop Mill etc. 22 | Run::close(); 23 | //Learn how much the scale is missing out 24 | long weight = UI::scale.get_stable_weight(); 25 | long offset = run_data - weight; 26 | /* Serial.begin(9600); 27 | Serial.print("\n"); 28 | Serial.print(run_data); 29 | Serial.print(","); 30 | Serial.print(weight); 31 | Serial.print(","); 32 | Serial.print(offset); 33 | */ 34 | //only believe offsets up to 0.5 grams 35 | if (offset < 10 && offset > -10) { 36 | /* Serial.print(","); 37 | Serial.print(*calibration_data); 38 | */ 39 | *calibration_data = *calibration_data + (offset / 2); 40 | /* Serial.print(","); 41 | Serial.print(*calibration_data); 42 | */ 43 | MillControl::TIME_MODE_SELECTOR.timeModes.eepromWrite(); 44 | } 45 | // Serial.flush(); 46 | UI::scale.power_down(); 47 | } 48 | else 49 | Run::loop(); 50 | } 51 | 52 | bool WeightRun::close() { 53 | Run::close(); 54 | UI::scale.power_down(); 55 | } 56 | 57 | 58 | void WeightRun::draw() { 59 | Run::draw(); 60 | 61 | #ifdef PORTRAIT_DISPLAY 62 | const char x = UI::DISPLAY_WIDTH - UI::LINE_HEIGHT; 63 | const char y = UI::DISPLAY_HEIGHT - 12 * UI::BORDER_WIDTH; 64 | #else 65 | const char x = UI::DISPLAY_WIDTH - UI::LINE_HEIGHT; //115; 66 | const char y = UI::DISPLAY_HEIGHT - 6 * UI::BORDER_WIDTH; //53; 67 | #endif 68 | 69 | UI::drawRunWeight(x, y, weight); 70 | } 71 | 72 | void WeightRun::millClick(unsigned char i) { 73 | close(); 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /MillControl/WeightRun.h: -------------------------------------------------------------------------------- 1 | #ifndef MILLCONTROL_WEIGHTRUN_H 2 | #define MILLCONTROL_WEIGHTRUN_H 3 | 4 | 5 | #include "Run.h" 6 | 7 | class WeightRun : public Run { 8 | //The mill may produce interferences with the scale when starting -> wait for things to calm down 9 | static const int STARTUP_DELAY = 1000; 10 | 11 | int *calibration_data; 12 | long weight = 0; 13 | long start_time; 14 | Mode *mode; 15 | public: 16 | WeightRun(const unsigned char run_icon, const int run_data, Mode *mode) : Run(run_icon, run_data), mode(mode) { } 17 | 18 | virtual bool start() override; 19 | 20 | virtual bool close() override; 21 | 22 | virtual void loop() override; 23 | 24 | virtual void draw() override; 25 | 26 | virtual void millClick(unsigned char i) override; 27 | }; 28 | 29 | 30 | #endif //MILLCONTROL_WEIGHTRUN_H 31 | -------------------------------------------------------------------------------- /MillControl/cmake/ArduinoToolchain.cmake: -------------------------------------------------------------------------------- 1 | #=============================================================================# 2 | # Author: Tomasz Bogdal (QueezyTheGreat) 3 | # Home: https://github.com/queezythegreat/arduino-cmake 4 | # 5 | # This Source Code Form is subject to the terms of the Mozilla Public 6 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | # You can obtain one at http://mozilla.org/MPL/2.0/. 8 | #=============================================================================# 9 | set(CMAKE_SYSTEM_NAME Arduino) 10 | 11 | set(CMAKE_C_COMPILER avr-gcc) 12 | set(CMAKE_CXX_COMPILER avr-g++) 13 | 14 | # Add current directory to CMake Module path automatically 15 | if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/Platform/Arduino.cmake) 16 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}) 17 | endif() 18 | 19 | #=============================================================================# 20 | # System Paths # 21 | #=============================================================================# 22 | if(UNIX) 23 | include(Platform/UnixPaths) 24 | if(APPLE) 25 | list(APPEND CMAKE_SYSTEM_PREFIX_PATH ~/Applications 26 | /Applications 27 | /Developer/Applications 28 | /sw # Fink 29 | /opt/local) # MacPorts 30 | endif() 31 | elseif(WIN32) 32 | include(Platform/WindowsPaths) 33 | endif() 34 | 35 | 36 | #=============================================================================# 37 | # Detect Arduino SDK # 38 | #=============================================================================# 39 | 40 | if(NOT ARDUINO_SDK_PATH) 41 | set(ARDUINO_PATHS) 42 | 43 | foreach(DETECT_VERSION_MAJOR 1) 44 | foreach(DETECT_VERSION_MINOR RANGE 5 0) 45 | list(APPEND ARDUINO_PATHS arduino-${DETECT_VERSION_MAJOR}.${DETECT_VERSION_MINOR}) 46 | foreach(DETECT_VERSION_PATCH RANGE 3 0) 47 | list(APPEND ARDUINO_PATHS arduino-${DETECT_VERSION_MAJOR}.${DETECT_VERSION_MINOR}.${DETECT_VERSION_PATCH}) 48 | endforeach() 49 | endforeach() 50 | endforeach() 51 | 52 | foreach(VERSION RANGE 23 19) 53 | list(APPEND ARDUINO_PATHS arduino-00${VERSION}) 54 | endforeach() 55 | 56 | if(UNIX) 57 | file(GLOB SDK_PATH_HINTS /usr/share/arduino* 58 | /opt/local/arduino* 59 | /opt/arduino* 60 | /usr/local/share/arduino*) 61 | elseif(WIN32) 62 | set(SDK_PATH_HINTS "C:\\Program Files\\Arduino" 63 | "C:\\Program Files (x86)\\Arduino" 64 | ) 65 | endif() 66 | list(SORT SDK_PATH_HINTS) 67 | list(REVERSE SDK_PATH_HINTS) 68 | endif() 69 | message(ARDUINO_SDK_PATH) 70 | find_path(ARDUINO_SDK_PATH 71 | NAMES lib/version.txt 72 | PATH_SUFFIXES share/arduino 73 | Arduino.app/Contents/Java/ 74 | Arduino.app/Contents/Resources/Java/ 75 | ${ARDUINO_PATHS} 76 | HINTS ${SDK_PATH_HINTS} 77 | DOC "Arduino SDK path.") 78 | 79 | if(ARDUINO_SDK_PATH) 80 | list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr) 81 | list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr/utils) 82 | else() 83 | message(FATAL_ERROR "Could not find Arduino SDK (set ARDUINO_SDK_PATH)!") 84 | endif() 85 | 86 | set(ARDUINO_CPUMENU) 87 | if(ARDUINO_CPU) 88 | set(ARDUINO_CPUMENU ".menu.cpu.${ARDUINO_CPU}") 89 | endif(ARDUINO_CPU) 90 | 91 | -------------------------------------------------------------------------------- /MillControl/cmake/ArduinoToolchain.cmake~: -------------------------------------------------------------------------------- 1 | #=============================================================================# 2 | # Author: Tomasz Bogdal (QueezyTheGreat) 3 | # Home: https://github.com/queezythegreat/arduino-cmake 4 | # 5 | # This Source Code Form is subject to the terms of the Mozilla Public 6 | # License, v. 2.0. If a copy of the MPL was not distributed with this file, 7 | # You can obtain one at http://mozilla.org/MPL/2.0/. 8 | #=============================================================================# 9 | set(CMAKE_SYSTEM_NAME Arduino) 10 | 11 | set(CMAKE_C_COMPILER avr-gcc) 12 | set(CMAKE_CXX_COMPILER avr-g++) 13 | 14 | # Add current directory to CMake Module path automatically 15 | if(EXISTS ${CMAKE_CURRENT_LIST_DIR}/Platform/Arduino.cmake) 16 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}) 17 | endif() 18 | 19 | #=============================================================================# 20 | # System Paths # 21 | #=============================================================================# 22 | if(UNIX) 23 | include(Platform/UnixPaths) 24 | if(APPLE) 25 | list(APPEND CMAKE_SYSTEM_PREFIX_PATH ~/Applications 26 | /Applications 27 | /Developer/Applications 28 | /sw # Fink 29 | /opt/local) # MacPorts 30 | endif() 31 | elseif(WIN32) 32 | include(Platform/WindowsPaths) 33 | endif() 34 | 35 | 36 | #=============================================================================# 37 | # Detect Arduino SDK # 38 | #=============================================================================# 39 | 40 | 41 | find_path(ARDUINO_SDK_PATH 42 | NAMES lib/version.txt 43 | PATH_SUFFIXES share/arduino 44 | Arduino.app/Contents/Java/ 45 | Arduino.app/Contents/Resources/Java/ 46 | ${ARDUINO_PATHS} 47 | HINTS ${SDK_PATH_HINTS} 48 | DOC "Arduino SDK path.") 49 | 50 | if(ARDUINO_SDK_PATH) 51 | list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr) 52 | list(APPEND CMAKE_SYSTEM_PREFIX_PATH ${ARDUINO_SDK_PATH}/hardware/tools/avr/utils) 53 | else() 54 | message(FATAL_ERROR "Could not find Arduino SDK (set ARDUINO_SDK_PATH)!") 55 | endif() 56 | 57 | set(ARDUINO_CPUMENU) 58 | if(ARDUINO_CPU) 59 | set(ARDUINO_CPUMENU ".menu.cpu.${ARDUINO_CPU}") 60 | endif(ARDUINO_CPU) 61 | 62 | -------------------------------------------------------------------------------- /MillControl/fonts/bdffont.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import urllib, sys, os, io, math, platform, re 4 | import Image, ImageDraw 5 | from bdflib import reader, writer 6 | 7 | if len(sys.argv) != 3 or sys.argv[2] not in ['numeric', 'symbol', 'regular']: 8 | print "Usage: fontname [numeric | symbol | regular]" 9 | print "fontname is as local filename or on https://github.com/olikraus/u8glib/tree/master/tools/font/bdf" 10 | sys.exit() 11 | 12 | mode = sys.argv[2] 13 | 14 | #------------------------------------------------------------------------------- 15 | # font download 16 | 17 | fontname = sys.argv[1] 18 | filename = "%s.bdf" % fontname 19 | if not os.path.isfile(filename): 20 | response = urllib.urlopen('https://raw.githubusercontent.com/olikraus/u8glib/master/tools/font/bdf/%s' % filename) 21 | src_bdf = response.read() 22 | else: 23 | with open(filename, 'r') as bdf_file: 24 | src_bdf=bdf_file.read() 25 | src_bdf.close() 26 | 27 | font = reader.read_bdf(iter(src_bdf.splitlines())) 28 | 29 | def asc(s): 30 | return ord(s.decode('utf-8').encode('iso-8859-1')) 31 | 32 | #------------------------------------------------------------------------------- 33 | # copy one glyph over another 34 | 35 | def replace(t, f): 36 | fr = font[asc(f)] 37 | to = font[asc(t)] 38 | #font.glyphs_by_codepoint[to] = font.glyphs_by_codepoint[fr] 39 | to.name = fr.name 40 | to.bbX = fr.bbX 41 | to.bbY = fr.bbY 42 | to.bbW = fr.bbW 43 | to.bbH = fr.bbH 44 | to.advance = fr.advance 45 | #to.codepoint = fr.codepoint 46 | to._set_data(fr.get_data()) 47 | 48 | #------------------------------------------------------------------------------ 49 | # dumps animage to bdf format 50 | 51 | def image_to_glyph(name, im, glyph, template = None): 52 | to = font[asc(glyph)] 53 | 54 | define = "#define SYMBOL_%s %i\n" % (name, asc(glyph)) 55 | 56 | if not template: 57 | template = glyph 58 | fr = font[asc(template)] 59 | 60 | hex_dump = [ "%02x" % ord(i) for i in im.tostring() ] 61 | 62 | #calc number of bytes per row 63 | parts = int(math.ceil(im.width / 8.0)) 64 | 65 | #concat the rows 66 | rows = [] 67 | for i in range(0, len(hex_dump), parts): 68 | rows.append("".join(hex_dump[i:i+parts])) 69 | 70 | #to.name = fr.name 71 | to.bbX = fr.bbX 72 | to.bbY = fr.bbY 73 | to.advance = im.width + (fr.advance - fr.bbW) #keeps the old spacing 74 | to.bbW = im.width 75 | to.bbH = im.height 76 | to._set_data(rows) 77 | 78 | return define 79 | 80 | #------------------------------------------------------------------------------- 81 | # special characters 82 | 83 | if not mode == 'numeric': 84 | #add umlauts 85 | replace('[', 'ä') 86 | replace('\\', 'ö') 87 | replace(']', 'ü') 88 | replace('{', 'Ä') 89 | replace('|', 'Ö') 90 | replace('}', 'Ü') 91 | replace('~', 'ß') 92 | 93 | #------------------------------------------------------------------------------- 94 | # symbols 95 | 96 | defines = "" 97 | if mode == 'regular': 98 | replace('<', '(') 99 | replace('>', ')') 100 | replace('=', '!') 101 | replace('@', ' ') 102 | 103 | if mode == 'symbol': 104 | replace('[', '(') 105 | replace(']', ')') 106 | 107 | #ok 108 | def ok(width): 109 | s = int(width * 0.3); 110 | height = width - s 111 | im = Image.new("1", (width, height), 0) 112 | draw = ImageDraw.Draw(im) 113 | draw.line([(0, height - s - 2), (s, height - 2), ((width - 1), (height - (width - s) - 1))], fill = 1, width = 2); 114 | return im 115 | 116 | defines += image_to_glyph('OK', ok(font[asc('A')].bbW), '_', 'A') 117 | 118 | #scale 119 | def scale(width, height): 120 | im = Image.new("1", (width, height), 0) 121 | draw = ImageDraw.Draw(im) 122 | s = int(im.width * 0.35); 123 | draw.ellipse([(0, im.height - 1 - s * 2), (im.width -1, im.height -1)], fill = 1, outline = 1) 124 | draw.rectangle([(0, im.height - 1 - s * 2), (im.width -1, im.height - 1 - s * 1)], fill = 0) 125 | draw.line([(1, im.height - 1 - s), ((im.width / 2 - 1), 1), ((im.width - 2), im.height - 1 - s)], fill = 1, width = 2); 126 | return im 127 | 128 | t = font[asc('A')] 129 | defines += image_to_glyph('SCALE', scale(t.bbW, t.bbH), '\\','A') 130 | 131 | #back 132 | def back(h): 133 | w0 = ((h-1) / 2) 134 | w1 = 0 135 | w = w0 + 6 136 | im = Image.new("1", (w, h), 0) 137 | draw = ImageDraw.Draw(im) 138 | for l in range(0,2): 139 | for c in range(0,2): 140 | x1 = c + l * 4; 141 | draw.line([(x1 + w0, 0), (x1, w0), (x1 + w0, w0 * 2)], fill = 1) 142 | return im 143 | t = font[asc(':')] 144 | defines += image_to_glyph('BACK', back(t.bbH), '^','a') 145 | 146 | #------------------------------------------------------------------------------ 147 | # write font 148 | fontname = fontname + mode[0] 149 | filename = "%s.bdf" % fontname 150 | with io.open(filename, 'wb') as file: 151 | writer.write_bdf(font, file) 152 | file.close() 153 | 154 | #------------------------------------------------------------------------------ 155 | # export to u8g 156 | 157 | #load bdf2u8g 158 | cmd_file = 'bdf2u8g.exe' 159 | urllib.urlretrieve ('https://github.com/olikraus/u8glib/raw/master/tools/font/bdf2u8g/bdf2u8g.exe', cmd_file) 160 | 161 | if platform.system() != 'Windows': 162 | cmd_file = 'wine ' + cmd_file 163 | 164 | if mode == 'numeric': 165 | begin = asc('.') 166 | end = asc('9') 167 | if mode == 'regular': 168 | begin = asc('.') 169 | end = asc('~') 170 | if mode == 'symbol': 171 | begin = asc('+') 172 | end = asc('~') 173 | 174 | defines += "#define %s_BEGIN %i\n" % (mode.upper(), begin) 175 | defines += "#define %s_END %i\n" % (mode.upper(), end) 176 | 177 | header_filename = "../%s.h" % fontname 178 | cmd = cmd_file + " -b %i -e %i %s %s %s" % (begin, end, filename, fontname, header_filename) 179 | print cmd 180 | os.system(cmd) 181 | 182 | with open(header_filename, 'r') as header_file: 183 | headers=header_file.read() 184 | header_file.close() 185 | 186 | headers = headers.replace('#include "u8g.h"','#include \n' + defines) 187 | headername = "%s_H" % fontname.upper() 188 | headers = "#ifndef %s\n#define %s\n" % (headername, headername) + headers + ("#endif //%s_H\n" % headername) 189 | 190 | #endif //MILLCONTROL_RUN_H 191 | with io.open(header_filename, 'wb') as header_file: 192 | header_file.write(headers) 193 | header_file.close() 194 | 195 | #needs bdflib and urllib 196 | #what fonts do i need? 197 | 198 | #heading font 199 | #numbers font 200 | #symbol font 201 | -------------------------------------------------------------------------------- /MillControl/fub20bn.h: -------------------------------------------------------------------------------- 1 | /* 2 | Fontname: -FreeType-FreeUniversal-Bold-R-Normal--28-200-100-100-P-139-ISO10646-1 3 | Copyright: FreeUniveral (c) Stephen Wilson 2009 Original Font Sil-Sophia Copyright (c) SIL International, 1994-2008. 4 | Capital A Height: 0, '1' Height: 20 5 | Calculated Max Values w=14 h=22 x= 3 y= 0 dx=16 dy= 0 ascent=21 len=44 6 | Font Bounding box w=41 h=37 x=-2 y=-7 7 | Calculated Min Values x= 0 y=-1 dx= 0 dy= 0 8 | Pure Font ascent =20 descent= 0 9 | X Font ascent =20 descent= 0 10 | Max Font ascent =21 descent=-1 11 | */ 12 | #include 13 | 14 | const u8g_fntpgm_uint8_t fub20bn[529] U8G_FONT_SECTION("fub20bn") = { 15 | 0, 41, 37, 254, 249, 20, 0, 0, 0, 0, 46, 57, 0, 21, 255, 20, 16 | 0, 3, 4, 4, 8, 3, 0, 224, 224, 224, 224, 9, 22, 44, 12, 2, 17 | 255, 3, 128, 3, 0, 7, 0, 7, 0, 6, 0, 14, 0, 14, 0, 14, 18 | 0, 28, 0, 28, 0, 28, 0, 24, 0, 56, 0, 56, 0, 48, 0, 112, 19 | 0, 112, 0, 112, 0, 224, 0, 224, 0, 224, 0, 192, 0, 14, 21, 42, 20 | 16, 1, 0, 3, 0, 31, 224, 63, 240, 124, 248, 120, 120, 112, 56, 240, 21 | 60, 240, 60, 240, 60, 240, 60, 240, 60, 240, 60, 240, 60, 240, 60, 240, 22 | 60, 240, 60, 120, 120, 120, 120, 63, 240, 63, 240, 15, 224, 8, 20, 20, 23 | 16, 3, 0, 15, 31, 127, 255, 247, 199, 7, 7, 7, 7, 7, 7, 7, 24 | 7, 7, 7, 7, 7, 7, 7, 14, 21, 42, 16, 1, 0, 1, 0, 31, 25 | 240, 63, 248, 127, 252, 120, 60, 120, 60, 0, 60, 0, 60, 0, 124, 0, 26 | 120, 0, 248, 1, 240, 3, 224, 7, 192, 31, 128, 62, 0, 124, 0, 248, 27 | 0, 255, 252, 255, 252, 255, 252, 14, 21, 42, 16, 1, 0, 3, 0, 31, 28 | 224, 63, 240, 127, 248, 248, 120, 240, 120, 0, 120, 0, 120, 0, 248, 7, 29 | 224, 7, 192, 7, 240, 0, 248, 0, 120, 0, 60, 240, 60, 240, 60, 120, 30 | 120, 127, 248, 63, 240, 31, 224, 14, 20, 40, 16, 1, 0, 1, 240, 3, 31 | 240, 7, 240, 7, 240, 15, 240, 14, 240, 28, 240, 60, 240, 56, 240, 120, 32 | 240, 240, 240, 240, 240, 255, 252, 255, 252, 255, 252, 255, 252, 0, 240, 0, 33 | 240, 0, 240, 0, 240, 14, 20, 40, 16, 1, 0, 127, 248, 127, 248, 127, 34 | 248, 120, 0, 120, 0, 112, 0, 112, 0, 119, 224, 127, 240, 255, 248, 248, 35 | 124, 240, 60, 0, 60, 0, 60, 0, 60, 240, 60, 240, 120, 127, 248, 127, 36 | 240, 31, 192, 14, 21, 42, 16, 1, 0, 3, 128, 15, 224, 31, 240, 62, 37 | 248, 124, 120, 120, 60, 112, 0, 240, 0, 243, 224, 247, 240, 255, 248, 252, 38 | 124, 248, 60, 248, 60, 248, 60, 248, 60, 120, 60, 120, 120, 127, 248, 63, 39 | 240, 31, 224, 14, 20, 40, 16, 1, 0, 255, 252, 255, 252, 255, 252, 0, 40 | 60, 0, 120, 0, 120, 0, 248, 0, 240, 0, 240, 1, 224, 1, 224, 3, 41 | 224, 3, 192, 7, 192, 7, 128, 15, 128, 15, 0, 31, 0, 31, 0, 30, 42 | 0, 14, 21, 42, 16, 1, 0, 3, 0, 63, 240, 127, 248, 127, 248, 248, 43 | 124, 248, 60, 248, 60, 120, 120, 124, 248, 31, 224, 31, 224, 63, 240, 120, 44 | 120, 240, 60, 240, 60, 240, 60, 240, 60, 248, 124, 127, 252, 127, 248, 31, 45 | 224, 14, 21, 42, 16, 1, 0, 3, 0, 31, 224, 63, 240, 127, 248, 120, 46 | 120, 240, 124, 240, 60, 240, 60, 240, 124, 240, 124, 120, 252, 127, 252, 63, 47 | 188, 14, 60, 0, 60, 0, 56, 240, 120, 120, 248, 127, 240, 63, 224, 31, 48 | 192}; 49 | -------------------------------------------------------------------------------- /MillControl/helvB10s.h: -------------------------------------------------------------------------------- 1 | #ifndef HELVB10S_H 2 | #define HELVB10S_H 3 | /* 4 | Fontname: -Adobe-Helvetica-Bold-R-Normal--14-100-100-100-P-82-ISO10646-1 5 | Copyright: Copyright (c) 1984, 1987 Adobe Systems Incorporated. All Rights Reserved. Copyright (c) 1988, 1991 Digital Equipment Corporation. All Rights Reserved. 6 | Capital A Height: 11, '1' Height: 11 7 | Calculated Max Values w=14 h=14 x= 2 y= 9 dx=14 dy= 0 ascent=14 len=28 8 | Font Bounding box w=17 h=23 x=-1 y=-6 9 | Calculated Min Values x= 0 y=-3 dx= 0 dy= 0 10 | Pure Font ascent =11 descent=-3 11 | X Font ascent =11 descent=-3 12 | Max Font ascent =14 descent=-3 13 | */ 14 | #include 15 | 16 | #define SYMBOL_OK 95 17 | #define SYMBOL_SCALE 92 18 | #define SYMBOL_BACK 94 19 | #define SYMBOL_BEGIN 43 20 | #define SYMBOL_END 126 21 | 22 | const u8g_fntpgm_uint8_t helvB10s[1609] U8G_FONT_SECTION("helvB10s") = { 23 | 0, 17, 23, 255, 250, 11, 1, 92, 4, 45, 43, 126, 253, 14, 253, 11, 24 | 253, 8, 7, 7, 9, 0, 1, 24, 24, 24, 255, 24, 24, 24, 3, 3, 25 | 3, 4, 0, 255, 96, 96, 192, 3, 1, 1, 4, 0, 4, 224, 2, 2, 26 | 2, 4, 1, 0, 192, 192, 4, 11, 11, 4, 0, 0, 16, 16, 48, 32, 27 | 32, 96, 64, 64, 192, 128, 128, 7, 11, 11, 8, 0, 0, 56, 108, 198, 28 | 198, 198, 198, 198, 198, 198, 108, 56, 4, 11, 11, 8, 1, 0, 48, 240, 29 | 48, 48, 48, 48, 48, 48, 48, 48, 48, 7, 11, 11, 8, 0, 0, 124, 30 | 198, 198, 6, 14, 12, 24, 48, 96, 192, 254, 7, 11, 11, 8, 0, 0, 31 | 124, 198, 198, 6, 6, 60, 6, 6, 198, 198, 124, 8, 11, 11, 8, 0, 32 | 0, 6, 14, 30, 54, 102, 198, 198, 255, 6, 6, 6, 7, 11, 11, 8, 33 | 0, 0, 126, 96, 96, 192, 252, 14, 6, 6, 198, 204, 120, 7, 11, 11, 34 | 8, 0, 0, 60, 102, 102, 192, 220, 230, 198, 198, 198, 198, 124, 7, 11, 35 | 11, 8, 0, 0, 254, 6, 12, 12, 24, 24, 48, 48, 96, 96, 96, 7, 36 | 11, 11, 8, 0, 0, 124, 198, 198, 198, 198, 124, 198, 198, 198, 198, 124, 37 | 7, 11, 11, 8, 0, 0, 124, 198, 198, 198, 198, 198, 126, 6, 198, 204, 38 | 120, 2, 8, 8, 5, 2, 0, 192, 192, 0, 0, 0, 0, 192, 192, 3, 39 | 9, 9, 5, 1, 255, 96, 96, 0, 0, 0, 0, 96, 96, 192, 6, 5, 40 | 5, 8, 1, 2, 28, 112, 192, 112, 28, 7, 3, 3, 9, 1, 3, 254, 41 | 0, 254, 6, 5, 5, 8, 1, 2, 224, 56, 12, 56, 224, 7, 11, 11, 42 | 9, 1, 0, 124, 198, 198, 6, 12, 24, 48, 48, 0, 48, 48, 13, 12, 43 | 24, 14, 0, 255, 15, 128, 56, 224, 112, 112, 102, 176, 205, 152, 217, 152, 44 | 219, 24, 219, 48, 206, 224, 96, 0, 49, 128, 31, 0, 10, 11, 22, 10, 45 | 0, 0, 12, 0, 12, 0, 30, 0, 18, 0, 51, 0, 51, 0, 97, 128, 46 | 127, 128, 97, 128, 192, 192, 192, 192, 8, 11, 11, 10, 1, 0, 254, 199, 47 | 195, 195, 198, 252, 198, 195, 195, 199, 254, 9, 11, 22, 11, 1, 0, 31, 48 | 0, 123, 128, 96, 128, 192, 0, 192, 0, 192, 0, 192, 0, 192, 0, 96, 49 | 128, 123, 128, 31, 0, 9, 11, 22, 11, 1, 0, 252, 0, 199, 0, 195, 50 | 0, 193, 128, 193, 128, 193, 128, 193, 128, 193, 128, 195, 0, 199, 0, 252, 51 | 0, 7, 11, 11, 9, 1, 0, 254, 192, 192, 192, 192, 254, 192, 192, 192, 52 | 192, 254, 7, 11, 11, 9, 1, 0, 254, 192, 192, 192, 192, 252, 192, 192, 53 | 192, 192, 192, 9, 11, 22, 11, 1, 0, 31, 0, 123, 128, 96, 128, 192, 54 | 0, 192, 0, 199, 128, 193, 128, 193, 128, 97, 128, 123, 128, 30, 128, 8, 55 | 11, 11, 10, 1, 0, 195, 195, 195, 195, 195, 255, 195, 195, 195, 195, 195, 56 | 2, 11, 11, 4, 1, 0, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 57 | 192, 7, 11, 11, 8, 0, 0, 6, 6, 6, 6, 6, 6, 6, 198, 198, 58 | 238, 124, 9, 11, 22, 10, 1, 0, 195, 0, 198, 0, 204, 0, 216, 0, 59 | 240, 0, 240, 0, 216, 0, 204, 0, 198, 0, 195, 0, 193, 128, 7, 11, 60 | 11, 8, 1, 0, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 254, 11, 61 | 11, 22, 13, 1, 0, 192, 96, 192, 96, 224, 224, 224, 224, 241, 224, 209, 62 | 96, 209, 96, 219, 96, 202, 96, 206, 96, 196, 96, 9, 11, 22, 11, 1, 63 | 0, 193, 128, 225, 128, 225, 128, 209, 128, 217, 128, 201, 128, 205, 128, 197, 64 | 128, 195, 128, 195, 128, 193, 128, 10, 11, 22, 12, 1, 0, 30, 0, 115, 65 | 128, 97, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 97, 128, 115, 66 | 128, 30, 0, 8, 11, 11, 10, 1, 0, 254, 199, 195, 195, 199, 254, 192, 67 | 192, 192, 192, 192, 10, 11, 22, 12, 1, 0, 30, 0, 115, 128, 97, 128, 68 | 192, 192, 192, 192, 192, 192, 192, 192, 198, 192, 99, 128, 115, 128, 30, 192, 69 | 9, 11, 22, 11, 1, 0, 254, 0, 199, 0, 195, 0, 195, 0, 198, 0, 70 | 254, 0, 199, 0, 195, 0, 195, 0, 195, 0, 193, 128, 8, 11, 11, 10, 71 | 1, 0, 126, 231, 195, 224, 120, 30, 7, 3, 195, 238, 124, 8, 11, 11, 72 | 8, 0, 0, 255, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 9, 11, 73 | 22, 11, 1, 0, 193, 128, 193, 128, 193, 128, 193, 128, 193, 128, 193, 128, 74 | 193, 128, 193, 128, 193, 128, 99, 0, 62, 0, 10, 11, 22, 10, 0, 0, 75 | 192, 192, 192, 192, 97, 128, 97, 128, 115, 128, 51, 0, 51, 0, 30, 0, 76 | 30, 0, 12, 0, 12, 0, 14, 11, 22, 14, 0, 0, 195, 12, 195, 12, 77 | 195, 12, 103, 152, 100, 152, 100, 152, 108, 216, 44, 208, 56, 112, 24, 96, 78 | 24, 96, 9, 11, 22, 9, 0, 0, 193, 128, 193, 128, 99, 0, 54, 0, 79 | 28, 0, 28, 0, 54, 0, 99, 0, 99, 0, 193, 128, 193, 128, 10, 11, 80 | 22, 10, 0, 0, 192, 192, 97, 128, 97, 128, 51, 0, 51, 0, 30, 0, 81 | 30, 0, 12, 0, 12, 0, 12, 0, 12, 0, 8, 11, 11, 9, 0, 0, 82 | 255, 3, 6, 12, 28, 24, 48, 112, 96, 192, 255, 4, 14, 14, 5, 1, 83 | 253, 48, 96, 96, 192, 192, 192, 192, 192, 192, 192, 192, 96, 96, 48, 10, 84 | 10, 20, 10, 0, 0, 28, 0, 30, 0, 54, 0, 39, 0, 99, 128, 65, 85 | 128, 193, 192, 255, 128, 255, 128, 62, 0, 4, 14, 14, 5, 0, 253, 192, 86 | 96, 96, 48, 48, 48, 48, 48, 48, 48, 48, 96, 96, 192, 9, 7, 14, 87 | 10, 1, 1, 25, 128, 51, 0, 102, 0, 204, 0, 102, 0, 51, 0, 25, 88 | 128, 10, 7, 14, 10, 0, 0, 1, 192, 3, 128, 71, 0, 238, 0, 124, 89 | 0, 56, 0, 16, 0, 3, 2, 2, 5, 1, 9, 192, 96, 7, 8, 8, 90 | 8, 1, 0, 120, 204, 12, 124, 204, 204, 220, 118, 7, 11, 11, 9, 1, 91 | 0, 192, 192, 192, 216, 236, 198, 198, 198, 198, 236, 216, 6, 8, 8, 8, 92 | 1, 0, 56, 108, 204, 192, 192, 204, 108, 56, 7, 11, 11, 9, 1, 0, 93 | 6, 6, 6, 54, 110, 198, 198, 198, 198, 110, 54, 6, 8, 8, 8, 1, 94 | 0, 120, 204, 204, 252, 192, 192, 236, 120, 5, 11, 11, 4, 0, 0, 56, 95 | 96, 96, 240, 96, 96, 96, 96, 96, 96, 96, 7, 11, 11, 9, 1, 253, 96 | 58, 110, 198, 198, 198, 198, 110, 54, 6, 206, 124, 7, 11, 11, 9, 1, 97 | 0, 192, 192, 192, 220, 238, 198, 198, 198, 198, 198, 198, 2, 11, 11, 4, 98 | 1, 0, 192, 192, 0, 192, 192, 192, 192, 192, 192, 192, 192, 3, 14, 14, 99 | 4, 0, 253, 96, 96, 0, 96, 96, 96, 96, 96, 96, 96, 96, 96, 224, 100 | 192, 6, 11, 11, 8, 1, 0, 192, 192, 192, 204, 216, 240, 240, 216, 216, 101 | 204, 204, 2, 11, 11, 4, 1, 0, 192, 192, 192, 192, 192, 192, 192, 192, 102 | 192, 192, 192, 10, 8, 16, 12, 1, 0, 219, 128, 238, 192, 204, 192, 204, 103 | 192, 204, 192, 204, 192, 204, 192, 204, 192, 7, 8, 8, 9, 1, 0, 220, 104 | 238, 198, 198, 198, 198, 198, 198, 7, 8, 8, 9, 1, 0, 56, 108, 198, 105 | 198, 198, 198, 108, 56, 7, 11, 11, 9, 1, 253, 216, 236, 198, 198, 198, 106 | 198, 236, 216, 192, 192, 192, 7, 11, 11, 9, 1, 253, 54, 110, 198, 198, 107 | 198, 198, 110, 54, 6, 6, 6, 5, 8, 8, 6, 1, 0, 216, 248, 192, 108 | 192, 192, 192, 192, 192, 6, 8, 8, 8, 1, 0, 120, 204, 224, 120, 28, 109 | 12, 236, 120, 5, 10, 10, 5, 0, 0, 96, 96, 248, 96, 96, 96, 96, 110 | 96, 104, 48, 7, 8, 8, 9, 1, 0, 198, 198, 198, 198, 198, 198, 238, 111 | 118, 8, 8, 8, 8, 0, 0, 195, 195, 102, 102, 36, 60, 24, 24, 10, 112 | 8, 16, 10, 0, 0, 204, 192, 204, 192, 204, 192, 109, 128, 109, 128, 51, 113 | 0, 51, 0, 51, 0, 7, 8, 8, 7, 0, 0, 198, 198, 108, 56, 56, 114 | 108, 198, 198, 8, 11, 11, 8, 0, 253, 195, 195, 102, 102, 36, 60, 24, 115 | 24, 24, 48, 112, 6, 8, 8, 6, 0, 0, 252, 12, 24, 48, 48, 96, 116 | 192, 252, 10, 14, 28, 10, 0, 0, 51, 0, 51, 0, 0, 0, 12, 0, 117 | 12, 0, 30, 0, 18, 0, 51, 0, 51, 0, 97, 128, 127, 128, 97, 128, 118 | 192, 192, 192, 192, 10, 14, 28, 12, 1, 0, 51, 0, 51, 0, 0, 0, 119 | 30, 0, 115, 128, 97, 128, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 120 | 97, 128, 115, 128, 30, 0, 9, 14, 28, 11, 1, 0, 99, 0, 99, 0, 121 | 0, 0, 193, 128, 193, 128, 193, 128, 193, 128, 193, 128, 193, 128, 193, 128, 122 | 193, 128, 193, 128, 99, 0, 62, 0, 6, 11, 11, 8, 1, 0, 120, 204, 123 | 204, 204, 216, 216, 204, 204, 204, 204, 216}; 124 | #endif //HELVB10S_H_H 125 | -------------------------------------------------------------------------------- /MillControl/helvB14r.h: -------------------------------------------------------------------------------- 1 | #ifndef HELVB14R_H 2 | #define HELVB14R_H 3 | /* 4 | Fontname: -Adobe-Helvetica-Bold-R-Normal--20-140-100-100-P-105-ISO10646-1 5 | Copyright: Copyright (c) 1984, 1987 Adobe Systems Incorporated. All Rights Reserved. Copyright (c) 1988, 1991 Digital Equipment Corporation. All Rights Reserved. 6 | Capital A Height: 14, '1' Height: 13 7 | Calculated Max Values w=15 h=18 x= 2 y=11 dx=17 dy= 0 ascent=18 len=36 8 | Font Bounding box w=22 h=29 x=-2 y=-7 9 | Calculated Min Values x=-1 y=-4 dx= 0 dy= 0 10 | Pure Font ascent =14 descent=-4 11 | X Font ascent =14 descent=-4 12 | Max Font ascent =18 descent=-4 13 | */ 14 | #include 15 | 16 | #define REGULAR_BEGIN 46 17 | #define REGULAR_END 126 18 | 19 | const u8g_fntpgm_uint8_t helvB14r[2334] U8G_FONT_SECTION("helvB14r") = { 20 | 0, 22, 29, 254, 249, 14, 1, 226, 5, 215, 46, 126, 252, 18, 252, 14, 21 | 252, 3, 3, 3, 5, 1, 0, 224, 224, 224, 5, 14, 14, 5, 0, 0, 22 | 24, 24, 24, 56, 48, 48, 48, 112, 96, 96, 224, 192, 192, 192, 9, 13, 23 | 26, 10, 0, 0, 28, 0, 127, 0, 119, 0, 227, 128, 227, 128, 227, 128, 24 | 227, 128, 227, 128, 227, 128, 227, 128, 119, 0, 127, 0, 28, 0, 6, 13, 25 | 13, 10, 1, 0, 28, 60, 252, 252, 28, 28, 28, 28, 28, 28, 28, 28, 26 | 28, 9, 13, 26, 10, 0, 0, 62, 0, 127, 0, 227, 128, 227, 128, 3, 27 | 128, 7, 0, 31, 0, 62, 0, 120, 0, 112, 0, 224, 0, 255, 128, 255, 28 | 128, 9, 13, 26, 10, 0, 0, 62, 0, 127, 0, 231, 0, 227, 0, 7, 29 | 0, 30, 0, 31, 0, 7, 128, 3, 128, 227, 128, 231, 128, 127, 0, 62, 30 | 0, 9, 13, 26, 10, 0, 0, 7, 0, 15, 0, 31, 0, 63, 0, 55, 31 | 0, 119, 0, 103, 0, 231, 0, 255, 128, 255, 128, 7, 0, 7, 0, 7, 32 | 0, 9, 13, 26, 10, 0, 0, 255, 0, 255, 0, 224, 0, 224, 0, 254, 33 | 0, 255, 0, 231, 128, 3, 128, 3, 128, 227, 128, 231, 128, 255, 0, 126, 34 | 0, 9, 13, 26, 10, 0, 0, 63, 0, 127, 128, 113, 128, 224, 0, 238, 35 | 0, 255, 0, 243, 128, 225, 128, 225, 128, 225, 128, 243, 128, 127, 0, 62, 36 | 0, 9, 13, 26, 10, 0, 0, 255, 128, 255, 128, 3, 128, 7, 0, 14, 37 | 0, 14, 0, 28, 0, 28, 0, 56, 0, 56, 0, 112, 0, 112, 0, 112, 38 | 0, 9, 13, 26, 10, 0, 0, 62, 0, 127, 0, 227, 128, 227, 128, 227, 39 | 128, 127, 0, 62, 0, 119, 0, 227, 128, 227, 128, 227, 128, 127, 0, 62, 40 | 0, 9, 13, 26, 10, 0, 0, 62, 0, 127, 0, 231, 128, 195, 128, 195, 41 | 128, 195, 128, 231, 128, 127, 128, 59, 128, 3, 128, 199, 0, 255, 0, 126, 42 | 0, 3, 10, 10, 6, 1, 0, 224, 224, 224, 0, 0, 0, 0, 224, 224, 43 | 224, 3, 13, 13, 6, 1, 253, 224, 224, 224, 0, 0, 0, 0, 224, 224, 44 | 224, 96, 192, 128, 6, 18, 18, 7, 1, 252, 28, 56, 48, 112, 96, 224, 45 | 224, 224, 224, 224, 224, 224, 224, 96, 112, 48, 56, 28, 3, 14, 14, 5, 46 | 1, 0, 224, 224, 224, 224, 224, 224, 224, 224, 192, 192, 0, 224, 224, 224, 47 | 6, 18, 18, 7, 0, 252, 224, 112, 48, 56, 24, 28, 28, 28, 28, 28, 48 | 28, 28, 28, 24, 56, 48, 112, 224, 8, 14, 14, 10, 1, 0, 126, 255, 49 | 231, 231, 14, 30, 28, 56, 56, 56, 0, 56, 56, 56, 0, 0, 0, 5, 50 | 0, 1, 12, 14, 28, 14, 1, 0, 15, 0, 15, 0, 31, 128, 25, 128, 51 | 25, 128, 57, 192, 57, 192, 48, 192, 112, 224, 127, 224, 127, 224, 224, 112, 52 | 224, 112, 224, 112, 11, 14, 28, 14, 2, 0, 254, 0, 255, 128, 227, 192, 53 | 225, 192, 225, 192, 227, 128, 255, 128, 255, 192, 225, 224, 224, 224, 224, 224, 54 | 225, 224, 255, 192, 255, 0, 12, 14, 28, 14, 1, 0, 15, 128, 63, 224, 55 | 120, 224, 112, 112, 240, 112, 224, 0, 224, 0, 224, 0, 224, 0, 240, 112, 56 | 112, 112, 120, 224, 63, 224, 15, 128, 12, 14, 28, 14, 1, 0, 255, 0, 57 | 255, 192, 225, 224, 224, 224, 224, 112, 224, 112, 224, 112, 224, 112, 224, 112, 58 | 224, 112, 224, 224, 225, 224, 255, 192, 255, 0, 10, 14, 28, 13, 2, 0, 59 | 255, 192, 255, 192, 224, 0, 224, 0, 224, 0, 224, 0, 255, 128, 255, 128, 60 | 224, 0, 224, 0, 224, 0, 224, 0, 255, 192, 255, 192, 10, 14, 28, 12, 61 | 1, 0, 255, 192, 255, 192, 224, 0, 224, 0, 224, 0, 224, 0, 255, 128, 62 | 255, 128, 224, 0, 224, 0, 224, 0, 224, 0, 224, 0, 224, 0, 12, 14, 63 | 28, 15, 1, 0, 15, 128, 63, 224, 120, 224, 112, 112, 240, 112, 224, 0, 64 | 224, 0, 227, 240, 227, 240, 240, 112, 112, 112, 120, 240, 63, 240, 31, 176, 65 | 12, 14, 28, 14, 1, 0, 224, 112, 224, 112, 224, 112, 224, 112, 224, 112, 66 | 224, 112, 255, 240, 255, 240, 224, 112, 224, 112, 224, 112, 224, 112, 224, 112, 67 | 224, 112, 3, 14, 14, 5, 1, 0, 224, 224, 224, 224, 224, 224, 224, 224, 68 | 224, 224, 224, 224, 224, 224, 9, 14, 28, 10, 0, 0, 3, 128, 3, 128, 69 | 3, 128, 3, 128, 3, 128, 3, 128, 3, 128, 3, 128, 3, 128, 227, 128, 70 | 227, 128, 247, 128, 127, 0, 62, 0, 13, 14, 28, 14, 1, 0, 224, 240, 71 | 225, 224, 227, 192, 231, 128, 239, 0, 254, 0, 252, 0, 254, 0, 239, 0, 72 | 231, 128, 227, 192, 225, 224, 224, 240, 224, 120, 9, 14, 28, 11, 1, 0, 73 | 224, 0, 224, 0, 224, 0, 224, 0, 224, 0, 224, 0, 224, 0, 224, 0, 74 | 224, 0, 224, 0, 224, 0, 224, 0, 255, 128, 255, 128, 14, 14, 28, 16, 75 | 1, 0, 224, 28, 224, 28, 240, 60, 240, 60, 248, 124, 248, 124, 248, 124, 76 | 236, 220, 236, 220, 236, 220, 231, 156, 231, 156, 227, 28, 227, 28, 12, 14, 77 | 28, 14, 1, 0, 224, 112, 240, 112, 240, 112, 248, 112, 252, 112, 236, 112, 78 | 238, 112, 230, 112, 231, 112, 227, 112, 225, 240, 225, 240, 224, 240, 224, 112, 79 | 13, 14, 28, 15, 1, 0, 15, 128, 63, 224, 120, 240, 112, 112, 240, 120, 80 | 224, 56, 224, 56, 224, 56, 224, 56, 240, 120, 112, 112, 120, 240, 63, 224, 81 | 15, 128, 11, 14, 28, 13, 1, 0, 255, 0, 255, 192, 225, 224, 224, 224, 82 | 224, 224, 224, 224, 225, 224, 255, 192, 255, 0, 224, 0, 224, 0, 224, 0, 83 | 224, 0, 224, 0, 13, 15, 30, 15, 1, 255, 15, 128, 63, 224, 120, 240, 84 | 112, 112, 240, 120, 224, 56, 224, 56, 224, 56, 224, 56, 243, 120, 115, 240, 85 | 121, 240, 63, 224, 15, 240, 0, 48, 12, 14, 28, 14, 1, 0, 255, 0, 86 | 255, 192, 225, 224, 224, 224, 224, 224, 225, 224, 255, 192, 255, 128, 225, 192, 87 | 224, 224, 224, 224, 224, 224, 224, 224, 224, 240, 11, 14, 28, 13, 1, 0, 88 | 63, 128, 127, 192, 241, 224, 224, 224, 240, 0, 126, 0, 63, 128, 15, 192, 89 | 1, 224, 224, 224, 224, 224, 241, 224, 127, 192, 63, 128, 11, 14, 28, 11, 90 | 0, 0, 255, 224, 255, 224, 14, 0, 14, 0, 14, 0, 14, 0, 14, 0, 91 | 14, 0, 14, 0, 14, 0, 14, 0, 14, 0, 14, 0, 14, 0, 12, 14, 92 | 28, 14, 1, 0, 224, 112, 224, 112, 224, 112, 224, 112, 224, 112, 224, 112, 93 | 224, 112, 224, 112, 224, 112, 224, 112, 224, 112, 112, 224, 127, 224, 31, 128, 94 | 13, 14, 28, 13, 0, 0, 224, 56, 224, 56, 112, 112, 112, 112, 48, 96, 95 | 56, 224, 56, 224, 29, 192, 29, 192, 13, 128, 15, 128, 15, 128, 7, 0, 96 | 7, 0, 15, 14, 28, 17, 1, 0, 227, 142, 227, 142, 227, 142, 227, 142, 97 | 115, 156, 115, 156, 115, 156, 118, 220, 54, 216, 54, 216, 62, 248, 28, 112, 98 | 28, 112, 28, 112, 12, 14, 28, 12, 0, 0, 224, 112, 224, 112, 112, 224, 99 | 121, 224, 25, 128, 31, 128, 15, 0, 31, 128, 25, 128, 57, 192, 112, 224, 100 | 112, 224, 224, 112, 224, 112, 13, 14, 28, 13, 0, 0, 224, 56, 224, 56, 101 | 112, 112, 56, 224, 56, 224, 29, 192, 29, 192, 15, 128, 7, 0, 7, 0, 102 | 7, 0, 7, 0, 7, 0, 7, 0, 10, 14, 28, 12, 1, 0, 255, 192, 103 | 255, 192, 1, 192, 3, 128, 7, 0, 7, 0, 14, 0, 28, 0, 56, 0, 104 | 56, 0, 112, 0, 224, 0, 255, 192, 255, 192, 10, 14, 28, 11, 1, 0, 105 | 51, 0, 51, 0, 51, 0, 0, 0, 62, 0, 127, 0, 115, 128, 7, 128, 106 | 63, 128, 123, 128, 227, 128, 231, 128, 251, 128, 123, 192, 10, 14, 28, 12, 107 | 1, 0, 51, 0, 51, 0, 51, 0, 0, 0, 30, 0, 127, 128, 115, 128, 108 | 225, 192, 225, 192, 225, 192, 225, 192, 115, 128, 127, 128, 30, 0, 9, 14, 109 | 28, 11, 1, 0, 51, 0, 51, 0, 51, 0, 0, 0, 227, 128, 227, 128, 110 | 227, 128, 227, 128, 227, 128, 227, 128, 227, 128, 231, 128, 255, 128, 123, 128, 111 | 10, 7, 14, 10, 0, 6, 12, 0, 30, 0, 30, 0, 51, 0, 115, 128, 112 | 97, 128, 225, 192, 10, 2, 4, 10, 0, 252, 255, 192, 255, 192, 5, 3, 113 | 3, 5, 0, 11, 224, 112, 56, 10, 10, 20, 11, 1, 0, 62, 0, 127, 114 | 0, 99, 128, 7, 128, 63, 128, 123, 128, 227, 128, 231, 128, 251, 128, 123, 115 | 192, 10, 14, 28, 12, 1, 0, 224, 0, 224, 0, 224, 0, 224, 0, 239, 116 | 0, 255, 128, 243, 128, 225, 192, 225, 192, 225, 192, 225, 192, 243, 128, 255, 117 | 128, 239, 0, 9, 10, 20, 11, 1, 0, 30, 0, 127, 128, 115, 128, 224, 118 | 0, 224, 0, 224, 0, 224, 0, 115, 128, 127, 128, 30, 0, 10, 14, 28, 119 | 12, 1, 0, 1, 192, 1, 192, 1, 192, 1, 192, 61, 192, 127, 192, 115, 120 | 192, 225, 192, 225, 192, 225, 192, 225, 192, 115, 192, 127, 192, 61, 192, 9, 121 | 10, 20, 11, 1, 0, 30, 0, 127, 0, 115, 128, 225, 128, 255, 128, 255, 122 | 128, 224, 0, 115, 128, 127, 128, 30, 0, 7, 14, 14, 7, 0, 0, 30, 123 | 62, 56, 56, 254, 254, 56, 56, 56, 56, 56, 56, 56, 56, 10, 14, 28, 124 | 12, 1, 252, 61, 192, 127, 192, 115, 192, 225, 192, 225, 192, 225, 192, 225, 125 | 192, 115, 192, 127, 192, 61, 192, 1, 192, 115, 128, 127, 128, 30, 0, 9, 126 | 14, 28, 11, 1, 0, 224, 0, 224, 0, 224, 0, 224, 0, 239, 0, 255, 127 | 128, 243, 128, 227, 128, 227, 128, 227, 128, 227, 128, 227, 128, 227, 128, 227, 128 | 128, 3, 14, 14, 5, 1, 0, 224, 224, 224, 0, 224, 224, 224, 224, 224, 129 | 224, 224, 224, 224, 224, 5, 18, 18, 5, 255, 252, 56, 56, 56, 0, 56, 130 | 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 248, 240, 9, 14, 28, 131 | 10, 1, 0, 224, 0, 224, 0, 224, 0, 224, 0, 231, 0, 238, 0, 252, 132 | 0, 248, 0, 248, 0, 252, 0, 238, 0, 231, 0, 231, 128, 227, 128, 3, 133 | 14, 14, 5, 1, 0, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 224, 134 | 224, 224, 224, 15, 10, 20, 17, 1, 0, 239, 60, 255, 254, 243, 206, 227, 135 | 142, 227, 142, 227, 142, 227, 142, 227, 142, 227, 142, 227, 142, 9, 10, 20, 136 | 11, 1, 0, 239, 0, 255, 128, 243, 128, 227, 128, 227, 128, 227, 128, 227, 137 | 128, 227, 128, 227, 128, 227, 128, 10, 10, 20, 12, 1, 0, 30, 0, 127, 138 | 128, 115, 128, 225, 192, 225, 192, 225, 192, 225, 192, 115, 128, 127, 128, 30, 139 | 0, 10, 14, 28, 12, 1, 252, 239, 0, 255, 128, 243, 128, 225, 192, 225, 140 | 192, 225, 192, 225, 192, 243, 128, 255, 128, 239, 0, 224, 0, 224, 0, 224, 141 | 0, 224, 0, 10, 14, 28, 12, 1, 252, 61, 192, 127, 192, 115, 192, 225, 142 | 192, 225, 192, 225, 192, 225, 192, 115, 192, 127, 192, 61, 192, 1, 192, 1, 143 | 192, 1, 192, 1, 192, 6, 10, 10, 7, 1, 0, 236, 252, 252, 224, 224, 144 | 224, 224, 224, 224, 224, 9, 10, 20, 11, 1, 0, 63, 0, 127, 128, 227, 145 | 128, 224, 0, 255, 0, 63, 128, 3, 128, 227, 128, 255, 0, 126, 0, 6, 146 | 13, 13, 6, 0, 0, 112, 112, 112, 252, 252, 112, 112, 112, 112, 112, 112, 147 | 124, 60, 9, 10, 20, 11, 1, 0, 227, 128, 227, 128, 227, 128, 227, 128, 148 | 227, 128, 227, 128, 227, 128, 231, 128, 255, 128, 123, 128, 9, 10, 20, 9, 149 | 0, 0, 227, 128, 227, 128, 227, 128, 119, 0, 119, 0, 119, 0, 62, 0, 150 | 62, 0, 28, 0, 28, 0, 15, 10, 20, 15, 0, 0, 227, 142, 227, 142, 151 | 227, 142, 115, 156, 119, 220, 118, 220, 62, 248, 60, 120, 28, 112, 28, 112, 152 | 9, 10, 20, 11, 1, 0, 227, 128, 227, 128, 119, 0, 62, 0, 28, 0, 153 | 62, 0, 119, 0, 119, 0, 227, 128, 227, 128, 9, 14, 28, 11, 1, 252, 154 | 227, 128, 227, 128, 227, 128, 119, 0, 119, 0, 119, 0, 62, 0, 62, 0, 155 | 28, 0, 28, 0, 28, 0, 24, 0, 120, 0, 112, 0, 8, 10, 10, 10, 156 | 1, 0, 255, 255, 7, 14, 28, 56, 112, 224, 255, 255, 12, 18, 36, 14, 157 | 1, 0, 25, 128, 25, 128, 25, 128, 0, 0, 15, 0, 15, 0, 31, 128, 158 | 25, 128, 25, 128, 57, 192, 57, 192, 48, 192, 112, 224, 127, 224, 127, 224, 159 | 224, 112, 224, 112, 224, 112, 13, 18, 36, 15, 1, 0, 12, 192, 12, 192, 160 | 12, 192, 0, 0, 15, 128, 63, 224, 120, 240, 112, 112, 240, 120, 224, 56, 161 | 224, 56, 224, 56, 224, 56, 240, 120, 112, 112, 120, 240, 63, 224, 15, 128, 162 | 12, 18, 36, 14, 1, 0, 25, 128, 25, 128, 25, 128, 0, 0, 224, 112, 163 | 224, 112, 224, 112, 224, 112, 224, 112, 224, 112, 224, 112, 224, 112, 224, 112, 164 | 224, 112, 224, 112, 112, 224, 127, 224, 31, 128, 8, 14, 14, 10, 1, 0, 165 | 60, 126, 231, 231, 231, 231, 238, 238, 231, 231, 231, 231, 239, 238}; 166 | #endif //HELVB14R_H_H 167 | -------------------------------------------------------------------------------- /MillControl/helvR14n.h: -------------------------------------------------------------------------------- 1 | #ifndef HELVR14N_H 2 | #define HELVR14N_H 3 | /* 4 | Fontname: -Adobe-Helvetica-Medium-R-Normal--20-140-100-100-P-100-ISO10646-1 5 | Copyright: Copyright (c) 1984, 1987 Adobe Systems Incorporated. All Rights Reserved. Copyright (c) 1988, 1991 Digital Equipment Corporation. All Rights Reserved. 6 | Capital A Height: 0, '1' Height: 13 7 | Calculated Max Values w= 9 h=14 x= 2 y= 0 dx=10 dy= 0 ascent=14 len=26 8 | Font Bounding box w=22 h=29 x=-2 y=-7 9 | Calculated Min Values x= 0 y= 0 dx= 0 dy= 0 10 | Pure Font ascent =13 descent= 0 11 | X Font ascent =13 descent= 0 12 | Max Font ascent =14 descent= 0 13 | */ 14 | #include 15 | 16 | #define NUMERIC_BEGIN 46 17 | #define NUMERIC_END 57 18 | 19 | const u8g_fntpgm_uint8_t helvR14n[248] U8G_FONT_SECTION("helvR14n") = { 20 | 0, 22, 29, 254, 249, 13, 0, 0, 0, 0, 46, 57, 0, 14, 0, 13, 21 | 0, 2, 2, 2, 5, 1, 0, 192, 192, 5, 14, 14, 5, 0, 0, 24, 22 | 24, 24, 24, 48, 48, 48, 96, 96, 96, 192, 192, 192, 192, 8, 13, 13, 23 | 10, 1, 0, 60, 126, 102, 195, 195, 195, 195, 195, 195, 195, 102, 126, 60, 24 | 5, 13, 13, 10, 2, 0, 24, 248, 248, 24, 24, 24, 24, 24, 24, 24, 25 | 24, 24, 24, 8, 13, 13, 10, 1, 0, 60, 254, 195, 3, 7, 14, 28, 26 | 56, 112, 224, 192, 255, 255, 8, 13, 13, 10, 1, 0, 62, 127, 195, 195, 27 | 6, 28, 30, 7, 3, 195, 199, 126, 60, 9, 13, 26, 10, 0, 0, 3, 28 | 0, 7, 0, 15, 0, 27, 0, 51, 0, 51, 0, 99, 0, 195, 0, 255, 29 | 128, 255, 128, 3, 0, 3, 0, 3, 0, 8, 13, 13, 10, 1, 0, 254, 30 | 254, 192, 192, 252, 254, 199, 3, 3, 195, 199, 254, 124, 8, 13, 13, 10, 31 | 1, 0, 60, 127, 99, 192, 192, 220, 254, 195, 195, 195, 227, 126, 60, 8, 32 | 13, 13, 10, 1, 0, 255, 255, 3, 6, 12, 12, 24, 24, 48, 48, 96, 33 | 96, 96, 8, 13, 13, 10, 1, 0, 60, 126, 231, 195, 195, 102, 126, 231, 34 | 195, 195, 231, 126, 60, 8, 13, 13, 10, 1, 0, 60, 126, 199, 195, 195, 35 | 195, 127, 59, 3, 3, 198, 254, 124}; 36 | #endif //HELVR14N_H_H 37 | -------------------------------------------------------------------------------- /MillControl/images/bean.xbm: -------------------------------------------------------------------------------- 1 | #define bean_width 39 2 | #define bean_height 39 3 | static unsigned char bean_bits[] = { 4 | 0x00, 0x00, 0xe0, 0xff, 0x00, 0x00, 0x00, 0xfc, 0xff, 0x03, 0x00, 0x00, 5 | 0xff, 0xff, 0x07, 0x00, 0xc0, 0xff, 0xff, 0x0f, 0x00, 0xe0, 0xff, 0xff, 6 | 0x01, 0x00, 0xf0, 0xff, 0x3f, 0x30, 0x00, 0xf8, 0xff, 0x0f, 0x3c, 0x00, 7 | 0xfe, 0xff, 0x07, 0x7f, 0x00, 0xff, 0xff, 0xc1, 0x7f, 0x80, 0xff, 0xff, 8 | 0xe0, 0x7f, 0x80, 0xff, 0x7f, 0xf0, 0x7f, 0xc0, 0xff, 0x3f, 0xf8, 0x7f, 9 | 0xe0, 0xff, 0x1f, 0xfc, 0x7f, 0xf0, 0xff, 0x0f, 0xfe, 0x7f, 0xf0, 0xff, 10 | 0x0f, 0xff, 0x7f, 0xf8, 0xff, 0x87, 0xff, 0x7f, 0xf8, 0xff, 0x87, 0xff, 11 | 0x7f, 0xfc, 0xff, 0xc7, 0xff, 0x7f, 0xfc, 0xff, 0xc3, 0xff, 0x3f, 0xfe, 12 | 0xff, 0xc3, 0xff, 0x3f, 0xfe, 0xff, 0xe3, 0xff, 0x3f, 0xfe, 0xff, 0xe1, 13 | 0xff, 0x1f, 0xfe, 0xff, 0xe1, 0xff, 0x1f, 0xff, 0xff, 0xf0, 0xff, 0x0f, 14 | 0xff, 0x7f, 0xf0, 0xff, 0x0f, 0xff, 0x7f, 0xf8, 0xff, 0x07, 0xff, 0x3f, 15 | 0xfc, 0xff, 0x03, 0xff, 0x1f, 0xfc, 0xff, 0x03, 0xff, 0x0f, 0xff, 0xff, 16 | 0x01, 0xff, 0x07, 0xff, 0xff, 0x00, 0xfe, 0xc1, 0xff, 0x7f, 0x00, 0xfe, 17 | 0xe0, 0xff, 0x3f, 0x00, 0x3c, 0xfc, 0xff, 0x1f, 0x00, 0x0c, 0xfe, 0xff, 18 | 0x0f, 0x00, 0xe0, 0xff, 0xff, 0x03, 0x00, 0xf0, 0xff, 0xff, 0x01, 0x00, 19 | 0xe0, 0xff, 0x7f, 0x00, 0x00, 0xc0, 0xff, 0x1f, 0x00, 0x00, 0x00, 0xff, 20 | 0x03, 0x00, 0x00 }; 21 | -------------------------------------------------------------------------------- /MillControl/images/bean20.xbm: -------------------------------------------------------------------------------- 1 | #define bean20_width 20 2 | #define bean20_height 20 3 | static unsigned char bean20_bits[] = { 4 | 0x00, 0xf8, 0x00, 0x00, 0xff, 0x03, 0x80, 0xff, 0x01, 0xc0, 0x3f, 0x06, 5 | 0xf0, 0x9f, 0x0f, 0xf0, 0xcf, 0x0f, 0xf8, 0xe7, 0x0f, 0xfc, 0xf3, 0x0f, 6 | 0xfc, 0xf3, 0x0f, 0xfe, 0xf9, 0x07, 0xfe, 0xf9, 0x07, 0xfe, 0xf9, 0x07, 7 | 0xff, 0xfc, 0x03, 0x7f, 0xfe, 0x01, 0x3f, 0xff, 0x01, 0x9e, 0xff, 0x00, 8 | 0xe6, 0x7f, 0x00, 0xf8, 0x1f, 0x00, 0xf8, 0x0f, 0x00, 0xf0, 0x01, 0x00 }; 9 | -------------------------------------------------------------------------------- /MillControl/images/cup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/romanseidl/MillControl/e3b6ef06889d4935146d5c611bbf856cb4223c41/MillControl/images/cup.png -------------------------------------------------------------------------------- /MillControl/images/cupS.xbm: -------------------------------------------------------------------------------- 1 | #define cupS_width 24 2 | #define cupS_height 30 3 | static unsigned char cupS_bits[] = { 4 | 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x06, 0x00, 0x00, 0x06, 0x00, 5 | 0x00, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 6 | 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x07, 0xff, 0xff, 0x07, 7 | 0xff, 0xff, 0x07, 0xff, 0xff, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe3, 8 | 0xff, 0xff, 0xc3, 0xff, 0xff, 0xc3, 0xfe, 0xff, 0xe3, 0xfe, 0xff, 0x63, 9 | 0xfe, 0xff, 0x73, 0xfe, 0xff, 0x39, 0xfe, 0xff, 0x1f, 0xfc, 0xff, 0x07, 10 | 0xfc, 0xff, 0x03, 0xfc, 0xff, 0x01, 0xf8, 0xff, 0x00, 0xf8, 0x7f, 0x00, 11 | 0xf0, 0x7f, 0x00, 0xf0, 0x3f, 0x00 }; 12 | -------------------------------------------------------------------------------- /MillControl/images/hand.xbm: -------------------------------------------------------------------------------- 1 | #define hand_width 39 2 | #define hand_height 53 3 | static unsigned char hand_bits[] = { 4 | 0x00, 0xe0, 0x0f, 0x00, 0x00, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0x00, 0xff, 5 | 0xff, 0x01, 0x00, 0x80, 0x1f, 0xf0, 0x07, 0x00, 0xe0, 0x07, 0xc0, 0x0f, 6 | 0x00, 0xe0, 0x01, 0x00, 0x1f, 0x00, 0xf0, 0x00, 0x00, 0x3e, 0x00, 0x78, 7 | 0x00, 0x00, 0x3c, 0x00, 0x3c, 0x00, 0x00, 0x78, 0x00, 0x3c, 0x00, 0x00, 8 | 0x70, 0x00, 0x1e, 0x00, 0x00, 0xf0, 0x00, 0x0e, 0x00, 0x00, 0xe0, 0x00, 9 | 0x0e, 0x00, 0x00, 0xe0, 0x01, 0x0e, 0x80, 0x03, 0xc0, 0x01, 0x0f, 0xc0, 10 | 0x07, 0xc0, 0x01, 0x07, 0xc0, 0x07, 0xc0, 0x01, 0x07, 0xe0, 0x0f, 0xc0, 11 | 0x01, 0x07, 0xe0, 0x0f, 0xc0, 0x01, 0x0e, 0xe0, 0x0f, 0xc0, 0x01, 0x0e, 12 | 0xe0, 0x0f, 0xc0, 0x01, 0x0e, 0xe0, 0x0f, 0xe0, 0x00, 0x0e, 0xe0, 0x0f, 13 | 0xe0, 0x00, 0x1e, 0xe0, 0x0f, 0xf0, 0x00, 0x1c, 0xe0, 0x0f, 0x00, 0x00, 14 | 0x3c, 0xe0, 0x0f, 0x00, 0x00, 0x78, 0xe0, 0x0f, 0x00, 0x00, 0xf0, 0xe0, 15 | 0x4f, 0x00, 0x00, 0xf0, 0xe1, 0xef, 0x01, 0x00, 0xe0, 0xe3, 0xff, 0x03, 16 | 0x00, 0x80, 0xe3, 0xff, 0x03, 0x00, 0x00, 0xe3, 0xff, 0xf7, 0x00, 0x00, 17 | 0xe0, 0xff, 0xff, 0x01, 0x00, 0xe0, 0xff, 0xff, 0x01, 0x00, 0xe0, 0xff, 18 | 0xff, 0x39, 0x00, 0xe0, 0xff, 0xff, 0x7d, 0x00, 0xe0, 0xff, 0xff, 0x7f, 19 | 0x00, 0xe0, 0xff, 0xff, 0x7f, 0x00, 0xe0, 0xff, 0xff, 0x7f, 0xf0, 0xe0, 20 | 0xff, 0xff, 0x7f, 0xf8, 0xe1, 0xff, 0xff, 0x7f, 0xf8, 0xe3, 0xff, 0xff, 21 | 0x7f, 0xf8, 0xe7, 0xff, 0xff, 0x7f, 0xf8, 0xe7, 0xff, 0xff, 0x7f, 0xf0, 22 | 0xef, 0xff, 0xff, 0x7f, 0xe0, 0xff, 0xff, 0xff, 0x7f, 0xc0, 0xff, 0xff, 23 | 0xff, 0x7f, 0xc0, 0xff, 0xff, 0xff, 0x7f, 0x80, 0xff, 0xff, 0xff, 0x7f, 24 | 0x00, 0xff, 0xff, 0xff, 0x7f, 0x00, 0xfe, 0xff, 0xff, 0x7f, 0x00, 0xfc, 25 | 0xff, 0xff, 0x7f, 0x00, 0xf8, 0xff, 0xff, 0x7f, 0x00, 0xe0, 0xff, 0xff, 26 | 0x3f }; 27 | -------------------------------------------------------------------------------- /MillControl/images/hand20.xbm: -------------------------------------------------------------------------------- 1 | #define hand20_width 21 2 | #define hand20_height 20 3 | static unsigned char hand20_bits[] = { 4 | 0x80, 0x07, 0x00, 0xf0, 0x1f, 0x00, 0x38, 0x70, 0x00, 0x0c, 0xe0, 0x00, 5 | 0x06, 0x80, 0x01, 0x06, 0x80, 0x01, 0x02, 0x00, 0x03, 0x03, 0x03, 0x03, 6 | 0x83, 0x07, 0x03, 0x82, 0x07, 0x03, 0x82, 0x07, 0x03, 0x82, 0x07, 0x01, 7 | 0x86, 0x07, 0x00, 0x8c, 0x07, 0x00, 0x9c, 0x1f, 0x00, 0x90, 0x3f, 0x00, 8 | 0x80, 0xff, 0x03, 0x80, 0xff, 0x0b, 0x80, 0xff, 0x1f, 0x80, 0xff, 0x1f }; 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MillControl 2 | ##Arduino Coffee Grinder Control 3 | 4 | ###THIS DESCRIPTION IS A BIT OUT OF DATE I WILL UPDATE IT WHEN I GET TO IT. 5 | If you speak german please refer to: 6 | https://www.kaffee-netz.de/threads/millcontrol-arduino-muehlensteuerung-mit-timer-gewichtsautomatik-und-brew-timer.95553/ 7 | 8 | This was designed to build a timer controlled coffe grinder out of any regular machine. It was developed to be used with a Graef CM 70 but it should work fine with any brand or model. 9 | 10 | ###Requirements 11 | - Runs on Arduino Pro Mini & compatible systems (should be most arduino machines having a ATmega328 or better CPU, needs 32k of storage space). 12 | - Needs a rotary encoder with a switch and an optional second switch (mill switch). If you only have one switch comment out the define in UI.h 13 | - Output is to a 128*64 graphics display, comment out the orientation define in UI.h 14 | 15 | ###Dependencies: 16 | - ClickButton - https://code.google.com/p/clickbutton/ 17 | - Encoder (v1.2) - http://www.pjrc.com/teensy/td_libs_Encoder.html 18 | - TimerOne (v1.1) - https://github.com/PaulStoffregen/TimerOne 19 | - U8Glib - https://github.com/olikraus/u8glib 20 | 21 | ###User Interface 22 | ####Select a Time Mode 23 | You can select from up to 20 timer modes with different timeings for a single click, double click and long click of the mill button. Modes can be timed, start/ stop (starting the mill on a click and stopping it at the next) and hold (_with extra mill button only_). 24 | 25 | _If there is no mill button then you can only choose from single and double click. Long click is then bound to the edit menu_ 26 | 27 | #####Portrait mode 28 | ![Select](https://raw.githubusercontent.com/romanseidl/MillControl/gh-pages/pictures/hoch_select.JPG) 29 | ![Select Direct](https://github.com/romanseidl/MillControl/blob/gh-pages/pictures/hoch_select_direct.JPG) 30 | #####Landscape Mode 31 | ![Select Landscape](https://raw.githubusercontent.com/romanseidl/MillControl/gh-pages/pictures/quer_select.JPG) 32 | ![Select Direct Landscape](https://raw.githubusercontent.com/romanseidl/MillControl/gh-pages/pictures/quer_select_d.JPG) 33 | 34 | ####Edit a Time Mode 35 | There is an extensive editor allowing you to add (+), delete (x), move (<>) and edit time modes. For a time mode the respective times and the title are editable. 36 | 37 | #####Portrait mode 38 | ![Editor](https://raw.githubusercontent.com/romanseidl/MillControl/gh-pages/pictures/hoch_edit_sp.JPG) 39 | ![Char Editor](https://raw.githubusercontent.com/romanseidl/MillControl/gh-pages/pictures/hoch_edit_char.JPG) 40 | #####Landscape Mode 41 | ![Landscape Editor](https://raw.githubusercontent.com/romanseidl/MillControl/gh-pages/pictures/quer_editor.JPG) 42 | 43 | ####Run!! 44 | Finally the idea of the timer ist to run. So there is a run mode... It is started from select mode as explained above. In a timed run there is a progress bar at the bottom of the screen. 45 | 46 | A run can be stopped any time by pressing the button used to start the run. For 5 seconds the run will pause and if you re-click it can be continued. 47 | 48 | #####Portrait mode 49 | ![Run Mode](https://raw.githubusercontent.com/romanseidl/MillControl/gh-pages/pictures/hoch_run.JPG) 50 | ![Direct Run Mode](https://raw.githubusercontent.com/romanseidl/MillControl/gh-pages/pictures/hoch_run_direct.JPG) 51 | #####Landscape mode 52 | ![Landscape Run Mode](https://github.com/romanseidl/MillControl/blob/gh-pages/pictures/quer_run.JPG) 53 | 54 | ###Schematic 55 | I prefer a old school schmatic style over those fanzy fritzing pictures. Still I added them below in case you prefer them. 56 | [![Schematic](https://raw.githubusercontent.com/romanseidl/MillControl/gh-pages/sketch/schematic.png)](https://raw.githubusercontent.com/romanseidl/MillControl/gh-pages/sketch/schematic.pdf) 57 | 58 | ###(c) 2015 by Roman Seidl 59 | 60 | This program is free software; you can redistribute it and/or modify 61 | it under the terms of the GNU General Public License as published by 62 | the Free Software Foundation; either version 3 of the License, or 63 | (at your option) any later version. 64 | 65 | This program is distributed in the hope that it will be useful, 66 | but WITHOUT ANY WARRANTY; without even the implied warranty of 67 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 68 | GNU General Public License for more details. 69 | 70 | You should have received a copy of the GNU General Public License 71 | along with this program; if not, write to the Free Software Foundation, 72 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 73 | 74 | All trademarks mentioned belong to their owners, third party brands, product names, trade names, corporate names and company names mentioned may be trademarks of their respective owners or registered trademarks of other companies and are used for purposes of explanation and to the owner's benefit, without implying a violation of copyright law. 75 | --------------------------------------------------------------------------------