├── .gitignore
├── .vscode
└── extensions.json
├── LICENSE.txt
├── README.md
├── examples
├── EditValues
│ ├── EditValues.ino
│ ├── editpagesetup.h
│ └── menusetup.h
└── Menu
│ └── Menu.ino
├── include
└── README
├── keywords.txt
├── lib
└── README
├── library.json
├── library.properties
├── platformio.ini
├── src
├── DisplayButton.cpp
├── DisplayButton.h
├── DisplayButtonList.cpp
├── DisplayButtonList.h
├── DisplayGlobals.h
├── DisplayLabel.cpp
├── DisplayLabel.h
├── DisplayLabelList.cpp
├── DisplayLabelList.h
├── DisplayMenu.cpp
├── DisplayMenu.h
├── DisplayPage.cpp
├── DisplayPage.h
├── DisplayPageList.cpp
├── DisplayPageList.h
└── LinkedList.h
└── test
└── README
/.gitignore:
--------------------------------------------------------------------------------
1 | .pio
2 | .vscode/.browse.c_cpp.db*
3 | .vscode/c_cpp_properties.json
4 | .vscode/launch.json
5 | .vscode/ipch
6 | /.project
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | // See http://go.microsoft.com/fwlink/?LinkId=827846
3 | // for the documentation about the extensions.json format
4 | "recommendations": [
5 | "platformio.platformio-ide"
6 | ]
7 | }
8 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | ### GNU GENERAL PUBLIC LICENSE
2 |
3 | Version 3, 29 June 2007
4 |
5 | Copyright (C) 2007 Free Software Foundation, Inc.
6 |
7 |
8 | Everyone is permitted to copy and distribute verbatim copies of this
9 | license document, but changing it is not allowed.
10 |
11 | ### Preamble
12 |
13 | The GNU General Public License is a free, copyleft license for
14 | software and other kinds of works.
15 |
16 | The licenses for most software and other practical works are designed
17 | to take away your freedom to share and change the works. By contrast,
18 | the GNU General Public License is intended to guarantee your freedom
19 | to share and change all versions of a program--to make sure it remains
20 | free software for all its users. We, the Free Software Foundation, use
21 | the GNU General Public License for most of our software; it applies
22 | also to any other work released this way by its authors. You can apply
23 | it to your programs, too.
24 |
25 | When we speak of free software, we are referring to freedom, not
26 | price. Our General Public Licenses are designed to make sure that you
27 | have the freedom to distribute copies of free software (and charge for
28 | them if you wish), that you receive source code or can get it if you
29 | want it, that you can change the software or use pieces of it in new
30 | free programs, and that you know you can do these things.
31 |
32 | To protect your rights, we need to prevent others from denying you
33 | these rights or asking you to surrender the rights. Therefore, you
34 | have certain responsibilities if you distribute copies of the
35 | software, or if you modify it: responsibilities to respect the freedom
36 | of others.
37 |
38 | For example, if you distribute copies of such a program, whether
39 | gratis or for a fee, you must pass on to the recipients the same
40 | freedoms that you received. You must make sure that they, too, receive
41 | or can get the source code. And you must show them these terms so they
42 | know their rights.
43 |
44 | Developers that use the GNU GPL protect your rights with two steps:
45 | (1) assert copyright on the software, and (2) offer you this License
46 | giving you legal permission to copy, distribute and/or modify it.
47 |
48 | For the developers' and authors' protection, the GPL clearly explains
49 | that there is no warranty for this free software. For both users' and
50 | authors' sake, the GPL requires that modified versions be marked as
51 | changed, so that their problems will not be attributed erroneously to
52 | authors of previous versions.
53 |
54 | Some devices are designed to deny users access to install or run
55 | modified versions of the software inside them, although the
56 | manufacturer can do so. This is fundamentally incompatible with the
57 | aim of protecting users' freedom to change the software. The
58 | systematic pattern of such abuse occurs in the area of products for
59 | individuals to use, which is precisely where it is most unacceptable.
60 | Therefore, we have designed this version of the GPL to prohibit the
61 | practice for those products. If such problems arise substantially in
62 | other domains, we stand ready to extend this provision to those
63 | domains in future versions of the GPL, as needed to protect the
64 | freedom of users.
65 |
66 | Finally, every program is threatened constantly by software patents.
67 | States should not allow patents to restrict development and use of
68 | software on general-purpose computers, but in those that do, we wish
69 | to avoid the special danger that patents applied to a free program
70 | could make it effectively proprietary. To prevent this, the GPL
71 | assures that patents cannot be used to render the program non-free.
72 |
73 | The precise terms and conditions for copying, distribution and
74 | modification follow.
75 |
76 | ### TERMS AND CONDITIONS
77 |
78 | #### 0. Definitions.
79 |
80 | "This License" refers to version 3 of the GNU General Public License.
81 |
82 | "Copyright" also means copyright-like laws that apply to other kinds
83 | of works, such as semiconductor masks.
84 |
85 | "The Program" refers to any copyrightable work licensed under this
86 | License. Each licensee is addressed as "you". "Licensees" and
87 | "recipients" may be individuals or organizations.
88 |
89 | To "modify" a work means to copy from or adapt all or part of the work
90 | in a fashion requiring copyright permission, other than the making of
91 | an exact copy. The resulting work is called a "modified version" of
92 | the earlier work or a work "based on" the earlier work.
93 |
94 | A "covered work" means either the unmodified Program or a work based
95 | on the Program.
96 |
97 | To "propagate" a work means to do anything with it that, without
98 | permission, would make you directly or secondarily liable for
99 | infringement under applicable copyright law, except executing it on a
100 | computer or modifying a private copy. Propagation includes copying,
101 | distribution (with or without modification), making available to the
102 | public, and in some countries other activities as well.
103 |
104 | To "convey" a work means any kind of propagation that enables other
105 | parties to make or receive copies. Mere interaction with a user
106 | through a computer network, with no transfer of a copy, is not
107 | conveying.
108 |
109 | An interactive user interface displays "Appropriate Legal Notices" to
110 | the extent that it includes a convenient and prominently visible
111 | feature that (1) displays an appropriate copyright notice, and (2)
112 | tells the user that there is no warranty for the work (except to the
113 | extent that warranties are provided), that licensees may convey the
114 | work under this License, and how to view a copy of this License. If
115 | the interface presents a list of user commands or options, such as a
116 | menu, a prominent item in the list meets this criterion.
117 |
118 | #### 1. Source Code.
119 |
120 | The "source code" for a work means the preferred form of the work for
121 | making modifications to it. "Object code" means any non-source form of
122 | a work.
123 |
124 | A "Standard Interface" means an interface that either is an official
125 | standard defined by a recognized standards body, or, in the case of
126 | interfaces specified for a particular programming language, one that
127 | is widely used among developers working in that language.
128 |
129 | The "System Libraries" of an executable work include anything, other
130 | than the work as a whole, that (a) is included in the normal form of
131 | packaging a Major Component, but which is not part of that Major
132 | Component, and (b) serves only to enable use of the work with that
133 | Major Component, or to implement a Standard Interface for which an
134 | implementation is available to the public in source code form. A
135 | "Major Component", in this context, means a major essential component
136 | (kernel, window system, and so on) of the specific operating system
137 | (if any) on which the executable work runs, or a compiler used to
138 | produce the work, or an object code interpreter used to run it.
139 |
140 | The "Corresponding Source" for a work in object code form means all
141 | the source code needed to generate, install, and (for an executable
142 | work) run the object code and to modify the work, including scripts to
143 | control those activities. However, it does not include the work's
144 | System Libraries, or general-purpose tools or generally available free
145 | programs which are used unmodified in performing those activities but
146 | which are not part of the work. For example, Corresponding Source
147 | includes interface definition files associated with source files for
148 | the work, and the source code for shared libraries and dynamically
149 | linked subprograms that the work is specifically designed to require,
150 | such as by intimate data communication or control flow between those
151 | subprograms and other parts of the work.
152 |
153 | The Corresponding Source need not include anything that users can
154 | regenerate automatically from other parts of the Corresponding Source.
155 |
156 | The Corresponding Source for a work in source code form is that same
157 | work.
158 |
159 | #### 2. Basic Permissions.
160 |
161 | All rights granted under this License are granted for the term of
162 | copyright on the Program, and are irrevocable provided the stated
163 | conditions are met. This License explicitly affirms your unlimited
164 | permission to run the unmodified Program. The output from running a
165 | covered work is covered by this License only if the output, given its
166 | content, constitutes a covered work. This License acknowledges your
167 | rights of fair use or other equivalent, as provided by copyright law.
168 |
169 | You may make, run and propagate covered works that you do not convey,
170 | without conditions so long as your license otherwise remains in force.
171 | You may convey covered works to others for the sole purpose of having
172 | them make modifications exclusively for you, or provide you with
173 | facilities for running those works, provided that you comply with the
174 | terms of this License in conveying all material for which you do not
175 | control copyright. Those thus making or running the covered works for
176 | you must do so exclusively on your behalf, under your direction and
177 | control, on terms that prohibit them from making any copies of your
178 | copyrighted material outside their relationship with you.
179 |
180 | Conveying under any other circumstances is permitted solely under the
181 | conditions stated below. Sublicensing is not allowed; section 10 makes
182 | it unnecessary.
183 |
184 | #### 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
185 |
186 | No covered work shall be deemed part of an effective technological
187 | measure under any applicable law fulfilling obligations under article
188 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
189 | similar laws prohibiting or restricting circumvention of such
190 | measures.
191 |
192 | When you convey a covered work, you waive any legal power to forbid
193 | circumvention of technological measures to the extent such
194 | circumvention is effected by exercising rights under this License with
195 | respect to the covered work, and you disclaim any intention to limit
196 | operation or modification of the work as a means of enforcing, against
197 | the work's users, your or third parties' legal rights to forbid
198 | circumvention of technological measures.
199 |
200 | #### 4. Conveying Verbatim Copies.
201 |
202 | You may convey verbatim copies of the Program's source code as you
203 | receive it, in any medium, provided that you conspicuously and
204 | appropriately publish on each copy an appropriate copyright notice;
205 | keep intact all notices stating that this License and any
206 | non-permissive terms added in accord with section 7 apply to the code;
207 | keep intact all notices of the absence of any warranty; and give all
208 | recipients a copy of this License along with the Program.
209 |
210 | You may charge any price or no price for each copy that you convey,
211 | and you may offer support or warranty protection for a fee.
212 |
213 | #### 5. Conveying Modified Source Versions.
214 |
215 | You may convey a work based on the Program, or the modifications to
216 | produce it from the Program, in the form of source code under the
217 | terms of section 4, provided that you also meet all of these
218 | conditions:
219 |
220 | - a) The work must carry prominent notices stating that you modified
221 | it, and giving a relevant date.
222 | - b) The work must carry prominent notices stating that it is
223 | released under this License and any conditions added under
224 | section 7. This requirement modifies the requirement in section 4
225 | to "keep intact all notices".
226 | - c) You must license the entire work, as a whole, under this
227 | License to anyone who comes into possession of a copy. This
228 | License will therefore apply, along with any applicable section 7
229 | additional terms, to the whole of the work, and all its parts,
230 | regardless of how they are packaged. This License gives no
231 | permission to license the work in any other way, but it does not
232 | invalidate such permission if you have separately received it.
233 | - d) If the work has interactive user interfaces, each must display
234 | Appropriate Legal Notices; however, if the Program has interactive
235 | interfaces that do not display Appropriate Legal Notices, your
236 | work need not make them do so.
237 |
238 | A compilation of a covered work with other separate and independent
239 | works, which are not by their nature extensions of the covered work,
240 | and which are not combined with it such as to form a larger program,
241 | in or on a volume of a storage or distribution medium, is called an
242 | "aggregate" if the compilation and its resulting copyright are not
243 | used to limit the access or legal rights of the compilation's users
244 | beyond what the individual works permit. Inclusion of a covered work
245 | in an aggregate does not cause this License to apply to the other
246 | parts of the aggregate.
247 |
248 | #### 6. Conveying Non-Source Forms.
249 |
250 | You may convey a covered work in object code form under the terms of
251 | sections 4 and 5, provided that you also convey the machine-readable
252 | Corresponding Source under the terms of this License, in one of these
253 | ways:
254 |
255 | - a) Convey the object code in, or embodied in, a physical product
256 | (including a physical distribution medium), accompanied by the
257 | Corresponding Source fixed on a durable physical medium
258 | customarily used for software interchange.
259 | - b) Convey the object code in, or embodied in, a physical product
260 | (including a physical distribution medium), accompanied by a
261 | written offer, valid for at least three years and valid for as
262 | long as you offer spare parts or customer support for that product
263 | model, to give anyone who possesses the object code either (1) a
264 | copy of the Corresponding Source for all the software in the
265 | product that is covered by this License, on a durable physical
266 | medium customarily used for software interchange, for a price no
267 | more than your reasonable cost of physically performing this
268 | conveying of source, or (2) access to copy the Corresponding
269 | Source from a network server at no charge.
270 | - c) Convey individual copies of the object code with a copy of the
271 | written offer to provide the Corresponding Source. This
272 | alternative is allowed only occasionally and noncommercially, and
273 | only if you received the object code with such an offer, in accord
274 | with subsection 6b.
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 | - e) Convey the object code using peer-to-peer transmission,
288 | provided you inform other peers where the object code and
289 | Corresponding Source of the work are being offered to the general
290 | public at no charge under subsection 6d.
291 |
292 | A separable portion of the object code, whose source code is excluded
293 | from the Corresponding Source as a System Library, need not be
294 | included in conveying the object code work.
295 |
296 | A "User Product" is either (1) a "consumer product", which means any
297 | tangible personal property which is normally used for personal,
298 | family, or household purposes, or (2) anything designed or sold for
299 | incorporation into a dwelling. In determining whether a product is a
300 | consumer product, doubtful cases shall be resolved in favor of
301 | coverage. For a particular product received by a particular user,
302 | "normally used" refers to a typical or common use of that class of
303 | product, regardless of the status of the particular user or of the way
304 | in which the particular user actually uses, or expects or is expected
305 | to use, the product. A product is a consumer product regardless of
306 | whether the product has substantial commercial, industrial or
307 | non-consumer uses, unless such uses represent the only significant
308 | 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
312 | install and execute modified versions of a covered work in that User
313 | Product from a modified version of its Corresponding Source. The
314 | information must suffice to ensure that the continued functioning of
315 | the modified object code is in no case prevented or interfered with
316 | solely because 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
331 | updates for a work that has been modified or installed by the
332 | recipient, or for the User Product in which it has been modified or
333 | installed. Access to a network may be denied when the modification
334 | itself materially and adversely affects the operation of the network
335 | or violates the rules and protocols for communication across the
336 | network.
337 |
338 | Corresponding Source conveyed, and Installation Information provided,
339 | in accord with this section must be in a format that is publicly
340 | documented (and with an implementation available to the public in
341 | source code form), and must require no special password or key for
342 | unpacking, reading or copying.
343 |
344 | #### 7. Additional Terms.
345 |
346 | "Additional permissions" are terms that supplement the terms of this
347 | License by making exceptions from one or more of its conditions.
348 | Additional permissions that are applicable to the entire Program shall
349 | be treated as though they were included in this License, to the extent
350 | that they are valid under applicable law. If additional permissions
351 | apply only to part of the Program, that part may be used separately
352 | under those permissions, but the entire Program remains governed by
353 | this License without regard to the additional permissions.
354 |
355 | When you convey a copy of a covered work, you may at your option
356 | remove any additional permissions from that copy, or from any part of
357 | it. (Additional permissions may be written to require their own
358 | removal in certain cases when you modify the work.) You may place
359 | additional permissions on material, added by you to a covered work,
360 | for which you have or can give appropriate copyright permission.
361 |
362 | Notwithstanding any other provision of this License, for material you
363 | add to a covered work, you may (if authorized by the copyright holders
364 | of that material) supplement the terms of this License with terms:
365 |
366 | - a) Disclaiming warranty or limiting liability differently from the
367 | terms of sections 15 and 16 of this License; or
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 | - c) Prohibiting misrepresentation of the origin of that material,
372 | or requiring that modified versions of such material be marked in
373 | reasonable ways as different from the original version; or
374 | - d) Limiting the use for publicity purposes of names of licensors
375 | or authors of the material; or
376 | - e) Declining to grant rights under trademark law for use of some
377 | trade names, trademarks, or service marks; or
378 | - f) Requiring indemnification of licensors and authors of that
379 | material by anyone who conveys the material (or modified versions
380 | of it) with contractual assumptions of liability to the recipient,
381 | for any liability that these contractual assumptions directly
382 | impose on those licensors and authors.
383 |
384 | All other non-permissive additional terms are considered "further
385 | restrictions" within the meaning of section 10. If the Program as you
386 | received it, or any part of it, contains a notice stating that it is
387 | governed by this License along with a term that is a further
388 | restriction, you may remove that term. If a license document contains
389 | a further restriction but permits relicensing or conveying under this
390 | License, you may add to a covered work material governed by the terms
391 | of that license document, provided that the further restriction does
392 | not survive such relicensing or conveying.
393 |
394 | If you add terms to a covered work in accord with this section, you
395 | must place, in the relevant source files, a statement of the
396 | additional terms that apply to those files, or a notice indicating
397 | where to find the applicable terms.
398 |
399 | Additional terms, permissive or non-permissive, may be stated in the
400 | form of a separately written license, or stated as exceptions; the
401 | above requirements apply either way.
402 |
403 | #### 8. Termination.
404 |
405 | You may not propagate or modify a covered work except as expressly
406 | provided under this License. Any attempt otherwise to propagate or
407 | modify it is void, and will automatically terminate your rights under
408 | this License (including any patent licenses granted under the third
409 | paragraph of section 11).
410 |
411 | However, if you cease all violation of this License, then your license
412 | from a particular copyright holder is reinstated (a) provisionally,
413 | unless and until the copyright holder explicitly and finally
414 | terminates your license, and (b) permanently, if the copyright holder
415 | fails to notify you of the violation by some reasonable means prior to
416 | 60 days after the cessation.
417 |
418 | Moreover, your license from a particular copyright holder is
419 | reinstated permanently if the copyright holder notifies you of the
420 | violation by some reasonable means, this is the first time you have
421 | received notice of violation of this License (for any work) from that
422 | copyright holder, and you cure the violation prior to 30 days after
423 | your receipt of the notice.
424 |
425 | Termination of your rights under this section does not terminate the
426 | licenses of parties who have received copies or rights from you under
427 | this License. If your rights have been terminated and not permanently
428 | reinstated, you do not qualify to receive new licenses for the same
429 | material under section 10.
430 |
431 | #### 9. Acceptance Not Required for Having Copies.
432 |
433 | You are not required to accept this License in order to receive or run
434 | a copy of the Program. Ancillary propagation of a covered work
435 | occurring solely as a consequence of using peer-to-peer transmission
436 | to receive a copy likewise does not require acceptance. However,
437 | nothing other than this License grants you permission to propagate or
438 | modify any covered work. These actions infringe copyright if you do
439 | not accept this License. Therefore, by modifying or propagating a
440 | covered work, you indicate your acceptance of this License to do so.
441 |
442 | #### 10. Automatic Licensing of Downstream Recipients.
443 |
444 | Each time you convey a covered work, the recipient automatically
445 | receives a license from the original licensors, to run, modify and
446 | propagate that work, subject to this License. You are not responsible
447 | for enforcing compliance by third parties with this License.
448 |
449 | An "entity transaction" is a transaction transferring control of an
450 | organization, or substantially all assets of one, or subdividing an
451 | organization, or merging organizations. If propagation of a covered
452 | work results from an entity transaction, each party to that
453 | transaction who receives a copy of the work also receives whatever
454 | licenses to the work the party's predecessor in interest had or could
455 | give under the previous paragraph, plus a right to possession of the
456 | Corresponding Source of the work from the predecessor in interest, if
457 | the predecessor has it or can get it with reasonable efforts.
458 |
459 | You may not impose any further restrictions on the exercise of the
460 | rights granted or affirmed under this License. For example, you may
461 | not impose a license fee, royalty, or other charge for exercise of
462 | rights granted under this License, and you may not initiate litigation
463 | (including a cross-claim or counterclaim in a lawsuit) alleging that
464 | any patent claim is infringed by making, using, selling, offering for
465 | sale, or importing the Program or any portion of it.
466 |
467 | #### 11. Patents.
468 |
469 | A "contributor" is a copyright holder who authorizes use under this
470 | License of the Program or a work on which the Program is based. The
471 | work thus licensed is called the contributor's "contributor version".
472 |
473 | A contributor's "essential patent claims" are all patent claims owned
474 | or controlled by the contributor, whether already acquired or
475 | hereafter acquired, that would be infringed by some manner, permitted
476 | by this License, of making, using, or selling its contributor version,
477 | but do not include claims that would be infringed only as a
478 | consequence of further modification of the contributor version. For
479 | purposes of this definition, "control" includes the right to grant
480 | patent sublicenses in a manner consistent with the requirements of
481 | this License.
482 |
483 | Each contributor grants you a non-exclusive, worldwide, royalty-free
484 | patent license under the contributor's essential patent claims, to
485 | make, use, sell, offer for sale, import and otherwise run, modify and
486 | propagate the contents of its contributor version.
487 |
488 | In the following three paragraphs, a "patent license" is any express
489 | agreement or commitment, however denominated, not to enforce a patent
490 | (such as an express permission to practice a patent or covenant not to
491 | sue for patent infringement). To "grant" such a patent license to a
492 | party means to make such an agreement or commitment not to enforce a
493 | patent against the party.
494 |
495 | If you convey a covered work, knowingly relying on a patent license,
496 | and the Corresponding Source of the work is not available for anyone
497 | to copy, free of charge and under the terms of this License, through a
498 | publicly available network server or other readily accessible means,
499 | then you must either (1) cause the Corresponding Source to be so
500 | available, or (2) arrange to deprive yourself of the benefit of the
501 | patent license for this particular work, or (3) arrange, in a manner
502 | consistent with the requirements of this License, to extend the patent
503 | license to downstream recipients. "Knowingly relying" means you have
504 | actual knowledge that, but for the patent license, your conveying the
505 | covered work in a country, or your recipient's use of the covered work
506 | in a country, would infringe one or more identifiable patents in that
507 | country that you have reason to believe are valid.
508 |
509 | If, pursuant to or in connection with a single transaction or
510 | arrangement, you convey, or propagate by procuring conveyance of, a
511 | covered work, and grant a patent license to some of the parties
512 | receiving the covered work authorizing them to use, propagate, modify
513 | or convey a specific copy of the covered work, then the patent license
514 | you grant is automatically extended to all recipients of the covered
515 | work and works based on it.
516 |
517 | A patent license is "discriminatory" if it does not include within the
518 | scope of its coverage, prohibits the exercise of, or is conditioned on
519 | the non-exercise of one or more of the rights that are specifically
520 | granted under this License. You may not convey a covered work if you
521 | are a party to an arrangement with a third party that is in the
522 | business of distributing software, under which you make payment to the
523 | third party based on the extent of your activity of conveying the
524 | work, and under which the third party grants, to any of the parties
525 | who would receive the covered work from you, a discriminatory patent
526 | license (a) in connection with copies of the covered work conveyed by
527 | you (or copies made from those copies), or (b) primarily for and in
528 | connection with specific products or compilations that contain the
529 | covered work, unless you entered into that arrangement, or that patent
530 | license was granted, prior to 28 March 2007.
531 |
532 | Nothing in this License shall be construed as excluding or limiting
533 | any implied license or other defenses to infringement that may
534 | otherwise be available to you under applicable patent law.
535 |
536 | #### 12. No Surrender of Others' Freedom.
537 |
538 | If conditions are imposed on you (whether by court order, agreement or
539 | otherwise) that contradict the conditions of this License, they do not
540 | excuse you from the conditions of this License. If you cannot convey a
541 | covered work so as to satisfy simultaneously your obligations under
542 | this License and any other pertinent obligations, then as a
543 | consequence you may not convey it at all. For example, if you agree to
544 | terms that obligate you to collect a royalty for further conveying
545 | from those to whom you convey the Program, the only way you could
546 | satisfy both those terms and this License would be to refrain entirely
547 | from conveying the Program.
548 |
549 | #### 13. Use with the GNU Affero General Public License.
550 |
551 | Notwithstanding any other provision of this License, you have
552 | permission to link or combine any covered work with a work licensed
553 | under version 3 of the GNU Affero General Public License into a single
554 | combined work, and to convey the resulting work. The terms of this
555 | License will continue to apply to the part which is the covered work,
556 | but the special requirements of the GNU Affero General Public License,
557 | section 13, concerning interaction through a network will apply to the
558 | combination as such.
559 |
560 | #### 14. Revised Versions of this License.
561 |
562 | The Free Software Foundation may publish revised and/or new versions
563 | of the GNU General Public License from time to time. Such new versions
564 | will be similar in spirit to the present version, but may differ in
565 | detail to address new problems or concerns.
566 |
567 | Each version is given a distinguishing version number. If the Program
568 | specifies that a certain numbered version of the GNU General Public
569 | License "or any later version" applies to it, you have the option of
570 | following the terms and conditions either of that numbered version or
571 | of any later version published by the Free Software Foundation. If the
572 | Program does not specify a version number of the GNU General Public
573 | License, you may choose any version ever published by the Free
574 | Software Foundation.
575 |
576 | If the Program specifies that a proxy can decide which future versions
577 | of the GNU General Public License can be used, that proxy's public
578 | statement of acceptance of a version permanently authorizes you to
579 | choose that version for the Program.
580 |
581 | Later license versions may give you additional or different
582 | permissions. However, no additional obligations are imposed on any
583 | author or copyright holder as a result of your choosing to follow a
584 | later version.
585 |
586 | #### 15. Disclaimer of Warranty.
587 |
588 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
589 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
590 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT
591 | WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT
592 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
593 | A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND
594 | PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE
595 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR
596 | CORRECTION.
597 |
598 | #### 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR
602 | CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
603 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
604 | ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
605 | NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR
606 | LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM
607 | TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER
608 | PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
609 |
610 | #### 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | You can contact the author by sending email to gudjonholm@gmail.com or
622 | by regular post to the address Haseyla 27, 260 Reykjanesbar, Iceland.
623 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DisplayMenu
2 |
3 | This library helps with creating menu pages when using graphical displays supported by the [TFT_eSPI] library.
4 |
5 | ## To use this library
6 |
7 |
8 | ### First
9 | - If you use the __Arduino IDE__, after installing the library [TFT_eSPI] you will need to change the file `User_Setup.h`. See here for an excellent [tutorial].
10 | - If you use the __Platform io__, you do not need to change the file `User_Setup.h` but instead you will need to add these build settings to the project `platformio.ini` file in your project folder.
11 | ```
12 | build_flags =
13 | ;###############################################################
14 | ; TFT_eSPI library setting here (no need to edit library files):
15 | ;###############################################################
16 | -Os
17 | -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
18 | -DUSER_SETUP_LOADED=1 ; Set this settings as valid
19 | -DILI9341_DRIVER=1 ; Select ILI9163 driver, a generic driver for common displays
20 | -DTFT_MISO=19
21 | -DTFT_MOSI=23
22 | -DTFT_SCLK=18
23 | -DTFT_CS=15 ; Chip select control pin
24 | -DTFT_DC=2 ; Data Command control pin
25 | -DTFT_RST=4 ; Reset pin (could connect to RST pin)
26 | -DTOUCH_CS=21 ; Chip select pin (T_CS) of touch screen
27 | -DLOAD_GLCD=1 ; Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
28 | -DLOAD_FONT2=1 ; Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
29 | -DLOAD_FONT4=1 ; Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
30 | -DLOAD_FONT6=1 ; Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only character 1234567890:-.apm
31 | -DLOAD_FONT7=1 ; Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only character 1234567890:-.
32 | -DLOAD_FONT8=1 ; Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only character 1234567890:-.
33 | -DLOAD_GFXFF=1 ; FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 an custom fonts
34 | -DSMOOTH_FONT=1
35 | -DSPI_FREQUENCY=27000000
36 | -DSPI_READ_FREQUENCY=20000000
37 | -DSPI_TOUCH_FREQUENCY=2500000
38 | ```
39 | ### Next
40 | Then you can just add
41 | ```
42 | #include
43 | ```
44 | and you'r good to go
45 |
46 |
47 | [TFT_eSPI]: https://github.com/Bodmer/TFT_eSPI
48 | [tutorial]: https://www.xtronical.com/esp32ili9341/
--------------------------------------------------------------------------------
/examples/EditValues/EditValues.ino:
--------------------------------------------------------------------------------
1 | /**
2 | * @file EditValues.ino
3 | * @author guttih (gudjonholm@gmail.com)
4 | * @brief A program that creates a menu with three pages.
5 | * @version 0.1
6 | * @date 2021-08-13
7 | *
8 | * @copyright Copyright (c) 2021
9 | *
10 | */
11 |
12 | #include
13 |
14 | #include
15 |
16 | #include
17 |
18 | #include
19 |
20 | #include // Hardware-specific library
21 |
22 | /**
23 | * @brief Global variables in the program
24 | *
25 | */
26 | struct GLOBAL_STRUCT {
27 | double temperature = 0; // Current temperature read from the Temperature sensor.
28 | double desiredTemp = 24; // The desired temperature which should be fed as the setpoint to the PID controller.
29 | double coldValveFlow = 12.34; // A number from 0 to 100 describing the opening of the COLD valve, 0 is fully closed and 100 fully open.
30 | double hotValveFlow = 56.78; // A number from 0 to 100 describing the opening of the HOT valve, 0 is fully closed and 100 fully open.
31 | } values;
32 |
33 |
34 | #define CALIBRATION_FILE "/TouchCalData3"
35 |
36 |
37 | const bool invertColors = false;
38 |
39 | #define REPEAT_CAL true
40 |
41 | TFT_eSPI tft = TFT_eSPI();
42 |
43 |
44 | DisplayMenu menu = DisplayMenu(&tft);
45 |
46 | void touch_calibrate();
47 | void setupMenu();
48 |
49 | #include "menusetup.h"
50 |
51 | unsigned long updateTempTimer = 0;
52 |
53 | void setup()
54 | {
55 | Serial.begin(115200);
56 |
57 | if (tft.width() >= 480)
58 | tft.setRotation(0);
59 | touch_calibrate();
60 |
61 | menu.invertColors(invertColors);
62 | setupMenu();
63 | menu.showPage(1);
64 | updateTempTimer = millis() + 10;
65 | }
66 |
67 | void loop()
68 | {
69 | menu.update();
70 |
71 | if (millis() > updateTempTimer) {
72 | globalTemperature+=0.1;
73 | updateTempTimer = millis() + 10;
74 | pTempShowButton->draw(); //drawn only when pageValve is visable
75 | }
76 | }
77 |
78 | void touch_calibrate()
79 | {
80 | uint16_t calData[5];
81 | uint8_t calDataOK = 0;
82 |
83 | // check file system exists
84 | if (!SPIFFS.begin())
85 | {
86 | Serial.println("Formating file system");
87 | SPIFFS.format();
88 | SPIFFS.begin();
89 | }
90 |
91 | // check if calibration file exists and size is correct
92 | if (SPIFFS.exists(CALIBRATION_FILE))
93 | {
94 | if (REPEAT_CAL)
95 | {
96 | // Delete if we want to re-calibrate
97 | SPIFFS.remove(CALIBRATION_FILE);
98 | }
99 | else
100 | {
101 | File f = SPIFFS.open(CALIBRATION_FILE, "r");
102 | if (f)
103 | {
104 | if (f.readBytes((char *)calData, 14) == 14)
105 | calDataOK = 1;
106 | f.close();
107 | }
108 | }
109 | }
110 |
111 | if (calDataOK && !REPEAT_CAL)
112 | {
113 | // calibration data valid
114 | tft.setTouch(calData);
115 | }
116 | else
117 | {
118 | tft.invertDisplay(false);
119 | // data not valid so recalibrate
120 | tft.fillScreen(TFT_BLACK);
121 | tft.setCursor(20, 0);
122 | tft.setTextFont(2);
123 | tft.setTextSize(1);
124 | tft.setTextColor(TFT_WHITE, TFT_BLACK);
125 |
126 | tft.println("Touch corners as indicated");
127 |
128 | tft.setTextFont(1);
129 | tft.println();
130 |
131 | if (REPEAT_CAL)
132 | {
133 | tft.setTextColor(TFT_RED, TFT_BLACK);
134 | tft.println("Set REPEAT_CAL to false to stop this running again!");
135 | }
136 |
137 | tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);
138 |
139 | tft.setTextColor(TFT_GREEN, TFT_BLACK);
140 | tft.println("Calibration complete!");
141 |
142 | // store data
143 | File f = SPIFFS.open(CALIBRATION_FILE, "w");
144 | if (f)
145 | {
146 | f.write((const unsigned char *)calData, 14);
147 | f.close();
148 | }
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/examples/EditValues/editpagesetup.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file editpagesetup.h
3 | * @author guttih (gudjonholm@gmail.com)
4 | * @brief Creates a page that can modify a number
5 | * @date 2021-07-30
6 | *
7 | * @copyright Copyright (c) 2021
8 | *
9 | */
10 |
11 | #ifndef EDITPAGESETUPH
12 | #define EDITPAGESETUPH
13 |
14 | #include "DisplayMenu.h"
15 |
16 | double globalValueDouble = 123.5;
17 | double globalValueLong = 123;
18 | double globalTemperature = 22.97;
19 | DisplayButton *pTempShowButton = NULL;
20 |
21 | bool allowDouble,
22 | allowMinus;
23 |
24 | //want full precision but no ending zeros and no ending dot
25 | String removeUnNecessaryDoubleEnding(String str)
26 | {
27 |
28 | if (str.indexOf('.') > -1)
29 | {
30 | int len = str.length();
31 | while (len > 1 && (str.charAt(len - 1) == '0'))
32 | {
33 | str.remove(len - 1, 1);
34 | len = str.length();
35 | }
36 | }
37 |
38 | if (str.endsWith("."))
39 | str.remove(str.length() - 1, 1);
40 |
41 | return str;
42 | }
43 |
44 | String toString(double num)
45 | {
46 | char output[50];
47 |
48 | snprintf(output, 50, "%.9f", num);
49 | return removeUnNecessaryDoubleEnding(output);
50 | }
51 |
52 | /**
53 | * @brief checks if a string can be converted to and from a double number, resulting in the exactly the same string
54 | *
55 | * @param str a string to be tested and remove un necessary endings like 0 and .
56 | * @return String if success a string which can be converted to double and if fail an empty string:
57 | */
58 | String convertToDoubleAndBackToSameString(String str)
59 | {
60 | double d = str.toDouble();
61 | int dotPos = str.indexOf('.');
62 | int fractionLength = dotPos < 0 ? 0 : str.length() - (dotPos + 1);
63 | String diffString = String(d, fractionLength);
64 |
65 | diffString = removeUnNecessaryDoubleEnding(diffString);
66 |
67 | if (diffString.equals(removeUnNecessaryDoubleEnding(str)))
68 | return diffString;
69 | else
70 | return "";
71 | }
72 |
73 | void onShowEditValuePage(DisplayPage *pPage)
74 | {
75 | DisplayButton *btn;
76 |
77 | //Hide or show dot button
78 | btn = pPage->getButtonByText(".");
79 |
80 | btn->setState(allowDouble ? VISABLE : HIDDEN);
81 |
82 | //Hide or show minus button
83 | btn = pPage->getButtonByText("-");
84 | btn->setState(allowMinus ? VISABLE : HIDDEN);
85 | DisplayButton *btnValue = pPage->getLastButton();
86 |
87 | btnValue->setText(toString(*btnValue->getLinkedValue()));
88 | }
89 |
90 | void onDrawEditValuePage(DisplayPage *pPage)
91 | {
92 | DisplayButton *btnValue = pPage->getLastButton();
93 | pPage->getDisplay()->drawString(btnValue->getLinkedValueName(), 12, 44);
94 | btnValue->draw();
95 | }
96 |
97 | void pageEditKeyPressed(DisplayButton *btn)
98 | {
99 | DisplayPage *pPage = btn->getPage();
100 |
101 | char firstChar = 'x';
102 |
103 | if (btn->getText().length() > 0)
104 | firstChar = btn->_values.text.charAt(0);
105 | else
106 | return; //bad text on button
107 |
108 | DisplayButton *valueButton = btn->getPage()->getLastButton();
109 | String currentValue = valueButton->getText();
110 | String newStr = "";
111 | int currentLength = currentValue.length();
112 | switch (firstChar)
113 | {
114 |
115 | case 'O': //OK
116 | if (valueButton->getLinkedValue())
117 | {
118 | newStr = convertToDoubleAndBackToSameString(currentValue);
119 | double newVal = newStr.toDouble();
120 | *(valueButton->getLinkedValue()) = newVal;
121 | }
122 |
123 | pPage->getMenu()->showPage(valueButton->getPageToOpen());
124 | return;
125 | break;
126 |
127 | case 'C': //Cancel
128 | pPage->getMenu()->showPage(valueButton->getPageToOpen());
129 | return;
130 | break;
131 |
132 | case 'R': //Reset
133 | valueButton->setText("0");
134 | break;
135 |
136 | case '-':
137 | if (currentValue.startsWith("-"))
138 | {
139 | currentValue.remove(0, 1);
140 | }
141 | else
142 | {
143 | // no negative sign at beginning
144 | if (currentLength > 0 && currentValue != "0")
145 | {
146 | currentValue = String('-') + currentValue;
147 | }
148 | }
149 | valueButton->setText(currentValue);
150 | break;
151 |
152 | case '0':
153 | case '1':
154 | case '2':
155 | case '3':
156 | case '4':
157 | case '5':
158 | case '6':
159 | case '7':
160 | case '8':
161 | case '9':
162 | if (currentValue == "0")
163 | {
164 | valueButton->setText(String(firstChar));
165 | }
166 | else
167 | {
168 | newStr = convertToDoubleAndBackToSameString(currentValue + firstChar);
169 |
170 | if (newStr.length() > 0)
171 | valueButton->setText(currentValue + firstChar);
172 | }
173 | break;
174 |
175 | case '.':
176 | if (currentValue.indexOf('.') < 0)
177 | {
178 | if (currentLength < 0)
179 | currentValue = '0';
180 |
181 | valueButton->setText(currentValue + firstChar);
182 | }
183 | break;
184 |
185 | case 'D': //delete
186 |
187 | if (currentLength > 1)
188 | {
189 | currentValue.remove(currentLength - 1, 1);
190 | valueButton->setText(currentValue);
191 | }
192 | else
193 | {
194 | valueButton->setText("0");
195 | }
196 | break;
197 | }
198 |
199 | onDrawEditValuePage(pPage);
200 | }
201 |
202 | void addPageEditValue(DisplayMenu *pMenu)
203 | {
204 | DisplayPage *pPage = pMenu->addPage();
205 | const int rowCount = 4;
206 | const int colCount = 4;
207 | const int keyCount = (rowCount * colCount);
208 | char keys[keyCount][7] = {
209 | "7", "8", "9", "Delete",
210 | "4", "5", "6", "Reset",
211 | "1", "2", "3", "Cancel",
212 | "0", ".", "-", "OK"};
213 |
214 | uint16_t commandColors[rowCount] = {
215 | //Delete, Reset, Cancel, OK,
216 | TFT_BROWN, TFT_BROWN, TFT_RED, TFT_DARKGREEN};
217 |
218 | struct COMMAND_BUTTON
219 | {
220 | char text[3];
221 | uint16_t fillColor;
222 | };
223 |
224 | const uint16_t TFT_BUTTON_OUTLINE = tft.color565(115, 149, 125),
225 | TFT_BUTTON_FILL = tft.color565(48, 73, 47),
226 | TFT_BUTTON_TEXT = TFT_GOLD;
227 |
228 | const int buttonWidth = 50,
229 | buttonHeight = 39,
230 | buttonMarginX = 10,
231 | buttonMarginY = 68,
232 | buttonPaddingX = 5,
233 | buttonPaddingY = 5,
234 | buttonCmdWidth = 130,
235 | buttonCmdMarginX = 180;
236 |
237 | int col, row = 0;
238 | for (int x = 0; x < keyCount; x++)
239 | {
240 | col = x % colCount;
241 | if (col < (colCount - 1))
242 | {
243 | pPage->addFunctionButton(buttonMarginX + (col * (buttonPaddingX + buttonWidth)), buttonMarginY + (row * (buttonHeight + buttonPaddingY)),
244 | buttonWidth, buttonHeight,
245 | TFT_BUTTON_OUTLINE, TFT_BUTTON_FILL, TFT_BUTTON_TEXT, 1, keys[x], pageEditKeyPressed);
246 | }
247 | else
248 | { //Command buttons
249 | pPage->addFunctionButton(buttonCmdMarginX, buttonMarginY + (row * (buttonHeight + buttonPaddingY)), buttonCmdWidth, buttonHeight, TFT_BUTTON_OUTLINE, commandColors[row], TFT_BUTTON_TEXT, 1, keys[x], pageEditKeyPressed);
250 | }
251 |
252 | if ((x + 1) % colCount == 0)
253 | row++;
254 | }
255 |
256 | //the input display at top of the screen
257 | DisplayButton *btn = pPage->addFunctionButton(10, 1, 300, buttonHeight, TFT_BUTTON_OUTLINE, pPage->getDisplay()->color565(25, 25, 25), TFT_BUTTON_TEXT, 1, "0", NULL);
258 |
259 | btn->setPageToOpen(pPage->getMenu()->getPage(0));
260 | btn->setTextAlign(ALIGN_RIGHT, 20, 3);
261 | pPage->registerOnDrawEvent(onDrawEditValuePage);
262 | pPage->registerOnShowEvent(onShowEditValuePage);
263 | }
264 | #endif
--------------------------------------------------------------------------------
/examples/EditValues/menusetup.h:
--------------------------------------------------------------------------------
1 | /**
2 | * @file menusetup.h
3 | * @author guttih (gudjonholm@gmail.com)
4 | * @brief Global program functions for setting upp the menu and pages for the TFT display.
5 | * @date 2021-07-21
6 | *
7 | * @copyright Copyright (c) 2021
8 | *
9 | */
10 |
11 | #ifndef MENUSETUPH
12 | #define MENUSETUPH
13 |
14 | #include
15 | #include "DisplayMenu.h"
16 | #include "DisplayPage.h"
17 | #include "DisplayButton.h"
18 | #include "editpagesetup.h"
19 |
20 | const uint16_t TFT_BUTTON_OUTLINE = tft.color565(115, 149, 125);
21 | const uint16_t TFT_BUTTON_FILL = tft.color565(48, 73, 47);
22 | const uint16_t TFT_BUTTON_TEXT = TFT_GOLD;
23 |
24 | void addPageMenu()
25 | {
26 | menu.addPage();
27 | }
28 |
29 | void showPageEditTemperature(DisplayButton *menuButton)
30 | {
31 |
32 | //about to open edit temperature page
33 | DisplayMenu *pMenu = menuButton->getPage()->getMenu();
34 | DisplayPage *pEditPage = pMenu->getPage(2);
35 |
36 | DisplayButton *valueButton = pEditPage->getLastButton();
37 | valueButton->setPageToOpen(pMenu->getPage(0));
38 | valueButton->setLinkToValue(&globalTemperature, "Temperature");
39 | allowDouble = true;
40 | allowMinus = true;
41 | pMenu->showPage(2);
42 | }
43 |
44 | void showPageEditGlobalDouble(DisplayButton *menuButton)
45 | {
46 |
47 | DisplayMenu *pMenu = menuButton->getPage()->getMenu();
48 | DisplayPage *pEditPage = pMenu->getPage(2);
49 |
50 | DisplayButton *valueButton = pEditPage->getLastButton();
51 | valueButton->setPageToOpen(pMenu->getPage(0));
52 | valueButton->setLinkToValue(&globalValueDouble, "Global double");
53 |
54 | allowDouble = true;
55 | allowMinus = true;
56 | pMenu->showPage(2);
57 | }
58 |
59 | void showPageEditGlobalLong(DisplayButton *menuButton)
60 | {
61 |
62 | DisplayMenu *pMenu = menuButton->getPage()->getMenu();
63 | DisplayPage *pEditPage = pMenu->getPage(2);
64 |
65 | DisplayButton *valueButton = pEditPage->getLastButton();
66 |
67 | valueButton->setPageToOpen(pMenu->getPage(0));
68 | valueButton->setLinkToValue(&globalValueLong, "Global long");
69 |
70 | allowDouble = false;
71 | allowMinus = true;
72 | pMenu->showPage(2);
73 | }
74 |
75 | void onDrawPageValves(DisplayPage *pPage)
76 | {
77 |
78 | if (values.coldValveFlow < 0)
79 | values.coldValveFlow = 0;
80 | if (values.coldValveFlow > 100)
81 | values.coldValveFlow = 100;
82 | if (values.hotValveFlow < 0)
83 | values.hotValveFlow = 0;
84 | if (values.hotValveFlow > 100)
85 | values.hotValveFlow = 100;
86 | tft.setFreeFont(&FreeSans12pt7b);
87 |
88 | int16_t screenXCenter = tft.width() / 2;
89 |
90 | uint8_t oldDatum = tft.getTextDatum();
91 |
92 | tft.setTextDatum(TL_DATUM);
93 |
94 | tft.setTextColor(TFT_CYAN);
95 | tft.drawString("Cold", 36, 40);
96 |
97 | int32_t h = 20, w = 100, x = 20, y = 70;
98 | tft.drawRect(x, y, w, h, pPage->getFillColor());
99 | tft.fillRect(x, y, w, h, pPage->getFillColor());
100 | tft.drawString((String(values.coldValveFlow, 2)) + "%", x, y);
101 |
102 | tft.setTextColor(tft.color24to16(0xfb745b));
103 | tft.drawString("Hot", 36 + 208, 40);
104 |
105 | x = 220, y = 70;
106 | tft.drawRect(x, y, w, h, pPage->getFillColor());
107 | tft.fillRect(x, y, w, h, pPage->getFillColor());
108 | tft.drawString((String(values.hotValveFlow, 2)) + "%", x, y);
109 |
110 | tft.setTextColor(TFT_GOLD);
111 | tft.setTextDatum(C_BASELINE);
112 |
113 | tft.setFreeFont(&FreeSans9pt7b);
114 | tft.drawString("Temperature", screenXCenter, 200);
115 | tft.setTextDatum(oldDatum);
116 | }
117 |
118 | void addValve(DisplayPage *pPage, bool hotValve)
119 | {
120 | const int buttonWidth = 42;
121 | const int buttonHeight = 39;
122 | const int buttonMarginX = 10;
123 | const int buttonMarginY = 100;
124 | const int buttonPaddingX = 3;
125 | const int buttonPaddingY = 3;
126 | const int x = hotValve ? 208 : 5;
127 | double *pPlowValue = hotValve ? &values.hotValveFlow : &values.coldValveFlow;
128 |
129 | int btnCount = -1;
130 | ++btnCount;
131 | pPage->addIncrementButton(buttonMarginX + ((btnCount % 2) * (buttonPaddingX + buttonWidth)) + x, buttonMarginY + (btnCount % 3) * (buttonHeight + buttonPaddingY), buttonWidth, buttonHeight, TFT_BUTTON_OUTLINE, TFT_BUTTON_FILL, TFT_BUTTON_TEXT, 1, "<", pPlowValue, -0.1);
132 | ++btnCount;
133 | pPage->addIncrementButton(buttonMarginX + ((btnCount % 2) * (buttonPaddingX + buttonWidth)) + x, buttonMarginY + (btnCount % 3) * (buttonHeight + buttonPaddingY), buttonWidth, buttonHeight, TFT_BUTTON_OUTLINE, TFT_BUTTON_FILL, TFT_BUTTON_TEXT, 1, ">>", pPlowValue, 1);
134 | ++btnCount;
135 | pPage->addIncrementButton(buttonMarginX + ((btnCount % 2) * (buttonPaddingX + buttonWidth)) + x, buttonMarginY + (btnCount % 3) * (buttonHeight + buttonPaddingY), buttonWidth, buttonHeight, TFT_BUTTON_OUTLINE, TFT_BUTTON_FILL, TFT_BUTTON_TEXT, 1, "<<<", pPlowValue, -10);
136 | ++btnCount;
137 | pPage->addIncrementButton(buttonMarginX + ((btnCount % 2) * (buttonPaddingX + buttonWidth)) + x, buttonMarginY + (btnCount % 3) * (buttonHeight + buttonPaddingY), buttonWidth, buttonHeight, TFT_BUTTON_OUTLINE, TFT_BUTTON_FILL, TFT_BUTTON_TEXT, 1, ">", pPlowValue, 0.1);
138 | ++btnCount;
139 | pPage->addIncrementButton(buttonMarginX + ((btnCount % 2) * (buttonPaddingX + buttonWidth)) + x, buttonMarginY + (btnCount % 3) * (buttonHeight + buttonPaddingY), buttonWidth, buttonHeight, TFT_BUTTON_OUTLINE, TFT_BUTTON_FILL, TFT_BUTTON_TEXT, 1, "<<", pPlowValue, -1);
140 | ++btnCount;
141 | pPage->addIncrementButton(buttonMarginX + ((btnCount % 2) * (buttonPaddingX + buttonWidth)) + x, buttonMarginY + (btnCount % 3) * (buttonHeight + buttonPaddingY), buttonWidth, buttonHeight, TFT_BUTTON_OUTLINE, TFT_BUTTON_FILL, TFT_BUTTON_TEXT, 1, ">>>", pPlowValue, 10);
142 | }
143 |
144 | void onDrawTemperatureButton(DisplayButton *ptrButton)
145 | {
146 |
147 | ptrButton->setText(toString(*ptrButton->getLinkedValue()));
148 | }
149 | void addPageValves()
150 | {
151 | DisplayPage *pPage = menu.addPage();
152 | pPage->registerOnDrawEvent(onDrawPageValves);
153 |
154 | addValve(pPage, false);
155 | addValve(pPage, true);
156 |
157 | //temperatue button used to show show the temperature and if pressed edit the temperature
158 | const int w = 100;
159 | pTempShowButton = pPage->addFunctionButton(((tft.width() - w) / 2), 210, 100, 20, pPage->getFillColor(), pPage->getFillColor(), TFT_GOLD, 1, NULL, showPageEditTemperature);
160 | pTempShowButton->setLinkToValue(&globalTemperature, "value missing!");
161 | pTempShowButton->setTextAlign(ALIGN_CENTER, 0, 0);
162 | pTempShowButton->registerOnDrawEvent(onDrawTemperatureButton);
163 | }
164 |
165 | void setupMenu()
166 | {
167 | Serial.println("Global addresses");
168 | Serial.printf(" - globalValueDouble: %p\n", (void *)&globalValueDouble);
169 | Serial.printf(" - globalValueLong: %p\n", (void *)&globalValueLong);
170 | Serial.printf(" - temp: %p\n", (void *)&globalTemperature);
171 |
172 | addPageMenu(); //index 0
173 | addPageValves(); //index 1
174 |
175 | addPageEditValue(&menu); //index 2
176 |
177 | menu.getPage(1)->addPageButton((tft.width() - 100) / 2, 0, 100, 50, tft.color565(115, 149, 125), tft.color565(48, 73, 47), TFT_GOLD, 1, "Menu", menu.getPage(0));
178 |
179 | //Add menu buttons
180 | const int buttonWidth = 170;
181 | const int buttonHeight = 50;
182 | const int buttonMargin = 20;
183 | const int x = (tft.width() - buttonWidth) / 2;
184 |
185 | DisplayPage *pPage = menu.getPage(0);
186 | pPage->addPageButton(x, buttonMargin, buttonWidth, buttonHeight, TFT_BUTTON_OUTLINE, TFT_BUTTON_FILL, TFT_BUTTON_TEXT, 1, "Valves", menu.getPage(1));
187 | pPage->addFunctionButton(x, buttonMargin + 1 * (buttonMargin + buttonHeight), buttonWidth, buttonHeight, TFT_BUTTON_OUTLINE, TFT_BUTTON_FILL, TFT_BUTTON_TEXT, 1, "Edit double", showPageEditGlobalDouble);
188 | pPage->addFunctionButton(x, buttonMargin + 2 * (buttonMargin + buttonHeight), buttonWidth, buttonHeight, TFT_BUTTON_OUTLINE, TFT_BUTTON_FILL, TFT_BUTTON_TEXT, 1, "Edit long", showPageEditGlobalLong);
189 |
190 | menu.showPage(1);//TODO: SET BACK TO SHOWPAGE 1
191 | allowMinus = true;
192 | allowDouble = false;
193 | }
194 |
195 | #endif
--------------------------------------------------------------------------------
/examples/Menu/Menu.ino:
--------------------------------------------------------------------------------
1 |
2 | #include
3 |
4 | #include
5 |
6 | #include
7 |
8 | #include
9 |
10 | #include // Hardware-specific library
11 |
12 | #define CALIBRATION_FILE "/TouchCalData3"
13 |
14 | #define REPEAT_CAL true
15 |
16 | TFT_eSPI tft = TFT_eSPI();
17 |
18 |
19 | void touch_calibrate();
20 |
21 |
22 | DisplayMenu menu = DisplayMenu(&tft);
23 | void setup()
24 | {
25 | const uint16_t buttonWidth = 120;
26 | const uint16_t buttonHeight = 50;
27 | const uint16_t centerHorizontal = (tft.width() - buttonWidth)/2;
28 | const uint16_t centerVertical = (tft.height() - buttonHeight)/2;
29 |
30 | touch_calibrate();
31 | DisplayPage *pMainMenu, *pSecondMenu, *pThirdMenu;
32 | DisplayLabel *pLabel;
33 | pMainMenu = menu.addPage(); //adding page at index 0
34 | pSecondMenu = menu.addPage(); //adding page at index 1
35 | pThirdMenu = menu.addPage(); //adding page at index 2
36 |
37 | // Adding labels to pages
38 | pLabel = pMainMenu->addPageLabel(centerHorizontal, 0, buttonWidth, buttonHeight, pMainMenu->getFillColor(), pMainMenu->getFillColor(), TFT_YELLOW, 1, "Main menu");
39 | pLabel->setTextAlign(ALIGN_CENTER, 0, 0);
40 |
41 | pLabel = pMainMenu->addPageLabel(centerHorizontal, tft.height()-buttonHeight, buttonWidth, buttonHeight, pMainMenu->getFillColor(), pMainMenu->getFillColor(), TFT_ORANGE, 1, "Hello world demo");
42 | pLabel->setTextAlign(ALIGN_CENTER, 0, 0);
43 | pSecondMenu->addPageLabel(centerHorizontal, 0, buttonWidth, buttonHeight, pMainMenu->getFillColor(), pMainMenu->getFillColor(), TFT_YELLOW, 1, "Page 1");
44 | //You can also get a page by page index like this
45 | menu.getPage(2)->addPageLabel(centerHorizontal, 0, buttonWidth, buttonHeight, pMainMenu->getFillColor(), pMainMenu->getFillColor(), TFT_YELLOW, 1, "Page 2");
46 |
47 |
48 | //add a open page buttons to main menu;
49 | pMainMenu->addPageButton(centerHorizontal, centerVertical - buttonHeight/1.5, buttonWidth, buttonHeight, TFT_WHITE, TFT_RED, TFT_GOLD, 1, "Page 1", menu.getPage(1));
50 | pMainMenu->addPageButton(centerHorizontal, centerVertical + buttonHeight/1.5, buttonWidth, buttonHeight, TFT_WHITE, TFT_RED, TFT_GOLD, 1, "Page 2", menu.getPage(2));
51 |
52 | //add a open main menu button to second page
53 | pSecondMenu->addPageButton(centerHorizontal, centerVertical, buttonWidth, buttonHeight, TFT_WHITE, TFT_RED, TFT_GOLD, 1, "Main menu", menu.getPage(0));
54 |
55 | //add a open main menu button to third page
56 | pThirdMenu->addPageButton(centerHorizontal, centerVertical, buttonWidth, buttonHeight, TFT_WHITE, TFT_RED, TFT_GOLD, 1, "Main menu", menu.getPage(0));
57 | menu.showPage(0);
58 | }
59 |
60 | void loop()
61 | {
62 | menu.update();
63 |
64 | }
65 |
66 | void touch_calibrate()
67 | {
68 | uint16_t calData[5];
69 | uint8_t calDataOK = 0;
70 |
71 | // check file system exists
72 | if (!SPIFFS.begin())
73 | {
74 | Serial.println("Formating file system");
75 | SPIFFS.format();
76 | SPIFFS.begin();
77 | }
78 |
79 | // check if calibration file exists and size is correct
80 | if (SPIFFS.exists(CALIBRATION_FILE))
81 | {
82 | if (REPEAT_CAL)
83 | {
84 | // Delete if we want to re-calibrate
85 | SPIFFS.remove(CALIBRATION_FILE);
86 | }
87 | else
88 | {
89 | File f = SPIFFS.open(CALIBRATION_FILE, "r");
90 | if (f)
91 | {
92 | if (f.readBytes((char *)calData, 14) == 14)
93 | calDataOK = 1;
94 | f.close();
95 | }
96 | }
97 | }
98 |
99 | if (calDataOK && !REPEAT_CAL)
100 | {
101 | // calibration data valid
102 | tft.setTouch(calData);
103 | }
104 | else
105 | {
106 | // data not valid so recalibrate
107 | tft.fillScreen(TFT_BLACK);
108 | tft.setCursor(20, 0);
109 | tft.setTextFont(2);
110 | tft.setTextSize(1);
111 | tft.setTextColor(TFT_WHITE, TFT_BLACK);
112 |
113 | tft.println("Touch corners as indicated");
114 |
115 | tft.setTextFont(1);
116 | tft.println();
117 |
118 | if (REPEAT_CAL)
119 | {
120 | tft.setTextColor(TFT_RED, TFT_BLACK);
121 | tft.println("Set REPEAT_CAL to false to stop this running again!");
122 | }
123 |
124 | tft.calibrateTouch(calData, TFT_MAGENTA, TFT_BLACK, 15);
125 |
126 | tft.setTextColor(TFT_GREEN, TFT_BLACK);
127 | tft.println("Calibration complete!");
128 |
129 | // store data
130 | File f = SPIFFS.open(CALIBRATION_FILE, "w");
131 | if (f)
132 | {
133 | f.write((const unsigned char *)calData, 14);
134 | f.close();
135 | }
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/include/README:
--------------------------------------------------------------------------------
1 |
2 | This directory is intended for project header files.
3 |
4 | A header file is a file containing C declarations and macro definitions
5 | to be shared between several project source files. You request the use of a
6 | header file in your project source file (C, C++, etc) located in `src` folder
7 | by including it, with the C preprocessing directive `#include'.
8 |
9 | ```src/main.c
10 |
11 | #include "header.h"
12 |
13 | int main (void)
14 | {
15 | ...
16 | }
17 | ```
18 |
19 | Including a header file produces the same results as copying the header file
20 | into each source file that needs it. Such copying would be time-consuming
21 | and error-prone. With a header file, the related declarations appear
22 | in only one place. If they need to be changed, they can be changed in one
23 | place, and programs that include the header file will automatically use the
24 | new version when next recompiled. The header file eliminates the labor of
25 | finding and changing all the copies as well as the risk that a failure to
26 | find one copy will result in inconsistencies within a program.
27 |
28 | In C, the usual convention is to give header files names that end with `.h'.
29 | It is most portable to use only letters, digits, dashes, and underscores in
30 | header file names, and at most one dot.
31 |
32 | Read more about using header files in official GCC documentation:
33 |
34 | * Include Syntax
35 | * Include Operation
36 | * Once-Only Headers
37 | * Computed Includes
38 |
39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
40 |
--------------------------------------------------------------------------------
/keywords.txt:
--------------------------------------------------------------------------------
1 | #######################################
2 | # Syntax Coloring Map For DisplayMenu #
3 | #######################################
4 | # Class & DataTypes #
5 | #######################################
6 |
7 | # Classes
8 | DisplayMenu KEYWORD1
9 | DisplayPage KEYWORD1
10 | DisplayButton KEYWORD1
11 | DisplayLabel KEYWORD1
12 |
13 | # DataTypes
14 | OnShowDisplayPage KEYWORD1
15 | OnDrawDisplayPage KEYWORD1
16 | ButtonPressedFunction KEYWORD1
17 | OnDrawDisplayButton KEYWORD1
18 | OnDrawDisplayLabel KEYWORD1
19 | DISPLAY_LABEL_VALUES KEYWORD1
20 | DisplayButtonType KEYWORD1
21 | DISPLAY_BUTTON_VALUES KEYWORD1
22 | DisplayState KEYWORD1
23 | TOUCHED_STRUCT KEYWORD1
24 |
25 | #######################################
26 | # Methods and Functions #
27 | #######################################
28 |
29 | #-------------------------
30 | #- DisplayMenu functions -
31 | #-------------------------
32 | update KEYWORD2
33 | addPage KEYWORD2
34 | getPage KEYWORD2
35 | showPage KEYWORD2
36 | getVisablePage KEYWORD2
37 | getVisablePageIndex KEYWORD2
38 | getLastPage KEYWORD2
39 |
40 | #-------------------------
41 | #- DisplayPage functions -
42 | #-------------------------
43 | getDisplay KEYWORD2
44 | addFunctionButton KEYWORD2
45 | addPageButton KEYWORD2
46 | addIncrementButton KEYWORD2
47 | addPageLabel KEYWORD2
48 | getButton KEYWORD2
49 | getButtonByText KEYWORD2
50 | getPressedButton KEYWORD2
51 | drawTouchButtonsState KEYWORD2
52 | getMenu KEYWORD2
53 | getFillColor KEYWORD2
54 | getLastButton KEYWORD2
55 | getLastLabel KEYWORD2
56 | registerOnDrawEvent KEYWORD2
57 | registerOnShowEvent KEYWORD2
58 |
59 | #------------------------------------------
60 | #- DisplayButton & DisplayLabel functions -
61 | #------------------------------------------
62 | getText KEYWORD2
63 | setText KEYWORD2
64 | setLinkToValue KEYWORD2
65 | getLinkedValue KEYWORD2
66 | getLinkedValueName KEYWORD2
67 | setPageToOpen KEYWORD2
68 | getPageToOpen KEYWORD2
69 | setTextAlign KEYWORD2
70 | setState KEYWORD2
71 | show KEYWORD2
72 | hide KEYWORD2
73 | resetPressState KEYWORD2
74 | draw KEYWORD2
75 | registerOnDrawEvent KEYWORD2
76 | contains KEYWORD2
77 | press KEYWORD2
78 | isPressed KEYWORD2
79 | justPressed KEYWORD2
80 | justReleased KEYWORD2
81 | executeCommand KEYWORD2
82 | getPage KEYWORD2
83 |
84 |
85 | #######################################
86 | # Constants
87 | #######################################
88 | VISABLE LITERAL1
89 | HIDDEN LITERAL1
--------------------------------------------------------------------------------
/lib/README:
--------------------------------------------------------------------------------
1 |
2 | This directory is intended for project specific (private) libraries.
3 | PlatformIO will compile them to static libraries and link into executable file.
4 |
5 | The source code of each library should be placed in a an own separate directory
6 | ("lib/your_library_name/[here are source files]").
7 |
8 | For example, see a structure of the following two libraries `Foo` and `Bar`:
9 |
10 | |--lib
11 | | |
12 | | |--Bar
13 | | | |--docs
14 | | | |--examples
15 | | | |--src
16 | | | |- Bar.c
17 | | | |- Bar.h
18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19 | | |
20 | | |--Foo
21 | | | |- Foo.c
22 | | | |- Foo.h
23 | | |
24 | | |- README --> THIS FILE
25 | |
26 | |- platformio.ini
27 | |--src
28 | |- main.c
29 |
30 | and a contents of `src/main.c`:
31 | ```
32 | #include
33 | #include
34 |
35 | int main (void)
36 | {
37 | ...
38 | }
39 |
40 | ```
41 |
42 | PlatformIO Library Dependency Finder will find automatically dependent
43 | libraries scanning project source files.
44 |
45 | More information about PlatformIO Library Dependency Finder
46 | - https://docs.platformio.org/page/librarymanager/ldf.html
47 |
--------------------------------------------------------------------------------
/library.json:
--------------------------------------------------------------------------------
1 |
2 | {
3 | "name": "DisplayMenu",
4 | "version": "1.0.0",
5 | "keywords": "Arduino, tft, graphical, display, menu, ePaper, display, Pico, RP2040, STM32, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9481, ILI9486, ILI9488, ST7789, RM68140, SSD1351, SSD1963, ILI9225, HX8357D",
6 | "description": "Create menu and pages with ease on a graphical display supported by the TFT_eSPI library.",
7 | "repository":
8 | {
9 | "type": "git",
10 | "url": "https://github.com/guttih/DisplayMenu"
11 | },
12 | "authors":
13 | [
14 | {
15 | "name": "guttih",
16 | "email": "guttih@gmail.com",
17 | "maintainer": true
18 | }
19 | ],
20 | "dependencies": {
21 | "bodmer/TFT_eSPI": "*"
22 | },
23 | "frameworks": "arduino",
24 | "platforms": "rp2040, espressif8266, espressif32, ststm32"
25 | }
--------------------------------------------------------------------------------
/library.properties:
--------------------------------------------------------------------------------
1 | name=DisplayMenu
2 | version=1.0.0
3 | author=guttih
4 | maintainer=guttih
5 | sentence=This library helps with creating menu pages when using graphical displays supported by the TFT_eSPI library.
6 | paragraph=Create a menu, add pages to that menu and add labels and buttons to the pages. The library allows you to create an custom onDraw event to link text on buttons and labels to your program variables.
7 | category=Display
8 | url=https://github.com/guttih/DisplayMenu
9 | architectures=*
10 | includes=DisplayMenu.h
11 | depends=TFT_eSPI
--------------------------------------------------------------------------------
/platformio.ini:
--------------------------------------------------------------------------------
1 | ; PlatformIO Project Configuration File
2 | ;
3 | ; Build options: build flags, source filter
4 | ; Upload options: custom upload port, speed and extra flags
5 | ; Library options: dependencies, extra library storages
6 | ; Advanced options: extra scripting
7 | ;
8 | ; Please visit documentation for the other options and examples
9 | ; https://docs.platformio.org/page/projectconf.html
10 |
11 | [env:esp32dev]
12 | platform = espressif32
13 | board = esp32dev
14 | framework = arduino
15 | lib_deps = TFT_eSPI
16 |
--------------------------------------------------------------------------------
/src/DisplayButton.cpp:
--------------------------------------------------------------------------------
1 | #include "DisplayButton.h"
2 | #include "DisplayMenu.h"
3 |
4 | DisplayButton::DisplayButton( TFT_eSPI *tft,
5 | int16_t x,
6 | int16_t y,
7 | uint16_t width,
8 | uint16_t height,
9 | uint16_t outlineColor,
10 | uint16_t fillColor,
11 | uint16_t textColor,
12 | uint8_t textsize,
13 | const char *text,
14 | DisplayButtonType type,
15 | DisplayPage *page,
16 | DisplayPage *pPageToOpen,
17 | ButtonPressedFunction buttonPressed
18 | )
19 | {
20 |
21 | init(tft, x, y, width, height, outlineColor, fillColor, textColor, textsize, text, type, VISABLE, page, "", NULL, 0, pPageToOpen, buttonPressed);
22 | }
23 |
24 |
25 | DisplayButton::DisplayButton( TFT_eSPI *tft,
26 | int16_t x,
27 | int16_t y,
28 | uint16_t width,
29 | uint16_t height,
30 | uint16_t outlineColor,
31 | uint16_t fillColor,
32 | uint16_t textColor,
33 | uint8_t textsize,
34 | const char *text,
35 | DisplayButtonType type,
36 | DisplayPage *page,
37 | double *pLinkedValue,
38 | double incrementValue
39 | )
40 | {
41 |
42 | init(tft, x, y, width, height, outlineColor, fillColor, textColor, textsize, text, type, VISABLE, page, "", pLinkedValue, incrementValue, NULL, NULL);
43 | }
44 |
45 | // Copy constructor
46 | DisplayButton::DisplayButton(const DisplayButton &button)
47 | {
48 | init(button._values.tft , button._values.x , button._values.y,
49 | button._values.width , button._values.height , button._values.outlineColor,
50 | button._values.fillColor , button._values.textColor , button._values.textsize,
51 | button._values.text.c_str() , button._values.type , button._values.state,
52 | button._values.pPage , button._values.linkedValueName, button._values.pLinkedValue,
53 | button._values.incrementValue, button._values.pPageToOpen , button._values.buttonPressedFunction,
54 | button._values.textAlign);
55 | }
56 |
57 | void DisplayButton::init( TFT_eSPI *tft,
58 | int16_t x,
59 | int16_t y,
60 | uint16_t width,
61 | uint16_t height,
62 | uint16_t outlineColor,
63 | uint16_t fillColor,
64 | uint16_t textColor,
65 | uint8_t textsize,
66 | const char *text,
67 | DisplayButtonType type,
68 | DisplayState state,
69 | DisplayPage *page,
70 | String linkedValueName,
71 | double *pLinkedValue,
72 | double incrementValue,
73 | DisplayPage *pPageToOpen,
74 | ButtonPressedFunction buttonPressedFunction,
75 | TextAlign textAlign
76 | )
77 | {
78 |
79 | _values.tft = tft;
80 | _values.x = x;
81 | _values.y = y;
82 | _values.width = width;
83 | _values.height = height;
84 | _values.outlineColor = outlineColor;
85 | _values.fillColor = fillColor;
86 | _values.textColor = textColor;
87 | _values.textsize = textsize;
88 | _values.text = text;
89 | _values.type = type;
90 | _values.state = state;
91 | _values.pPage = page;
92 | _values.linkedValueName = linkedValueName;
93 | _values.pLinkedValue = pLinkedValue;
94 | _values.incrementValue = incrementValue;
95 | _values.pPageToOpen = pPageToOpen;
96 | _values.buttonPressedFunction = buttonPressedFunction;
97 |
98 | //defaults
99 | _values.radius = min(width, height) / 6; // Corner radius
100 | _values.textAlign = textAlign;
101 | _values.xDatumOffset = 0;
102 | _values.yDatumOffset = -4;
103 | _values.onDrawDisplayButton = NULL;
104 | _values.allowOnlyOneButtonPressedAtATime = type == OPEN_PAGE || type == RUN_FUNCTION? true: false;
105 | }
106 |
107 | void DisplayButton::resetPressState () {
108 | _lastState = false;
109 | _currentState = false;
110 | }
111 |
112 | void DisplayButton::draw(bool inverted, bool cancelDrawIfPageIsNotVisable)
113 | {
114 | if (_values.state == HIDDEN) {
115 | return;
116 | }
117 |
118 | if (cancelDrawIfPageIsNotVisable)
119 | {
120 | DisplayPage *pPage = getPage();
121 | if (pPage)
122 | {
123 | DisplayMenu *pMenu = pPage->getMenu();
124 | if (pMenu && pPage != pMenu->getVisablePage())
125 | return;
126 | }
127 | }
128 |
129 | if (_values.onDrawDisplayButton)
130 | _values.onDrawDisplayButton(this);
131 |
132 | uint16_t fillColor, outlineColor, textColor;
133 | if (!inverted)
134 | {
135 | fillColor = _values.fillColor;
136 | outlineColor = _values.outlineColor;
137 | textColor = _values.textColor;
138 | }
139 | else
140 | {
141 | fillColor = _values.textColor;
142 | outlineColor = _values.outlineColor;
143 | textColor = _values.fillColor;
144 | }
145 |
146 | int32_t x, xText, y, yText;
147 | x = xText = _values.x;
148 | y = yText = _values.y;
149 |
150 | //X calc
151 | int16_t textWidth = _values.tft->textWidth(_values.text);
152 | if (_values.textAlign == ALIGN_CENTER)
153 | {
154 | xText = _values.x + ((_values.width - textWidth) / 2) + _values.xDatumOffset;
155 | } else if (_values.textAlign == ALIGN_RIGHT)
156 | {
157 | xText = x + (_values.width - textWidth) - _values.xDatumOffset;
158 | }
159 |
160 | //Y calc
161 | yText = _values.y + (_values.height / 2) + _values.yDatumOffset;
162 |
163 | uint16_t before_color = _values.tft->textcolor;
164 | uint8_t before_textSize = _values.tft->textsize;
165 | uint8_t before_textDatum = _values.tft->getTextDatum();
166 | uint8_t before_textPadding = _values.tft->getTextPadding();
167 |
168 | _values.tft->setTextColor(textColor);
169 | _values.tft->setTextSize(_values.textsize);
170 | //Going to calculate everything from ML
171 | _values.tft->setTextDatum(ML_DATUM);
172 | _values.tft->setTextPadding(0);
173 |
174 | _values.tft->fillRoundRect(x, y, _values.width, _values.height, _values.radius, fillColor);
175 | _values.tft->drawRoundRect(x, y, _values.width, _values.height, _values.radius, outlineColor);
176 |
177 | _values.tft->drawString(_values.text, xText, yText);
178 |
179 | _values.tft->setTextColor(before_color);
180 | _values.tft->setTextSize(before_textSize);
181 | _values.tft->setTextDatum(before_textDatum);
182 | _values.tft->setTextPadding(before_textPadding);
183 |
184 | }
185 |
186 | bool DisplayButton::contains(int16_t x, int16_t y) {
187 | return ((x >= _values.x) && (x < (_values.x + _values.width)) &&
188 | (y >= _values.y) && (y < (_values.y + _values.height)));
189 | }
190 |
191 | void DisplayButton::press(bool isPressed) {
192 | _lastState = _currentState;
193 | _currentState = isPressed;
194 | }
195 |
196 | bool DisplayButton::isPressed() {
197 | return _currentState;
198 | }
199 | bool DisplayButton::justPressed() {
200 | return (_currentState && !_lastState);
201 | }
202 | bool DisplayButton::justReleased() {
203 | return (!_currentState && _lastState);
204 | }
205 |
206 | bool DisplayButton::executeCommand()
207 | {
208 | if (_values.state == HIDDEN)
209 | return false;
210 |
211 | switch (_values.type)
212 | {
213 | case RUN_FUNCTION:
214 | if (_values.buttonPressedFunction)
215 | {
216 | _values.buttonPressedFunction(this);
217 | return true;
218 | }
219 | break;
220 |
221 | case OPEN_PAGE:
222 | if (_values.pPageToOpen)
223 | {
224 | DisplayMenu *pMenu = _values.pPageToOpen->getMenu();
225 | if (pMenu)
226 | pMenu->showPage(_values.pPageToOpen);
227 | return true;
228 | }
229 | break;
230 |
231 | case INCREMENT_VALUE:
232 | if (_values.pLinkedValue && _values.incrementValue)
233 | {
234 |
235 | *_values.pLinkedValue += _values.incrementValue;
236 | if (_values.pPage)
237 | _values.pPage->draw(false);
238 | return true;
239 | }
240 |
241 | break;
242 | }
243 | return false;
244 | }
245 |
246 | void DisplayButton::setLinkToValue(double *pLinkedValue, String valueName) {
247 | _values.pLinkedValue = pLinkedValue;
248 | _values.linkedValueName = valueName;
249 | };
250 |
251 | void DisplayButton::setText(String newText, bool drawScreenNow)
252 | {
253 | _values.text = newText;
254 | if (drawScreenNow)
255 | draw();
256 | };
257 |
258 | void DisplayButton::setTextAlign(TextAlign textAlign, int16_t xDatumOffset, int16_t yDatumOffset)
259 | {
260 | _values.textAlign = textAlign;
261 | _values.xDatumOffset = xDatumOffset;
262 | _values.yDatumOffset = yDatumOffset;
263 | };
--------------------------------------------------------------------------------
/src/DisplayButton.h:
--------------------------------------------------------------------------------
1 | #ifndef DISPLAYBUTTON_H
2 | #define DISPLAYBUTTON_H
3 |
4 |
5 | #include
6 |
7 | #include
8 |
9 | #include
10 |
11 | #include
12 |
13 | #include "DisplayGlobals.h"
14 |
15 | class DisplayButton;
16 |
17 | typedef void (*ButtonPressedFunction) (DisplayButton *ptrButton);
18 | typedef void (*OnDrawDisplayButton) (DisplayButton *ptrButton);
19 |
20 | /**
21 | * @brief DisplayButton type enumeration which holds information on how the button behaves when it is pressed.
22 | *
23 | */
24 | enum DisplayButtonType {
25 | RUN_FUNCTION,
26 | OPEN_PAGE,
27 | INCREMENT_VALUE
28 | };
29 |
30 | class DisplayPage;
31 |
32 | struct DISPLAY_BUTTON_VALUES {
33 | TFT_eSPI *tft;
34 | int16_t x;
35 | int16_t y;
36 | int16_t xDatumOffset;
37 | int16_t yDatumOffset;
38 | uint16_t width;
39 | uint16_t height;
40 | uint16_t outlineColor;
41 | uint16_t fillColor;
42 | uint16_t textColor;
43 | uint8_t textsize;
44 | TextAlign textAlign;
45 | uint8_t radius;
46 | String text;
47 | bool allowOnlyOneButtonPressedAtATime;
48 |
49 | DisplayButtonType type;
50 | DisplayState state;
51 | DisplayPage *pPage;
52 | double *pLinkedValue;
53 | String linkedValueName;
54 | double incrementValue;
55 | DisplayPage *pPageToOpen;
56 | ButtonPressedFunction buttonPressedFunction;
57 | OnDrawDisplayButton onDrawDisplayButton;
58 | };
59 |
60 | class DisplayButton
61 | {
62 | private:
63 | double _dTemp;
64 | void init( TFT_eSPI *tft,
65 | int16_t x,
66 | int16_t y,
67 | uint16_t width,
68 | uint16_t height,
69 | uint16_t outlineColor,
70 | uint16_t fillColor,
71 | uint16_t textColor,
72 | uint8_t textsize,
73 | const char *text,
74 | DisplayButtonType type,
75 | DisplayState state,
76 | DisplayPage *page,
77 | String linkedValueName,
78 | double *pLinkedValue,
79 | double incrementValue,
80 | DisplayPage *pageToOpen,
81 | ButtonPressedFunction buttonPressedFunction,
82 | TextAlign textAlign = ALIGN_CENTER
83 | );
84 | public:
85 | bool _currentState,
86 | _lastState;
87 | String getText() { return _values.text; };
88 |
89 | /**
90 | * @brief Set the Text of the button
91 | *
92 | * @param newText New text to be set
93 | * @param drawScreenNow Should the screen be udpdated right away?
94 | */
95 | void setText(String newText, bool drawScreenNow = false);
96 | void setLinkToValue(double *pLinkedValue, String valueName);
97 |
98 | double *getLinkedValue() { return _values.pLinkedValue; };
99 | String getLinkedValueName() { return _values.linkedValueName; };
100 | void setPageToOpen(DisplayPage *pageToOpen) { _values.pPageToOpen = pageToOpen; };
101 | DisplayPage *getPageToOpen() { return _values.pPageToOpen; };
102 | void setTextAlign(TextAlign textAlign, int16_t xDatumOffset = 0, int16_t yDatumOffset = 0);
103 | void setState(DisplayState state) { _values.state = state; };
104 | void show() { _values.state = DisplayState::VISABLE; };
105 | void hide() { _values.state = DisplayState::HIDDEN; };
106 | DISPLAY_BUTTON_VALUES _values;
107 | DISPLAY_BUTTON_VALUES getValues() { return _values; };
108 |
109 | DisplayButton(const DisplayButton &button);
110 |
111 | DisplayButton( TFT_eSPI *tft,
112 | int16_t x,
113 | int16_t y,
114 | uint16_t width,
115 | uint16_t height,
116 | uint16_t outlineColor,
117 | uint16_t fillColor,
118 | uint16_t textColor,
119 | uint8_t textsize,
120 | const char *text,
121 | DisplayButtonType type,
122 | DisplayPage *page,
123 | DisplayPage *pPageToOpen,
124 | ButtonPressedFunction buttonPressed
125 | );
126 |
127 | DisplayButton( TFT_eSPI *tft,
128 | int16_t x,
129 | int16_t y,
130 | uint16_t width,
131 | uint16_t height,
132 | uint16_t outlineColor,
133 | uint16_t fillColor,
134 | uint16_t textColor,
135 | uint8_t textsize,
136 | const char *text,
137 | DisplayButtonType type,
138 | DisplayPage *page,
139 | double *pLinkedValue,
140 | double incrementValue
141 | );
142 | void resetPressState();
143 |
144 | /**
145 | * @brief draws the button on to the screen
146 | *
147 | * @param inverted Should the button colors be drawn inverted
148 | * @param cancelDrawIfPageIsNotVisable should the draw be canceled if the page this button belongs to is hidden.
149 | * Node if you need more speed this variable should be false;
150 | */
151 | void draw(bool inverted=false, bool cancelDrawIfPageIsNotVisable = true);
152 | void registerOnDrawEvent(OnDrawDisplayButton pOnDrawDisplayButton) {
153 | _values.onDrawDisplayButton = pOnDrawDisplayButton;
154 | }
155 | void registerOnButtonPressedEvent(ButtonPressedFunction buttonPressed) {
156 | _values.buttonPressedFunction = buttonPressed;
157 | }
158 | bool contains(int16_t x, int16_t y);
159 |
160 | void press(bool isPressed);
161 | bool isPressed();
162 | bool justPressed();
163 | bool justReleased();
164 | bool executeCommand();
165 | DisplayPage *getPage() { return _values.pPage; }
166 | };
167 |
168 |
169 | #endif
--------------------------------------------------------------------------------
/src/DisplayButtonList.cpp:
--------------------------------------------------------------------------------
1 | #include "DisplayButtonList.h"
2 | bool DisplayButtonList::add(DisplayButton button) {
3 | return LinkedList::add(new DisplayButton(button));
4 | }
5 |
6 | DisplayButton *DisplayButtonList::findButtonByText(String text) {
7 |
8 | for (int i = 0; i < _size; i++)
9 | {
10 | DisplayButton *btn = get(i);
11 | if (btn->getText().equals(text))
12 | return btn;
13 | }
14 | return NULL;
15 | }
16 |
17 | void DisplayButtonList::destory() {
18 | DisplayButton* p;
19 | for (int i = 0; i < size(); i++) {
20 | p = get(i);
21 | if (p != NULL)
22 | {
23 | delay(10);
24 | delete p;
25 | set(i, NULL);
26 | }
27 | }
28 | clear();
29 | }
--------------------------------------------------------------------------------
/src/DisplayButtonList.h:
--------------------------------------------------------------------------------
1 | #ifndef DISPLAYBUTTONLIST_H
2 | #define DISPLAYBUTTONLIST_H
3 |
4 |
5 | #include "LinkedList.h"
6 | #include "DisplayButton.h"
7 |
8 | class DisplayButtonList : public LinkedList {
9 |
10 | private:
11 |
12 | /**
13 | * @brief The cleanup function used by the list's deconstructor;
14 | *
15 | */
16 | void destory();
17 |
18 | public:
19 | bool add(DisplayButton page);
20 |
21 | /**
22 | * @brief Searches for a button by the button text
23 | *
24 | * @param text
25 | * @return DisplayButton* if a button was found, otherwise NULL
26 | */
27 | DisplayButton *findButtonByText(String text);
28 |
29 | /**
30 | * @brief The count of items in the list
31 | *
32 | * @return int
33 | */
34 | int count() { return size(); };
35 |
36 |
37 | ~DisplayButtonList() { destory(); }
38 |
39 | };
40 |
41 | #endif
--------------------------------------------------------------------------------
/src/DisplayGlobals.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef DISPLAYGLOBAL_H
3 | #define DISPLAYGLOBAL_H
4 |
5 | enum DisplayState {
6 | VISABLE,
7 | HIDDEN
8 | };
9 |
10 | enum TextAlign {
11 | ALIGN_LEFT,
12 | ALIGN_CENTER,
13 | ALIGN_RIGHT
14 |
15 | };
16 |
17 | #endif
--------------------------------------------------------------------------------
/src/DisplayLabel.cpp:
--------------------------------------------------------------------------------
1 | #include "DisplayLabel.h"
2 | #include "DisplayMenu.h"
3 |
4 | DisplayLabel::DisplayLabel( TFT_eSPI *tft,
5 | int16_t x,
6 | int16_t y,
7 | uint16_t width,
8 | uint16_t height,
9 | uint16_t outlineColor,
10 | uint16_t fillColor,
11 | uint16_t textColor,
12 | uint8_t textsize,
13 | const char *text,
14 | DisplayPage *page
15 | )
16 | {
17 |
18 | init(tft, x, y, width, height, outlineColor, fillColor, textColor, textsize, text, VISABLE, page, "", NULL, 0);
19 | }
20 |
21 |
22 | DisplayLabel::DisplayLabel( TFT_eSPI *tft,
23 | int16_t x,
24 | int16_t y,
25 | uint16_t width,
26 | uint16_t height,
27 | uint16_t outlineColor,
28 | uint16_t fillColor,
29 | uint16_t textColor,
30 | uint8_t textsize,
31 | const char *text,
32 | DisplayPage *page,
33 | double *pLinkedValue,
34 | double incrementValue
35 | )
36 | {
37 |
38 | init(tft, x, y, width, height, outlineColor, fillColor, textColor, textsize, text, VISABLE, page, "", pLinkedValue, incrementValue);
39 | }
40 |
41 | // Copy constructor
42 | DisplayLabel::DisplayLabel(const DisplayLabel &label)
43 | {
44 | init(label._values.tft , label._values.x , label._values.y,
45 | label._values.width , label._values.height , label._values.outlineColor,
46 | label._values.fillColor , label._values.textColor , label._values.textsize,
47 | label._values.text.c_str() , label._values.state , label._values.pPage,
48 | label._values.linkedValueName, label._values.pLinkedValue , label._values.incrementValue,
49 | label._values.textAlign);
50 | }
51 |
52 | void DisplayLabel::init( TFT_eSPI *tft,
53 | int16_t x,
54 | int16_t y,
55 | uint16_t width,
56 | uint16_t height,
57 | uint16_t outlineColor,
58 | uint16_t fillColor,
59 | uint16_t textColor,
60 | uint8_t textsize,
61 | const char *text,
62 | DisplayState state,
63 | DisplayPage *page,
64 | String linkedValueName,
65 | double *pLinkedValue,
66 | double incrementValue,
67 | TextAlign textAlign
68 | )
69 | {
70 |
71 | _values.tft = tft;
72 | _values.x = x;
73 | _values.y = y;
74 | _values.width = width;
75 | _values.height = height;
76 | _values.outlineColor = outlineColor;
77 | _values.fillColor = fillColor;
78 | _values.textColor = textColor;
79 | _values.textsize = textsize;
80 | _values.text = text;
81 | _values.state = state;
82 | _values.pPage = page;
83 | _values.linkedValueName = linkedValueName;
84 | _values.pLinkedValue = pLinkedValue;
85 | _values.incrementValue = incrementValue;
86 |
87 | //defaults
88 | _values.radius = 0;
89 | _values.textAlign = textAlign;
90 | _values.xDatumOffset = 0;
91 | _values.yDatumOffset = -4;
92 | _values.onDrawDisplayLabel = NULL;
93 | }
94 |
95 | void DisplayLabel::resetPressState () {
96 | _lastState = false;
97 | _currentState = false;
98 | }
99 |
100 | void DisplayLabel::draw(bool inverted, bool cancelDrawIfPageIsNotVisable)
101 | {
102 | if (_values.state == HIDDEN) {
103 | return;
104 | }
105 |
106 | if (cancelDrawIfPageIsNotVisable)
107 | {
108 | DisplayPage *pPage = getPage();
109 | if (pPage)
110 | {
111 | DisplayMenu *pMenu = pPage->getMenu();
112 | if (pMenu && pPage != pMenu->getVisablePage())
113 | return;
114 | }
115 | }
116 |
117 | if (_values.onDrawDisplayLabel)
118 | _values.onDrawDisplayLabel(this);
119 |
120 | uint16_t fillColor, outlineColor, textColor;
121 | if (!inverted)
122 | {
123 | fillColor = _values.fillColor;
124 | outlineColor = _values.outlineColor;
125 | textColor = _values.textColor;
126 | }
127 | else
128 | {
129 | fillColor = _values.textColor;
130 | outlineColor = _values.outlineColor;
131 | textColor = _values.fillColor;
132 | }
133 |
134 | int32_t x, xText, y, yText;
135 | x = xText = _values.x;
136 | y = yText = _values.y;
137 |
138 | //X calc
139 | int16_t textWidth = _values.tft->textWidth(_values.text);
140 | if (_values.textAlign == ALIGN_CENTER)
141 | {
142 | xText = _values.x + ((_values.width - textWidth) / 2) + _values.xDatumOffset;
143 | } else if (_values.textAlign == ALIGN_RIGHT)
144 | {
145 | xText = x + (_values.width - textWidth) - _values.xDatumOffset;
146 | }
147 |
148 | //Y calc
149 | yText = _values.y + (_values.height / 2) + _values.yDatumOffset;
150 |
151 | uint16_t before_color = _values.tft->textcolor;
152 | uint8_t before_textSize = _values.tft->textsize;
153 | uint8_t before_textDatum = _values.tft->getTextDatum();
154 | uint8_t before_textPadding = _values.tft->getTextPadding();
155 |
156 | _values.tft->setTextColor(textColor);
157 | _values.tft->setTextSize(_values.textsize);
158 | //Going to calculate everything from ML
159 | _values.tft->setTextDatum(ML_DATUM);
160 | _values.tft->setTextPadding(0);
161 |
162 | _values.tft->fillRoundRect(x, y, _values.width, _values.height, _values.radius, fillColor);
163 | _values.tft->drawRoundRect(x, y, _values.width, _values.height, _values.radius, outlineColor);
164 |
165 | _values.tft->drawString(_values.text, xText, yText);
166 |
167 | _values.tft->setTextColor(before_color);
168 | _values.tft->setTextSize(before_textSize);
169 | _values.tft->setTextDatum(before_textDatum);
170 | _values.tft->setTextPadding(before_textPadding);
171 |
172 | }
173 |
174 | void DisplayLabel::setLinkToValue(double *pLinkedValue, String valueName) {
175 | _values.pLinkedValue = pLinkedValue;
176 | _values.linkedValueName = valueName;
177 | };
178 |
179 | void DisplayLabel::setText(String newText, bool drawScreenNow)
180 | {
181 | _values.text = newText;
182 | if (drawScreenNow)
183 | draw();
184 | };
185 |
186 | void DisplayLabel::setTextAlign(TextAlign textAlign, int16_t xDatumOffset, int16_t yDatumOffset)
187 | {
188 | _values.textAlign = textAlign;
189 | _values.xDatumOffset = xDatumOffset;
190 | _values.yDatumOffset = yDatumOffset;
191 | };
--------------------------------------------------------------------------------
/src/DisplayLabel.h:
--------------------------------------------------------------------------------
1 | #ifndef DISPLAYLABEL_H
2 | #define DISPLAYLABEL_H
3 |
4 |
5 | #include
6 |
7 | #include
8 |
9 | #include
10 |
11 | #include
12 |
13 | #include "DisplayGlobals.h"
14 |
15 | class DisplayLabel;
16 |
17 | typedef void (*OnDrawDisplayLabel) (DisplayLabel *ptrLabel);
18 |
19 | class DisplayPage;
20 |
21 | struct DISPLAY_LABEL_VALUES {
22 | TFT_eSPI *tft;
23 | int16_t x;
24 | int16_t y;
25 | int16_t xDatumOffset;
26 | int16_t yDatumOffset;
27 | uint16_t width;
28 | uint16_t height;
29 | uint16_t outlineColor;
30 | uint16_t fillColor;
31 | uint16_t textColor;
32 | uint8_t textsize;
33 | TextAlign textAlign;
34 | uint8_t radius;
35 | String text;
36 | DisplayState state;
37 | DisplayPage *pPage;
38 | double *pLinkedValue;
39 | String linkedValueName;
40 | double incrementValue;
41 | OnDrawDisplayLabel onDrawDisplayLabel;
42 | };
43 |
44 | class DisplayLabel
45 | {
46 | private:
47 | double _dTemp;
48 | void init( TFT_eSPI *tft,
49 | int16_t x,
50 | int16_t y,
51 | uint16_t width,
52 | uint16_t height,
53 | uint16_t outlineColor,
54 | uint16_t fillColor,
55 | uint16_t textColor,
56 | uint8_t textsize,
57 | const char *text,
58 | DisplayState state,
59 | DisplayPage *page,
60 | String linkedValueName,
61 | double *pLinkedValue,
62 | double incrementValue,
63 | TextAlign textAlign = ALIGN_LEFT
64 | );
65 | public:
66 | bool _currentState,
67 | _lastState;
68 | String getText() { return _values.text; };
69 |
70 | /**
71 | * @brief Set the Text of the label
72 | *
73 | * @param newText New text to be set
74 | * @param drawScreenNow Should the screen be udpdated right away?
75 | */
76 | void setText(String newText, bool drawScreenNow = false);
77 |
78 | void setLinkToValue(double *pLinkedValue, String valueName);
79 |
80 | double *getLinkedValue() { return _values.pLinkedValue; };
81 | String getLinkedValueName() { return _values.linkedValueName; };
82 | void setTextAlign(TextAlign textAlign, int16_t xDatumOffset = 0, int16_t yDatumOffset = 0);
83 | void setState(DisplayState state) { _values.state = state; };
84 | void show() { _values.state = DisplayState::VISABLE; };
85 | void hide() { _values.state = DisplayState::HIDDEN; };
86 | DISPLAY_LABEL_VALUES _values;
87 | DISPLAY_LABEL_VALUES getValues() { return _values; };
88 |
89 | DisplayLabel(const DisplayLabel &label);
90 |
91 | DisplayLabel( TFT_eSPI *tft,
92 | int16_t x,
93 | int16_t y,
94 | uint16_t width,
95 | uint16_t height,
96 | uint16_t outlineColor,
97 | uint16_t fillColor,
98 | uint16_t textColor,
99 | uint8_t textsize,
100 | const char *text,
101 | DisplayPage *page
102 | );
103 |
104 | DisplayLabel( TFT_eSPI *tft,
105 | int16_t x,
106 | int16_t y,
107 | uint16_t width,
108 | uint16_t height,
109 | uint16_t outlineColor,
110 | uint16_t fillColor,
111 | uint16_t textColor,
112 | uint8_t textsize,
113 | const char *text,
114 | DisplayPage *page,
115 | double *pLinkedValue,
116 | double incrementValue
117 | );
118 | void resetPressState();
119 |
120 | /**
121 | * @brief draws the button on to the screen
122 | *
123 | * @param inverted Should the button colors be drawn inverted
124 | * @param checkIfPageIsVisable should the draw be canceled if the page this button belongs to is hidden.
125 | * Node if you need more speed this variable should be false;
126 | */
127 | void draw(bool inverted=false, bool checkIfPageIsVisable = true);
128 | void registerOnDrawEvent(OnDrawDisplayLabel pOnDrawDisplayLabel) {
129 | _values.onDrawDisplayLabel = pOnDrawDisplayLabel;
130 | }
131 |
132 | DisplayPage *getPage() { return _values.pPage; }
133 | };
134 |
135 |
136 | #endif
--------------------------------------------------------------------------------
/src/DisplayLabelList.cpp:
--------------------------------------------------------------------------------
1 | #include "DisplayLabelList.h"
2 | bool DisplayLabelList::add(DisplayLabel button) {
3 | return LinkedList::add(new DisplayLabel(button));
4 | }
5 |
6 | DisplayLabel *DisplayLabelList::findButtonByText(String text) {
7 |
8 | for (int i = 0; i < _size; i++)
9 | {
10 | DisplayLabel *btn = get(i);
11 | if (btn->getText().equals(text))
12 | return btn;
13 | }
14 | return NULL;
15 | }
16 |
17 | void DisplayLabelList::destory() {
18 | DisplayLabel* p;
19 | for (int i = 0; i < size(); i++) {
20 | p = get(i);
21 | if (p != NULL)
22 | {
23 | delay(10);
24 | delete p;
25 | set(i, NULL);
26 | }
27 | }
28 | clear();
29 | }
--------------------------------------------------------------------------------
/src/DisplayLabelList.h:
--------------------------------------------------------------------------------
1 | #ifndef DISPLAYLABELLIST_H
2 | #define DISPLAYLABELLIST_H
3 |
4 |
5 | #include "LinkedList.h"
6 | #include "DisplayLabel.h"
7 |
8 | class DisplayLabelList : public LinkedList {
9 |
10 | private:
11 |
12 | /**
13 | * @brief The cleanup function used by the list's deconstructor;
14 | *
15 | */
16 | void destory();
17 |
18 | public:
19 | bool add(DisplayLabel page);
20 |
21 | /**
22 | * @brief Searches for a button by the button text
23 | *
24 | * @param text
25 | * @return DisplayLabel* if a button was found, otherwise NULL
26 | */
27 | DisplayLabel *findButtonByText(String text);
28 |
29 | /**
30 | * @brief The count of items in the list
31 | *
32 | * @return int
33 | */
34 | int count() { return size(); };
35 |
36 |
37 | ~DisplayLabelList() { destory(); }
38 |
39 | };
40 |
41 | #endif
--------------------------------------------------------------------------------
/src/DisplayMenu.cpp:
--------------------------------------------------------------------------------
1 | #include "DisplayMenu.h"
2 |
3 | DisplayMenu::DisplayMenu(TFT_eSPI *tft, uint16_t fillColor)
4 | {
5 | init(tft, fillColor);
6 | }
7 |
8 | void DisplayMenu::init(TFT_eSPI *tft, uint16_t fillColor)
9 | {
10 | _tft = tft;
11 | _fillColor = fillColor;
12 |
13 | _tft->init();
14 | // // Set the rotation before we calibrate
15 | _tft->setRotation(1);
16 | // // Clear screen
17 | _tft->fillScreen(fillColor);
18 | _tft->setFreeFont(&FreeMonoBold9pt7b);
19 |
20 | //_tft->setFreeFont(&FreeMono9pt7b);
21 | //_tft->setFreeFont(&FreeSans9pt7b);
22 | //_tft->setFreeFont(&FreeSansBold9pt7b);
23 | //_tft->setFreeFont(&FreeSansBoldOblique9pt7b);
24 | // _tft->setFreeFont(&FreeSerif9pt7b); //fallegur en ekki vel lesanlegur
25 | //_tft->setFreeFont(&FreeSerifBold9pt7b);
26 | //_tft->setFreeFont(&FreeSerifBoldItalic9pt7b);
27 | //_tft->setFreeFont(&FreeSerifItalic9pt7b);
28 |
29 |
30 | _touch.pressed = false;
31 | _touch.x = 0;
32 | _touch.y = 0;
33 | _visablePage = -1;
34 | }
35 |
36 | void DisplayMenu::showPage(int index)
37 | {
38 |
39 | _visablePage = index;
40 | DisplayPage *pPage = getPage(_visablePage);
41 | pPage->show();
42 | }
43 |
44 | void DisplayMenu::showPage(DisplayPage *pPage)
45 | {
46 |
47 | int index = pages.indexOf(pPage);
48 | showPage(index);
49 | }
50 |
51 | DisplayPage *DisplayMenu::getVisablePage()
52 | {
53 |
54 | if (_visablePage < 0)
55 | return NULL;
56 |
57 | return getPage(_visablePage);
58 | }
59 |
60 | DisplayPage *DisplayMenu::getPage(int index)
61 | {
62 | return pages.get(index);
63 | }
64 |
65 |
66 | DisplayPage * DisplayMenu::addPage()
67 | {
68 | return addPage(_fillColor);
69 | }
70 |
71 | DisplayPage * DisplayMenu::addPage(uint16_t fillColor)
72 | {
73 | DisplayPage page(_tft, this, fillColor);
74 | return pages.add(page)? getLastPage() : NULL;
75 | }
76 |
77 | DisplayPage * DisplayMenu::addPage(DisplayPage page)
78 | {
79 | return pages.add(page)? getLastPage() : NULL;
80 | }
81 |
82 | DisplayPage *DisplayMenu::getLastPage()
83 | {
84 | int size = pages.size();
85 | if (size < 1)
86 | return NULL;
87 |
88 | return pages.get(size - 1);
89 | }
90 |
91 | bool DisplayMenu::update()
92 | {
93 | bool didUpdate = false;
94 |
95 | _touch.pressed = _tft->getTouch(&_touch.x, &_touch.y);
96 |
97 | if (_touch.pressed)
98 | {
99 | DisplayPage *pCurrentPage = getVisablePage();
100 | if (pCurrentPage)
101 | {
102 | DisplayButton *btn = pCurrentPage->getPressedButton(_touch.x, _touch.y);
103 | pCurrentPage->drawTouchButtonsState();
104 | delay(100);
105 | didUpdate = true;
106 | if (btn)
107 | {
108 | if (btn->_values.allowOnlyOneButtonPressedAtATime)
109 | {
110 | do
111 | {
112 | delay(50);
113 | _touch.pressed = _tft->getTouch(&_touch.x, &_touch.y);
114 | if (!_touch.pressed)
115 | {
116 | delay(10);
117 | _touch.pressed = _tft->getTouch(&_touch.x, &_touch.y);
118 | }
119 | } while (_touch.pressed); //wait until no touch, then execute
120 |
121 | //make button not inverted
122 | btn->resetPressState();
123 | btn->draw();
124 | }
125 | btn->executeCommand();
126 | }
127 | }
128 | }
129 | return didUpdate;
130 | }
--------------------------------------------------------------------------------
/src/DisplayMenu.h:
--------------------------------------------------------------------------------
1 | #ifndef DISPLAYMENU_H
2 | #define DISPLAYMENU_H
3 |
4 |
5 | #include
6 | #include
7 | #include
8 | #include // Hardware-specific library
9 |
10 | #include "DisplayPage.h"
11 | #include "DisplayPageList.h"
12 |
13 | struct TOUCHED_STRUCT {
14 | uint16_t x;
15 | uint16_t y;
16 | bool pressed;
17 |
18 | };
19 |
20 | class DisplayMenu
21 | {
22 | private:
23 | TFT_eSPI *_tft;
24 | int _visablePage;
25 | uint16_t _fillColor; //default fill color for pages
26 | TOUCHED_STRUCT _touch;
27 | DisplayPageList pages;
28 | unsigned long myTouchTimer;
29 | unsigned long myTouchDelay;
30 |
31 | void init(TFT_eSPI *tft, uint16_t fillColor);
32 |
33 | public:
34 | void invertColors(bool invert) { _tft->invertDisplay(invert); }
35 | DisplayMenu(TFT_eSPI *tft, uint16_t fillColor = TFT_BLACK);
36 | DisplayPage * addPage();
37 | DisplayPage * addPage(uint16_t fillColor);
38 | DisplayPage * addPage(DisplayPage page);
39 | DisplayPage *getPage(int index);
40 |
41 | //called when a page is beeing made visable;
42 | void showPage(int index);
43 | void showPage(DisplayPage *pPage);
44 | DisplayPage *getVisablePage();
45 |
46 | /**
47 | * @brief Get the Visable Page Index
48 | *
49 | * @return int if no page is visable -1 is returned
50 | */
51 | int getVisablePageIndex() { return _visablePage; };
52 | DisplayPage* getLastPage();
53 |
54 | //DisplayPage* getVisablePageIndex() { return _visablePage; };
55 | /**
56 | * @brief checks if a button was pressed and updates it's value and runs it's associated actions.
57 | *
58 | * @return true a button was pressed and a button status did change.
59 | * @return false no button was pressed.
60 | */
61 | bool update();
62 | };
63 |
64 |
65 | #endif
--------------------------------------------------------------------------------
/src/DisplayPage.cpp:
--------------------------------------------------------------------------------
1 | #include "DisplayPage.h"
2 |
3 | // Copy constructor
4 | DisplayPage::DisplayPage(const DisplayPage &page)
5 | {
6 |
7 | DisplayPage &ref = const_cast(page);
8 | init(ref._tft, ref._pMenu, ref._fillColor);
9 | int buttonCount = ref.buttonCount();
10 | DisplayButton *pBtn;
11 |
12 | for (int i = 0; i < buttonCount; i++)
13 | {
14 | pBtn = ref.buttons.get(i);
15 | addButton(*pBtn);
16 | }
17 | }
18 |
19 | DisplayPage::DisplayPage(TFT_eSPI *tft, DisplayMenu *menu, uint16_t fillColor)
20 | {
21 | init(tft, menu, fillColor);
22 | }
23 |
24 | void DisplayPage::init(TFT_eSPI *tft, DisplayMenu *menu, uint16_t fillColor)
25 | {
26 | _tft = tft;
27 | _fillColor = fillColor;
28 | _onDrawDisplayPage = NULL;
29 | _onShowDisplayPage = NULL;
30 | _pMenu = menu;
31 | }
32 |
33 |
34 |
35 | DisplayButton *DisplayPage::addButton(const DisplayButton button)
36 | {
37 | if (buttons.add(button))
38 | return getLastButton();
39 | return NULL;
40 | }
41 |
42 | DisplayLabel *DisplayPage::addLabel(const DisplayLabel label)
43 | {
44 | if (labels.add(label))
45 | return getLastLabel();
46 | return NULL;
47 | }
48 |
49 | DisplayButton *DisplayPage::addPageButton(int16_t x,
50 | int16_t y,
51 | uint16_t width,
52 | uint16_t height,
53 | uint16_t outlineColor,
54 | uint16_t fillColor,
55 | uint16_t textColor,
56 | uint8_t textsize,
57 | const char *text,
58 | DisplayPage *pPageToOpen,
59 | TextAlign textAlign
60 | )
61 | {
62 |
63 | DisplayButton pageButton(getDisplay(), x, y, width, height, outlineColor, fillColor, textColor, textsize, text, DisplayButtonType::OPEN_PAGE, this, pPageToOpen, NULL);
64 | pageButton.setTextAlign(textAlign);
65 |
66 | if (buttons.add(pageButton))
67 | return getLastButton();
68 | return NULL;
69 | }
70 |
71 | DisplayButton *DisplayPage::addFunctionButton(int16_t x,
72 | int16_t y,
73 | uint16_t width,
74 | uint16_t height,
75 | uint16_t outlineColor,
76 | uint16_t fillColor,
77 | uint16_t textColor,
78 | uint8_t textsize,
79 | const char *text,
80 | ButtonPressedFunction buttonPressedFunction
81 | )
82 | {
83 |
84 | DisplayButton functionButton(getDisplay(), x, y, width, height, outlineColor, fillColor, textColor, textsize, text, DisplayButtonType::RUN_FUNCTION, this, NULL, buttonPressedFunction);
85 | if (buttons.add(functionButton))
86 | return getLastButton();
87 | return NULL;
88 | }
89 |
90 | DisplayButton *DisplayPage::addIncrementButton( int16_t x,
91 | int16_t y,
92 | uint16_t width,
93 | uint16_t height,
94 | uint16_t outlineColor,
95 | uint16_t fillColor,
96 | uint16_t textColor,
97 | uint8_t textsize,
98 | const char *text,
99 | double *pLinkedValue,
100 | double incrementValue
101 | )
102 | {
103 |
104 | DisplayButton incrementButton(getDisplay(), x, y, width, height, outlineColor, fillColor, textColor, textsize, text, DisplayButtonType::INCREMENT_VALUE, this, pLinkedValue, incrementValue);
105 | if (buttons.add(incrementButton))
106 | return getLastButton();
107 | return NULL;
108 | }
109 |
110 | DisplayLabel *DisplayPage::addPageLabel(int16_t x,
111 | int16_t y,
112 | uint16_t width,
113 | uint16_t height,
114 | uint16_t outlineColor,
115 | uint16_t fillColor,
116 | uint16_t textColor,
117 | uint8_t textsize,
118 | const char *text,
119 | TextAlign textAlign)
120 | {
121 | DisplayLabel pageLabel(getDisplay(), x, y, width, height, outlineColor, fillColor, textColor, textsize, text, this);
122 | pageLabel.setTextAlign(textAlign);
123 | if (labels.add(pageLabel))
124 | return getLastLabel();
125 | return NULL;
126 | }
127 |
128 | void DisplayPage::drawButtons()
129 | {
130 | int count = buttonCount();
131 | for (int i = 0; i < count; i++)
132 | {
133 | DisplayButton *btn = buttons.get(i);
134 | btn->resetPressState();
135 | btn->draw();
136 | }
137 | }
138 |
139 | void DisplayPage::drawLabels()
140 | {
141 | int count = labelCount();
142 | for (int i = 0; i < count; i++)
143 | {
144 | DisplayLabel *lbl = labels.get(i);
145 | lbl->resetPressState();
146 | lbl->draw();
147 | }
148 | }
149 |
150 | void DisplayPage::draw(bool wipeScreen) {
151 |
152 | if (wipeScreen)
153 | _tft->fillScreen(_fillColor);
154 |
155 | if (_onDrawDisplayPage) {
156 | _onDrawDisplayPage(this);
157 | }
158 |
159 | _tft->setFreeFont(&FreeMonoBold9pt7b);
160 | drawLabels();
161 | drawButtons();
162 | }
163 |
164 | void DisplayPage::show() {
165 |
166 | if (_onShowDisplayPage) {
167 | _onShowDisplayPage(this);
168 | }
169 |
170 | draw(true);
171 | }
172 |
173 | DisplayButton *DisplayPage::getButton(int index)
174 | {
175 | return buttons.get(index);
176 | }
177 |
178 | DisplayLabel *DisplayPage::getLabel(int index)
179 | {
180 | return labels.get(index);
181 | }
182 |
183 |
184 | DisplayButton *DisplayPage::getPressedButton(uint16_t x, uint16_t y){
185 |
186 | int buttonCount = this->buttonCount();
187 | DisplayButton *pressedBtn = NULL;
188 | for (int i = buttonCount-1; i > -1; i--)
189 | {
190 | DisplayButton *btn = buttons.get(i);
191 |
192 | if (btn->contains(x, y)) {
193 |
194 | if (pressedBtn == NULL)
195 | pressedBtn = btn; //only return last button added
196 | btn->press(true);
197 | }
198 | else {
199 | btn->press(false);
200 | }
201 | }
202 | return pressedBtn;
203 | }
204 |
205 | DisplayButton *DisplayPage::getLastButton()
206 | {
207 | int size = buttons.size();
208 | if (size < 1)
209 | return NULL;
210 |
211 | return buttons.get(size - 1);
212 | }
213 |
214 | DisplayLabel *DisplayPage::getLastLabel()
215 | {
216 | int size = labels.size();
217 | if (size < 1)
218 | return NULL;
219 |
220 | return labels.get(size - 1);
221 | }
222 |
223 | void DisplayPage::drawTouchButtonsState() {
224 |
225 | int buttonCount = this->buttonCount();
226 |
227 | for (int i = 0; i < buttonCount; i++)
228 | {
229 | DisplayButton *btn = buttons.get(i);
230 | if (btn->justPressed())
231 | btn->draw(true);
232 |
233 | else if (btn->justReleased())
234 | btn->draw(false);
235 | }
236 |
237 | }
238 |
--------------------------------------------------------------------------------
/src/DisplayPage.h:
--------------------------------------------------------------------------------
1 | #ifndef DISPLAYPAGE_H
2 | #define DISPLAYPAGE_H
3 |
4 | #include
5 |
6 | #include
7 |
8 | #include
9 |
10 | #include // Hardware-specific library
11 |
12 | #include "DisplayLabel.h"
13 | #include "DisplayLabelList.h"
14 | #include "DisplayButton.h"
15 | #include "DisplayButtonList.h"
16 |
17 | class DisplayMenu;
18 |
19 |
20 | typedef void (*OnShowDisplayPage) (DisplayPage *pPage);
21 | typedef void (*OnDrawDisplayPage) (DisplayPage *pPage);
22 |
23 | class DisplayPage
24 | {
25 | private:
26 | TFT_eSPI *_tft;
27 | DisplayMenu *_pMenu;
28 | uint16_t _fillColor;
29 | DisplayButtonList buttons;
30 | DisplayLabelList labels;
31 | OnShowDisplayPage _onShowDisplayPage;
32 | OnDrawDisplayPage _onDrawDisplayPage;
33 | void init(TFT_eSPI *tft, DisplayMenu *menu, uint16_t fillColor);
34 | DisplayButton *addButton(const DisplayButton button);
35 | DisplayLabel *addLabel(const DisplayLabel label);
36 |
37 | public:
38 | /**
39 | * @brief Construct a new Display Page object (Copy constructor)
40 | *
41 | * @param page Page to copy values from to the new Constructed object.
42 | */
43 | DisplayPage(const DisplayPage &page);
44 |
45 | DisplayPage(TFT_eSPI *tft, DisplayMenu *menu, uint16_t fillColor = TFT_BLACK);
46 | /**
47 | * @brief draws all items on the page
48 | *
49 | */
50 | TFT_eSPI *getDisplay() { return _tft; }
51 |
52 | /**
53 | * @brief Adds a new button which runs a function every time it is pressed
54 | *
55 | * @param x Button upper left corner, x coordinate
56 | * @param y Button upper left corner, y coordinate
57 | * @param width Button width
58 | * @param height Button height
59 | * @param outlineColor Color of the line surrounding the button
60 | * @param fillColor Button color
61 | * @param textColor Button text color
62 | * @param textsize Button text multiplier size (2 is 100% bigger than normal).
63 | * @param text Button text
64 | * @param customDrawFunction
65 | * @return a pointer to the added button
66 | *
67 | */
68 | DisplayButton *addFunctionButton(int16_t x,
69 | int16_t y,
70 | uint16_t width,
71 | uint16_t height,
72 | uint16_t outlineColor,
73 | uint16_t fillColor,
74 | uint16_t textColor,
75 | uint8_t textsize,
76 | const char *text,
77 | ButtonPressedFunction buttonPressedFunction);
78 | /**
79 | * @brief Adds a new button which opens a given page
80 | *
81 | * @param x Button upper left corner, x coordinate
82 | * @param y Button upper left corner, y coordinate
83 | * @param width Button width
84 | * @param height Button height
85 | * @param outlineColor Color of the line surrounding the button
86 | * @param fillColor Button color
87 | * @param textColor Button text color
88 | * @param textsize Button text multiplier size (2 is 100% bigger than normal).
89 | * @param text Button text
90 | * @param pPageToOpen page the button belongs to
91 | * @return a pointer to the added button
92 | */
93 | DisplayButton *addPageButton( int16_t x,
94 | int16_t y,
95 | uint16_t width,
96 | uint16_t height,
97 | uint16_t outlineColor,
98 | uint16_t fillColor,
99 | uint16_t textColor,
100 | uint8_t textsize,
101 | const char *text,
102 | DisplayPage *pPageToOpen,
103 | TextAlign TextAlign = ALIGN_CENTER
104 | );
105 |
106 | /**
107 | * @brief Adds a new increment button to the page
108 | *
109 | * @param x Button upper left corner, x coordinate
110 | * @param y Button upper left corner, y coordinate
111 | * @param width Button width
112 | * @param height Button height
113 | * @param outlineColor Color of the line surrounding the button
114 | * @param fillColor Button color
115 | * @param textColor Button text color
116 | * @param textsize Button text multiplier size (2 is 100% bigger than normal).
117 | * @param text Button text
118 | * @param pLinkedValue value this button is suppose to change
119 | * @param incrementValue how munch should be value be incremented in each press
120 | * @return a pointer to the added button
121 | */
122 | DisplayButton *addIncrementButton( int16_t x,
123 | int16_t y,
124 | uint16_t width,
125 | uint16_t height,
126 | uint16_t outlineColor,
127 | uint16_t fillColor,
128 | uint16_t textColor,
129 | uint8_t textsize,
130 | const char *text,
131 | double *pLinkedValue,
132 | double incrementValue
133 | );
134 |
135 |
136 | DisplayLabel *addPageLabel(int16_t x,
137 | int16_t y,
138 | uint16_t width,
139 | uint16_t height,
140 | uint16_t outlineColor,
141 | uint16_t fillColor,
142 | uint16_t textColor,
143 | uint8_t textsize,
144 | const char *text,
145 | TextAlign TextAlign = ALIGN_LEFT);
146 | /**
147 | * @brief Get a pointer to a specific button stored in the page.
148 | *
149 | * @param index Index of the button to get.
150 | * @return DisplayButton*
151 | * @return if no button is found at the given index NULL is returned.
152 | */
153 | DisplayButton* getButton(int index);
154 |
155 | /**
156 | * @brief Get a pointer to a specific label stored in the page.
157 | *
158 | * @param index
159 | * @return DisplayLabel*
160 | * @return if no label is found at the given index NULL is returned.
161 | */
162 | DisplayLabel* getLabel(int index);
163 |
164 | /**
165 | * @brief Searches for a button by the button text
166 | *
167 | * @param text
168 | * @return DisplayButton* if a button was found, otherwise NULL
169 | */
170 | DisplayButton *getButtonByText(String text) { return buttons.findButtonByText(text); }
171 |
172 | int buttonCount() { return buttons.count(); } ;
173 | int labelCount() { return labels.count(); } ;
174 | void drawButtons();
175 | void drawLabels();
176 | void show();
177 | void draw(bool wipeScreen = true);
178 |
179 | DisplayButton *getPressedButton(uint16_t x, uint16_t y);
180 | void drawTouchButtonsState();
181 | DisplayMenu *getMenu() { return _pMenu; };
182 | uint16_t getFillColor() { return _fillColor; };
183 |
184 |
185 | /**
186 | * @brief Get the Last Button added to this page
187 | *
188 | * @return DisplayButton*
189 | */
190 | DisplayButton * getLastButton();
191 |
192 | /**
193 | * @brief Get the Last Label added to this page
194 | *
195 | * @return DisplayLabel*
196 | */
197 | DisplayLabel *getLastLabel();
198 |
199 | /**
200 | * @brief Provies a user defined function to be called every time before the page should be drawn.
201 | *
202 | * @code .cpp
203 | *
204 | * When function draw() is called, it will call this function and print out to serial most of the page values.
205 | *
206 | * TFT_eSPI tft = TFT_eSPI();
207 | * void myCustomPageDrawFunc(DisplayPage *pPage)
208 | * {
209 | * Serial.println("doing stuff");
210 | * }
211 | *
212 |
213 | * void setup()
214 | * {
215 | * DisplayPage page1(&tft);
216 | * page1.registerOnDrawEvent(myCustomPageDrawFunc);
217 | * page1.addPageButton(100, 120, 136, 40, TFT_RED, TFT_PURPLE, TFT_WHITE, 1, "Hello world", NULL);
218 | * page1.draw();
219 | * }
220 | * @endcode
221 | *
222 | * @param pOnDrawDisplayPage a pointer to a function which will be called just before the page is drawn
223 | */
224 | void registerOnDrawEvent(OnDrawDisplayPage pOnDrawDisplayPage) {
225 | _onDrawDisplayPage = pOnDrawDisplayPage;
226 | }
227 |
228 | /**
229 | * @brief Provies a user defined function to be called every time before the page should be shown.
230 | *
231 | * @param pOnShowDisplayPage a pointer to a function which will be called just before the page is shown
232 | */
233 | void registerOnShowEvent(OnShowDisplayPage pOnShowDisplayPage) {
234 | _onShowDisplayPage = pOnShowDisplayPage;
235 | }
236 |
237 | };
238 |
239 |
240 | #endif
--------------------------------------------------------------------------------
/src/DisplayPageList.cpp:
--------------------------------------------------------------------------------
1 | #include "DisplayPageList.h"
2 | bool DisplayPageList::add(DisplayPage page) {
3 | return LinkedList::add(new DisplayPage(page));
4 | }
5 |
6 | void DisplayPageList::destory() {
7 | DisplayPage* p;
8 | for (int i = 0; i < size(); i++) {
9 | p = get(i);
10 | if (p != NULL)
11 | {
12 | delay(10);
13 | delete p;
14 | set(i, NULL);
15 | }
16 | }
17 | clear();
18 | }
--------------------------------------------------------------------------------
/src/DisplayPageList.h:
--------------------------------------------------------------------------------
1 | #ifndef DISPLAYPAGELIST_H
2 | #define DISPLAYPAGELIST_H
3 |
4 | #include "LinkedList.h"
5 | #include "DisplayPage.h"
6 |
7 | class DisplayPageList : public LinkedList
8 | {
9 |
10 | private:
11 | /**
12 | * @brief The cleanup function used by the list's deconstructor;
13 | *
14 | */
15 | void destory();
16 |
17 | public:
18 | bool add(DisplayPage page);
19 |
20 | /**
21 | * @brief The count of items in the list
22 | *
23 | * @return int
24 | */
25 | int count() { return size(); };
26 |
27 | ~DisplayPageList() { destory(); }
28 | };
29 |
30 | #endif
--------------------------------------------------------------------------------
/src/LinkedList.h:
--------------------------------------------------------------------------------
1 | // LinkedList.h
2 |
3 | #ifndef _LINKEDLIST_h
4 | #define _LINKEDLIST_h
5 |
6 | // #if defined(ARDUINO) && ARDUINO >= 100
7 | //
8 | #include
9 | // #else
10 | // #include "WProgram.h"
11 | // #endif
12 | #include
13 | //INSERT_FROM_HERE
14 | #ifndef CODE_BLOCK_LinkedList
15 |
16 | //do not remove the comment below this line
17 | //INSERT_FROM_HERE
18 |
19 | // ---------------------------------------------------------------
20 | // LinkedList.h - V1.1 - Generic LinkedList implementation
21 | // For instructions, go to https://github.com/ivanseidel/LinkedList
22 |
23 | // Created by Ivan Seidel Gomes, March, 2013.
24 | // Released into the public domain.
25 | // ---------------------------------------------------------------
26 |
27 | template
28 | struct ListNode
29 | {
30 | T data;
31 | ListNode *next;
32 | };
33 |
34 |
35 | ///
36 | /// A general linked list ready to be used or Inherited
37 | ///
38 | template
39 | class LinkedList {
40 |
41 | protected:
42 | int _size;
43 | ListNode *root;
44 | ListNode *last;
45 |
46 | // Helps "get" method, by saving last position
47 | ListNode *lastNodeGot;
48 | int lastIndexGot;
49 | // isCached should be set to FALSE
50 | // everytime the list suffer changes
51 | bool isCached;
52 |
53 | ListNode* getNode(int index);
54 |
55 | public:
56 | LinkedList();
57 | ~LinkedList();
58 |
59 | /*
60 | Returns current size of LinkedList
61 | */
62 | virtual int size();
63 | /*
64 | Adds a T object in the specified index;
65 | Unlink and link the LinkedList correcly;
66 | Increment _size
67 | */
68 | virtual bool add(int index, T);
69 | /*
70 | Adds a T object in the end of the LinkedList;
71 | Increment _size;
72 | */
73 | virtual bool add(T);
74 | /*
75 | Adds a T object in the start of the LinkedList;
76 | Increment _size;
77 | */
78 | virtual bool unshift(T);
79 | /*
80 | Set the object at index, with T;
81 | Increment _size;
82 | */
83 | virtual bool set(int index, T);
84 | /*
85 | Remove object at index;
86 | If index is not reachable, returns false;
87 | else, decrement _size
88 | */
89 | virtual T remove(int index);
90 | /*
91 | Remove last object;
92 | */
93 | virtual T pop();
94 | /*
95 | Remove first object;
96 | */
97 | virtual T shift();
98 | /*
99 | Get the index'th element on the list;
100 | Return Element if accessible,
101 | else, return false;
102 | */
103 | virtual T get(int index);
104 |
105 | virtual int indexOf(T &pNode);
106 | /*
107 | Clear the entire array
108 | */
109 | virtual void clear();
110 |
111 | };
112 |
113 | // Initialize LinkedList with false values
114 | template
115 | LinkedList::LinkedList()
116 | {
117 | root = NULL;
118 | last = NULL;
119 | _size = 0;
120 |
121 | lastNodeGot = root;
122 | lastIndexGot = 0;
123 | isCached = false;
124 | }
125 |
126 | // Clear Nodes and free Memory
127 | template
128 | LinkedList::~LinkedList()
129 | {
130 | ListNode* tmp;
131 | while (root != NULL)
132 | {
133 | tmp = root;
134 | root = root->next;
135 | delete tmp;
136 | }
137 | last = NULL;
138 | _size = 0;
139 | isCached = false;
140 | }
141 |
142 | /*
143 | Actualy "logic" coding
144 | */
145 |
146 | template
147 | ListNode* LinkedList::getNode(int index) {
148 |
149 | int _pos = 0;
150 | ListNode* current = root;
151 |
152 | // Check if the node trying to get is
153 | // immediatly AFTER the previous got one
154 | if (isCached && lastIndexGot <= index) {
155 | _pos = lastIndexGot;
156 | current = lastNodeGot;
157 | }
158 |
159 | while (_pos < index && current) {
160 | current = current->next;
161 |
162 | _pos++;
163 | }
164 |
165 | // Check if the object index got is the same as the required
166 | if (_pos == index) {
167 | isCached = true;
168 | lastIndexGot = index;
169 | lastNodeGot = current;
170 |
171 | return current;
172 | }
173 |
174 | return NULL;
175 | }
176 |
177 | template
178 | int LinkedList::indexOf(T &data) {
179 |
180 |
181 | int pos = 0;
182 | ListNode* current = root;
183 |
184 | while ( (pos < _size) && current) {
185 | if (current->data == data)
186 | return pos;
187 | current = current->next;
188 |
189 | pos++;
190 | }
191 |
192 | return -1;
193 |
194 | // T p;
195 | // for (int i = 0; i < size(); i++) {
196 | // p = get(i);
197 | // if (p == data)
198 | // return i;
199 | // }
200 | // return -1;
201 |
202 | }
203 |
204 |
205 |
206 |
207 | template
208 | int LinkedList::size() {
209 | return _size;
210 | }
211 |
212 | template
213 | bool LinkedList::add(int index, T _t) {
214 |
215 | if (index >= _size)
216 | return add(_t);
217 |
218 | if (index == 0)
219 | return unshift(_t);
220 |
221 | ListNode *tmp = new ListNode(),
222 | *_prev = getNode(index - 1);
223 | tmp->data = _t;
224 | tmp->next = _prev->next;
225 | _prev->next = tmp;
226 |
227 | _size++;
228 | isCached = false;
229 |
230 | return true;
231 | }
232 |
233 | template
234 | bool LinkedList::add(T _t) {
235 |
236 | ListNode *tmp = new ListNode();
237 | tmp->data = _t;
238 | tmp->next = NULL;
239 |
240 | if (root) {
241 | // Already have elements inserted
242 | last->next = tmp;
243 | last = tmp;
244 | }
245 | else {
246 | // First element being inserted
247 | root = tmp;
248 | last = tmp;
249 | }
250 |
251 | _size++;
252 | isCached = false;
253 |
254 | return true;
255 | }
256 |
257 | template
258 | bool LinkedList::unshift(T _t) {
259 |
260 | if (_size == 0)
261 | return add(_t);
262 |
263 | ListNode *tmp = new ListNode();
264 | tmp->next = root;
265 | tmp->data = _t;
266 | root = tmp;
267 |
268 | _size++;
269 | isCached = false;
270 |
271 | return true;
272 | }
273 |
274 | template
275 | bool LinkedList::set(int index, T _t) {
276 | // Check if index position is in bounds
277 | if (index < 0 || index >= _size)
278 | return false;
279 |
280 | getNode(index)->data = _t;
281 | return true;
282 | }
283 |
284 | template
285 | T LinkedList::pop() {
286 | if (_size <= 0)
287 | return T();
288 |
289 | isCached = false;
290 |
291 | if (_size >= 2) {
292 | ListNode *tmp = getNode(_size - 2);
293 | T ret = tmp->next->data;
294 | delete(tmp->next);
295 | tmp->next = NULL;
296 | last = tmp;
297 | _size--;
298 | return ret;
299 | }
300 | else {
301 | // Only one element left on the list
302 | T ret = root->data;
303 | delete(root);
304 | root = NULL;
305 | last = NULL;
306 | _size = 0;
307 | return ret;
308 | }
309 | }
310 |
311 | template
312 | T LinkedList::shift() {
313 | if (_size <= 0)
314 | return T();
315 |
316 | if (_size > 1) {
317 | ListNode *_next = root->next;
318 | T ret = root->data;
319 | delete(root);
320 | root = _next;
321 | _size--;
322 | isCached = false;
323 |
324 | return ret;
325 | }
326 | else {
327 | // Only one left, then pop()
328 | return pop();
329 | }
330 |
331 | }
332 |
333 | template
334 | T LinkedList::remove(int index) {
335 | if (index < 0 || index >= _size)
336 | {
337 | return T();
338 | }
339 |
340 | if (index == 0)
341 | return shift();
342 |
343 | if (index == _size - 1)
344 | {
345 | return pop();
346 | }
347 |
348 | ListNode *tmp = getNode(index - 1);
349 | ListNode *toDelete = tmp->next;
350 | T ret = toDelete->data;
351 | tmp->next = tmp->next->next;
352 | delete(toDelete);
353 | _size--;
354 | isCached = false;
355 | return ret;
356 | }
357 |
358 |
359 | template
360 | T LinkedList::get(int index) {
361 | ListNode *tmp = getNode(index);
362 |
363 | return (tmp ? tmp->data : T());
364 | }
365 |
366 | template
367 | void LinkedList::clear() {
368 | while (size() > 0)
369 | shift();
370 | }
371 | #endif //CODE_BLOCK_LinkedList
372 | //INSERT_TO_HERE
373 | //do not remove the comment above this line
374 |
375 | #endif
376 |
--------------------------------------------------------------------------------
/test/README:
--------------------------------------------------------------------------------
1 |
2 | This directory is intended for PlatformIO Unit Testing and project tests.
3 |
4 | Unit Testing is a software testing method by which individual units of
5 | source code, sets of one or more MCU program modules together with associated
6 | control data, usage procedures, and operating procedures, are tested to
7 | determine whether they are fit for use. Unit testing finds problems early
8 | in the development cycle.
9 |
10 | More information about PlatformIO Unit Testing:
11 | - https://docs.platformio.org/page/plus/unit-testing.html
12 |
--------------------------------------------------------------------------------