소스 검색

Add metta send/receive status line

Birds don't blink (not used for metta send/receive status)
master
The Dod 4 달 전
부모
커밋
2ad8702247
1개의 변경된 파일38개의 추가작업 그리고 8개의 파일을 삭제
  1. 38
    8
      talismetta/talismetta.ino

+ 38
- 8
talismetta/talismetta.ino 파일 보기

@@ -41,7 +41,9 @@ unsigned long outro_start;
41 41
 #define YOURBIRD_X 53
42 42
 #define YOURBIRD_Y 5
43 43
 
44
-
44
+#define STATUS_SEND_MILLIS 1000
45
+#define STATUS_RECEIVE_MILLIS 1058 // 2X23X23 to make things resonate
46
+#define STATUS_COLOR TFT_SKYBLUE
45 47
 
46 48
 #define SEND_INTERVAL 3000
47 49
 unsigned long next_send = 0;
@@ -71,9 +73,9 @@ enum frameType {
71 73
 };
72 74
 
73 75
 frameType frames[NUM_FRAMES] = {
74
-  FRAME_ME, FRAME_US, FRAME_U,
75
-  FRAME_U, FRAME_US, FRAME_U,
76
-  FRAME_U, FRAME_US, FRAME_ME
76
+  FRAME_ME, FRAME_ME, FRAME_US, 
77
+  FRAME_U, FRAME_U, FRAME_US, 
78
+  FRAME_US, FRAME_US, FRAME_US
77 79
 };
78 80
 
79 81
 const unsigned short *frame2image(frameType frame, bool is_salam, bool metta_from_me, bool metta_from_you) {
@@ -102,6 +104,7 @@ TFT_eSprite leftSprite = TFT_eSprite(&tft);
102 104
 TFT_eSprite rightSprite = TFT_eSprite(&tft);
103 105
 TFT_eSprite mybirdSprite = TFT_eSprite(&tft);
104 106
 TFT_eSprite yourbirdSprite = TFT_eSprite(&tft);
107
+TFT_eSprite statusSprite = TFT_eSprite(&tft);
105 108
 
106 109
 
107 110
 // lifted from MacAddress.c
@@ -207,6 +210,9 @@ void setup() {
207 210
   yourbirdSprite.createSprite(YOURBIRD_WIDTH, YOURBIRD_HEIGHT);
208 211
   yourbirdSprite.setSwapBytes(true);
209 212
   yourbirdSprite.pushImage(0, 0, YOURBIRD_WIDTH, YOURBIRD_HEIGHT, yourbird);
213
+
214
+  statusSprite.createSprite(240, 18);
215
+  statusSprite.setSwapBytes(true);
210 216
 }
211 217
 
212 218
 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) {
@@ -230,6 +236,21 @@ void do_scroll(const unsigned short *left_image, const unsigned short *right_ima
230 236
   }
231 237
 }
232 238
 
239
+void do_status(bool is_send) {
240
+  unsigned long cycle = is_send ? STATUS_SEND_MILLIS : STATUS_RECEIVE_MILLIS;
241
+  float quotient = float(millis() % cycle) / cycle;
242
+  if (!is_send) {
243
+    quotient = 1.0 - quotient;
244
+  }
245
+  int32_t r_in = 130 * quotient; // a bit larger than 240/2
246
+  int32_t r_out = 130 * pow(quotient, 0.75); // grows faster
247
+
248
+  statusSprite.fillSprite(TFT_BLACK);
249
+  statusSprite.fillEllipse(120, 9, r_out, 10, STATUS_COLOR);
250
+  statusSprite.fillEllipse(120, 9, r_in, 10, TFT_BLACK);
251
+  statusSprite.pushToSprite(&background, 0, 116, TFT_BLACK);
252
+}
253
+
233 254
 void loop() {
234 255
   unsigned long nowmillis = millis();
235 256
   if (digitalRead(BUTTON1PIN) == LOW) {
@@ -264,16 +285,25 @@ void loop() {
264 285
     0, 0, 240, 135,
265 286
     frame2image(frames[current_frame], is_salam, metta_from_me_since, metta_from_you));
266 287
 
267
-  // mybird (steady, pulse if metta_from_me_Since)
268
-  if (!metta_from_me_since || frames[current_frame] == FRAME_ME) {
288
+  // mybird (always on)
289
+  if (true /* !metta_from_me_since || frames[current_frame] == FRAME_ME || frames[current_frame] == FRAME_US */) {
269 290
     mybirdSprite.pushToSprite(&background, MYBIRD_X, MYBIRD_Y, TFT_BLACK);
270 291
   }
271 292
 
272
-  // yourbird (steady if nearby, heart beat if metta_from_you)
273
-  if (nearby && (!metta_from_you || frames[current_frame] == FRAME_U)) {
293
+  // yourbird (if nearby)
294
+  if (nearby /* && (!metta_from_you || frames[current_frame] == FRAME_U || frames[current_frame] == FRAME_US) */) {
274 295
     yourbirdSprite.pushToSprite(&background, YOURBIRD_X, YOURBIRD_Y, TFT_BLACK);
275 296
   }
276 297
 
298
+  // "send" status
299
+  if (metta_from_me_since) {
300
+    do_status(true);
301
+  }
302
+
303
+  // "receive" status
304
+  if (metta_from_you) {
305
+    do_status(false);
306
+  }
277 307
 
278 308
   // Scroll overlays
279 309
   if (outro_start) { // Outro scroll overlay

Loading…
취소
저장