]> mj.ucw.cz Git - home-hw.git/commitdiff
Morseovkový dekodér meggy
authorMartin Mares <mj@ucw.cz>
Wed, 8 Aug 2018 20:06:26 +0000 (22:06 +0200)
committerMartin Mares <mj@ucw.cz>
Wed, 8 Aug 2018 20:06:26 +0000 (22:06 +0200)
nucleo-test/Src/test.c

index 1e1d58486f5120f267168981fea94ef5a7fab99d..570f89d54e110353309f7c53f1fd165a806ee6fd 100644 (file)
@@ -137,26 +137,79 @@ void debug_printf(const char *fmt, ...)
   va_end(args);
 }
 
+void decide_set(int n){
+    switch (n){
+      case 1:
+       LL_GPIO_SetOutputPin(MEGGY1_GPIO_Port, MEGGY1_Pin);
+       break;
+      case 2:
+       LL_GPIO_SetOutputPin(MEGGY2_GPIO_Port, MEGGY2_Pin);
+       break;
+      case 3:
+       LL_GPIO_SetOutputPin(MEGGY3_GPIO_Port, MEGGY3_Pin);
+       break;
+      case 0:
+       LL_GPIO_SetOutputPin(MEGGY4_GPIO_Port, MEGGY4_Pin);
+       break;
+    }
+}
+
+void decide_reset(int n){
+    switch (n){
+      case 1:
+       LL_GPIO_ResetOutputPin(MEGGY1_GPIO_Port, MEGGY1_Pin);
+       break;
+      case 2:
+       LL_GPIO_ResetOutputPin(MEGGY2_GPIO_Port, MEGGY2_Pin);
+       break;
+      case 3:
+       LL_GPIO_ResetOutputPin(MEGGY3_GPIO_Port, MEGGY3_Pin);
+       break;
+      case 0:
+       LL_GPIO_ResetOutputPin(MEGGY4_GPIO_Port, MEGGY4_Pin);
+       break;
+    }
+}
+
+byte recognize(int n){
+    if (n<150) return 0;
+    else return 1;
+}
+
 void run_test(void)
 {
   uint cnt = 0;
+  uint cnt2 = 0;
+  static const char mtree[]="**ETIANMSURWDKGOHVF*L*PJBXCYZQ**";
+  int letter=1;
 
   for (;;)
     {
-      debug_printf(">>> %d\n", cnt);
-      cnt++;
       LL_GPIO_SetOutputPin(LD2_GPIO_Port, LD2_Pin);
-      LL_GPIO_SetOutputPin(MEGGY1_GPIO_Port, MEGGY1_Pin);
-      LL_GPIO_SetOutputPin(MEGGY2_GPIO_Port, MEGGY2_Pin);
-      LL_GPIO_SetOutputPin(MEGGY3_GPIO_Port, MEGGY3_Pin);
-      if (LL_GPIO_IsInputPinSet(BLUE_BUTTON_GPIO_Port, BLUE_BUTTON_Pin))
-       LL_GPIO_SetOutputPin(MEGGY4_GPIO_Port, MEGGY4_Pin);
-      LL_mDelay(100);
+      cnt=0;
+      while (!LL_GPIO_IsInputPinSet(BLUE_BUTTON_GPIO_Port, BLUE_BUTTON_Pin)){
+         cnt++;
+         LL_mDelay(1);
+      }
       LL_GPIO_ResetOutputPin(LD2_GPIO_Port, LD2_Pin);
-      LL_GPIO_ResetOutputPin(MEGGY1_GPIO_Port, MEGGY1_Pin);
-      LL_GPIO_ResetOutputPin(MEGGY2_GPIO_Port, MEGGY2_Pin);
-      LL_GPIO_ResetOutputPin(MEGGY3_GPIO_Port, MEGGY3_Pin);
-      LL_GPIO_ResetOutputPin(MEGGY4_GPIO_Port, MEGGY4_Pin);
-      LL_mDelay(100);
+      // debug_printf(">>> %d\n", cnt);
+      letter=(letter<<1)+recognize(cnt);
+      cnt=0;
+      while (LL_GPIO_IsInputPinSet(BLUE_BUTTON_GPIO_Port, BLUE_BUTTON_Pin)){
+         cnt++;
+         LL_mDelay(1);
+         if (cnt==150) {
+             debug_putc(mtree[letter]);
+             letter=1;
+         }
+         if (cnt==1500) debug_putc(' ');
+         if (cnt==4000) debug_putc('\n');
+      }
+
+      cnt2++;
+      for (int i=0;i<4;i++){
+         if (cnt2&(1<<i)) decide_set((i+1)%4);
+         else decide_reset((i+1)%4);
+      }
     }
 }