Skip to content

Commit

Permalink
Merge pull request #2 from 3110/develop
Browse files Browse the repository at this point in the history
v0.0.3
  • Loading branch information
3110 authored Mar 20, 2022
2 parents afc72a0 + 1499ccc commit 9aa83ee
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ATOM Babies は M5Stack 社の<a href="https://shop.m5stack.com/collections/atom

### Arduino IDE

[https://github.com/3110/atom-babies-arduino/archive/refs/tags/v0.0.2.zip](https://github.com/3110/atom-babies-arduino/archive/refs/tags/v0.0.2.zip) をダウンロードし,メニューの「スケッチ」-「ライブラリをインクルード」-「.ZIP 形式のライブラリをインストール...」を選択して ZIP ファイルを読み込みます。読み込み後,念のために Arduino IDE を再起動してください。
[https://github.com/3110/atom-babies-arduino/archive/refs/tags/v0.0.3.zip](https://github.com/3110/atom-babies-arduino/archive/refs/tags/v0.0.3.zip) をダウンロードし,メニューの「スケッチ」-「ライブラリをインクルード」-「.ZIP 形式のライブラリをインストール...」を選択して ZIP ファイルを読み込みます。読み込み後,念のために Arduino IDE を再起動してください。

サンプルはメニューの「ファイル」-「スケッチ例」にある「カスタムライブラリのスケッチ例」から「ATOM Babies」を選択し,「AllFaces」「Blink」「Bow」「Greeting」のいずれかを選びます。

Expand Down
72 changes: 42 additions & 30 deletions src/AtomBabies.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,32 @@ void AtomBabies::setBlinkParam(const BlinkParam& param) {
this->_blinkParam = param;
}

void AtomBabies::setOrientation(FaceOrientation orientation) {
clearFace();
this->_orientation = orientation;
setFace(this->_position);
}

void AtomBabies::setFace(FacePosition position) {
clearFace();
this->_position = position;
setEyes(this->_eyeColor);
setCheeks(this->_cheekColor);
}

void AtomBabies::clearFace(bool partial) {
if (partial) {
setEyes(this->_backgroundColor);
setCheeks(this->_backgroundColor);
} else {
fillFace(this->_backgroundColor);
}
}

void AtomBabies::fillFace(const CRGB& color) {
M5.dis.fillpix(color);
}

void AtomBabies::bow(bool deep) {
setFace(FaceNormal);
delay(this->_bowParam.before);
Expand All @@ -150,6 +176,18 @@ void AtomBabies::setBowParam(const BowParam& param) {
this->_bowParam = param;
}

void AtomBabies::setEyesColor(const CRGB& color) {
this->_eyeColor = color;
}

void AtomBabies::setCheeksColor(const CRGB& color) {
this->_cheekColor = color;
}

void AtomBabies::setBackgroundColor(const CRGB& color) {
this->_backgroundColor = color;
}

void AtomBabies::_doBlink(void) {
for (int i = 0, n = random(1, this->_blinkParam.loop + 1); i < n; ++i) {
if (!isBlinking()) {
Expand All @@ -165,30 +203,12 @@ void AtomBabies::_doBlink(void) {
}
}

void AtomBabies::setOrientation(FaceOrientation orientation) {
clearFace();
this->_orientation = orientation;
setFace(this->_position);
}

void AtomBabies::setFace(FacePosition position) {
clearFace();
this->_position = position;
setEyes(this->_eyeColor);
setCheeks(this->_cheekColor);
}

void AtomBabies::clearFace(bool partial) {
if (partial) {
setEyes(this->_backgroundColor);
setCheeks(this->_backgroundColor);
} else {
fillFace(this->_backgroundColor);
}
void AtomBabies::setEyes(const CRGB& color) {
setLEDs(color, EYE_POSITIONS[this->_position]);
}

void AtomBabies::fillFace(const CRGB& color) {
M5.dis.fillpix(color);
void AtomBabies::setCheeks(const CRGB& color) {
setLEDs(color, CHEEK_POSITIONS[this->_position]);
}

void AtomBabies::setLED(const CRGB& color, uint8_t position) {
Expand All @@ -206,14 +226,6 @@ void AtomBabies::setLEDs(const CRGB& color,
}
}

void AtomBabies::setEyes(const CRGB& color) {
setLEDs(color, EYE_POSITIONS[this->_position]);
}

void AtomBabies::setCheeks(const CRGB& color) {
setLEDs(color, CHEEK_POSITIONS[this->_position]);
}

uint8_t AtomBabies::getLEDPosition(uint8_t position) {
if (position == 0) {
return 0;
Expand Down
9 changes: 7 additions & 2 deletions src/AtomBabies.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,19 @@ class AtomBabies {
virtual void bow(bool deep = false);
virtual void setBowParam(const BowParam& param);

virtual void setEyesColor(const CRGB& color);
virtual void setCheeksColor(const CRGB& color);
virtual void setBackgroundColor(const CRGB& color);

virtual void _doBlink(void); // called from thread

protected:
virtual void setEyes(const CRGB& color);
virtual void setCheeks(const CRGB& color);

virtual void setLED(const CRGB& color, uint8_t position);
virtual void setLEDs(const CRGB& color,
const uint8_t (&position)[N_POSITIONS]);
virtual void setEyes(const CRGB& color);
virtual void setCheeks(const CRGB& color);
virtual uint8_t getLEDPosition(uint8_t position);

private:
Expand Down
2 changes: 1 addition & 1 deletion src/AtomBabiesVersion.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#define VER_STR(x, y, z) (STR(x) "." STR(y) "." STR(z))
#define ATOM_BABIES_VERSION_MAJOR 0
#define ATOM_BABIES_VERSION_MINOR 0
#define ATOM_BABIES_VERSION_REVISION 2
#define ATOM_BABIES_VERSION_REVISION 3
#define ATOM_BABIES_VERSION \
VER_STR(ATOM_BABIES_VERSION_MAJOR, ATOM_BABIES_VERSION_MINOR, \
ATOM_BABIES_VERSION_REVISION)

0 comments on commit 9aa83ee

Please sign in to comment.