X-Git-Url: http://git.droids-corp.org/?p=beacon-rx-433.git;a=blobdiff_plain;f=main.c;h=35a86cf7de11c84fe90de9eba40665301eea7e71;hp=1a9b01eb5c726ab618823949d796fda09fed923d;hb=0878ff0726cff2df249e065eebdbd9c35ce9071c;hpb=6c2b37ed3725443a7342e0baca30c6dc97ee2578 diff --git a/main.c b/main.c index 1a9b01e..35a86cf 100644 --- a/main.c +++ b/main.c @@ -19,9 +19,19 @@ #endif /* port B */ -#define BUZ_BIT 0 -#define RADIO_BIT 2 -#define LED_BIT 4 +#define BUZZER_BIT 0 +#define BUZZER_ON() PORTB |= _BV(BUZZER_BIT) +#define BUZZER_OFF() PORTB &= (~_BV(BUZZER_BIT)) + +#define RADIO_BIT 2 +#define RADIO_READ() (!!(PINB & (_BV(RADIO_BIT)))) + +#define BUTTON_BIT 3 +#define BUTTON_IS_PRESSED() (!!(PINB & (_BV(BUTTON_BIT)))) + +#define LED_BIT 4 +#define LED_ON() PORTB |= _BV(LED_BIT) +#define LED_OFF() PORTB &= (~_BV(LED_BIT)) static uint32_t bitfield; @@ -330,28 +340,7 @@ static uint8_t get_input(int i) #ifdef HOST_VERSION return !!x[i]; #else - return !!(PINB & RADIO_BIT); -#endif -} - -static void set_output(int16_t i) -{ - int8_t detected = 0; - - if (cpt_filter > 250) - detected = 1; - -#ifdef HOST_VERSION - printf("%d fil_fond=%d fil_harm1=%d fil_other=%d\n", - i, fil_fond, fil_harm1, fil_other); - printf("%d pow_fond=%d pow_harm1=%d pow_other=%d cpt_filter=%d detected=%d\n", - i, pow_fond, pow_harm1, pow_other, cpt_filter, detected); -#else - /* when we receive, output a square signal at 625 hz */ - if ((detected == 1) && (i & 4)) - PORTB |= (1 << BUZ_BIT); - else - PORTB &= ~(1 << BUZ_BIT); + return RADIO_READ(); #endif } @@ -364,11 +353,12 @@ static void set_output(int16_t i) */ int main(void) { + int8_t detected = 0; int16_t i; /* led and buzzer are outputs */ #if defined(__AVR_ATtiny45__) - DDRB |= (1 << LED_BIT) | (1 << BUZ_BIT); + DDRB |= (1 << LED_BIT) | (1 << BUZZER_BIT); #endif i = 0; @@ -396,10 +386,31 @@ int main(void) else if (cpt_filter > 0) cpt_filter--; - set_output(i); - #ifdef HOST_VERSION + /* display values */ + printf("%d fil_fond=%d fil_harm1=%d fil_other=%d\n", + i, fil_fond, fil_harm1, fil_other); + printf("%d pow_fond=%d pow_harm1=%d pow_other=%d " + "cpt_filter=%d detected=%d\n", + i, pow_fond, pow_harm1, pow_other, cpt_filter, detected); +#else + if (detected) + LED_ON(); + else + LED_OFF(); + + /* output a square signal at 625 hz if beacon is + * detected */ + if ((detected == 1) && (i & 4)) + BUZZER_ON(); + else + BUZZER_OFF(); + +#endif + i ++; + +#ifdef HOST_VERSION if (i >= sizeof(x)) break; #endif