Browse Source

Added birds

master
The Dod 4 months ago
parent
commit
752752cd31
4 changed files with 55 additions and 25 deletions
  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 View File


graphics/birds/bird2.png → graphics/birds/yourbird.png View File


+ 1
- 2
talismetta/README.md View File

6
 
6
 
7
 ```
7
 ```
8
 === Talis-Metta ===
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
 Copy this to the `SALAM` or `SHALOM` definition at `config.h`
12
 Copy this to the `SALAM` or `SHALOM` definition at `config.h`

+ 54
- 23
talismetta/talismetta.ino View File

11
 #include "metta.h"
11
 #include "metta.h"
12
 #include "loving.h"
12
 #include "loving.h"
13
 #include "kindness.h"
13
 #include "kindness.h"
14
+#include "mybird.h"
15
+#include "yourbird.h"
14
 
16
 
15
 #define DEBUG true
17
 #define DEBUG true
16
 
18
 
29
 #define OUTRO_FREEZE_MILLIS 1000
31
 #define OUTRO_FREEZE_MILLIS 1000
30
 unsigned long outro_start;
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
 #define SEND_INTERVAL 3000
46
 #define SEND_INTERVAL 3000
34
 unsigned long next_send = 0;
47
 unsigned long next_send = 0;
37
 String my_mac;
50
 String my_mac;
38
 bool is_salam;
51
 bool is_salam;
39
 bool metta_from_you;
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
 #define MANTRA_I "May I be filled with loving kindness"
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
 uint8_t peer_mac_addr[6];
60
 uint8_t peer_mac_addr[6];
91
 TFT_eSprite background = TFT_eSprite(&tft);
104
 TFT_eSprite background = TFT_eSprite(&tft);
92
 TFT_eSprite leftSprite = TFT_eSprite(&tft);
105
 TFT_eSprite leftSprite = TFT_eSprite(&tft);
93
 TFT_eSprite rightSprite = TFT_eSprite(&tft);
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
 // lifted from MacAddress.c
111
 // lifted from MacAddress.c
116
     metta_from_you = false;
131
     metta_from_you = false;
117
   }
132
   }
118
   if (DEBUG) {
133
   if (DEBUG) {
119
-    Serial.println(nearby ? "Nearby" : "Not nearby");
134
+    Serial.println(nearby ? "||" : "|");
120
   }
135
   }
121
 }
136
 }
122
 
137
 
123
 void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int data_len) {
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
   if (DEBUG) {
140
   if (DEBUG) {
126
     // char macStr[18];
141
     // char macStr[18];
127
     // snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
142
     // snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
128
     //          mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
143
     //          mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
129
     // Serial.print("Packet Recv from: "); Serial.println(macStr);
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
 
162
 
148
   // determine peer mac address
163
   // determine peer mac address
149
   my_mac = WiFi.macAddress();
164
   my_mac = WiFi.macAddress();
150
-  Serial.println("My MAC:");
165
+  Serial.print("My MAC: ");
151
   Serial.println(my_mac);
166
   Serial.println(my_mac);
152
   if (my_mac.equals(SHALOM)) {
167
   if (my_mac.equals(SHALOM)) {
153
     if (DEBUG) {
168
     if (DEBUG) {
163
     str2mac(SHALOM, peer_mac_addr);
178
     str2mac(SHALOM, peer_mac_addr);
164
   }
179
   }
165
   outro_start = 0;
180
   outro_start = 0;
166
-  metta_from_me_start = 0;
181
+  metta_from_me_since = 0;
167
   metta_from_you = false;
182
   metta_from_you = false;
168
 
183
 
169
   WiFi.mode(WIFI_STA);
184
   WiFi.mode(WIFI_STA);
185
 
200
 
186
   leftSprite.createSprite(120, 135);
201
   leftSprite.createSprite(120, 135);
187
   leftSprite.setSwapBytes(true);
202
   leftSprite.setSwapBytes(true);
188
-  leftSprite.pushImage(0, 0, 120, 135, talis);
189
 
203
 
190
   rightSprite.createSprite(120, 135);
204
   rightSprite.createSprite(120, 135);
191
   rightSprite.setSwapBytes(true);
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
 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) {
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
     outro_start = nowmillis;
240
     outro_start = nowmillis;
220
   }
241
   }
221
   if (digitalRead(BUTTON2PIN) == LOW) {
242
   if (digitalRead(BUTTON2PIN) == LOW) {
222
-    metta_from_me_start = nowmillis;
243
+    metta_from_me_since = nowmillis;
223
   }
244
   }
224
   if (nowmillis > next_send) {
245
   if (nowmillis > next_send) {
225
     if (DEBUG) {
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
     esp_now_send(
250
     esp_now_send(
230
       peerInfo.peer_addr,
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
     next_send = nowmillis + SEND_INTERVAL;
254
     next_send = nowmillis + SEND_INTERVAL;
234
   }
255
   }
235
   if (nowmillis > PING_START_MILLIS) {
256
   if (nowmillis > PING_START_MILLIS) {
245
   // FRAME_ME or animation frame
266
   // FRAME_ME or animation frame
246
   background.pushImage(
267
   background.pushImage(
247
     0, 0, 240, 135,
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
   // Scroll overlays
281
   // Scroll overlays
251
   if (outro_start) { // Outro scroll overlay
282
   if (outro_start) { // Outro scroll overlay
257
     }
288
     }
258
   } else if (nowmillis < INTRO_FREEZE_MILLIS + INTRO_SCROLL_MILLIS) { // Intro scroll overlay
289
   } else if (nowmillis < INTRO_FREEZE_MILLIS + INTRO_SCROLL_MILLIS) { // Intro scroll overlay
259
     do_scroll(talis, metta, 0, INTRO_FREEZE_MILLIS, INTRO_SCROLL_MILLIS, false);
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
   background.pushSprite(0, 0);
294
   background.pushSprite(0, 0);
264
 
295
 

Loading…
Cancel
Save