Compare commits

..

No commits in common. "master" and "5.3.0" have entirely different histories.

29 changed files with 1544 additions and 2427 deletions

View File

@ -1,30 +1,7 @@
# 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-2021, Scott Allen
Copyright (c) 2016-2020, Scott Allen
All rights reserved.
The Arduboy2 library was forked from the Arduboy library:
@ -18,14 +18,13 @@ 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-2020, Scott Allen
Copyright (c) 2018, Scott Allen
All rights reserved.
Redistribution and use in source and binary forms, with or without
@ -165,9 +164,6 @@ 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 original *Arduboy* library is no longer being maintained.
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 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,10 +47,9 @@ 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.
**Note:**
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 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.
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
@ -166,99 +165,63 @@ with
Arduboy2Base arduboy;
```
#### Substitute or remove boot up features
#### Remove boot up features
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.
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.
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.
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.
Here is a template that provides the equivalent of *begin()*
As of this writing, the begin function is:
```cpp
void setup()
void Arduboy2Base::begin()
{
// Required to initialize the hardware.
arduboy.boot();
boot(); // raw hardware
// 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();
display(); // blank the display (sBuffer is global, so cleared automatically)
// flashlight() or safeMode() should always be included to provide
// a method of recovering from the bootloader "magic key" problem.
arduboy.flashlight();
// arduboy.safeMode();
flashlight(); // light the RGB LED and screen if UP button is being held.
// 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();
// check for and handle buttons held during start up for system control
systemButtons();
// This is required to initialize the speaker. It's not needed if
// the sketch doesn't produce any sounds.
arduboy.audio.begin();
audio.begin();
// 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...
bootLogo();
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 *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.
- *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.
- *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()* 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`
- *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()*.
#### Use the SpritesB class instead of Sprites
@ -283,8 +246,6 @@ 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:
@ -428,7 +389,7 @@ Arduboy2 arduboy;
ArduboyPlaytune tunes(arduboy.audio.enabled);
```
The sound channels must then be initialized and assigned to the speaker pins. This code would go in the *setup()* function:
The sound channels must then be initialzed and assigned to the speaker pins. This code would go in the *setup()* function:
```cpp
// audio setup
@ -463,13 +424,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. *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:
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:
```cpp
arduboy.beginDoFirst();
arduboy.waitNoButtons();
arduboy.boot();
arduboy.display();
arduboy.flashlight();
arduboy.audio.begin();
```
----------

View File

@ -271,7 +271,7 @@ void moveBall()
topBrick = 6 * row + 1;
bottomBrick = 6 * row + 7;
//If A collision has occurred
//If A collison has occured
if (topBall <= bottomBrick && bottomBall >= topBrick &&
leftBall <= rightBrick && rightBall >= leftBrick)
{
@ -293,7 +293,7 @@ void moveBall()
}
}
//Horizontal collision
//Hoizontal 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 high scores
//Function by nootropic design to display highscores
boolean displayHighScores(byte file)
{
byte y = 8;
@ -736,14 +736,14 @@ void enterHighScore(byte file)
}
}
// Play a tone at a frequency corresponding to the specified precomputed count,
// Play a tone at a frequency coresponding 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 corresponding to the specified precomputed count,
// Play a tone at a frequency coresponding 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,8 +52,6 @@ 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
@ -129,7 +127,7 @@ void loop() {
objectX = 0;
}
arduboy.display();
arduboy.display(CLEAR_BUFFER);
}
void commandText(const char* text) {

View File

@ -22,10 +22,10 @@ char title[] = "Press Buttons!";
byte x;
byte y;
// Width of each character including inter-character space
// Width of each charcter including inter-character space
#define CHAR_WIDTH 6
// Height of each character
// Height of each charater
#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 frame rate to 30, we do not need to run at default 60 and
// here we set the framerate 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 finally we tell the arduboy to display what we just wrote to the display.
// then we finaly we tell the arduboy to display what we just wrote to the display.
arduboy.display();
}

View File

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

View File

@ -1,122 +0,0 @@
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

@ -1,127 +0,0 @@
/*
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 frame rate to 15, we do not need to run at
// here we set the framerate 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 finally we tell the arduboy to display what we just wrote to the display
// then we finaly 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 information for one digital color
// Draw the informaton 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.2
// Version 2.0
/*
------------------------------------------------------------------------------
Copyright (c) 2018-2020, Scott Allen
Copyright (c) 2018, 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
constexpr uint8_t frameRate = 10;
#define FRAME_RATE 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
constexpr unsigned int idRepeatFrames = 3;
#define ID_REPEAT_FRAMES 3
// Delay time before button auto-repeat starts, in milliseconds
constexpr unsigned int repeatDelay = 700;
#define REPEAT_DELAY 700
// All the constant stings
const char StrName[] PROGMEM = "NAME";
@ -119,20 +119,24 @@ 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 + charHeight + 3)
#define MENU_NAME_Y (MENU_BTN_CHANGE_NAME_Y + CHAR_HEIGHT + 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 + charHeight + 1)
#define MENU_HEADINGS_Y (MENU_BTN_CHANGE_ID_Y + CHAR_HEIGHT + 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 + charHeight + 1)
#define MENU_ID_Y (MENU_HEADINGS_Y + CHAR_HEIGHT + 1)
#define MENU_BTN_FLAGS_X 0
#define MENU_BTN_FLAGS_Y 56
@ -161,9 +165,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 * 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_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_Y (NAME_LARGE_Y + 3)
@ -180,7 +184,7 @@ const char StrDecimal[] PROGMEM = "decimal";
#define ID_2_DECIMAL_X 12
#define ID_2_DECIMAL_Y 38
#define ID_DECIMAL_X (WIDTH - (charWidth * 5 + 12))
#define ID_DECIMAL_X (WIDTH - (CHAR_WIDTH * 5 + 12))
#define ID_DECIMAL_Y ID_2_DECIMAL_Y
#define ID_BINARY_X 0
@ -191,9 +195,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 * 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_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_Y (ID_LARGE_Y + 1)
#define FLAGS_TITLE_X centerStr_P(StrFlags)
@ -208,7 +212,7 @@ const char StrDecimal[] PROGMEM = "decimal";
#define FLAGS_LEDS_Y 27
#define FLAGS_NAME_Y 40
#define FLAGS_Q_X (charWidth * 2)
#define FLAGS_Q_X (CHAR_WIDTH * 2)
#define FLAGS_SET_X rightStr_P(StrYes)
#define FLAGS_CURSOR_X 0
@ -216,74 +220,74 @@ const char StrDecimal[] PROGMEM = "decimal";
#define FLAGS_TEST_Y 56
#define FLAGS_SAVED_X centerStr2_P(StrSaved)
#define FLAGS_SAVED_Y ((HEIGHT / 2) - (char2Height / 2))
#define FLAGS_SAVED_Y ((HEIGHT / 2) - CHAR_HEIGHT)
#define FLAGS_NO_LOGO_1_X centerStr_P(StrNoLogo1)
#define FLAGS_NO_LOGO_1_Y ((HEIGHT / 2) - charHeight - 1)
#define FLAGS_NO_LOGO_1_Y ((HEIGHT / 2) - CHAR_HEIGHT - 1)
#define FLAGS_NO_LOGO_2_X centerStr_P(StrNoLogo2)
#define FLAGS_NO_LOGO_2_Y (FLAGS_NO_LOGO_1_Y + charHeight + 2)
#define FLAGS_NO_LOGO_2_Y (FLAGS_NO_LOGO_1_Y + CHAR_HEIGHT + 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 + charHeight)
#define RESET_BTN_SYS_EEPROM_Y (RESET_BTN_SYS_Y + CHAR_HEIGHT)
#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 + charHeight)
#define RESET_BTN_USER_EEPROM_Y (RESET_BTN_USER_Y + CHAR_HEIGHT)
#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 + charHeight)
#define RESET_SYS_TEXT_2_Y (RESET_SYS_TEXT_1_Y + CHAR_HEIGHT)
#define RESET_SYS_TEXT_3_X centerStr_P(StrResetSys3)
#define RESET_SYS_TEXT_3_Y (RESET_SYS_TEXT_2_Y + charHeight)
#define RESET_SYS_TEXT_3_Y (RESET_SYS_TEXT_2_Y + CHAR_HEIGHT)
#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 + charHeight)
#define RESET_SYS_BTN_NO_Y (RESET_SYS_BTN_YES_Y + CHAR_HEIGHT)
#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 + char2Height + 2)
#define RESET_SYS_CONFIRMED_2_Y (RESET_SYS_CONFIRMED_1_Y + (CHAR_HEIGHT * 2) + 2)
#define RESET_SYS_CONFIRMED_3_X centerStr2_P(StrReset)
#define RESET_SYS_CONFIRMED_3_Y (RESET_SYS_CONFIRMED_2_Y + char2Height + 2)
#define RESET_SYS_CONFIRMED_3_Y (RESET_SYS_CONFIRMED_2_Y + (CHAR_HEIGHT * 2) + 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 + charHeight)
#define RESET_USER_TEXT_2_Y (RESET_USER_TEXT_1_Y + CHAR_HEIGHT)
#define RESET_USER_TEXT_3_X centerStr_P(StrResetUser3)
#define RESET_USER_TEXT_3_Y (RESET_USER_TEXT_2_Y + charHeight)
#define RESET_USER_TEXT_3_Y (RESET_USER_TEXT_2_Y + CHAR_HEIGHT)
#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 + charHeight)
#define RESET_USER_BTN_NO_Y (RESET_USER_BTN_YES_Y + CHAR_HEIGHT)
#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 + char2Height + 2)
#define RESET_USER_CONFIRMED_2_Y (RESET_USER_CONFIRMED_1_Y + (CHAR_HEIGHT * 2) + 2)
#define RESET_USER_CONFIRMED_3_X centerStr2_P(StrReset)
#define RESET_USER_CONFIRMED_3_Y (RESET_USER_CONFIRMED_2_Y + char2Height + 2)
#define RESET_USER_CONFIRMED_3_Y (RESET_USER_CONFIRMED_2_Y + (CHAR_HEIGHT * 2) + 2)
#define RESET_USER_WRITING_X centerStr2_P(StrWriting)
#define RESET_USER_WRITING_Y ((HEIGHT / 2) - (char2Height / 2 - 1))
#define RESET_USER_WRITING_Y ((HEIGHT / 2) - (CHAR_HEIGHT - 1))
// EEPROM addresses
constexpr unsigned int EEPROMstart = 0x0000;
constexpr unsigned int EEPROMsize = 1024;
constexpr unsigned int EEPROMend = EEPROMstart + EEPROMsize - 1;
#define EEPROM_START (0x0000)
#define EEPROM_SIZE (1024)
#define EEPROM_END (EEPROM_START + EEPROM_SIZE - 1)
// Calculation of the number of frames to wait before button auto-repeat starts
constexpr unsigned int delayFrames = repeatDelay / (1000 / frameRate);
#define DELAY_FRAMES (REPEAT_DELAY / (1000 / FRAME_RATE))
// The Arduino "magic" has trouble creating prototypes for functions called
// by pointers, so they're declared here manually
@ -294,39 +298,27 @@ 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];
uint8_t nameIndex;
byte nameIndex;
uint16_t unitID;
uint8_t idIndex;
byte idIndex;
bool showLogoFlag;
bool showLEDsFlag;
bool showNameFlag;
boolean showLogoFlag;
boolean showLEDsFlag;
boolean showNameFlag;
// Selected flag
enum class SelectedFlag : uint8_t {
enum SelectedFlag : byte {
selFlagLogo,
selFlagLEDs,
selFlagName
};
SelectedFlag currentFlag;
byte currentFlag;
// Assign numbers for each state/screen
enum class State : uint8_t {
enum State : byte {
sMain,
sName,
sID,
@ -339,10 +331,10 @@ enum class State : uint8_t {
sMAX = sResetUser
};
State currentState;
byte currentState;
// Function pointer array for button handling
void (*stateFunc[static_cast<uint8_t>(State::sMAX) + 1])() = {
void (*stateFunc[sMAX + 1])() = {
stateMain,
stateName,
stateID,
@ -355,7 +347,7 @@ void (*stateFunc[static_cast<uint8_t>(State::sMAX) + 1])() = {
};
// Function pointer array for screen drawing
void (*screenFunc[static_cast<uint8_t>(State::sMAX) + 1])() = {
void (*screenFunc[sMAX + 1])() = {
screenMain,
screenName,
screenID,
@ -368,14 +360,14 @@ void (*screenFunc[static_cast<uint8_t>(State::sMAX) + 1])() = {
};
unsigned int delayCount = 0;
bool repeating = false;
boolean repeating = false;
// ============================= SETUP ===================================
void setup() {
arduboy.begin();
arduboy.setFrameRate(frameRate);
setState(State::sMain);
arduboy.setFrameRate(FRAME_RATE);
setState(sMain);
}
// =======================================================================
@ -388,7 +380,7 @@ void loop() {
arduboy.pollButtons();
(*stateFunc[static_cast<uint8_t>(currentState)])();
(*stateFunc[currentState])();
if ((delayCount != 0) && (--delayCount == 0)) {
repeating = true;
@ -401,7 +393,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(State newState) {
void setState(byte newState) {
currentState = newState;
stopButtonRepeat();
drawScreen();
@ -410,16 +402,16 @@ void setState(State newState) {
// STATE: Main selection screen
void stateMain() {
if (arduboy.justPressed(UP_BUTTON)) {
setState(State::sName);
setState(sName);
}
else if (arduboy.justPressed(DOWN_BUTTON)) {
setState(State::sID);
setState(sID);
}
else if (arduboy.justPressed(LEFT_BUTTON)) {
setState(State::sFlags);
setState(sFlags);
}
else if (arduboy.justPressed(RIGHT_BUTTON)) {
setState(State::sReset);
setState(sReset);
}
}
@ -446,10 +438,10 @@ void stateName() {
nameCursorLeft();
}
else if (arduboy.justPressed(A_BUTTON)) {
setState(State::sMain);
setState(sMain);
}
else if (arduboy.justPressed(B_BUTTON)) {
setState(State::sSaveName);
setState(sSaveName);
}
else if (repeating) {
stopButtonRepeat();
@ -467,12 +459,12 @@ void stateID() {
startButtonDelay();
}
else if (repeating && arduboy.pressed(UP_BUTTON)) {
if (arduboy.everyXFrames(idRepeatFrames)) {
if (arduboy.everyXFrames(ID_REPEAT_FRAMES)) {
idDigitInc();
}
}
else if (repeating && arduboy.pressed(DOWN_BUTTON)) {
if (arduboy.everyXFrames(idRepeatFrames)) {
if (arduboy.everyXFrames(ID_REPEAT_FRAMES)) {
idDigitDec();
}
}
@ -483,10 +475,10 @@ void stateID() {
idCursorLeft();
}
else if (arduboy.justPressed(A_BUTTON)) {
setState(State::sMain);
setState(sMain);
}
else if (arduboy.justPressed(B_BUTTON)) {
setState(State::sSaveID);
setState(sSaveID);
}
else if (repeating) {
stopButtonRepeat();
@ -504,8 +496,8 @@ void stateFlags() {
else {
displayNoLogo();
}
currentFlag = SelectedFlag::selFlagLogo;
setState(State::sFlags);
currentFlag = selFlagLogo;
setState(sFlags);
}
else if (arduboy.justPressed(UP_BUTTON)) {
flagsCursorUp();
@ -518,24 +510,24 @@ void stateFlags() {
flagToggle();
}
else if (arduboy.justPressed(A_BUTTON)) {
setState(State::sMain);
setState(sMain);
}
else if (arduboy.justPressed(B_BUTTON)) {
saveFlags();
setState(State::sFlags);
setState(sFlags);
}
}
// STATE: Reset EEPROM areas
void stateReset() {
if (arduboy.justPressed(UP_BUTTON)) {
setState(State::sResetSys);
setState(sResetSys);
}
else if (arduboy.justPressed(DOWN_BUTTON)) {
setState(State::sResetUser);
setState(sResetUser);
}
else if (arduboy.justPressed(A_BUTTON)) {
setState(State::sMain);
setState(sMain);
}
}
@ -543,10 +535,10 @@ void stateReset() {
void stateSaveName() {
if (arduboy.justPressed(A_BUTTON)) {
arduboy.writeUnitName(unitName);
setState(State::sMain);
setState(sMain);
}
else if (arduboy.justPressed(B_BUTTON)) {
setState(State::sName);
setState(sName);
}
}
@ -554,10 +546,10 @@ void stateSaveName() {
void stateSaveID() {
if (arduboy.justPressed(A_BUTTON)) {
arduboy.writeUnitID(unitID);
setState(State::sMain);
setState(sMain);
}
else if (arduboy.justPressed(B_BUTTON)) {
setState(State::sID);
setState(sID);
}
}
@ -565,13 +557,13 @@ void stateSaveID() {
void stateResetSys() {
if (arduboy.justPressed(B_BUTTON) && arduboy.pressed(A_BUTTON)) {
resetSysEEPROM();
setState(State::sReset);
setState(sReset);
}
else if (arduboy.justPressed(UP_BUTTON) ||
arduboy.justPressed(DOWN_BUTTON) ||
arduboy.justPressed(RIGHT_BUTTON) ||
arduboy.justPressed(LEFT_BUTTON)) {
setState(State::sReset);
setState(sReset);
}
}
@ -579,13 +571,13 @@ void stateResetSys() {
void stateResetUser() {
if (arduboy.justPressed(B_BUTTON) && arduboy.pressed(A_BUTTON)) {
resetUserEEPROM();
setState(State::sReset);
setState(sReset);
}
else if (arduboy.justPressed(UP_BUTTON) ||
arduboy.justPressed(DOWN_BUTTON) ||
arduboy.justPressed(RIGHT_BUTTON) ||
arduboy.justPressed(LEFT_BUTTON)) {
setState(State::sReset);
setState(sReset);
}
}
@ -594,7 +586,7 @@ void stateResetUser() {
// Display the screen for the current state
void drawScreen() {
arduboy.clear();
(*screenFunc[static_cast<uint8_t>(currentState)])();
(*screenFunc[currentState])();
arduboy.display();
}
@ -602,7 +594,7 @@ void drawScreen() {
void screenMain() {
readEEPROM();
nameIndex = idIndex = 0;
currentFlag = SelectedFlag::selFlagLogo;
currentFlag = selFlagLogo;
printStr_P(MENU_BTN_CHANGE_NAME_X, MENU_BTN_CHANGE_NAME_Y, StrBtnChangeName);
printName(MENU_NAME_X, MENU_NAME_Y);
@ -675,7 +667,7 @@ void screenSaveID() {
printIDLarge(ID_SAVE_X, ID_SAVE_Y);
}
// DISPLAY: Prompt to reset the system EEPROM area
// DISPLAY: Propmt 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);
@ -685,7 +677,7 @@ void screenResetSys() {
printStr_P(RESET_SYS_BTN_NO_X, RESET_SYS_BTN_NO_Y, StrBtnResetNo);
}
// DISPLAY: Prompt to reset the user EEPROM area
// DISPLAY: Propmt 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);
@ -716,7 +708,7 @@ void saveFlags() {
// Reset the system EEPROM area and display the confirmation message
void resetSysEEPROM() {
for (unsigned int i = EEPROMstart; i < EEPROM_STORAGE_SPACE_START; i++) {
for (unsigned int i = EEPROM_START; i < EEPROM_STORAGE_SPACE_START; i++) {
EEPROM.update(i, 0xFF);
}
arduboy.clear();
@ -734,7 +726,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 <= EEPROMend; i++) {
for (unsigned int i = EEPROM_STORAGE_SPACE_START; i <= EEPROM_END; i++) {
EEPROM.update(i, 0xFF);
}
printStrLargeRev_P(RESET_USER_CONFIRMED_1_X, RESET_USER_CONFIRMED_1_Y, StrUser);
@ -753,7 +745,7 @@ void printNameScreenCommon() {
printNameDecimal(NAME_DECIMAL_X, NAME_DECIMAL_Y);
}
// Print the ID entry screen common information
// Print the name entry screen common information
void printIDScreenCommon() {
printStr_P(ID_TITLE_X, ID_TITLE_Y, StrID);
printIDDecimalBytes(ID_2_DECIMAL_X, ID_2_DECIMAL_Y);
@ -763,45 +755,41 @@ void printIDScreenCommon() {
// Print the name screen cursors
void printNameCursors() {
arduboy.fillRect(NAME_LARGE_X + (nameIndex * char2Width),
NAME_LARGE_Y + char2Height + 2,
char2Width - char2Spacing, 2);
arduboy.fillRect(NAME_LARGE_X + (nameIndex * CHAR_WIDTH * 2),
NAME_LARGE_Y + (CHAR_HEIGHT * 2) + 2,
(CHAR_WIDTH * 2) - 2, 2);
arduboy.drawFastHLine(NAME_HEX_X +
(nameIndex * (charWidth * 3 + smallSpace)),
NAME_HEX_Y + charHeight + 1,
charWidth * 3 - charSpacing);
(nameIndex * (CHAR_WIDTH * 3 + SMALL_SPACE)),
NAME_HEX_Y + CHAR_HEIGHT + 1, CHAR_WIDTH * 3 - 1);
arduboy.drawFastHLine(NAME_DECIMAL_X +
(nameIndex * (charWidth * 3 + smallSpace)),
NAME_DECIMAL_Y + charHeight + 1,
charWidth * 3 - charSpacing);
(nameIndex * (CHAR_WIDTH * 3 + SMALL_SPACE)),
NAME_DECIMAL_Y + CHAR_HEIGHT + 1, CHAR_WIDTH * 3 - 1);
}
// Print the ID screen cursors
void printIDCursors() {
arduboy.fillRect(ID_LARGE_X + ((idIndex + 1) * char2Width),
ID_LARGE_Y + char2Height,
char2Width - char2Spacing, 2);
arduboy.fillRect(ID_LARGE_X + ((idIndex + 1) * (CHAR_WIDTH * 2)),
ID_LARGE_Y + (CHAR_HEIGHT * 2),
(CHAR_WIDTH * 2) - 2, 2);
arduboy.drawFastHLine(ID_2_DECIMAL_X +
((idIndex / 2) * (charWidth * 3 + smallSpace)),
ID_2_DECIMAL_Y + charHeight + 1,
charWidth * 3 - charSpacing);
((idIndex / 2) * (CHAR_WIDTH * 3 + SMALL_SPACE)),
ID_2_DECIMAL_Y + CHAR_HEIGHT + 1, CHAR_WIDTH * 3 - 1);
arduboy.drawFastHLine(ID_DECIMAL_X, ID_DECIMAL_Y + charHeight + 1,
charWidth * 5 - 1);
arduboy.drawFastHLine(ID_DECIMAL_X, ID_DECIMAL_Y + CHAR_HEIGHT + 1,
CHAR_WIDTH * 5 - 1);
arduboy.drawFastHLine((ID_BINARY_X + charWidth + smallSpace) +
(idIndex * (charWidth * 4 + smallSpace)),
ID_BINARY_Y + charHeight + 1,
charWidth * 4 - charSpacing);
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);
}
// Print the values and cursor for the flags
void printFlagSettings() {
int cursorY;
uint8_t cursorLen = strlen_P(StrYes) * charWidth - charSpacing;
byte cursorLen = strlen_P(StrYes) * CHAR_WIDTH - 1 ;
if (showLogoFlag) {
printStr_P(FLAGS_SET_X, FLAGS_LOGO_Y, StrYes);
@ -825,22 +813,22 @@ void printFlagSettings() {
}
switch (currentFlag) {
case SelectedFlag::selFlagLEDs:
case selFlagLEDs:
cursorY = FLAGS_LEDS_Y;
if (!showLEDsFlag) {
cursorLen = strlen_P(StrNo) * charWidth - charSpacing;
cursorLen = strlen_P(StrNo) * CHAR_WIDTH - 1;
}
break;
case SelectedFlag::selFlagName:
case selFlagName:
cursorY = FLAGS_NAME_Y;
if (!showNameFlag) {
cursorLen = strlen_P(StrNo) * charWidth - charSpacing;
cursorLen = strlen_P(StrNo) * CHAR_WIDTH - 1;
}
break;
default: // selFlagLogo
cursorY = FLAGS_LOGO_Y;
if (!showLogoFlag) {
cursorLen = strlen_P(StrNo) * charWidth - charSpacing;
cursorLen = strlen_P(StrNo) * CHAR_WIDTH - 1;
}
break;
}
@ -848,7 +836,7 @@ void printFlagSettings() {
arduboy.setCursor(FLAGS_CURSOR_X, cursorY);
arduboy.print('\x10');
arduboy.drawFastHLine(FLAGS_SET_X, cursorY + charHeight, cursorLen);
arduboy.drawFastHLine(FLAGS_SET_X, cursorY + CHAR_HEIGHT, cursorLen);
}
// Print the unit name in normal size including an extent underline
@ -856,9 +844,9 @@ void printFlagSettings() {
void printName(int x, int y) {
printStr(x, y, unitName);
y += (charHeight + 1);
for (uint8_t i = 0; i < ARDUBOY_UNIT_NAME_LEN; i++, x += charWidth) {
arduboy.drawFastHLine(x, y, charWidth - charSpacing);
y += (CHAR_HEIGHT + 1);
for (byte i = 0; i < ARDUBOY_UNIT_NAME_LEN; i++, x += CHAR_WIDTH) {
arduboy.drawFastHLine(x, y, CHAR_WIDTH - 1);
}
}
@ -876,8 +864,8 @@ void printNameUnderline(int x, int y) {
if (unitName[0] != 0) {
x -= 1;
y += (char2Height + 6);
lWidth = (strlen(unitName) * char2Width);
y += ((CHAR_HEIGHT * 2) + 6);
lWidth = (strlen(unitName) * (CHAR_WIDTH * 2));
arduboy.drawPixel(x, y);
arduboy.drawPixel(x + lWidth - 1, y);
arduboy.drawFastHLine(x, y + 1, lWidth);
@ -886,17 +874,17 @@ void printNameUnderline(int x, int y) {
// Print the unit name in hex at the given location
void printNameHex(int x, int y) {
for (uint8_t i = 0; i < ARDUBOY_UNIT_NAME_LEN; i++) {
for (byte i = 0; i < ARDUBOY_UNIT_NAME_LEN; i++) {
printHex8(x, y, unitName[i]);
x += charWidth * 3 + smallSpace;
x += CHAR_WIDTH * 3 + SMALL_SPACE;
}
}
// Print the unit name in decimal at the given location
void printNameDecimal(int x, int y) {
for (uint8_t i = 0; i < ARDUBOY_UNIT_NAME_LEN; i++) {
for (byte i = 0; i < ARDUBOY_UNIT_NAME_LEN; i++) {
printDecimal8(x, y, unitName[i]);
x += charWidth * 3 + smallSpace;
x += CHAR_WIDTH * 3 + SMALL_SPACE;
}
}
@ -915,7 +903,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 + charWidth * 3 + smallSpace, y, unitID & 0x00FF);
printDecimal8(x + CHAR_WIDTH * 3 + SMALL_SPACE, y, unitID & 0x00FF);
}
// Print the unit ID in decimal at the given location
@ -928,17 +916,17 @@ void printIDDecimal(int x, int y) {
void printIDBinary(int x, int y) {
arduboy.setCursor(x, y);
arduboy.print('b');
x += charWidth + smallSpace;
x += CHAR_WIDTH + SMALL_SPACE;
for (char i = 3 * 4; i >= 0; i -= 4) {
printBinaryNybble(x, y, static_cast<uint8_t>(unitID >> i));
x += charWidth * 4 + smallSpace;
printBinaryNybble(x, y, (byte)(unitID >> i));
x += CHAR_WIDTH * 4 + SMALL_SPACE;
}
}
// 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) * charWidth + 3, charHeight + 3);
strlen_P(StrSaveQ) * CHAR_WIDTH + 3, CHAR_HEIGHT + 3);
arduboy.setTextColor(BLACK);
arduboy.setTextBackground(WHITE);
printStr_P(x, y, StrSaveQ);
@ -959,18 +947,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, uint8_t val) {
void printDecimal8(int x, int y, byte 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, uint16_t val) {
void printDecimal16(int x, int y, unsigned int 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, uint8_t width, uint16_t pwr10,
uint16_t val) {
void printDecimalHelper(int x, int y, byte width, unsigned int pwr10,
unsigned int val) {
arduboy.setCursor(x, y);
while (width > 0) {
if (val >= pwr10) {
@ -984,7 +972,7 @@ void printDecimalHelper(int x, int y, uint8_t width, uint16_t pwr10,
}
// Print an 8 bit hex number with leading x and zeros
void printHex8(int x, int y, uint8_t val) {
void printHex8(int x, int y, byte val) {
arduboy.setCursor(x, y);
arduboy.print('x');
if (val < 16) {
@ -994,7 +982,7 @@ void printHex8(int x, int y, uint8_t val) {
}
// Print a 16 bit hex number with leading x and zeros
void printHex16(int x, int y, uint16_t val) {
void printHex16(int x, int y, unsigned int val) {
arduboy.setCursor(x, y);
arduboy.print('x');
for (char i = 3 * 4; i >= 0; i -= 4) {
@ -1003,7 +991,7 @@ void printHex16(int x, int y, uint16_t val) {
}
// Print a nybble in binary from the lowest 4 bits of the provided byte
void printBinaryNybble(int x, int y, uint8_t val) {
void printBinaryNybble(int x, int y, byte val) {
arduboy.setCursor(x, y);
for (char i = 3; i >= 0; i--) {
@ -1014,7 +1002,7 @@ void printBinaryNybble(int x, int y, uint8_t 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) * char2Width + 6, char2Height + 6);
strlen_P(string) * CHAR_WIDTH * 2 + 6, CHAR_HEIGHT * 2 + 6);
arduboy.setTextColor(BLACK);
arduboy.setTextBackground(WHITE);
arduboy.setTextSize(2);
@ -1049,8 +1037,8 @@ void nameCharDec() {
}
// Return true if the given character is not allowed
bool invalidChar(char c) {
return (c == '\n') || (c == '\r') || (static_cast<uint8_t>(c) == 0xFF);
boolean invalidChar(char c) {
return (c == '\n') || (c == '\r') || ((byte)c == 0xFF);
}
// Move the name cursor right
@ -1112,14 +1100,14 @@ void idCursorLeft() {
// Move the Flags cursor down
void flagsCursorDown() {
switch (currentFlag) {
case SelectedFlag::selFlagLogo:
currentFlag = SelectedFlag::selFlagLEDs;
case selFlagLogo:
currentFlag = selFlagLEDs;
break;
case SelectedFlag::selFlagLEDs:
currentFlag = SelectedFlag::selFlagName;
case selFlagLEDs:
currentFlag = selFlagName;
break;
case SelectedFlag::selFlagName:
currentFlag = SelectedFlag::selFlagLogo;
case selFlagName:
currentFlag = selFlagLogo;
break;
}
drawScreen();
@ -1128,14 +1116,14 @@ void flagsCursorDown() {
// Move the Flags cursor up
void flagsCursorUp() {
switch (currentFlag) {
case SelectedFlag::selFlagName:
currentFlag = SelectedFlag::selFlagLEDs;
case selFlagName:
currentFlag = selFlagLEDs;
break;
case SelectedFlag::selFlagLEDs:
currentFlag = SelectedFlag::selFlagLogo;
case selFlagLEDs:
currentFlag = selFlagLogo;
break;
case SelectedFlag::selFlagLogo:
currentFlag = SelectedFlag::selFlagName;
case selFlagLogo:
currentFlag = selFlagName;
break;
}
drawScreen();
@ -1144,13 +1132,13 @@ void flagsCursorUp() {
// Toggle the currently selected flag
void flagToggle() {
switch (currentFlag) {
case SelectedFlag::selFlagLogo:
case selFlagLogo:
showLogoFlag = !showLogoFlag;
break;
case SelectedFlag::selFlagLEDs:
case selFlagLEDs:
showLEDsFlag = !showLEDsFlag;
break;
case SelectedFlag::selFlagName:
case selFlagName:
showNameFlag = !showNameFlag;
break;
}
@ -1159,7 +1147,7 @@ void flagToggle() {
// Start the button auto-repeat delay
void startButtonDelay() {
delayCount = delayFrames;
delayCount = DELAY_FRAMES;
repeating = false;
}
@ -1171,22 +1159,22 @@ void stopButtonRepeat() {
// Calculate the X coordinate to center a string of the given length
int centerStrLen(unsigned int len) {
return (WIDTH / 2) - (len * charWidth / 2);
return (WIDTH / 2) - (len * CHAR_WIDTH / 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) * charWidth / 2);
return (WIDTH / 2) - (strlen_P(str) * CHAR_WIDTH / 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) * char2Width / 2);
return (WIDTH / 2) - (strlen_P(str) * CHAR_WIDTH);
}
// Calculate the X coordinate to right justify a string in program memory
int rightStr_P(const char* str) {
return WIDTH - (strlen_P(str) * charWidth) + charSpacing;
return WIDTH - (strlen_P(str) * CHAR_WIDTH) + 1;
}

View File

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

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 238 B

After

Width:  |  Height:  |  Size: 1.6 KiB

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 343 B

After

Width:  |  Height:  |  Size: 434 B

View File

@ -77,13 +77,10 @@ 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 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.
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.
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 2020, September 2020
Modifications by Scott Allen - July 2016
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,18 +332,12 @@ 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 = (unsigned char *)malloc(rawlen); memset(bmp0, 0, rawlen);
bmp1 = (unsigned char *)malloc(rawlen); memset(bmp1, 0, rawlen);
bmp0 = malloc(rawlen); memset(bmp0, 0, rawlen);
bmp1 = malloc(rawlen); memset(bmp1, 0, rawlen);
printf("// %s width: %u height: %u\n", argv[1], w, h);

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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 B

After

Width:  |  Height:  |  Size: 280 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 committed just before tagging the new release.
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.
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 committed just before tagging the new release.
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.
See the [PlatformIO library.json](https://docs.platformio.org/en/latest/librarymanager/config.html) documentation for details.

View File

@ -26,7 +26,6 @@ blank KEYWORD2
boot KEYWORD2
bootLogo KEYWORD2
bootLogoCompressed KEYWORD2
bootLogoExtra KEYWORD2
bootLogoShell KEYWORD2
bootLogoSpritesBOverwrite KEYWORD2
bootLogoSpritesBSelfMasked KEYWORD2
@ -68,16 +67,11 @@ 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
@ -110,7 +104,6 @@ setFrameRate KEYWORD2
setRGBled KEYWORD2
setTextBackground KEYWORD2
setTextColor KEYWORD2
setTextRawMode KEYWORD2
setTextSize KEYWORD2
setTextWrap KEYWORD2
SPItransfer KEYWORD2
@ -138,21 +131,6 @@ 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": "6.0.0",
"version": "5.3.0",
"export":
{
"exclude": "extras"

View File

@ -1,5 +1,5 @@
name=Arduboy2
version=6.0.0
version=5.3.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,40 +12,20 @@
uint8_t Arduboy2Base::sBuffer[];
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;
Arduboy2Base::Arduboy2Base()
{
currentButtonState = 0;
previousButtonState = 0;
// frame management
setFrameDuration(16);
frameCount = 0;
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.
//
// This code and it's documentation should be kept in sync with
// Aruduboy2::begin()
// provides by default
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
@ -57,6 +37,17 @@ void Arduboy2Base::beginDoFirst()
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()
@ -168,12 +159,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
bool Arduboy2Base::bootLogoShell(void (&drawLogo)(int16_t))
void Arduboy2Base::bootLogoShell(void (*drawLogo)(int16_t))
{
bool showLEDs = readShowBootLogoLEDsFlag();
if (!readShowBootLogoFlag()) {
return false;
return;
}
if (showLEDs) {
@ -183,7 +174,7 @@ bool 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 false;
return;
}
if (showLEDs && y == 4) {
@ -206,12 +197,14 @@ bool Arduboy2Base::bootLogoShell(void (&drawLogo)(int16_t))
delayShort(400);
digitalWriteRGB(BLUE_LED, RGB_OFF);
return true;
bootLogoExtra();
}
// 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());
@ -294,10 +287,12 @@ 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;
@ -336,10 +331,12 @@ 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;
@ -581,10 +578,10 @@ void Arduboy2Base::drawFastHLine
w = xEnd - x;
// buffer pointer plus row offset + x offset
uint8_t *pBuf = sBuffer + ((y / 8) * WIDTH) + x;
register uint8_t *pBuf = sBuffer + ((y / 8) * WIDTH) + x;
// pixel mask
uint8_t mask = 1 << (y & 7);
register uint8_t mask = 1 << (y & 7);
switch (color)
{
@ -623,7 +620,7 @@ void Arduboy2Base::fillScreen(uint8_t color)
// {
// color = 0xFF; // all pixels on
// }
// for (int16_t i = 0; i < WIDTH * HEIGHT / 8; i++)
// for (int16_t i = 0; i < WIDTH * HEIGTH / 8; i++)
// {
// sBuffer[i] = color;
// }
@ -863,18 +860,17 @@ void Arduboy2Base::drawSlowXYBitmap
}
}
// Helper for drawCompressed()
class Arduboy2Base::BitStreamReader
struct Arduboy2Base::BitStreamReader
{
private:
const uint8_t *source;
uint16_t sourceIndex;
uint8_t bitBuffer;
uint8_t byteBuffer;
public:
BitStreamReader(const uint8_t *bitmap)
: source(bitmap), sourceIndex(), bitBuffer(), byteBuffer()
BitStreamReader(const uint8_t *source)
: source(source), sourceIndex(), bitBuffer(), byteBuffer()
{
}
@ -883,17 +879,17 @@ class Arduboy2Base::BitStreamReader
uint16_t result = 0;
for (uint16_t i = 0; i < bitCount; i++)
{
if (bitBuffer == 0)
if (this->bitBuffer == 0)
{
bitBuffer = 0x1;
byteBuffer = pgm_read_byte(&source[sourceIndex]);
++sourceIndex;
this->bitBuffer = 0x1;
this->byteBuffer = pgm_read_byte(&this->source[this->sourceIndex]);
++this->sourceIndex;
}
if ((byteBuffer & bitBuffer) != 0)
if ((this->byteBuffer & this->bitBuffer) != 0)
result |= (1 << i);
bitBuffer <<= 1;
this->bitBuffer <<= 1;
}
return result;
}
@ -902,7 +898,7 @@ class Arduboy2Base::BitStreamReader
void Arduboy2Base::drawCompressed(int16_t sx, int16_t sy, const uint8_t *bitmap, uint8_t color)
{
// set up decompress state
BitStreamReader cs(bitmap);
BitStreamReader cs = BitStreamReader(bitmap);
// read header
int width = (int)cs.readBits(8) + 1;
@ -1153,83 +1149,14 @@ void Arduboy2Base::swapInt16(int16_t& a, int16_t& b)
//========== class 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()
Arduboy2::Arduboy2()
{
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();
}
cursor_x = 0;
cursor_y = 0;
textColor = 1;
textBackground = 0;
textSize = 1;
textWrap = 0;
}
// bootLogoText() should be kept in sync with bootLogoShell()
@ -1246,7 +1173,7 @@ void Arduboy2::bootLogoText()
digitalWriteRGB(RED_LED, RGB_ON);
}
for (int16_t y = -15; y <= 24; y++) {
for (int16_t y = -16; y <= 24; y++) {
if (pressed(RIGHT_BUTTON)) {
digitalWriteRGB(RGB_OFF, RGB_OFF, RGB_OFF); // all LEDs off
return;
@ -1310,106 +1237,64 @@ void Arduboy2::bootLogoExtra()
size_t Arduboy2::write(uint8_t c)
{
if ((c == '\r') && !textRaw)
{
return 1;
}
if (((c == '\n') && !textRaw) ||
(textWrap && (cursor_x > (WIDTH - (characterWidth * textSize)))))
if (c == '\n')
{
cursor_y += textSize * 8;
cursor_x = 0;
cursor_y += fullCharacterHeight * textSize;
}
if ((c != '\n') || textRaw)
else if (c == '\r')
{
// skip em
}
else
{
drawChar(cursor_x, cursor_y, c, textColor, textBackground, textSize);
cursor_x += fullCharacterWidth * 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');
}
}
return 1;
}
void Arduboy2::drawChar
(int16_t x, int16_t y, uint8_t c, uint8_t color, uint8_t bg, uint8_t size)
(int16_t x, int16_t y, unsigned char c, uint8_t color, uint8_t bg, uint8_t size)
{
// 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
uint8_t line;
bool draw_background = bg != color;
const uint8_t* bitmap = font5x7 + c * 5;
if ((x >= WIDTH) || // Clip right
(y >= HEIGHT) || // Clip bottom
((x + characterWidth * size - 1) < 0) || // Clip left
((y + characterHeight * size - 1) < 0) // Clip top
((x + 5 * size - 1) < 0) || // Clip left
((y + 8 * size - 1) < 0) // Clip top
)
{
return;
}
#endif
bool drawBackground = bg != color;
const uint8_t* bitmap =
&font5x7[c * characterWidth * ((characterHeight + 8 - 1) / 8)];
for (uint8_t i = 0; i < fullCharacterWidth; i++)
for (uint8_t i = 0; i < 6; i++ )
{
uint8_t column;
if (characterHeight <= 8)
{
column = (i < characterWidth) ? pgm_read_byte(bitmap++) : 0;
}
else
{
column = 0;
line = pgm_read_byte(bitmap++);
if (i == 5) {
line = 0x0;
}
// 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++)
for (uint8_t j = 0; j < 8; j++)
{
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++);
}
}
uint8_t draw_color = (line & 0x1) ? color : bg;
// 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);
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);
}
}
}
line >>= 1;
}
}
}
@ -1481,16 +1366,6 @@ 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,8 +80,11 @@ class Arduboy2Audio
*
* \details
* The speaker is initialized based on the current mute setting saved in
* system EEPROM.
*/
* 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()`.
*/
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,6 +13,8 @@
//========== 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,6 +337,7 @@ class Arduboy2Core : public Arduboy2NoUSB
friend class Arduboy2Ex;
public:
Arduboy2Core();
/** \brief
* Idle the CPU to save power.
@ -572,7 +573,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 non-inverted.
* display to no-inverted.
*
* \details
* Calling this function with a value of `true` will set the display to
@ -796,21 +797,14 @@ 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 as space permits.
* 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.
*
* 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()
* \see Arduboy2Base::begin()
*/
static void boot();
@ -824,8 +818,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 don't
* call `flashlight()`.
* This function should be called after `boot()` in sketches that
* potentially could cause the problem.
*
* 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 px (176 bytes)
// 88x16
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 px (151 bytes)
// 88x16
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 px (178 bytes)
// 88x16
const PROGMEM uint8_t Arduboy2Base::arduboy_logo_sprite[] = {
88, 16,
0xF0, 0xF8, 0x9C, 0x8E, 0x87, 0x83, 0x87, 0x8E, 0x9C, 0xF8,