Bladeren bron

Added birds

master
The Dod 4 maanden geleden
bovenliggende
commit
752752cd31
4 gewijzigde bestanden met toevoegingen van 55 en 25 verwijderingen
  1. 0
    0
      graphics/birds/mybird.png
  2. 0
    0
      graphics/birds/yourbird.png
  3. 1
    2
      talismetta/README.md
  4. 54
    23
      talismetta/talismetta.ino

graphics/birds/bird1.png → graphics/birds/mybird.png Bestand weergeven


graphics/birds/bird2.png → graphics/birds/yourbird.png Bestand weergeven


+ 1
- 2
talismetta/README.md Bestand weergeven

@@ -6,8 +6,7 @@ In order to figure out the address, upload the code to the talismetta, then you
6 6
 
7 7
 ```
8 8
 === Talis-Metta ===
9
-My MAC:
10
-0B:0A:0D:0A:05:05
9
+My MAC: BB:AA:DD:AA:55:55
11 10
 ```
12 11
 
13 12
 Copy this to the `SALAM` or `SHALOM` definition at `config.h`

+ 54
- 23
talismetta/talismetta.ino Bestand weergeven

@@ -11,6 +11,8 @@
11 11
 #include "metta.h"
12 12
 #include "loving.h"
13 13
 #include "kindness.h"
14
+#include "mybird.h"
15
+#include "yourbird.h"
14 16
 
15 17
 #define DEBUG true
16 18
 
@@ -29,6 +31,17 @@
29 31
 #define OUTRO_FREEZE_MILLIS 1000
30 32
 unsigned long outro_start;
31 33
 
34
+#define MYBIRD_WIDTH 30
35
+#define MYBIRD_HEIGHT 36
36
+#define MYBIRD_X 20
37
+#define MYBIRD_Y 10
38
+
39
+#define YOURBIRD_WIDTH 32
40
+#define YOURBIRD_HEIGHT 33
41
+#define YOURBIRD_X 53
42
+#define YOURBIRD_Y 5
43
+
44
+
32 45
 
33 46
 #define SEND_INTERVAL 3000
34 47
 unsigned long next_send = 0;
@@ -37,11 +50,11 @@ unsigned long next_send = 0;
37 50
 String my_mac;
38 51
 bool is_salam;
39 52
 bool metta_from_you;
40
-unsigned long metta_from_me_start = 0;
53
+unsigned long metta_from_me_since = 0;
41 54
 
42 55
 
43 56
 #define MANTRA_I "May I be filled with loving kindness"
44
-#define MANTRA_WE "May we be filled with loving kindness"
57
+#define MANTRA_YOU "May you be filled with loving kindness"
45 58
 
46 59
 
47 60
 uint8_t peer_mac_addr[6];
@@ -91,6 +104,8 @@ TFT_eSPI tft = TFT_eSPI();
91 104
 TFT_eSprite background = TFT_eSprite(&tft);
92 105
 TFT_eSprite leftSprite = TFT_eSprite(&tft);
93 106
 TFT_eSprite rightSprite = TFT_eSprite(&tft);
107
+TFT_eSprite mybirdSprite = TFT_eSprite(&tft);
108
+TFT_eSprite yourbirdSprite = TFT_eSprite(&tft);
94 109
 
95 110
 
96 111
 // lifted from MacAddress.c
@@ -116,24 +131,24 @@ void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
116 131
     metta_from_you = false;
117 132
   }
118 133
   if (DEBUG) {
119
-    Serial.println(nearby ? "Nearby" : "Not nearby");
134
+    Serial.println(nearby ? "||" : "|");
120 135
   }
121 136
 }
122 137
 
123 138
 void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
124
-  metta_from_you = (data_len == strlen(MANTRA_WE)) && !strncmp((const char *)data, MANTRA_WE, data_len);
139
+  metta_from_you = (data_len == strlen(MANTRA_YOU)) && !strncmp((const char *)data, MANTRA_YOU, data_len);
125 140
   if (DEBUG) {
126 141
     // char macStr[18];
127 142
     // snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
128 143
     //          mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
129 144
     // Serial.print("Packet Recv from: "); Serial.println(macStr);
130
-    //String msg = "";
131
-    //for (int i = 0 ; i < data_len; i++) {
132
-    //  msg.concat(char(data[i]));
133
-    //}
134
-    //Serial.print("Packet Recv message: "); Serial.println(msg);
135
-    Serial.print("Packet Recv message length: "); Serial.println(data_len);
136
-    Serial.print("Metta from other: "); Serial.println(metta_from_you);
145
+    char msg[64];
146
+    int msglen = min(data_len, 63);
147
+    strncpy(msg, (const char *)data, msglen);
148
+    msg[msglen] = '\0';
149
+    Serial.print("<<< "); Serial.println(msg);
150
+    Serial.print(metta_from_me_since ? "_/" : "__");
151
+    Serial.println(metta_from_you ? "\\_" : "__");
137 152
   }
138 153
 }
139 154
 
@@ -147,7 +162,7 @@ void setup() {
147 162
 
148 163
   // determine peer mac address
149 164
   my_mac = WiFi.macAddress();
150
-  Serial.println("My MAC:");
165
+  Serial.print("My MAC: ");
151 166
   Serial.println(my_mac);
152 167
   if (my_mac.equals(SHALOM)) {
153 168
     if (DEBUG) {
@@ -163,7 +178,7 @@ void setup() {
163 178
     str2mac(SHALOM, peer_mac_addr);
164 179
   }
165 180
   outro_start = 0;
166
-  metta_from_me_start = 0;
181
+  metta_from_me_since = 0;
167 182
   metta_from_you = false;
168 183
 
169 184
   WiFi.mode(WIFI_STA);
@@ -185,11 +200,17 @@ void setup() {
185 200
 
186 201
   leftSprite.createSprite(120, 135);
187 202
   leftSprite.setSwapBytes(true);
188
-  leftSprite.pushImage(0, 0, 120, 135, talis);
189 203
 
190 204
   rightSprite.createSprite(120, 135);
191 205
   rightSprite.setSwapBytes(true);
192
-  rightSprite.pushImage(0, 0, 120, 135, metta);
206
+
207
+  mybirdSprite.createSprite(MYBIRD_WIDTH, MYBIRD_HEIGHT);
208
+  mybirdSprite.setSwapBytes(true);
209
+  mybirdSprite.pushImage(0, 0, MYBIRD_WIDTH, MYBIRD_HEIGHT, mybird);
210
+
211
+  yourbirdSprite.createSprite(YOURBIRD_WIDTH, YOURBIRD_HEIGHT);
212
+  yourbirdSprite.setSwapBytes(true);
213
+  yourbirdSprite.pushImage(0, 0, YOURBIRD_WIDTH, YOURBIRD_HEIGHT, yourbird);
193 214
 }
194 215
 
195 216
 void do_scroll(const unsigned short *left_image, const unsigned short *right_image, unsigned long start_time, unsigned long freeze_duration, unsigned long scroll_duration, bool is_reverse) {
@@ -219,17 +240,17 @@ void loop() {
219 240
     outro_start = nowmillis;
220 241
   }
221 242
   if (digitalRead(BUTTON2PIN) == LOW) {
222
-    metta_from_me_start = nowmillis;
243
+    metta_from_me_since = nowmillis;
223 244
   }
224 245
   if (nowmillis > next_send) {
225 246
     if (DEBUG) {
226
-      Serial.print("Sending: ");
227
-      Serial.println(metta_from_me_start ? MANTRA_WE : MANTRA_I);
247
+      Serial.print(">>> ");
248
+      Serial.println(metta_from_me_since ? MANTRA_YOU : MANTRA_I);
228 249
     }
229 250
     esp_now_send(
230 251
       peerInfo.peer_addr,
231
-      metta_from_me_start ? (const uint8_t *)MANTRA_WE : (const uint8_t *)MANTRA_I,
232
-      metta_from_me_start ? strlen(MANTRA_WE) : strlen(MANTRA_I));
252
+      metta_from_me_since ? (const uint8_t *)MANTRA_YOU : (const uint8_t *)MANTRA_I,
253
+      metta_from_me_since ? strlen(MANTRA_YOU) : strlen(MANTRA_I));
233 254
     next_send = nowmillis + SEND_INTERVAL;
234 255
   }
235 256
   if (nowmillis > PING_START_MILLIS) {
@@ -245,7 +266,17 @@ void loop() {
245 266
   // FRAME_ME or animation frame
246 267
   background.pushImage(
247 268
     0, 0, 240, 135,
248
-    frame2image((metta_from_me_start && metta_from_you) ? frames[current_frame] : FRAME_ME, is_salam));
269
+    frame2image((metta_from_me_since && metta_from_you) ? frames[current_frame] : FRAME_ME, is_salam));
270
+
271
+  // mybird
272
+  if (metta_from_me_since) {
273
+    mybirdSprite.pushToSprite(&background, MYBIRD_X, MYBIRD_Y, TFT_BLACK);
274
+  }
275
+
276
+  if (nearby && frames[current_frame] == FRAME_U) {
277
+    yourbirdSprite.pushToSprite(&background, YOURBIRD_X, YOURBIRD_Y, TFT_BLACK);
278
+  }
279
+
249 280
 
250 281
   // Scroll overlays
251 282
   if (outro_start) { // Outro scroll overlay
@@ -257,8 +288,8 @@ void loop() {
257 288
     }
258 289
   } else if (nowmillis < INTRO_FREEZE_MILLIS + INTRO_SCROLL_MILLIS) { // Intro scroll overlay
259 290
     do_scroll(talis, metta, 0, INTRO_FREEZE_MILLIS, INTRO_SCROLL_MILLIS, false);
260
-  } else if (metta_from_me_start && nowmillis < metta_from_me_start + METTA_FREEZE_MILLIS + METTA_SCROLL_MILLIS) {
261
-    do_scroll(loving, kindness, metta_from_me_start, METTA_FREEZE_MILLIS, METTA_SCROLL_MILLIS, false);
291
+  } else if (metta_from_me_since && nowmillis < metta_from_me_since + METTA_FREEZE_MILLIS + METTA_SCROLL_MILLIS) {
292
+    do_scroll(loving, kindness, metta_from_me_since, METTA_FREEZE_MILLIS, METTA_SCROLL_MILLIS, false);
262 293
   }
263 294
   background.pushSprite(0, 0);
264 295
 

Laden…
Annuleren
Opslaan