Compare commits

...

29 Commits

Author SHA1 Message Date
Scott Allen bc460a2cff Fix typo in invert() function documentation 2023-08-14 14:59:19 -04:00
Scott Allen ca1c3ae024 Fix links to duration variable in BeepPin1 docs 2022-06-05 13:58:01 -04:00
Scott Allen 031e9164aa
Merge pull request #71 from Pharap/make-cabi-cpp-compatible
Make cabi C++ compatible
2022-05-01 10:38:18 -04:00
Pharap 7f456cff69
Make cabi C++ compatible
Casting the result of these calls to malloc should be all that is required to make cabi compilable as C++.
Without these casts cabi won't compile as C++ because in C++ `void *` is not implicitly convertible to other data types.
LodePNG already has C++ compatibility.
2022-05-01 08:41:41 +01:00
Scott Allen 2374247788
Merge pull request #63 from ace-dent/PR0626-Contributing
Clarify Contribution style requirements
2021-07-01 18:02:43 -04:00
Scott Allen 98afc7229f
Merge pull request #62 from ace-dent/PR0625-Typos
Fix typos in a few places
2021-07-01 17:57:11 -04:00
Scott Allen 4f0d802d50
Merge pull request #57 from ace-dent/PR0930-OptimizePNG
Optimize png images
2021-07-01 17:55:48 -04:00
Andrew Dent ccedf84434 Clarify Contribution style requirements
Add examples to give clear guidance (and a reminder),
of commit message style requirements.
2021-06-26 00:18:59 +01:00
Andrew Dent 279fd9d0f4 Fix typos in a few places
Pedantic tweaks:

- Fix spellings in a few places.

- Update License copyright year.
2021-06-26 00:13:05 +01:00
Scott Allen 36cbdc734c Fix typo in fillScreen() C++ equivalent code 2021-06-05 07:37:01 -04:00
Scott Allen ab4df7c77a Remove register keywords 2021-04-16 08:47:32 -04:00
Andrew Dent b4b4d45009 Optimize png images
The project’s images have been run through lossless optimization.
It will not affect the project but saves a few bytes for each
download of the repository.
See: https://github.com/ace-dent/pngslim
2020-09-30 11:41:46 +01:00
Scott Allen 7dc88bed30 Change version to 6.0.0
The major version number has been incremented only because there's a
chance that a sketch that sets text wrap on will behave differently,
due to the changes in the way wrapping is now handled.
2020-09-29 09:44:41 -04:00
Scott Allen 191e9a2e45 Document bitmap image height requirements
Added the requirement that bitmap heights must be a multiple of
8 pixels in the documentation for drawBitmap() and drawCompressed().
2020-09-29 09:44:41 -04:00
Scott Allen 014e6e0a8b Add FontDemo example sketch
Shows the entire font and demonstrates the wrap and raw mode handling.
2020-09-29 09:44:40 -04:00
Scott Allen 500d81abb7 Add image height check to cabi.c
An image converted using the cabi utility must have a height that is
a multiple of 8 pixels. An error is now reported if not.

Also, the README.md file for cabi was updated with this requirement.
2020-09-29 09:44:40 -04:00
Scott Allen 2baca75689 Fix colors in logo PNG files
Files arduboy_logo.png and arduboy_screen.png had some pixels that
were a dark gray color instead of fully black. The images now contain
only fully black and fully white pixels.
2020-09-29 09:44:40 -04:00
Scott Allen 2f1c515672 Add public variables to keywords.txt 2020-09-29 09:44:40 -04:00
Scott Allen 98f03773b2 Make state variables used by pollButtons() public
The variables currentButtonState and previousButtonState used by
pollButtons(), justPressed() and justReleased() have been made public.
This allows them to be manipulated if circumstances require it.

The documentation added for previousButtonState includes an example.
2020-09-29 09:44:40 -04:00
Scott Allen 4698dd276e Make all possible functions and variables static
This is mainly to reduce code size.

The write() function in class Arduboy2 has to remain virtual,
so functions that result in it eventually being called could
not be made static.

The members of the Point and Rect structures could not be made static
due to their intended use as having multiple instances.

Also to reduce code size, bootLogoExtra() was made non-virtual.
This meant that the begin() and bootLogo...() functions in the
Arduboy2Base class had to have duplicate or equivalent functions
added to the Arduboy2 class.

Related documentation was updated and some minor changes were made to
non-related documentation.
2020-09-29 09:44:40 -04:00
Scott Allen e78e7c9d55 Add more Doxygen cross-referencing
Also:
- Rearrange the order of some member function declarations.
- Minor documentation changes.
2020-09-29 09:44:40 -04:00
Scott Allen 1264edc748 Refactor function BitStreamReader()
Changed from struct to class.

Removed explicit use of the "this" pointer for consistency with
the rest of the library.
2020-09-29 09:44:40 -04:00
Scott Allen aaf4159274 Remove PIXEL_SAFE_MODE define
The ability to compile drawPixel() to not check for
drawing pixels off screen has been removed.
2020-09-29 09:44:20 -04:00
Scott Allen 86169a0027 Modify SetSystemEEPROM to use char size functions
The library functions to get the dimensions of text characters replace
values hard coded in the sketch.

Also changed some #define constants to constexpr variables.

The actual operation of the sketch is unchanged.
2020-09-28 21:12:31 -04:00
Scott Allen 58a35e2ad9 Refactor text code and add char size functions
- Functions write() and drawChar() were refactored for smaller code
  size and to make text wrapping operate more like what would normally
  be expected.

- A new flag variable, textRaw, has been added, along with functions
  setTextRawMode() and getTextRawMode() to set and read it.
  When set, the write() function will render the value \n (0x0a) as
  an "inverse white circle" instead of handling it as a newline and
  render value \r (0x0d) as a "musical eighth note" instead of
  ignoring it.

- Spacing added at the end of each character is no longer factored in
  when determining if a character will fit on screen at the end of
  a line.

- Checking if line wrap is neccessary is done before drawing a
  character, instead of doing it after drawing to prepare for the
  next character. This fixed a problem with requested line feeds
  interacting with wrapping, resulting in unexpected blank lines.

- Fixed a bug that caused the drawing of characters with a transparent
  background to not work properly. (This is selected by setting the
  background color to be the same as the text color.)

- Added new functions getCharacterWidth() getCharacterHeight()
  getCharacterSpacing() getLineSpacing() to programmatically get
  the dimensions of a character, given the desired text size.

- Functions write() and drawChar() are now able to render a font of
  any character size, and with any character and line spacing, by
  setting variables characterWidth characterHeight characterSpacing
  and lineSpacing, and providing a matching font array. This doesn't
  affect their use with this library but has been done for the sake
  of code portability.
2020-09-28 21:11:13 -04:00
Andrew Dent bbebec346d Add array lengths to comments for boot logos 2020-08-23 15:23:01 -04:00
Scott Allen 350a6ee629 Fix a cursor position bug in BeepDemo example 2020-08-23 15:23:00 -04:00
Scott Allen 7fcbd35266 Fix minor documentation issues 2020-08-23 15:21:28 -04:00
Scott Allen 5d154f817a Make SetSystemEEPROM more C++ correct
(Compiled output is identical to previous)

- Made enumerations scoped
- Changed all type byte to uint8_t
- Changed all type boolean to bool
- Changed some type unsigned int to uint16_t
- Changed C-style casts to static_cast
2020-07-27 09:37:55 -04:00
29 changed files with 2427 additions and 1544 deletions

View File

@ -1,7 +1,30 @@
# Commit message style
When submitting changes via a pull request, or any other means, please format commit messages using ["50/72" guidelines, as suggested by Tim Pope](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
Summary:
## Summary:
- Maximum 50 character first "title" line, written as a capitalized [imperative sentence](http://examples.yourdictionary.com/imperative-sentence-examples.html).
- If necessary, more detailed explanatory paragraphs following a blank line, with lines wrapped at maximum 72 characters.
- If used, bullet points have a "hanging indent".
## Example 1:
```
Make state variables used by pollButtons() public
The variables currentButtonState and previousButtonState used by
pollButtons(), justPressed() and justReleased() have been made public.
This allows them to be manipulated if circumstances require it.
The documentation added for previousButtonState includes an example.
```
## Example 2:
```
Refactor text code and add char size functions
- Functions write() and drawChar() were refactored for smaller code
size and to make text wrapping operate more like what would normally
be expected.
- A new flag variable, textRaw, has been added, along with functions
setTextRawMode() and getTextRawMode() to set and read it.
```

View File

@ -8,7 +8,7 @@ Software License Agreements
Licensed under the BSD 3-clause license:
Arduboy2 library:
Copyright (c) 2016-2020, Scott Allen
Copyright (c) 2016-2021, Scott Allen
All rights reserved.
The Arduboy2 library was forked from the Arduboy library:
@ -18,13 +18,14 @@ Copyright (c) 2016, Chris Martinez
Copyright (c) 2016, Josh Goebel
Copyright (c) 2016, Scott Allen
All rights reserved.
which is in turn partially based on the Adafruit_SSD1306 library
- which is in turn partially based on the Adafruit_SSD1306 library
https://github.com/adafruit/Adafruit_SSD1306
Copyright (c) 2012, Adafruit Industries
All rights reserved.
SetSystemEEPROM example sketch:
Copyright (c) 2018, Scott Allen
Copyright (c) 2018-2020, Scott Allen
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -164,6 +165,9 @@ https://creativecommons.org/publicdomain/zero/1.0/
BeepDemo example sketch:
By Scott Allen
FontDemo example sketch:
By Scott Allen
RGBled example sketch:
By Scott Allen

135
README.md
View File

@ -4,7 +4,7 @@ The Arduboy2 library is maintained in a git repository hosted on [GitHub](https:
https://github.com/MLXXXp/Arduboy2
The **Arduboy2** library is a fork of the [Arduboy library](https://github.com/Arduboy/Arduboy), which provides a standard *application programming interface* (API) to the display, buttons and other hardware of the Arduino based [Arduboy miniature game system](https://www.arduboy.com/).
The **Arduboy2** library is a fork of the [Arduboy library](https://github.com/Arduboy/Arduboy), which provides a standard *application programming interface* (API) to the display, buttons and other hardware of the Arduino based [Arduboy miniature game system](https://www.arduboy.com/). The original *Arduboy* library is no longer being maintained.
The name *Arduboy2* doesn't indicate that it's for a new "next generation" of the Arduboy hardware. The name was changed so it can coexist in the Arduino IDE with the current *Arduboy* library, without conflict. This way, existing sketches can continue to use the *Arduboy* library and class, without changes, while new sketches can be written (or old ones modified) to use and take advantage of the capabilities of the *Arduboy2* class and library.
@ -47,9 +47,10 @@ A user settable *unit name* can be saved in system EEPROM memory. If set, this n
Once the logo display sequence completes, the sketch continues.
For developers who wish to quickly begin testing, or impatient users who want to go strait to playing their game, the boot logo sequence can be bypassed by holding the *RIGHT* button while powering up, and then releasing it. Alternatively, the *RIGHT* button can be pressed while the logo is scrolling down.
**Note:**
For users who wish to always disable the displaying of the boot logo sequence on boot up, a flag in system EEPROM is available for this. The included *SetSystemEEPROM* example sketch can be used to set this flag.
- For developers who wish to quickly begin testing, or impatient users who want to go strait to playing their game, the boot logo sequence can be bypassed by holding the *RIGHT* button while powering up, and then releasing it. Alternatively, the *RIGHT* button can be pressed while the logo is scrolling down.
- For users who wish to always disable the displaying of the boot logo sequence on boot up, a flag in system EEPROM is available for this. The included *SetSystemEEPROM* example sketch can be used to set this flag.
### "Flashlight" mode
@ -165,63 +166,99 @@ with
Arduboy2Base arduboy;
```
#### Remove boot up features
#### Substitute or remove boot up features
As previously described, the *begin()* function includes features that are intended to be available to all sketches during boot up. However, if you're looking to gain some code space, you can call *boot()* instead of *begin()*. This will initialize the system but not include any of the extra boot up features. If desired, you can then add back in any of these features by calling the functions that perform them. You will have to trade off between the desirability of having a feature and how much memory you can recover by not including it.
As previously described in the _Start up features_ section, the *begin()* function includes features that are intended to be available to all sketches during boot up. However, if you're looking to gain some code space, you can call *boot()* instead of *begin()*. This will initialize the system but not include any of the extra boot up features. You can then add back in any of these features by calling the functions that perform them. You will have to trade off between the desirability of having a feature and how much memory you can recover by not including it.
A good way to use *boot()* instead of *begin()* is to copy the code from the body of the *begin()* function, in file *Arduboy2.cpp*, into your sketch and then edit it to retain the *boot()* call and any feature calls desired.
You should at least call either *flashlight()* or *safeMode()* as a safeguard to allow uploading a new sketch when the bootloader "magic key" problem is an issue.
As of this writing, the begin function is:
Here is a template that provides the equivalent of *begin()*
```cpp
void Arduboy2Base::begin()
void setup()
{
boot(); // raw hardware
// Required to initialize the hardware.
arduboy.boot();
display(); // blank the display (sBuffer is global, so cleared automatically)
// This clears the display. (The screen buffer will be all zeros)
// It may not be needed if something clears the display later on but
// "garbage" will be displayed if systemButtons() is used without it.
arduboy.display();
flashlight(); // light the RGB LED and screen if UP button is being held.
// flashlight() or safeMode() should always be included to provide
// a method of recovering from the bootloader "magic key" problem.
arduboy.flashlight();
// arduboy.safeMode();
// check for and handle buttons held during start up for system control
systemButtons();
// This allows sound to be turned on or muted. If the sketch provides
// its own way of toggling sound, or doesn't produce any sound, this
// function may not be required.
arduboy.systemButtons();
audio.begin();
// This is required to initialize the speaker. It's not needed if
// the sketch doesn't produce any sounds.
arduboy.audio.begin();
bootLogo();
// This displays the boot logo sequence but note that the logo can
// be suppressed by the user, by pressing the RIGHT button or using
// a system EEPROM setting. If not removed entirely, an alternative
// bootLogo...() function may save some memory.
arduboy.bootLogo();
// arduboy.bootLogoCompressed();
// arduboy.bootLogoSpritesSelfMasked();
// arduboy.bootLogoSpritesOverwrite();
// arduboy.bootLogoSpritesBSelfMasked();
// arduboy.bootLogoSpritesBOverwrite();
// arduboy.bootLogoText();
// Wait for all buttons to be released, in case a pressed one might
// cause problems by being acted upon when the actual sketch code
// starts. If neither systemButtons() nor bootLogo() is kept, this
// function isn't required.
arduboy.waitNoButtons();
// Additional setup code...
waitNoButtons(); // wait for all buttons to be released
}
```
To incorporate it into your sketch just keep *boot()* and whatever feature calls are desired, if any. Comment out or delete the rest. Remember to add the class object name in front of each function call, since they're now being called from outside the class itself. If your sketch uses sound, it's a good idea to keep the call to *audio.begin()*.
For example: Let's say a sketch has its own code to enable, disable and save the *audio on/off* setting, and wants to keep the *flashlight* function. In *setup()* it could replace *begin()* with:
```cpp
arduboy.boot(); // raw hardware
// *** This particular sketch clears the display soon, so it doesn't need this:
// display(); // blank the display (sBuffer is global, so cleared automatically)
arduboy.flashlight(); // light the RGB LED and screen if UP button is being held.
// check for and handle buttons held during start up for system control
// systemButtons();
arduboy.audio.begin();
// bootLogo();
// waitNoButtons(); // wait for all buttons to be released
```
This saves whatever code *display()*, *systemButtons()*, *bootLogo()* and *waitNoButtons()* would use.
There are a few functions provided that are roughly equivalent to the standard functions used by *begin()* but which use less code space.
- *bootLogoCompressed()*, *bootLogoSpritesSelfMasked()*, *bootLogoSpritesOverwrite()*, *bootLogoSpritesBSelfMasked()* and *bootLogoSpritesBOverwrite()* will do the same as *bootLogo()* but will use *drawCompressed()*, or *Sprites* / *SpritesB* class *drawSelfMasked()* or *drawOverwrite()* functions respectively, instead of *drawBitmask()*, to render the logo. If the sketch uses one of these functions, then using the boot logo function that also uses it may reduce code size. It's best to try each of them to see which one produces the smallest size.
- *bootLogoCompressed()*, *bootLogoSpritesSelfMasked()*, *bootLogoSpritesOverwrite()*, *bootLogoSpritesBSelfMasked()* and *bootLogoSpritesBOverwrite()* will do the same as *bootLogo()* but will use *drawCompressed()*, or *Sprites* / *SpritesB* class *drawSelfMasked()* or *drawOverwrite()* functions respectively, instead of *drawBitmap()*, to render the logo. If the sketch uses one of these functions, then using the boot logo function that also uses it may reduce code size. It's best to try each of them to see which one produces the smallest size.
- *bootLogoText()* can be used in place *bootLogo()* in the case where the sketch uses text functions. It renders the logo as text instead of as a bitmap (so doesn't look as good).
- *safeMode()* can be used in place of *flashlight()* for cases where it's needed to allow uploading a new sketch when the bootloader "magic key" problem is an issue. It only lights the red RGB LED, so you don't get the bright light that is the primary purpose of *flashlight()*.
- *safeMode()* can be used in place of *flashlight()* as a safeguard to allow uploading a new sketch when the bootloader "magic key" problem is an issue. It only lights the red RGB LED, so you don't get the bright light that is the primary purpose of *flashlight()*.
It is also possible to replace the boot logo drawing function with one that uses a different bitmap rendering function used elsewhere in your sketch. This may save memory by using this bitmap function for the logo, instead of the logo using a separate function that only ends up being used once. For example, if you use the *ArdBitmap* library's *drawCompressed()* function in your sketch, you could convert the **ARDUBOY** logo to *Ardbitmap* compressed format, and create *drawLogoArdCompressed()* and *bootLogoArdCompressed()* functions:
```cpp
void drawLogoArdCompressed(int16_t y)
{
ardbitmap.drawCompressed(20, y, arduboy_logo_ardbitmap,
WHITE, ALIGN_CENTER, MIRROR_NONE);
}
void bootLogoArdCompressed()
{
if (arduboy.bootLogoShell(drawLogoArdCompressed))
{
arduboy.bootLogoExtra();
}
}
void setup()
{
arduboy.beginDoFirst();
bootLogoArdCompressed();
arduboy.waitNoButtons();
// Additional setup code...
}
```
The **ARDUBOY** logo, in PNG format, is included in the library repository as file:
`extras/assets/arduboy_logo.png`
#### Use the SpritesB class instead of Sprites
@ -246,6 +283,8 @@ The *ARDUBOY_NO_USB* macro is used to eliminate the USB code. The *exitToBootloa
## What's different from Arduboy library V1.1
(These notes apply to when the *Arduboy2* library was first released. There will have been many additional changes, enhancements and features added to *Arduboy2* since then.)
A main goal of Arduboy2 is to provide ways in which more code space can be freed for use by large sketches. Another goal is to allow methods other than the *tunes* functions to be used to produce sounds. Arduboy2 remains substantially compatible with [Arduboy library V1.1](https://github.com/Arduboy/Arduboy/releases/tag/v1.1), which was the latest stable release at the time of the fork. Arduboy2 is based on the code targeted for Arduboy library V1.2, which was still in development and unreleased at the time it was forked.
Main differences between Arduboy2 and Arduboy V1.1 are:
@ -389,7 +428,7 @@ Arduboy2 arduboy;
ArduboyPlaytune tunes(arduboy.audio.enabled);
```
The sound channels must then be initialzed and assigned to the speaker pins. This code would go in the *setup()* function:
The sound channels must then be initialized and assigned to the speaker pins. This code would go in the *setup()* function:
```cpp
// audio setup
@ -424,13 +463,13 @@ The benefit of using *ArduboyTones* would be reduced code size and possibly easi
### Sketch uses the beginNoLogo() function instead of begin()
The *beginNoLogo()* function has been removed. Instead, *boot()* can be used with additional functions following it to add back in desired boot functionality. See the information above, under the heading *Remove boot up features*, for more details. Assuming the object is named *arduboy*, a direct replacement for *beginNoLogo()* would be:
The *beginNoLogo()* function has been removed. *beginNoLogo()* can be replaced with *begin()*, since users can choose to suppress the logo sequence using the *RIGHT* button or by setting a flag in system EEPROM.
If using *begin()* results in the sketch program memory size being too large, *beginDoFirst()* or *boot()* can be used with additional functions following it to add back in desired boot functionality. See the information above, under the heading *Substitute or remove boot up features*, for more details. Assuming the object is named *arduboy*, an equivalent replacement for *beginNoLogo()* would be:
```cpp
arduboy.boot();
arduboy.display();
arduboy.flashlight();
arduboy.audio.begin();
arduboy.beginDoFirst();
arduboy.waitNoButtons();
```
----------

View File

@ -271,7 +271,7 @@ void moveBall()
topBrick = 6 * row + 1;
bottomBrick = 6 * row + 7;
//If A collison has occured
//If A collision has occurred
if (topBall <= bottomBrick && bottomBall >= topBrick &&
leftBall <= rightBrick && rightBall >= leftBrick)
{
@ -293,7 +293,7 @@ void moveBall()
}
}
//Hoizontal collision
//Horizontal collision
if (leftBall < leftBrick || rightBall > rightBrick)
{
//Only bounce once brick each ball move
@ -459,7 +459,7 @@ boolean pollFireButton(int n)
return false;
}
//Function by nootropic design to display highscores
//Function by nootropic design to display high scores
boolean displayHighScores(byte file)
{
byte y = 8;
@ -736,14 +736,14 @@ void enterHighScore(byte file)
}
}
// Play a tone at a frequency coresponding to the specified precomputed count,
// Play a tone at a frequency corresponding to the specified precomputed count,
// for the specified number of frames.
void playTone(uint16_t count, uint8_t frames)
{
beep.tone(count, frames);
}
// Play a tone at a frequency coresponding to the specified precomputed count,
// Play a tone at a frequency corresponding to the specified precomputed count,
// for the specified duration in milliseconds, using a delay.
// Used when beep.timer() isn't being called.
void playToneTimed(uint16_t count, uint16_t duration)

View File

@ -52,6 +52,8 @@ void loop() {
arduboy.pollButtons();
arduboy.clear();
if (arduboy.justPressed(LEFT_BUTTON)) {
// Play a 523.251Hz tone (piano note C5) for 5 frames (200ms at 25 FPS)
// beep.freq(523.251) is used to convert 523.251Hz to the required count
@ -127,7 +129,7 @@ void loop() {
objectX = 0;
}
arduboy.display(CLEAR_BUFFER);
arduboy.display();
}
void commandText(const char* text) {

View File

@ -22,10 +22,10 @@ char title[] = "Press Buttons!";
byte x;
byte y;
// Width of each charcter including inter-character space
// Width of each character including inter-character space
#define CHAR_WIDTH 6
// Height of each charater
// Height of each character
#define CHAR_HEIGHT 8
// To get the number of characters, we subtract 1 from the length of
@ -49,7 +49,7 @@ void setup() {
//initiate arduboy instance
arduboy.begin();
// here we set the framerate to 30, we do not need to run at default 60 and
// here we set the frame rate to 30, we do not need to run at default 60 and
// it saves us battery life.
arduboy.setFrameRate(30);
@ -101,6 +101,6 @@ void loop() {
// then we print to screen what is stored in our title variable we declared earlier
arduboy.print(title);
// then we finaly we tell the arduboy to display what we just wrote to the display.
// then we finally we tell the arduboy to display what we just wrote to the display.
arduboy.display();
}

View File

@ -1,4 +1,4 @@
Buttons
=======
A an example that demonstrates how to capture input from the buttons.
An example that demonstrates how to capture input from the buttons.

122
examples/FontDemo/COPYING Normal file
View File

@ -0,0 +1,122 @@
Creative Commons Legal Code
CC0 1.0 Universal
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.
Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.
1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:
i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.
3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.
4. Limitations and Disclaimers.
a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.

View File

@ -0,0 +1,127 @@
/*
FontDemo.ino
This sketch draws all the characters of the library's font as a 16 x 16 block.
The bottom half of the block will be initially off screen. An information
overlay will be drawn on top of the block showing the X and Y cursor position
of the start of the block, the current text wrap state and the current text
raw mode state.
The block can be moved around and off the screen using the direction buttons,
to view all the characters and show how the wrap and raw modes behave.
Controls:
Direction Buttons: Move the block 1 pixel.
Hold A with Direction Buttons: Continuously move the block.
B Button: Toggle text raw mode on and off.
Hold A, press B: Toggle text wrap mode on and off.
*/
/*
Written in September 2020 by Scott Allen saydisp-git@yahoo.ca
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
worldwide. This software is distributed without any warranty.
You should have received a copy of the CC0 Public Domain Dedication along with
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include <Arduboy2.h>
Arduboy2 arduboy;
constexpr uint8_t charWidth = arduboy.getCharacterWidth() + arduboy.getCharacterSpacing();
constexpr uint8_t charHeight = arduboy.getCharacterHeight() + arduboy.getLineSpacing();
constexpr uint16_t infoX = charWidth * 8;
constexpr uint16_t infoY = charHeight * 2;
constexpr uint8_t infoWidth = charWidth * 5;
constexpr uint8_t infoBorder = 1;
int16_t xPos = 0;
int16_t yPos = 0;
void setup() {
arduboy.begin();
arduboy.setFrameRate(20);
arduboy.clear();
arduboy.print(F("DISPLAY AND MOVE FONT\n\n"
" Dpad: move 1\n"
"A + Dpad: repeat move\n"
" B: toggle raw\n"
" A + B: toggle wrap\n\n"
" Press A to start"));
arduboy.display();
while (!arduboy.pressed(A_BUTTON)) {
arduboy.idle();
}
}
void loop() {
if (!arduboy.nextFrame()) {
return;
}
arduboy.pollButtons();
if (arduboy.justPressed(B_BUTTON)) {
if (arduboy.pressed(A_BUTTON)) {
arduboy.setTextWrap(!arduboy.getTextWrap());
}
else {
arduboy.setTextRawMode(!arduboy.getTextRawMode());
}
}
if (arduboy.justPressed(UP_BUTTON) ||
arduboy.pressed(UP_BUTTON + A_BUTTON)) {
--yPos;
}
if (arduboy.justPressed(DOWN_BUTTON) ||
arduboy.pressed(DOWN_BUTTON + A_BUTTON)) {
++yPos;
}
if (arduboy.justPressed(LEFT_BUTTON) ||
arduboy.pressed(LEFT_BUTTON | A_BUTTON)) {
--xPos;
}
if (arduboy.justPressed(RIGHT_BUTTON) ||
arduboy.pressed(RIGHT_BUTTON | A_BUTTON)) {
++xPos;
}
arduboy.clear();
char code = 0;
for (uint8_t i = 0; i < 16; ++i) {
arduboy.setCursor(xPos, yPos + (charHeight * i));
for (uint8_t j = 0; j < 16; ++j) {
arduboy.print(code);
++code;
}
}
arduboy.fillRect(infoX - infoBorder, infoY - infoBorder,
infoWidth + infoBorder, charHeight * 4 + infoBorder);
arduboy.setTextColor(BLACK);
arduboy.setTextBackground(WHITE);
arduboy.setCursor(infoX, infoY);
arduboy.print(F("X:"));
arduboy.print(xPos);
arduboy.setCursor(infoX, infoY + charHeight);
arduboy.print(F("Y:"));
arduboy.print(yPos);
arduboy.setCursor(infoX, infoY + (charHeight * 2));
arduboy.print(F("W:"));
arduboy.print(arduboy.getTextWrap() ? F("Yes") : F("No"));
arduboy.setCursor(infoX, infoY + (charHeight * 3));
arduboy.print(F("R:"));
arduboy.print(arduboy.getTextRawMode() ? F("Yes") : F("No"));
arduboy.setTextColor(WHITE);
arduboy.setTextBackground(BLACK);
arduboy.display();
}

View File

@ -23,7 +23,7 @@ void setup() {
// initiate arduboy instance
arduboy.begin();
// here we set the framerate to 15, we do not need to run at
// here we set the frame rate to 15, we do not need to run at
// default 60 and it saves us battery life
arduboy.setFrameRate(15);
}
@ -46,6 +46,6 @@ void loop() {
// then we print to screen what is in the Quotation marks ""
arduboy.print(F("Hello, world!"));
// then we finaly we tell the arduboy to display what we just wrote to the display
// then we finally we tell the arduboy to display what we just wrote to the display
arduboy.display();
}

View File

@ -321,7 +321,7 @@ void drawBar(int y, Color color, byte value) {
}
}
// Draw the informaton for one digital color
// Draw the information for one digital color
void drawDigital(int y, Color color, const char* name) {
byte state = digitalState[(byte)color];

View File

@ -33,11 +33,11 @@ This sketch also allows:
------------------------------------------------------------------------------
*/
// Version 2.0
// Version 2.2
/*
------------------------------------------------------------------------------
Copyright (c) 2018, Scott Allen
Copyright (c) 2018-2020, Scott Allen
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -69,14 +69,14 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <EEPROM.h>
// The frame rate determines the button auto-repeat rate for unit name entry
#define FRAME_RATE 10
constexpr uint8_t frameRate = 10;
// The unit ID auto-repeat rate is slowed, compared to the unit name rate, by
// repeating only once per the defined number of frames
#define ID_REPEAT_FRAMES 3
constexpr unsigned int idRepeatFrames = 3;
// Delay time before button auto-repeat starts, in milliseconds
#define REPEAT_DELAY 700
constexpr unsigned int repeatDelay = 700;
// All the constant stings
const char StrName[] PROGMEM = "NAME";
@ -119,24 +119,20 @@ const char StrReset[] PROGMEM = "RESET";
const char StrHex[] PROGMEM = "hex";
const char StrDecimal[] PROGMEM = "decimal";
#define CHAR_WIDTH 6
#define CHAR_HEIGHT 8
#define SMALL_SPACE 4 // The number of pixels for a small space between groups
// Defines for text and field locations
#define MENU_BTN_CHANGE_NAME_X centerStr_P(StrBtnChangeName)
#define MENU_BTN_CHANGE_NAME_Y 0
#define MENU_NAME_X centerStrLen(ARDUBOY_UNIT_NAME_LEN)
#define MENU_NAME_Y (MENU_BTN_CHANGE_NAME_Y + CHAR_HEIGHT + 3)
#define MENU_NAME_Y (MENU_BTN_CHANGE_NAME_Y + charHeight + 3)
#define MENU_BTN_CHANGE_ID_X centerStr_P(StrBtnChangeID)
#define MENU_BTN_CHANGE_ID_Y 26
#define MENU_HEADING_HEX_X (centerStr_P(StrHex) - (WIDTH / 4))
#define MENU_HEADING_DECIMAL_X (centerStr_P(StrDecimal) + (WIDTH / 4))
#define MENU_HEADINGS_Y (MENU_BTN_CHANGE_ID_Y + CHAR_HEIGHT + 1)
#define MENU_HEADINGS_Y (MENU_BTN_CHANGE_ID_Y + charHeight + 1)
#define MENU_ID_HEX_X (centerStrLen(5) - (WIDTH / 4))
#define MENU_ID_DECIMAL_X (centerStrLen(5) + (WIDTH / 4))
#define MENU_ID_Y (MENU_HEADINGS_Y + CHAR_HEIGHT + 1)
#define MENU_ID_Y (MENU_HEADINGS_Y + charHeight + 1)
#define MENU_BTN_FLAGS_X 0
#define MENU_BTN_FLAGS_Y 56
@ -165,9 +161,9 @@ const char StrDecimal[] PROGMEM = "decimal";
#define NAME_BTN_NO_X rightStr_P(StrBtnNo)
#define NAME_BTN_NO_Y NAME_BTN_YES_Y
#define NAME_SAVE_Q_X (centerStr_P(StrSaveQ) - ((6 * CHAR_WIDTH) + (CHAR_WIDTH / 2)))
#define NAME_SAVE_Q_Y (NAME_LARGE_Y + (CHAR_HEIGHT / 2) + 3)
#define NAME_SAVE_X (NAME_SAVE_Q_X + ((strlen_P(StrSaveQ) * CHAR_WIDTH) + CHAR_WIDTH))
#define NAME_SAVE_Q_X (centerStr_P(StrSaveQ) - ((6 * charWidth) + (charWidth / 2)))
#define NAME_SAVE_Q_Y (NAME_LARGE_Y + (charHeight / 2) + 3)
#define NAME_SAVE_X (NAME_SAVE_Q_X + ((strlen_P(StrSaveQ) * charWidth) + charWidth))
#define NAME_SAVE_Y (NAME_LARGE_Y + 3)
@ -184,7 +180,7 @@ const char StrDecimal[] PROGMEM = "decimal";
#define ID_2_DECIMAL_X 12
#define ID_2_DECIMAL_Y 38
#define ID_DECIMAL_X (WIDTH - (CHAR_WIDTH * 5 + 12))
#define ID_DECIMAL_X (WIDTH - (charWidth * 5 + 12))
#define ID_DECIMAL_Y ID_2_DECIMAL_Y
#define ID_BINARY_X 0
@ -195,9 +191,9 @@ const char StrDecimal[] PROGMEM = "decimal";
#define ID_BTN_NO_X rightStr_P(StrBtnNo)
#define ID_BTN_NO_Y ID_BTN_YES_Y
#define ID_SAVE_Q_X (centerStr_P(StrSaveQ) - ((5 * CHAR_WIDTH) + (CHAR_WIDTH / 2)))
#define ID_SAVE_Q_Y (ID_LARGE_Y + (CHAR_HEIGHT / 2) + 1)
#define ID_SAVE_X (ID_SAVE_Q_X + ((strlen_P(StrSaveQ) * CHAR_WIDTH) + CHAR_WIDTH))
#define ID_SAVE_Q_X (centerStr_P(StrSaveQ) - ((5 * charWidth) + (charWidth / 2)))
#define ID_SAVE_Q_Y (ID_LARGE_Y + (charHeight / 2) + 1)
#define ID_SAVE_X (ID_SAVE_Q_X + ((strlen_P(StrSaveQ) * charWidth) + charWidth))
#define ID_SAVE_Y (ID_LARGE_Y + 1)
#define FLAGS_TITLE_X centerStr_P(StrFlags)
@ -212,7 +208,7 @@ const char StrDecimal[] PROGMEM = "decimal";
#define FLAGS_LEDS_Y 27
#define FLAGS_NAME_Y 40
#define FLAGS_Q_X (CHAR_WIDTH * 2)
#define FLAGS_Q_X (charWidth * 2)
#define FLAGS_SET_X rightStr_P(StrYes)
#define FLAGS_CURSOR_X 0
@ -220,74 +216,74 @@ const char StrDecimal[] PROGMEM = "decimal";
#define FLAGS_TEST_Y 56
#define FLAGS_SAVED_X centerStr2_P(StrSaved)
#define FLAGS_SAVED_Y ((HEIGHT / 2) - CHAR_HEIGHT)
#define FLAGS_SAVED_Y ((HEIGHT / 2) - (char2Height / 2))
#define FLAGS_NO_LOGO_1_X centerStr_P(StrNoLogo1)
#define FLAGS_NO_LOGO_1_Y ((HEIGHT / 2) - CHAR_HEIGHT - 1)
#define FLAGS_NO_LOGO_1_Y ((HEIGHT / 2) - charHeight - 1)
#define FLAGS_NO_LOGO_2_X centerStr_P(StrNoLogo2)
#define FLAGS_NO_LOGO_2_Y (FLAGS_NO_LOGO_1_Y + CHAR_HEIGHT + 2)
#define FLAGS_NO_LOGO_2_Y (FLAGS_NO_LOGO_1_Y + charHeight + 2)
#define RESET_BTN_MENU_X centerStr_P(StrBtnMenu)
#define RESET_BTN_MENU_Y 0
#define RESET_BTN_SYS_X centerStr_P(StrBtnResetSys)
#define RESET_BTN_SYS_Y 16
#define RESET_BTN_SYS_EEPROM_X centerStr_P(StrEEPROM)
#define RESET_BTN_SYS_EEPROM_Y (RESET_BTN_SYS_Y + CHAR_HEIGHT)
#define RESET_BTN_SYS_EEPROM_Y (RESET_BTN_SYS_Y + charHeight)
#define RESET_BTN_USER_X centerStr_P(StrBtnResetUser)
#define RESET_BTN_USER_Y 40
#define RESET_BTN_USER_EEPROM_X centerStr_P(StrEEPROM)
#define RESET_BTN_USER_EEPROM_Y (RESET_BTN_USER_Y + CHAR_HEIGHT)
#define RESET_BTN_USER_EEPROM_Y (RESET_BTN_USER_Y + charHeight)
#define RESET_SYS_TEXT_1_X centerStr_P(StrResetSys1)
#define RESET_SYS_TEXT_1_Y 0
#define RESET_SYS_TEXT_2_X centerStr_P(StrResetSys2)
#define RESET_SYS_TEXT_2_Y (RESET_SYS_TEXT_1_Y + CHAR_HEIGHT)
#define RESET_SYS_TEXT_2_Y (RESET_SYS_TEXT_1_Y + charHeight)
#define RESET_SYS_TEXT_3_X centerStr_P(StrResetSys3)
#define RESET_SYS_TEXT_3_Y (RESET_SYS_TEXT_2_Y + CHAR_HEIGHT)
#define RESET_SYS_TEXT_3_Y (RESET_SYS_TEXT_2_Y + charHeight)
#define RESET_SYS_SURE_Q_X centerStr_P(StrAreYouSureQ)
#define RESET_SYS_SURE_Q_Y 32
#define RESET_SYS_BTN_YES_X centerStr_P(StrBtnResetYes)
#define RESET_SYS_BTN_YES_Y 48
#define RESET_SYS_BTN_NO_X centerStr_P(StrBtnResetYes)
#define RESET_SYS_BTN_NO_Y (RESET_SYS_BTN_YES_Y + CHAR_HEIGHT)
#define RESET_SYS_BTN_NO_Y (RESET_SYS_BTN_YES_Y + charHeight)
#define RESET_SYS_CONFIRMED_1_X centerStr2_P(StrSystem)
#define RESET_SYS_CONFIRMED_1_Y 7
#define RESET_SYS_CONFIRMED_2_X centerStr2_P(StrEEPROM)
#define RESET_SYS_CONFIRMED_2_Y (RESET_SYS_CONFIRMED_1_Y + (CHAR_HEIGHT * 2) + 2)
#define RESET_SYS_CONFIRMED_2_Y (RESET_SYS_CONFIRMED_1_Y + char2Height + 2)
#define RESET_SYS_CONFIRMED_3_X centerStr2_P(StrReset)
#define RESET_SYS_CONFIRMED_3_Y (RESET_SYS_CONFIRMED_2_Y + (CHAR_HEIGHT * 2) + 2)
#define RESET_SYS_CONFIRMED_3_Y (RESET_SYS_CONFIRMED_2_Y + char2Height + 2)
#define RESET_USER_TEXT_1_X centerStr_P(StrResetUser1)
#define RESET_USER_TEXT_1_Y 0
#define RESET_USER_TEXT_2_X centerStr_P(StrResetUser2)
#define RESET_USER_TEXT_2_Y (RESET_USER_TEXT_1_Y + CHAR_HEIGHT)
#define RESET_USER_TEXT_2_Y (RESET_USER_TEXT_1_Y + charHeight)
#define RESET_USER_TEXT_3_X centerStr_P(StrResetUser3)
#define RESET_USER_TEXT_3_Y (RESET_USER_TEXT_2_Y + CHAR_HEIGHT)
#define RESET_USER_TEXT_3_Y (RESET_USER_TEXT_2_Y + charHeight)
#define RESET_USER_SURE_Q_X centerStr_P(StrAreYouSureQ)
#define RESET_USER_SURE_Q_Y 32
#define RESET_USER_BTN_YES_X centerStr_P(StrBtnResetYes)
#define RESET_USER_BTN_YES_Y 48
#define RESET_USER_BTN_NO_X centerStr_P(StrBtnResetYes)
#define RESET_USER_BTN_NO_Y (RESET_USER_BTN_YES_Y + CHAR_HEIGHT)
#define RESET_USER_BTN_NO_Y (RESET_USER_BTN_YES_Y + charHeight)
#define RESET_USER_CONFIRMED_1_X centerStr2_P(StrUser)
#define RESET_USER_CONFIRMED_1_Y 7
#define RESET_USER_CONFIRMED_2_X centerStr2_P(StrEEPROM)
#define RESET_USER_CONFIRMED_2_Y (RESET_USER_CONFIRMED_1_Y + (CHAR_HEIGHT * 2) + 2)
#define RESET_USER_CONFIRMED_2_Y (RESET_USER_CONFIRMED_1_Y + char2Height + 2)
#define RESET_USER_CONFIRMED_3_X centerStr2_P(StrReset)
#define RESET_USER_CONFIRMED_3_Y (RESET_USER_CONFIRMED_2_Y + (CHAR_HEIGHT * 2) + 2)
#define RESET_USER_CONFIRMED_3_Y (RESET_USER_CONFIRMED_2_Y + char2Height + 2)
#define RESET_USER_WRITING_X centerStr2_P(StrWriting)
#define RESET_USER_WRITING_Y ((HEIGHT / 2) - (CHAR_HEIGHT - 1))
#define RESET_USER_WRITING_Y ((HEIGHT / 2) - (char2Height / 2 - 1))
// EEPROM addresses
#define EEPROM_START (0x0000)
#define EEPROM_SIZE (1024)
#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
constexpr unsigned int EEPROMstart = 0x0000;
constexpr unsigned int EEPROMsize = 1024;
constexpr unsigned int EEPROMend = EEPROMstart + EEPROMsize - 1;
// Calculation of the number of frames to wait before button auto-repeat starts
#define DELAY_FRAMES (REPEAT_DELAY / (1000 / FRAME_RATE))
constexpr unsigned int delayFrames = repeatDelay / (1000 / frameRate);
// The Arduino "magic" has trouble creating prototypes for functions called
// by pointers, so they're declared here manually
@ -298,27 +294,39 @@ void screenSaveName(), screenSaveID(), screenResetSys(), screenResetUser();
Arduboy2 arduboy;
constexpr uint8_t charSpacing = arduboy.getCharacterSpacing(1);
constexpr uint8_t char2Spacing = arduboy.getCharacterSpacing(2);
constexpr uint8_t charWidth = arduboy.getCharacterWidth(1) + charSpacing;
constexpr uint8_t char2Width = arduboy.getCharacterWidth(2) + char2Spacing;
constexpr uint8_t charHeight = arduboy.getCharacterHeight(1) +
arduboy.getLineSpacing(1);
constexpr uint8_t char2Height = arduboy.getCharacterHeight(2) +
arduboy.getLineSpacing(2);
// The number of pixels for a small space between groups
constexpr uint8_t smallSpace = 4;
char unitName[ARDUBOY_UNIT_NAME_BUFFER_SIZE];
byte nameIndex;
uint8_t nameIndex;
uint16_t unitID;
byte idIndex;
uint8_t idIndex;
boolean showLogoFlag;
boolean showLEDsFlag;
boolean showNameFlag;
bool showLogoFlag;
bool showLEDsFlag;
bool showNameFlag;
// Selected flag
enum SelectedFlag : byte {
enum class SelectedFlag : uint8_t {
selFlagLogo,
selFlagLEDs,
selFlagName
};
byte currentFlag;
SelectedFlag currentFlag;
// Assign numbers for each state/screen
enum State : byte {
enum class State : uint8_t {
sMain,
sName,
sID,
@ -331,10 +339,10 @@ enum State : byte {
sMAX = sResetUser
};
byte currentState;
State currentState;
// Function pointer array for button handling
void (*stateFunc[sMAX + 1])() = {
void (*stateFunc[static_cast<uint8_t>(State::sMAX) + 1])() = {
stateMain,
stateName,
stateID,
@ -347,7 +355,7 @@ void (*stateFunc[sMAX + 1])() = {
};
// Function pointer array for screen drawing
void (*screenFunc[sMAX + 1])() = {
void (*screenFunc[static_cast<uint8_t>(State::sMAX) + 1])() = {
screenMain,
screenName,
screenID,
@ -360,14 +368,14 @@ void (*screenFunc[sMAX + 1])() = {
};
unsigned int delayCount = 0;
boolean repeating = false;
bool repeating = false;
// ============================= SETUP ===================================
void setup() {
arduboy.begin();
arduboy.setFrameRate(FRAME_RATE);
setState(sMain);
arduboy.setFrameRate(frameRate);
setState(State::sMain);
}
// =======================================================================
@ -380,7 +388,7 @@ void loop() {
arduboy.pollButtons();
(*stateFunc[currentState])();
(*stateFunc[static_cast<uint8_t>(currentState)])();
if ((delayCount != 0) && (--delayCount == 0)) {
repeating = true;
@ -393,7 +401,7 @@ void loop() {
// Set to the given state and display the screen for that state
// Can be called with the current state to update the current screen
void setState(byte newState) {
void setState(State newState) {
currentState = newState;
stopButtonRepeat();
drawScreen();
@ -402,16 +410,16 @@ void setState(byte newState) {
// STATE: Main selection screen
void stateMain() {
if (arduboy.justPressed(UP_BUTTON)) {
setState(sName);
setState(State::sName);
}
else if (arduboy.justPressed(DOWN_BUTTON)) {
setState(sID);
setState(State::sID);
}
else if (arduboy.justPressed(LEFT_BUTTON)) {
setState(sFlags);
setState(State::sFlags);
}
else if (arduboy.justPressed(RIGHT_BUTTON)) {
setState(sReset);
setState(State::sReset);
}
}
@ -438,10 +446,10 @@ void stateName() {
nameCursorLeft();
}
else if (arduboy.justPressed(A_BUTTON)) {
setState(sMain);
setState(State::sMain);
}
else if (arduboy.justPressed(B_BUTTON)) {
setState(sSaveName);
setState(State::sSaveName);
}
else if (repeating) {
stopButtonRepeat();
@ -459,12 +467,12 @@ void stateID() {
startButtonDelay();
}
else if (repeating && arduboy.pressed(UP_BUTTON)) {
if (arduboy.everyXFrames(ID_REPEAT_FRAMES)) {
if (arduboy.everyXFrames(idRepeatFrames)) {
idDigitInc();
}
}
else if (repeating && arduboy.pressed(DOWN_BUTTON)) {
if (arduboy.everyXFrames(ID_REPEAT_FRAMES)) {
if (arduboy.everyXFrames(idRepeatFrames)) {
idDigitDec();
}
}
@ -475,10 +483,10 @@ void stateID() {
idCursorLeft();
}
else if (arduboy.justPressed(A_BUTTON)) {
setState(sMain);
setState(State::sMain);
}
else if (arduboy.justPressed(B_BUTTON)) {
setState(sSaveID);
setState(State::sSaveID);
}
else if (repeating) {
stopButtonRepeat();
@ -496,8 +504,8 @@ void stateFlags() {
else {
displayNoLogo();
}
currentFlag = selFlagLogo;
setState(sFlags);
currentFlag = SelectedFlag::selFlagLogo;
setState(State::sFlags);
}
else if (arduboy.justPressed(UP_BUTTON)) {
flagsCursorUp();
@ -510,24 +518,24 @@ void stateFlags() {
flagToggle();
}
else if (arduboy.justPressed(A_BUTTON)) {
setState(sMain);
setState(State::sMain);
}
else if (arduboy.justPressed(B_BUTTON)) {
saveFlags();
setState(sFlags);
setState(State::sFlags);
}
}
// STATE: Reset EEPROM areas
void stateReset() {
if (arduboy.justPressed(UP_BUTTON)) {
setState(sResetSys);
setState(State::sResetSys);
}
else if (arduboy.justPressed(DOWN_BUTTON)) {
setState(sResetUser);
setState(State::sResetUser);
}
else if (arduboy.justPressed(A_BUTTON)) {
setState(sMain);
setState(State::sMain);
}
}
@ -535,10 +543,10 @@ void stateReset() {
void stateSaveName() {
if (arduboy.justPressed(A_BUTTON)) {
arduboy.writeUnitName(unitName);
setState(sMain);
setState(State::sMain);
}
else if (arduboy.justPressed(B_BUTTON)) {
setState(sName);
setState(State::sName);
}
}
@ -546,10 +554,10 @@ void stateSaveName() {
void stateSaveID() {
if (arduboy.justPressed(A_BUTTON)) {
arduboy.writeUnitID(unitID);
setState(sMain);
setState(State::sMain);
}
else if (arduboy.justPressed(B_BUTTON)) {
setState(sID);
setState(State::sID);
}
}
@ -557,13 +565,13 @@ void stateSaveID() {
void stateResetSys() {
if (arduboy.justPressed(B_BUTTON) && arduboy.pressed(A_BUTTON)) {
resetSysEEPROM();
setState(sReset);
setState(State::sReset);
}
else if (arduboy.justPressed(UP_BUTTON) ||
arduboy.justPressed(DOWN_BUTTON) ||
arduboy.justPressed(RIGHT_BUTTON) ||
arduboy.justPressed(LEFT_BUTTON)) {
setState(sReset);
setState(State::sReset);
}
}
@ -571,13 +579,13 @@ void stateResetSys() {
void stateResetUser() {
if (arduboy.justPressed(B_BUTTON) && arduboy.pressed(A_BUTTON)) {
resetUserEEPROM();
setState(sReset);
setState(State::sReset);
}
else if (arduboy.justPressed(UP_BUTTON) ||
arduboy.justPressed(DOWN_BUTTON) ||
arduboy.justPressed(RIGHT_BUTTON) ||
arduboy.justPressed(LEFT_BUTTON)) {
setState(sReset);
setState(State::sReset);
}
}
@ -586,7 +594,7 @@ void stateResetUser() {
// Display the screen for the current state
void drawScreen() {
arduboy.clear();
(*screenFunc[currentState])();
(*screenFunc[static_cast<uint8_t>(currentState)])();
arduboy.display();
}
@ -594,7 +602,7 @@ void drawScreen() {
void screenMain() {
readEEPROM();
nameIndex = idIndex = 0;
currentFlag = selFlagLogo;
currentFlag = SelectedFlag::selFlagLogo;
printStr_P(MENU_BTN_CHANGE_NAME_X, MENU_BTN_CHANGE_NAME_Y, StrBtnChangeName);
printName(MENU_NAME_X, MENU_NAME_Y);
@ -667,7 +675,7 @@ void screenSaveID() {
printIDLarge(ID_SAVE_X, ID_SAVE_Y);
}
// DISPLAY: Propmt to reset the system EEPROM area
// DISPLAY: Prompt to reset the system EEPROM area
void screenResetSys() {
printStr_P(RESET_SYS_TEXT_1_X, RESET_SYS_TEXT_1_Y, StrResetSys1);
printStr_P(RESET_SYS_TEXT_2_X, RESET_SYS_TEXT_2_Y, StrResetSys2);
@ -677,7 +685,7 @@ void screenResetSys() {
printStr_P(RESET_SYS_BTN_NO_X, RESET_SYS_BTN_NO_Y, StrBtnResetNo);
}
// DISPLAY: Propmt to reset the user EEPROM area
// DISPLAY: Prompt to reset the user EEPROM area
void screenResetUser() {
printStr_P(RESET_USER_TEXT_1_X, RESET_USER_TEXT_1_Y, StrResetUser1);
printStr_P(RESET_USER_TEXT_2_X, RESET_USER_TEXT_2_Y, StrResetUser2);
@ -708,7 +716,7 @@ void saveFlags() {
// Reset the system EEPROM area and display the confirmation message
void resetSysEEPROM() {
for (unsigned int i = EEPROM_START; i < EEPROM_STORAGE_SPACE_START; i++) {
for (unsigned int i = EEPROMstart; i < EEPROM_STORAGE_SPACE_START; i++) {
EEPROM.update(i, 0xFF);
}
arduboy.clear();
@ -726,7 +734,7 @@ void resetUserEEPROM() {
printStr_P(RESET_USER_WRITING_X, RESET_USER_WRITING_Y, StrWriting);
arduboy.setTextSize(1);
arduboy.display(CLEAR_BUFFER);
for (unsigned int i = EEPROM_STORAGE_SPACE_START; i <= EEPROM_END; i++) {
for (unsigned int i = EEPROM_STORAGE_SPACE_START; i <= EEPROMend; i++) {
EEPROM.update(i, 0xFF);
}
printStrLargeRev_P(RESET_USER_CONFIRMED_1_X, RESET_USER_CONFIRMED_1_Y, StrUser);
@ -745,7 +753,7 @@ void printNameScreenCommon() {
printNameDecimal(NAME_DECIMAL_X, NAME_DECIMAL_Y);
}
// Print the name entry screen common information
// Print the ID entry screen common information
void printIDScreenCommon() {
printStr_P(ID_TITLE_X, ID_TITLE_Y, StrID);
printIDDecimalBytes(ID_2_DECIMAL_X, ID_2_DECIMAL_Y);
@ -755,41 +763,45 @@ void printIDScreenCommon() {
// Print the name screen cursors
void printNameCursors() {
arduboy.fillRect(NAME_LARGE_X + (nameIndex * CHAR_WIDTH * 2),
NAME_LARGE_Y + (CHAR_HEIGHT * 2) + 2,
(CHAR_WIDTH * 2) - 2, 2);
arduboy.fillRect(NAME_LARGE_X + (nameIndex * char2Width),
NAME_LARGE_Y + char2Height + 2,
char2Width - char2Spacing, 2);
arduboy.drawFastHLine(NAME_HEX_X +
(nameIndex * (CHAR_WIDTH * 3 + SMALL_SPACE)),
NAME_HEX_Y + CHAR_HEIGHT + 1, CHAR_WIDTH * 3 - 1);
(nameIndex * (charWidth * 3 + smallSpace)),
NAME_HEX_Y + charHeight + 1,
charWidth * 3 - charSpacing);
arduboy.drawFastHLine(NAME_DECIMAL_X +
(nameIndex * (CHAR_WIDTH * 3 + SMALL_SPACE)),
NAME_DECIMAL_Y + CHAR_HEIGHT + 1, CHAR_WIDTH * 3 - 1);
(nameIndex * (charWidth * 3 + smallSpace)),
NAME_DECIMAL_Y + charHeight + 1,
charWidth * 3 - charSpacing);
}
// Print the ID screen cursors
void printIDCursors() {
arduboy.fillRect(ID_LARGE_X + ((idIndex + 1) * (CHAR_WIDTH * 2)),
ID_LARGE_Y + (CHAR_HEIGHT * 2),
(CHAR_WIDTH * 2) - 2, 2);
arduboy.fillRect(ID_LARGE_X + ((idIndex + 1) * char2Width),
ID_LARGE_Y + char2Height,
char2Width - char2Spacing, 2);
arduboy.drawFastHLine(ID_2_DECIMAL_X +
((idIndex / 2) * (CHAR_WIDTH * 3 + SMALL_SPACE)),
ID_2_DECIMAL_Y + CHAR_HEIGHT + 1, CHAR_WIDTH * 3 - 1);
((idIndex / 2) * (charWidth * 3 + smallSpace)),
ID_2_DECIMAL_Y + charHeight + 1,
charWidth * 3 - charSpacing);
arduboy.drawFastHLine(ID_DECIMAL_X, ID_DECIMAL_Y + CHAR_HEIGHT + 1,
CHAR_WIDTH * 5 - 1);
arduboy.drawFastHLine(ID_DECIMAL_X, ID_DECIMAL_Y + charHeight + 1,
charWidth * 5 - 1);
arduboy.drawFastHLine((ID_BINARY_X + CHAR_WIDTH + SMALL_SPACE) +
(idIndex * (CHAR_WIDTH * 4 + SMALL_SPACE)),
ID_BINARY_Y + CHAR_HEIGHT + 1, CHAR_WIDTH * 4 - 1);
arduboy.drawFastHLine((ID_BINARY_X + charWidth + smallSpace) +
(idIndex * (charWidth * 4 + smallSpace)),
ID_BINARY_Y + charHeight + 1,
charWidth * 4 - charSpacing);
}
// Print the values and cursor for the flags
void printFlagSettings() {
int cursorY;
byte cursorLen = strlen_P(StrYes) * CHAR_WIDTH - 1 ;
uint8_t cursorLen = strlen_P(StrYes) * charWidth - charSpacing;
if (showLogoFlag) {
printStr_P(FLAGS_SET_X, FLAGS_LOGO_Y, StrYes);
@ -813,22 +825,22 @@ void printFlagSettings() {
}
switch (currentFlag) {
case selFlagLEDs:
case SelectedFlag::selFlagLEDs:
cursorY = FLAGS_LEDS_Y;
if (!showLEDsFlag) {
cursorLen = strlen_P(StrNo) * CHAR_WIDTH - 1;
cursorLen = strlen_P(StrNo) * charWidth - charSpacing;
}
break;
case selFlagName:
case SelectedFlag::selFlagName:
cursorY = FLAGS_NAME_Y;
if (!showNameFlag) {
cursorLen = strlen_P(StrNo) * CHAR_WIDTH - 1;
cursorLen = strlen_P(StrNo) * charWidth - charSpacing;
}
break;
default: // selFlagLogo
cursorY = FLAGS_LOGO_Y;
if (!showLogoFlag) {
cursorLen = strlen_P(StrNo) * CHAR_WIDTH - 1;
cursorLen = strlen_P(StrNo) * charWidth - charSpacing;
}
break;
}
@ -836,7 +848,7 @@ void printFlagSettings() {
arduboy.setCursor(FLAGS_CURSOR_X, cursorY);
arduboy.print('\x10');
arduboy.drawFastHLine(FLAGS_SET_X, cursorY + CHAR_HEIGHT, cursorLen);
arduboy.drawFastHLine(FLAGS_SET_X, cursorY + charHeight, cursorLen);
}
// Print the unit name in normal size including an extent underline
@ -844,9 +856,9 @@ void printFlagSettings() {
void printName(int x, int y) {
printStr(x, y, unitName);
y += (CHAR_HEIGHT + 1);
for (byte i = 0; i < ARDUBOY_UNIT_NAME_LEN; i++, x += CHAR_WIDTH) {
arduboy.drawFastHLine(x, y, CHAR_WIDTH - 1);
y += (charHeight + 1);
for (uint8_t i = 0; i < ARDUBOY_UNIT_NAME_LEN; i++, x += charWidth) {
arduboy.drawFastHLine(x, y, charWidth - charSpacing);
}
}
@ -864,8 +876,8 @@ void printNameUnderline(int x, int y) {
if (unitName[0] != 0) {
x -= 1;
y += ((CHAR_HEIGHT * 2) + 6);
lWidth = (strlen(unitName) * (CHAR_WIDTH * 2));
y += (char2Height + 6);
lWidth = (strlen(unitName) * char2Width);
arduboy.drawPixel(x, y);
arduboy.drawPixel(x + lWidth - 1, y);
arduboy.drawFastHLine(x, y + 1, lWidth);
@ -874,17 +886,17 @@ void printNameUnderline(int x, int y) {
// Print the unit name in hex at the given location
void printNameHex(int x, int y) {
for (byte i = 0; i < ARDUBOY_UNIT_NAME_LEN; i++) {
for (uint8_t i = 0; i < ARDUBOY_UNIT_NAME_LEN; i++) {
printHex8(x, y, unitName[i]);
x += CHAR_WIDTH * 3 + SMALL_SPACE;
x += charWidth * 3 + smallSpace;
}
}
// Print the unit name in decimal at the given location
void printNameDecimal(int x, int y) {
for (byte i = 0; i < ARDUBOY_UNIT_NAME_LEN; i++) {
for (uint8_t i = 0; i < ARDUBOY_UNIT_NAME_LEN; i++) {
printDecimal8(x, y, unitName[i]);
x += CHAR_WIDTH * 3 + SMALL_SPACE;
x += charWidth * 3 + smallSpace;
}
}
@ -903,7 +915,7 @@ void printIDHex(int x, int y) {
// Print the unit ID as 2 decimal bytes at the given location
void printIDDecimalBytes(int x, int y) {
printDecimal8(x, y, unitID >> 8);
printDecimal8(x + CHAR_WIDTH * 3 + SMALL_SPACE, y, unitID & 0x00FF);
printDecimal8(x + charWidth * 3 + smallSpace, y, unitID & 0x00FF);
}
// Print the unit ID in decimal at the given location
@ -916,17 +928,17 @@ void printIDDecimal(int x, int y) {
void printIDBinary(int x, int y) {
arduboy.setCursor(x, y);
arduboy.print('b');
x += CHAR_WIDTH + SMALL_SPACE;
x += charWidth + smallSpace;
for (char i = 3 * 4; i >= 0; i -= 4) {
printBinaryNybble(x, y, (byte)(unitID >> i));
x += CHAR_WIDTH * 4 + SMALL_SPACE;
printBinaryNybble(x, y, static_cast<uint8_t>(unitID >> i));
x += charWidth * 4 + smallSpace;
}
}
// Print the save prompt in reverse at the given location
void printSavePrompt(int x, int y) {
arduboy.fillRect(x - 2, y - 2,
strlen_P(StrSaveQ) * CHAR_WIDTH + 3, CHAR_HEIGHT + 3);
strlen_P(StrSaveQ) * charWidth + 3, charHeight + 3);
arduboy.setTextColor(BLACK);
arduboy.setTextBackground(WHITE);
printStr_P(x, y, StrSaveQ);
@ -947,18 +959,18 @@ void printStr_P(int x, int y, const char* str) {
}
// Print an 8 bit number in decimal, right justified with leading spaces
void printDecimal8(int x, int y, byte val) {
void printDecimal8(int x, int y, uint8_t val) {
printDecimalHelper(x, y, 2, 100, val);
}
// Print a 16 bit number in decimal, right justified with leading spaces
void printDecimal16(int x, int y, unsigned int val) {
void printDecimal16(int x, int y, uint16_t val) {
printDecimalHelper(x, y, 4, 10000, val);
}
// Print a right justified decimal number, given width-1 and (width-1)^10
void printDecimalHelper(int x, int y, byte width, unsigned int pwr10,
unsigned int val) {
void printDecimalHelper(int x, int y, uint8_t width, uint16_t pwr10,
uint16_t val) {
arduboy.setCursor(x, y);
while (width > 0) {
if (val >= pwr10) {
@ -972,7 +984,7 @@ void printDecimalHelper(int x, int y, byte width, unsigned int pwr10,
}
// Print an 8 bit hex number with leading x and zeros
void printHex8(int x, int y, byte val) {
void printHex8(int x, int y, uint8_t val) {
arduboy.setCursor(x, y);
arduboy.print('x');
if (val < 16) {
@ -982,7 +994,7 @@ void printHex8(int x, int y, byte val) {
}
// Print a 16 bit hex number with leading x and zeros
void printHex16(int x, int y, unsigned int val) {
void printHex16(int x, int y, uint16_t val) {
arduboy.setCursor(x, y);
arduboy.print('x');
for (char i = 3 * 4; i >= 0; i -= 4) {
@ -991,7 +1003,7 @@ void printHex16(int x, int y, unsigned int val) {
}
// Print a nybble in binary from the lowest 4 bits of the provided byte
void printBinaryNybble(int x, int y, byte val) {
void printBinaryNybble(int x, int y, uint8_t val) {
arduboy.setCursor(x, y);
for (char i = 3; i >= 0; i--) {
@ -1002,7 +1014,7 @@ void printBinaryNybble(int x, int y, byte val) {
// Print a constant string in large size and reversed
void printStrLargeRev_P(int x, int y, const char* string) {
arduboy.fillRect(x - 4, y - 4,
strlen_P(string) * CHAR_WIDTH * 2 + 6, CHAR_HEIGHT * 2 + 6);
strlen_P(string) * char2Width + 6, char2Height + 6);
arduboy.setTextColor(BLACK);
arduboy.setTextBackground(WHITE);
arduboy.setTextSize(2);
@ -1037,8 +1049,8 @@ void nameCharDec() {
}
// Return true if the given character is not allowed
boolean invalidChar(char c) {
return (c == '\n') || (c == '\r') || ((byte)c == 0xFF);
bool invalidChar(char c) {
return (c == '\n') || (c == '\r') || (static_cast<uint8_t>(c) == 0xFF);
}
// Move the name cursor right
@ -1100,14 +1112,14 @@ void idCursorLeft() {
// Move the Flags cursor down
void flagsCursorDown() {
switch (currentFlag) {
case selFlagLogo:
currentFlag = selFlagLEDs;
case SelectedFlag::selFlagLogo:
currentFlag = SelectedFlag::selFlagLEDs;
break;
case selFlagLEDs:
currentFlag = selFlagName;
case SelectedFlag::selFlagLEDs:
currentFlag = SelectedFlag::selFlagName;
break;
case selFlagName:
currentFlag = selFlagLogo;
case SelectedFlag::selFlagName:
currentFlag = SelectedFlag::selFlagLogo;
break;
}
drawScreen();
@ -1116,14 +1128,14 @@ void flagsCursorDown() {
// Move the Flags cursor up
void flagsCursorUp() {
switch (currentFlag) {
case selFlagName:
currentFlag = selFlagLEDs;
case SelectedFlag::selFlagName:
currentFlag = SelectedFlag::selFlagLEDs;
break;
case selFlagLEDs:
currentFlag = selFlagLogo;
case SelectedFlag::selFlagLEDs:
currentFlag = SelectedFlag::selFlagLogo;
break;
case selFlagLogo:
currentFlag = selFlagName;
case SelectedFlag::selFlagLogo:
currentFlag = SelectedFlag::selFlagName;
break;
}
drawScreen();
@ -1132,13 +1144,13 @@ void flagsCursorUp() {
// Toggle the currently selected flag
void flagToggle() {
switch (currentFlag) {
case selFlagLogo:
case SelectedFlag::selFlagLogo:
showLogoFlag = !showLogoFlag;
break;
case selFlagLEDs:
case SelectedFlag::selFlagLEDs:
showLEDsFlag = !showLEDsFlag;
break;
case selFlagName:
case SelectedFlag::selFlagName:
showNameFlag = !showNameFlag;
break;
}
@ -1147,7 +1159,7 @@ void flagToggle() {
// Start the button auto-repeat delay
void startButtonDelay() {
delayCount = DELAY_FRAMES;
delayCount = delayFrames;
repeating = false;
}
@ -1159,22 +1171,22 @@ void stopButtonRepeat() {
// Calculate the X coordinate to center a string of the given length
int centerStrLen(unsigned int len) {
return (WIDTH / 2) - (len * CHAR_WIDTH / 2);
return (WIDTH / 2) - (len * charWidth / 2);
}
// Calculate the X coordinate to center a string located in program memory
int centerStr_P(const char* str) {
return (WIDTH / 2) - (strlen_P(str) * CHAR_WIDTH / 2);
return (WIDTH / 2) - (strlen_P(str) * charWidth / 2);
}
// Calculate the X coordinate to center a size 2 string located in
// program memory
int centerStr2_P(const char* str) {
return (WIDTH / 2) - (strlen_P(str) * CHAR_WIDTH);
return (WIDTH / 2) - (strlen_P(str) * char2Width / 2);
}
// Calculate the X coordinate to right justify a string in program memory
int rightStr_P(const char* str) {
return WIDTH - (strlen_P(str) * CHAR_WIDTH) + 1;
return WIDTH - (strlen_P(str) * charWidth) + charSpacing;
}

View File

@ -5,7 +5,7 @@
#---------------------------------------------------------------------------
DOXYFILE_ENCODING = UTF-8
PROJECT_NAME = "Arduboy2 Library"
PROJECT_NUMBER = 5.3.0
PROJECT_NUMBER = 6.0.0
PROJECT_BRIEF =
PROJECT_LOGO =
OUTPUT_DIRECTORY = doxygen

BIN
extras/assets/arduboy_logo.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 238 B

BIN
extras/assets/arduboy_screen.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 434 B

After

Width:  |  Height:  |  Size: 343 B

View File

@ -77,10 +77,13 @@ given and a non-zero exit code will be returned.
## Input file decoding
The input file should be a PNG file containing the image to be converted. The
image will be translated to a raw array of 32 bit RGBA (Red, Green, Blue, Alpha)
pixels internally before being processed to output. Ideally, pixels that are to
be drawn (represented as a 1 in the image output) should be fully white.
The input file should be a PNG file containing the image to be converted.
The height of the image must be a multiple of 8 pixels (8, 16, 24, 32, ...).
The width can be any size.
The image will be translated to a raw array of 32 bit RGBA (Red, Green, Blue,
Alpha) pixels internally before being processed to output. Ideally, pixels that
are to be drawn (represented as a 1 in the image output) should be fully white.
Non-drawn (0) pixels should be fully black. Pixels intended to be masked out of
the image (represented as a 0 in both the image and mask output), should be
fully transparent and their color doesn't matter.

View File

@ -11,7 +11,7 @@ https://www.lexaloffle.com/bbs/?uid=1
https://twitter.com/lexaloffle
Contributed to Team A.R.G.
Modifications by Scott Allen - July 2016
Modifications by Scott Allen - July 2020, September 2020
To the extent possible under law, the author(s) have dedicated all copyright
and related and neighboring rights to this software to the public domain
@ -332,12 +332,18 @@ int main(int argc, char **argv)
exit(result);
}
if (h % 8 != 0) {
printf("error 120: file %s: image height must be a multiple of 8 but is %u\n", argv[1], h);
free(bmp);
exit(120);
}
// generate sprite and mask
rawlen = w * (h+7) / 8;
bmp0 = malloc(rawlen); memset(bmp0, 0, rawlen);
bmp1 = malloc(rawlen); memset(bmp1, 0, rawlen);
bmp0 = (unsigned char *)malloc(rawlen); memset(bmp0, 0, rawlen);
bmp1 = (unsigned char *)malloc(rawlen); memset(bmp1, 0, rawlen);
printf("// %s width: %u height: %u\n", argv[1], w, h);

BIN
extras/cabi/sample.png Normal file → Executable file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 280 B

After

Width:  |  Height:  |  Size: 199 B

View File

@ -6,7 +6,7 @@ Documentation for files contained in this repository that aren't self explanator
Provides information so that this library can be installed and updated in the Arduino IDE using the [Library Manager](https://www.arduino.cc/en/Guide/Libraries#toc3).
The value of *version* must be set to the latest stable tagged release. This should be changed and commited just before tagging the new release.
The value of *version* must be set to the latest stable tagged release. This should be changed and committed just before tagging the new release.
See the [Arduino IDE 1.5: Library specification](https://arduino.github.io/arduino-cli/library-specification/) for details.
@ -14,7 +14,7 @@ See the [Arduino IDE 1.5: Library specification](https://arduino.github.io/ardui
This JSON file is a manifest used by the [PlatformIO IDE](https://platformio.org/) to make this library available in its [Library Manager](https://docs.platformio.org/en/latest/librarymanager/index.html).
The value of *version* must be set to the latest stable tagged release. This should be changed and commited just before tagging the new release.
The value of *version* must be set to the latest stable tagged release. This should be changed and committed just before tagging the new release.
See the [PlatformIO library.json](https://docs.platformio.org/en/latest/librarymanager/config.html) documentation for details.

View File

@ -26,6 +26,7 @@ blank KEYWORD2
boot KEYWORD2
bootLogo KEYWORD2
bootLogoCompressed KEYWORD2
bootLogoExtra KEYWORD2
bootLogoShell KEYWORD2
bootLogoSpritesBOverwrite KEYWORD2
bootLogoSpritesBSelfMasked KEYWORD2
@ -67,11 +68,16 @@ flipHorizontal KEYWORD2
freeRGBled KEYWORD2
generateRandomSeed KEYWORD2
getBuffer KEYWORD2
getCharacterHeight KEYWORD2
getCharacterSpacing KEYWORD2
getCharacterWidth KEYWORD2
getCursorX KEYWORD2
getCursorY KEYWORD2
getLineSpacing KEYWORD2
getPixel KEYWORD2
getTextBackground KEYWORD2
getTextColor KEYWORD2
getTextRawMode KEYWORD2
getTextSize KEYWORD2
getTextWrap KEYWORD2
height KEYWORD2
@ -104,6 +110,7 @@ setFrameRate KEYWORD2
setRGBled KEYWORD2
setTextBackground KEYWORD2
setTextColor KEYWORD2
setTextRawMode KEYWORD2
setTextSize KEYWORD2
setTextWrap KEYWORD2
SPItransfer KEYWORD2
@ -131,6 +138,21 @@ drawOverwrite KEYWORD2
drawPlusMask KEYWORD2
drawSelfMasked KEYWORD2
##### Public variables #####
audio KEYWORD2
arduboy_logo KEYWORD2
arduboy_logo_compressed KEYWORD2
arduboy_logo_sprite KEYWORD2
currentButtonState KEYWORD2
font5x7 KEYWORD2
frameCount KEYWORD2
previousButtonState KEYWORD2
sBuffer KEYWORD2
# Arduboy2Beep classes
duration KEYWORD2
#######################################
# Constants (LITERAL1)
#######################################

View File

@ -7,7 +7,7 @@
"type": "git",
"url": "https://github.com/MLXXXp/Arduboy2.git"
},
"version": "5.3.0",
"version": "6.0.0",
"export":
{
"exclude": "extras"

View File

@ -1,5 +1,5 @@
name=Arduboy2
version=5.3.0
version=6.0.0
author=Chris J. Martinez, Kevin Bates, Josh Goebel, Scott Allen, Ross O. Shoger
maintainer=Scott Allen <saydisp-git@yahoo.ca>
sentence=An alternative library for use with the Arduboy game system.

View File

@ -12,20 +12,40 @@
uint8_t Arduboy2Base::sBuffer[];
Arduboy2Base::Arduboy2Base()
{
currentButtonState = 0;
previousButtonState = 0;
// frame management
setFrameDuration(16);
frameCount = 0;
justRendered = false;
}
uint16_t Arduboy2Base::frameCount = 0;
uint8_t Arduboy2Base::currentButtonState = 0;
uint8_t Arduboy2Base::previousButtonState = 0;
uint8_t Arduboy2Base::eachFrameMillis = 16;
uint8_t Arduboy2Base::thisFrameStart;
uint8_t Arduboy2Base::lastFrameDurationMs;
bool Arduboy2Base::justRendered = false;
// functions called here should be public so users can create their
// own init functions if they need different behavior than `begin`
// provides by default
// provides by default.
//
// This code and it's documentation should be kept in sync with
// Aruduboy2::begin()
void Arduboy2Base::begin()
{
beginDoFirst();
bootLogo();
// alternative logo functions. Work the same as bootLogo() but may reduce
// memory size if the sketch uses the same bitmap drawing function or
// `Sprites`/`SpritesB` class
// bootLogoCompressed();
// bootLogoSpritesSelfMasked();
// bootLogoSpritesOverwrite();
// bootLogoSpritesBSelfMasked();
// bootLogoSpritesBOverwrite();
waitNoButtons(); // wait for all buttons to be released
}
void Arduboy2Base::beginDoFirst()
{
boot(); // raw hardware
@ -37,17 +57,6 @@ void Arduboy2Base::begin()
systemButtons();
audio.begin();
bootLogo();
// alternative logo functions. Work the same as bootLogo() but may reduce
// memory size if the sketch uses the same bitmap drawing function
// bootLogoCompressed();
// bootLogoSpritesSelfMasked();
// bootLogoSpritesOverwrite();
// bootLogoSpritesBSelfMasked();
// bootLogoSpritesBOverwrite();
waitNoButtons(); // wait for all buttons to be released
}
void Arduboy2Base::flashlight()
@ -159,12 +168,12 @@ void Arduboy2Base::drawLogoSpritesBOverwrite(int16_t y)
// bootLogoText() should be kept in sync with bootLogoShell()
// if changes are made to one, equivalent changes should be made to the other
void Arduboy2Base::bootLogoShell(void (*drawLogo)(int16_t))
bool Arduboy2Base::bootLogoShell(void (&drawLogo)(int16_t))
{
bool showLEDs = readShowBootLogoLEDsFlag();
if (!readShowBootLogoFlag()) {
return;
return false;
}
if (showLEDs) {
@ -174,7 +183,7 @@ void Arduboy2Base::bootLogoShell(void (*drawLogo)(int16_t))
for (int16_t y = -15; y <= 24; y++) {
if (pressed(RIGHT_BUTTON)) {
digitalWriteRGB(RGB_OFF, RGB_OFF, RGB_OFF); // all LEDs off
return;
return false;
}
if (showLEDs && y == 4) {
@ -197,14 +206,12 @@ void Arduboy2Base::bootLogoShell(void (*drawLogo)(int16_t))
delayShort(400);
digitalWriteRGB(BLUE_LED, RGB_OFF);
bootLogoExtra();
return true;
}
// Virtual function overridden by derived class
void Arduboy2Base::bootLogoExtra() { }
// wait for all buttons to be released
void Arduboy2Base::waitNoButtons() {
void Arduboy2Base::waitNoButtons()
{
do {
delayShort(50); // simple button debounce
} while (buttonsState());
@ -287,12 +294,10 @@ void Arduboy2Base::clear()
void Arduboy2Base::drawPixel(int16_t x, int16_t y, uint8_t color)
{
#ifdef PIXEL_SAFE_MODE
if (x < 0 || x > (WIDTH-1) || y < 0 || y > (HEIGHT-1))
{
return;
}
#endif
uint16_t row_offset;
uint8_t bit;
@ -331,12 +336,10 @@ void Arduboy2Base::drawPixel(int16_t x, int16_t y, uint8_t color)
// For reference, this is the C++ equivalent
void Arduboy2Base::drawPixel(int16_t x, int16_t y, uint8_t color)
{
#ifdef PIXEL_SAFE_MODE
if (x < 0 || x > (WIDTH-1) || y < 0 || y > (HEIGHT-1))
{
return;
}
#endif
uint16_t row_offset;
uint8_t bit;
@ -578,10 +581,10 @@ void Arduboy2Base::drawFastHLine
w = xEnd - x;
// buffer pointer plus row offset + x offset
register uint8_t *pBuf = sBuffer + ((y / 8) * WIDTH) + x;
uint8_t *pBuf = sBuffer + ((y / 8) * WIDTH) + x;
// pixel mask
register uint8_t mask = 1 << (y & 7);
uint8_t mask = 1 << (y & 7);
switch (color)
{
@ -620,7 +623,7 @@ void Arduboy2Base::fillScreen(uint8_t color)
// {
// color = 0xFF; // all pixels on
// }
// for (int16_t i = 0; i < WIDTH * HEIGTH / 8; i++)
// for (int16_t i = 0; i < WIDTH * HEIGHT / 8; i++)
// {
// sBuffer[i] = color;
// }
@ -860,17 +863,18 @@ void Arduboy2Base::drawSlowXYBitmap
}
}
// Helper for drawCompressed()
struct Arduboy2Base::BitStreamReader
class Arduboy2Base::BitStreamReader
{
private:
const uint8_t *source;
uint16_t sourceIndex;
uint8_t bitBuffer;
uint8_t byteBuffer;
BitStreamReader(const uint8_t *source)
: source(source), sourceIndex(), bitBuffer(), byteBuffer()
public:
BitStreamReader(const uint8_t *bitmap)
: source(bitmap), sourceIndex(), bitBuffer(), byteBuffer()
{
}
@ -879,17 +883,17 @@ struct Arduboy2Base::BitStreamReader
uint16_t result = 0;
for (uint16_t i = 0; i < bitCount; i++)
{
if (this->bitBuffer == 0)
if (bitBuffer == 0)
{
this->bitBuffer = 0x1;
this->byteBuffer = pgm_read_byte(&this->source[this->sourceIndex]);
++this->sourceIndex;
bitBuffer = 0x1;
byteBuffer = pgm_read_byte(&source[sourceIndex]);
++sourceIndex;
}
if ((this->byteBuffer & this->bitBuffer) != 0)
if ((byteBuffer & bitBuffer) != 0)
result |= (1 << i);
this->bitBuffer <<= 1;
bitBuffer <<= 1;
}
return result;
}
@ -898,7 +902,7 @@ struct Arduboy2Base::BitStreamReader
void Arduboy2Base::drawCompressed(int16_t sx, int16_t sy, const uint8_t *bitmap, uint8_t color)
{
// set up decompress state
BitStreamReader cs = BitStreamReader(bitmap);
BitStreamReader cs(bitmap);
// read header
int width = (int)cs.readBits(8) + 1;
@ -1149,14 +1153,83 @@ void Arduboy2Base::swapInt16(int16_t& a, int16_t& b)
//========== class Arduboy2 ==========
//====================================
Arduboy2::Arduboy2()
int16_t Arduboy2::cursor_x = 0;
int16_t Arduboy2::cursor_y = 0;
uint8_t Arduboy2::textColor = WHITE;
uint8_t Arduboy2::textBackground = BLACK;
uint8_t Arduboy2::textSize = 1;
bool Arduboy2::textWrap = false;
bool Arduboy2::textRaw = false;
// functions called here should be public so users can create their
// own init functions if they need different behavior than `begin`
// provides by default.
//
// This code and it's documentation should be kept in sync with
// Aruduboy2Base::begin()
void Arduboy2::begin()
{
cursor_x = 0;
cursor_y = 0;
textColor = 1;
textBackground = 0;
textSize = 1;
textWrap = 0;
beginDoFirst();
bootLogo();
// alternative logo functions. Work the same as bootLogo() but may reduce
// memory size if the sketch uses the same bitmap drawing function or
// `Sprites`/`SpritesB` class
// bootLogoCompressed();
// bootLogoSpritesSelfMasked();
// bootLogoSpritesOverwrite();
// bootLogoSpritesBSelfMasked();
// bootLogoSpritesBOverwrite();
waitNoButtons();
}
void Arduboy2::bootLogo()
{
if (bootLogoShell(drawLogoBitmap))
{
bootLogoExtra();
}
}
void Arduboy2::bootLogoCompressed()
{
if (bootLogoShell(drawLogoCompressed))
{
bootLogoExtra();
}
}
void Arduboy2::bootLogoSpritesSelfMasked()
{
if (bootLogoShell(drawLogoSpritesSelfMasked))
{
bootLogoExtra();
}
}
void Arduboy2::bootLogoSpritesOverwrite()
{
if (bootLogoShell(drawLogoSpritesOverwrite))
{
bootLogoExtra();
}
}
void Arduboy2::bootLogoSpritesBSelfMasked()
{
if (bootLogoShell(drawLogoSpritesBSelfMasked))
{
bootLogoExtra();
}
}
void Arduboy2::bootLogoSpritesBOverwrite()
{
if (bootLogoShell(drawLogoSpritesBOverwrite))
{
bootLogoExtra();
}
}
// bootLogoText() should be kept in sync with bootLogoShell()
@ -1173,7 +1246,7 @@ void Arduboy2::bootLogoText()
digitalWriteRGB(RED_LED, RGB_ON);
}
for (int16_t y = -16; y <= 24; y++) {
for (int16_t y = -15; y <= 24; y++) {
if (pressed(RIGHT_BUTTON)) {
digitalWriteRGB(RGB_OFF, RGB_OFF, RGB_OFF); // all LEDs off
return;
@ -1237,64 +1310,106 @@ void Arduboy2::bootLogoExtra()
size_t Arduboy2::write(uint8_t c)
{
if (c == '\n')
if ((c == '\r') && !textRaw)
{
return 1;
}
if (((c == '\n') && !textRaw) ||
(textWrap && (cursor_x > (WIDTH - (characterWidth * textSize)))))
{
cursor_y += textSize * 8;
cursor_x = 0;
cursor_y += fullCharacterHeight * textSize;
}
else if (c == '\r')
{
// skip em
}
else
if ((c != '\n') || textRaw)
{
drawChar(cursor_x, cursor_y, c, textColor, textBackground, textSize);
cursor_x += textSize * 6;
if (textWrap && (cursor_x > (WIDTH - textSize * 6)))
{
// calling ourselves recursively for 'newline' is
// 12 bytes smaller than doing the same math here
write('\n');
}
cursor_x += fullCharacterWidth * textSize;
}
return 1;
}
void Arduboy2::drawChar
(int16_t x, int16_t y, unsigned char c, uint8_t color, uint8_t bg, uint8_t size)
(int16_t x, int16_t y, uint8_t c, uint8_t color, uint8_t bg, uint8_t size)
{
uint8_t line;
bool draw_background = bg != color;
const uint8_t* bitmap = font5x7 + c * 5;
// It is assumed that rendering characters fully off screen will be rare,
// so let drawPixel() handle off screen checks, to reduce code size at the
// expense of slower off screen character handling.
#if 0
if ((x >= WIDTH) || // Clip right
(y >= HEIGHT) || // Clip bottom
((x + 5 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0) // Clip top
((x + characterWidth * size - 1) < 0) || // Clip left
((y + characterHeight * size - 1) < 0) // Clip top
)
{
return;
}
#endif
for (uint8_t i = 0; i < 6; i++ )
bool drawBackground = bg != color;
const uint8_t* bitmap =
&font5x7[c * characterWidth * ((characterHeight + 8 - 1) / 8)];
for (uint8_t i = 0; i < fullCharacterWidth; i++)
{
line = pgm_read_byte(bitmap++);
if (i == 5) {
line = 0x0;
uint8_t column;
if (characterHeight <= 8)
{
column = (i < characterWidth) ? pgm_read_byte(bitmap++) : 0;
}
else
{
column = 0;
}
for (uint8_t j = 0; j < 8; j++)
// draw the character by columns. Top to bottom, left to right
// including character spacing on the right
for (uint8_t j = 0; j < characterHeight; j++)
{
uint8_t draw_color = (line & 0x1) ? color : bg;
if (characterHeight > 8)
{
// at this point variable "column" will be 0, either from initialization
// or by having eight 0 bits shifted in by the >>= operation below
if ((j % 8 == 0) && (i < characterWidth))
{
column = pgm_read_byte(bitmap++);
}
}
if (draw_color || draw_background) {
for (uint8_t a = 0; a < size; a++ ) {
for (uint8_t b = 0; b < size; b++ ) {
drawPixel(x + (i * size) + a, y + (j * size) + b, draw_color);
// pixelIsSet should be a bool but at the time of writing,
// the GCC AVR compiler generates less code if it's a uint8_t
uint8_t pixelIsSet = column & 0x01;
if (pixelIsSet || drawBackground)
{
for (uint8_t a = 0; a < size; a++)
{
for (uint8_t b = 0; b < size; b++)
{
drawPixel(x + (i * size) + a, y + (j * size) + b,
pixelIsSet ? color : bg);
}
}
}
column >>= 1;
}
// draw the inter-line spacing pixels for this column if required
if (drawBackground)
{
for (uint8_t j = characterHeight; j < fullCharacterHeight; j++)
{
for (uint8_t a = 0; a < size; a++)
{
for (uint8_t b = 0; b < size; b++)
{
drawPixel(x + (i * size) + a, y + (j * size) + b, bg);
}
}
}
line >>= 1;
}
}
}
@ -1366,6 +1481,16 @@ bool Arduboy2::getTextWrap()
return textWrap;
}
void Arduboy2::setTextRawMode(bool raw)
{
textRaw = raw;
}
bool Arduboy2::getTextRawMode()
{
return textRaw;
}
void Arduboy2::clear()
{
Arduboy2Base::clear();

File diff suppressed because it is too large Load Diff

View File

@ -80,11 +80,8 @@ class Arduboy2Audio
*
* \details
* The speaker is initialized based on the current mute setting saved in
* system EEPROM. This function is called by `Arduboy2Base::begin()` so it
* isn't normally required to call it within a sketch. However, if
* `Arduboy2Core::boot()` is used instead of `Arduboy2Base::begin()` and the
* sketch includes sound, then this function should be called after `boot()`.
*/
* system EEPROM.
*/
static void begin();
/** \brief

View File

@ -45,9 +45,9 @@
* for. For example, with a rate of 60 frames per second a duration of 30
* would be used to play a tone for half a second.
*
* The variable named `#duration` is the counter that times the duration of a
* The variable named #duration is the counter that times the duration of a
* tone. A sketch can determine if a tone is currently playing by testing if
* the `#duration` variable is non-zero (assuming it's a timed tone, not a
* the #duration variable is non-zero (assuming it's a timed tone, not a
* continuous tone).
*
* To keep the code small and efficient, the frequency of a tone is specified

View File

@ -13,8 +13,6 @@
//========== class Arduboy2Core ==========
//========================================
Arduboy2Core::Arduboy2Core() { }
// Commands sent to the OLED display to initialize it
const PROGMEM uint8_t Arduboy2Core::lcdBootProgram[] = {
// boot defaults are commented out but left here in case they

View File

@ -337,7 +337,6 @@ class Arduboy2Core : public Arduboy2NoUSB
friend class Arduboy2Ex;
public:
Arduboy2Core();
/** \brief
* Idle the CPU to save power.
@ -573,7 +572,7 @@ class Arduboy2Core : public Arduboy2NoUSB
* Invert the entire display or set it back to normal.
*
* \param inverse `true` will invert the display. `false` will set the
* display to no-inverted.
* display to non-inverted.
*
* \details
* Calling this function with a value of `true` will set the display to
@ -797,14 +796,21 @@ class Arduboy2Core : public Arduboy2NoUSB
* \details
* This function initializes the display, buttons, etc.
*
* This function is called by begin() so isn't normally called within a
* This function is called by `begin()` so isn't normally called within a
* sketch. However, in order to free up some code space, by eliminating
* some of the start up features, it can be called in place of begin().
* The functions that begin() would call after boot() can then be called
* to add back in some of the start up features, if desired.
* See the README file or documentation on the main page for more details.
* The functions that `begin()` would call after `boot()` can then be
* called to add back in some of the start up features as space permits.
*
* \see Arduboy2Base::begin()
* See the README file or main page, in section
* _Substitute or remove boot up features_, for more details.
*
* \warning
* If this function is used, it is recommended that at least `flashlight()`
* or `safeMode()` be called after it to provide a means to upload a new
* sketch if the bootloader "magic number" problem is encountered.
*
* \see Arduboy2::begin() Arduboy2Base::flashlight() safeMode()
*/
static void boot();
@ -818,8 +824,8 @@ class Arduboy2Core : public Arduboy2NoUSB
* sketch, for sketches that interfere with the bootloader "magic number".
* The problem occurs with certain sketches that use large amounts of RAM.
*
* This function should be called after `boot()` in sketches that
* potentially could cause the problem.
* This function should be called after `boot()` in sketches that don't
* call `flashlight()`.
*
* It is intended to replace the `flashlight()` function when more
* program space is required. If possible, it is more desirable to use

View File

@ -9,7 +9,7 @@
// arduboy_logo.png
// drawBitmap() format
// 88x16
// 88x16 px (176 bytes)
const PROGMEM uint8_t Arduboy2Base::arduboy_logo[] = {
0xF0, 0xF8, 0x9C, 0x8E, 0x87, 0x83, 0x87, 0x8E, 0x9C, 0xF8,
0xF0, 0x00, 0x00, 0xFE, 0xFF, 0x03, 0x03, 0x03, 0x03, 0x03,
@ -33,7 +33,7 @@ const PROGMEM uint8_t Arduboy2Base::arduboy_logo[] = {
// arduboy_logo.png
// drawCompressed() format
// 88x16
// 88x16 px (151 bytes)
const PROGMEM uint8_t Arduboy2Base::arduboy_logo_compressed[] = {
0x57, 0x0F, 0x9C, 0x53, 0x72, 0x75, 0x29, 0xE5, 0x9C, 0x92,
0xCE, 0x95, 0x52, 0xAD, 0x4E, 0x49, 0xE7, 0x08, 0x09, 0xED,
@ -55,7 +55,7 @@ const PROGMEM uint8_t Arduboy2Base::arduboy_logo_compressed[] = {
// arduboy_logo.png
// Sprites::drawSelfMasked() format
// 88x16
// 88x16 px (178 bytes)
const PROGMEM uint8_t Arduboy2Base::arduboy_logo_sprite[] = {
88, 16,
0xF0, 0xF8, 0x9C, 0x8E, 0x87, 0x83, 0x87, 0x8E, 0x9C, 0xF8,