#define LED_ON() PORTB |= _BV(LED_BIT)
#define LED_OFF() PORTB &= (~_BV(LED_BIT))
+#define MODE_NO_FILTER 0
+#define MODE_FILTER_THRES1 1
+#define MODE_FILTER_THRES2 2
+#define MODE_MAX 3
+
static uint32_t bitfield;
#ifdef HOST_VERSION
#endif
}
+#ifndef HOST_VERSION
+static void beep(void)
+{
+ uint16_t i;
+
+ for (i = 0; i < 1000; i++) {
+ if (i < 250 && (i & 1))
+ BUZZER_ON();
+ else
+ BUZZER_OFF();
+ }
+}
+#endif
+
/*
The CPU runs at 8Mhz.
Fe = 5Khz
int main(void)
{
int8_t detected = 0;
+ uint8_t mode = MODE_FILTER_THRES2;
int16_t i;
+#ifndef HOST_VERSION
+ uint8_t button = 0, button_filter = 0;
+#endif
/* led and buzzer are outputs */
#if defined(__AVR_ATtiny45__)
while (1) {
+ /* wait until 200us is elapsed since previous call (5Khz) */
wait_period();
+#ifndef HOST_VERSION
+ /* filter button */
+ button = 0;
+ if (BUTTON_IS_PRESSED() && button_filter < 10) {
+ button_filter++;
+ if (button_filter == 10)
+ button = 1;
+ }
+ else if (!BUTTON_IS_PRESSED())
+ button_filter = 0;
+
+ /* change mode if button is pressed */
+ if (button) {
+ uint8_t j;
+
+ mode ++;
+ if (mode >= MODE_MAX)
+ mode = 0;
+
+ for (j = 0; j <= mode; j++)
+ beep();
+
+ /* reset input history */
+ bitfield = 0;
+ }
+#endif
+
/* push one bit in bitfield */
bitfield <<= 1UL;
bitfield |= (uint32_t)get_input(i);
+ /* filter the input */
apply_filters();
mean_pow(&pow_fond, fil_fond);
mean_pow(&pow_harm1, fil_harm1);
else if (cpt_filter > 0)
cpt_filter--;
+ switch (mode) {
+ case MODE_NO_FILTER:
+ case MODE_FILTER_THRES1:
+ /* low threshold, some risk of false positive */
+ if (cpt_filter > 100)
+ detected = 1;
+ break;
+ case MODE_FILTER_THRES2:
+ /* high threshold */
+ if (cpt_filter > 250)
+ detected = 1;
+ break;
+ default:
+ break;
+ }
+
#ifdef HOST_VERSION
/* display values */
printf("%d fil_fond=%d fil_harm1=%d fil_other=%d\n",
else
LED_OFF();
- /* output a square signal at 625 hz if beacon is
- * detected */
- if ((detected == 1) && (i & 4))
- BUZZER_ON();
- else
- BUZZER_OFF();
-
+ /* if filtering is disabled, just copy the radio input
+ * on the buzzer */
+ if (mode == MODE_NO_FILTER) {
+ if (RADIO_READ())
+ BUZZER_ON();
+ else
+ BUZZER_OFF();
+ }
+ /* with filtering enabled, output a square signal at
+ * 625 hz if beacon is detected */
+ else {
+ if ((detected == 1) && (i & 4))
+ BUZZER_ON();
+ else
+ BUZZER_OFF();
+ }
#endif
i ++;
#ifdef HOST_VERSION
+ /* exit when all samples are processed */
if (i >= sizeof(x))
break;
#endif