From: Martin Mares Date: Wed, 8 Aug 2018 20:06:26 +0000 (+0200) Subject: Morseovkový dekodér X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fmeggy;p=home-hw.git Morseovkový dekodér --- diff --git a/nucleo-test/Src/test.c b/nucleo-test/Src/test.c index 1e1d584..570f89d 100644 --- a/nucleo-test/Src/test.c +++ b/nucleo-test/Src/test.c @@ -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<