Initial project import with ESP32 animated eyes
Add initial project files for ESP32 animated eyes, including main application sources, assets, CMake configuration, and supporting ESP-IDF components for LCD and touch functionality. Includes documentation, test apps, and configuration files.
This commit is contained in:
93
esp32-eyes-main/Face.cpp
Normal file
93
esp32-eyes-main/Face.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/***************************************************
|
||||
Copyright (c) 2020 Luis Llamas
|
||||
(www.luisllamas.es)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses
|
||||
****************************************************/
|
||||
|
||||
|
||||
#include "Face.h"
|
||||
#include "Common.h"
|
||||
|
||||
U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /* clock=*/ 4, /* data= */ 5);
|
||||
|
||||
Face::Face(uint16_t screenWidth, uint16_t screenHeight, uint16_t eyeSize)
|
||||
: LeftEye(*this), RightEye(*this), Blink(*this), Look(*this), Behavior(*this), Expression(*this) {
|
||||
|
||||
// Unlike almost every other Arduino library (and the I2C address scanner script etc.)
|
||||
// u8g2 uses 8-bit I2C address, so we shift the 7-bit address left by one
|
||||
u8g2.setI2CAddress(0x3C<<1);
|
||||
u8g2.begin();
|
||||
u8g2.clearBuffer();
|
||||
|
||||
Width = screenWidth;
|
||||
Height = screenHeight;
|
||||
EyeSize = eyeSize;
|
||||
|
||||
CenterX = Width / 2;
|
||||
CenterY = Height / 2;
|
||||
|
||||
LeftEye.IsMirrored = true;
|
||||
|
||||
Behavior.Clear();
|
||||
Behavior.Timer.Start();
|
||||
}
|
||||
|
||||
void Face::LookFront() {
|
||||
Look.LookAt(0.0, 0.0);
|
||||
}
|
||||
|
||||
void Face::LookRight() {
|
||||
Look.LookAt(-1.0, 0.0);
|
||||
}
|
||||
|
||||
void Face::LookLeft() {
|
||||
Look.LookAt(1.0, 0.0);
|
||||
}
|
||||
|
||||
void Face::LookTop() {
|
||||
Look.LookAt(0.0, 1.0);
|
||||
}
|
||||
|
||||
void Face::LookBottom() {
|
||||
Look.LookAt(0.0, -1.0);
|
||||
}
|
||||
|
||||
void Face::Wait(unsigned long milliseconds) {
|
||||
unsigned long start;
|
||||
start = millis();
|
||||
while (millis() - start < milliseconds) {
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
void Face::DoBlink() {
|
||||
Blink.Blink();
|
||||
}
|
||||
|
||||
void Face::Update() {
|
||||
if(RandomBehavior) Behavior.Update();
|
||||
if(RandomLook) Look.Update();
|
||||
if(RandomBlink) Blink.Update();
|
||||
Draw();
|
||||
}
|
||||
|
||||
void Face::Draw() {
|
||||
// Clear the display
|
||||
u8g2.clearBuffer();
|
||||
// Draw left eye
|
||||
LeftEye.CenterX = CenterX - EyeSize / 2 - EyeInterDistance;
|
||||
LeftEye.CenterY = CenterY;
|
||||
LeftEye.Draw();
|
||||
// Draw right eye
|
||||
RightEye.CenterX = CenterX + EyeSize / 2 + EyeInterDistance;
|
||||
RightEye.CenterY = CenterY;
|
||||
RightEye.Draw();
|
||||
// Transfer the redrawn buffer to the display
|
||||
u8g2.sendBuffer();
|
||||
}
|
||||
Reference in New Issue
Block a user