|
1 | | -#include <M5Unified.h> |
2 | 1 | #include <Avatar.h> |
3 | | -#include <faces/DogFace.h> |
| 2 | +#include <M5Unified.h> |
| 3 | + |
| 4 | +#include <faces/FaceTemplates.hpp> |
4 | 5 |
|
5 | 6 | using namespace m5avatar; |
6 | 7 |
|
7 | 8 | Avatar avatar; |
8 | 9 |
|
9 | | -Face* faces[2]; |
10 | | -const int facesSize = sizeof(faces) / sizeof(Face*); |
11 | | -int faceIdx = 0; |
| 10 | +Face* faces[5]; |
| 11 | +const int num_faces = sizeof(faces) / sizeof(Face*); |
| 12 | +int face_idx = 0; // face index |
12 | 13 |
|
13 | | -const Expression expressions[] = { |
14 | | - Expression::Angry, |
15 | | - Expression::Sleepy, |
16 | | - Expression::Happy, |
17 | | - Expression::Sad, |
18 | | - Expression::Doubt, |
19 | | - Expression::Neutral |
20 | | -}; |
21 | | -const int expressionsSize = sizeof(expressions) / sizeof(Expression); |
| 14 | +const Expression expressions[] = {Expression::Angry, Expression::Sleepy, |
| 15 | + Expression::Happy, Expression::Sad, |
| 16 | + Expression::Doubt, Expression::Neutral}; |
| 17 | +const int num_expressions = sizeof(expressions) / sizeof(Expression); |
22 | 18 | int idx = 0; |
23 | 19 |
|
24 | | -ColorPalette* cps[4]; |
25 | | -const int cpsSize = sizeof(cps) / sizeof(ColorPalette*); |
26 | | -int cpsIdx = 0; |
| 20 | +ColorPalette* color_palettes[5]; |
| 21 | +const int num_palettes = sizeof(color_palettes) / sizeof(ColorPalette*); |
| 22 | +int palette_idx = 0; |
27 | 23 |
|
28 | 24 | bool isShowingQR = false; |
29 | 25 |
|
30 | | -void setup() |
31 | | -{ |
32 | | - M5.begin(); |
33 | | - M5.Lcd.setBrightness(30); |
34 | | - M5.Lcd.clear(); |
| 26 | +void setup() { |
| 27 | + M5.begin(); |
| 28 | + M5.Lcd.setBrightness(30); |
| 29 | + M5.Lcd.clear(); |
35 | 30 |
|
36 | | - faces[0] = avatar.getFace(); |
37 | | - faces[1] = new DogFace(); |
| 31 | + faces[0] = avatar.getFace(); // native face |
| 32 | + faces[1] = new DoggyFace(); |
| 33 | + faces[2] = new OmegaFace(); |
| 34 | + faces[3] = new GirlyFace(); |
| 35 | + faces[4] = new PinkDemonFace(); |
38 | 36 |
|
39 | | - cps[0] = new ColorPalette(); |
40 | | - cps[1] = new ColorPalette(); |
41 | | - cps[2] = new ColorPalette(); |
42 | | - cps[3] = new ColorPalette(); |
43 | | - cps[1]->set(COLOR_PRIMARY, TFT_YELLOW); |
44 | | - cps[1]->set(COLOR_BACKGROUND, TFT_DARKCYAN); |
45 | | - cps[2]->set(COLOR_PRIMARY, TFT_DARKGREY); |
46 | | - cps[2]->set(COLOR_BACKGROUND, TFT_WHITE); |
47 | | - cps[3]->set(COLOR_PRIMARY, TFT_RED); |
48 | | - cps[3]->set(COLOR_BACKGROUND, TFT_PINK); |
| 37 | + color_palettes[0] = new ColorPalette(); |
| 38 | + color_palettes[1] = new ColorPalette(); |
| 39 | + color_palettes[2] = new ColorPalette(); |
| 40 | + color_palettes[3] = new ColorPalette(); |
| 41 | + color_palettes[4] = new ColorPalette(); |
| 42 | + color_palettes[1]->set(COLOR_PRIMARY, |
| 43 | + M5.Lcd.color24to16(0x383838)); // eye |
| 44 | + color_palettes[1]->set(COLOR_BACKGROUND, |
| 45 | + M5.Lcd.color24to16(0xfac2a8)); // skin |
| 46 | + color_palettes[1]->set(COLOR_SECONDARY, |
| 47 | + TFT_PINK); // cheek |
| 48 | + color_palettes[2]->set(COLOR_PRIMARY, TFT_YELLOW); |
| 49 | + color_palettes[2]->set(COLOR_BACKGROUND, TFT_DARKCYAN); |
| 50 | + color_palettes[3]->set(COLOR_PRIMARY, TFT_DARKGREY); |
| 51 | + color_palettes[3]->set(COLOR_BACKGROUND, TFT_WHITE); |
| 52 | + color_palettes[4]->set(COLOR_PRIMARY, TFT_RED); |
| 53 | + color_palettes[4]->set(COLOR_BACKGROUND, TFT_PINK); |
49 | 54 |
|
50 | | - avatar.init(); |
51 | | - avatar.setColorPalette(*cps[0]); |
| 55 | + avatar.init(8); // start drawing w/ 8bit color mode |
| 56 | + avatar.setColorPalette(*color_palettes[0]); |
52 | 57 | } |
53 | 58 |
|
54 | | -void loop() |
55 | | -{ |
56 | | - M5.update(); |
57 | | - if (M5.BtnA.wasPressed()) |
58 | | - { |
59 | | - avatar.setFace(faces[faceIdx]); |
60 | | - faceIdx = (faceIdx + 1) % facesSize; |
61 | | - } |
62 | | - if (M5.BtnB.wasPressed()) |
63 | | - { |
64 | | - avatar.setColorPalette(*cps[cpsIdx]); |
65 | | - cpsIdx = (cpsIdx + 1) % cpsSize; |
66 | | - } |
67 | | - if (M5.BtnC.wasPressed()) |
68 | | - { |
69 | | - avatar.setExpression(expressions[idx]); |
70 | | - idx = (idx + 1) % expressionsSize; |
71 | | - } |
| 59 | +void loop() { |
| 60 | + M5.update(); |
| 61 | + // M5Stack Core's button layout: |
| 62 | + // ----------- |
| 63 | + // | | |
| 64 | + // | | |
| 65 | + // ----------- |
| 66 | + // [A] [B] [C] |
| 67 | + if (M5.BtnA.wasPressed()) { |
| 68 | + avatar.setFace(faces[face_idx]); |
| 69 | + face_idx = (face_idx + 1) % num_faces; // loop index |
| 70 | + } |
| 71 | + if (M5.BtnB.wasPressed()) { |
| 72 | + avatar.setColorPalette(*color_palettes[palette_idx]); |
| 73 | + palette_idx = (palette_idx + 1) % num_palettes; |
| 74 | + } |
| 75 | + if (M5.BtnC.wasPressed()) { |
| 76 | + avatar.setExpression(expressions[idx]); |
| 77 | + idx = (idx + 1) % num_expressions; |
| 78 | + } |
72 | 79 | } |
0 commit comments