From 43a7f3f89fa570b6e119d2619e4b150fc9147925 Mon Sep 17 00:00:00 2001 From: bigalex Date: Fri, 5 Oct 2012 21:12:26 +0200 Subject: [PATCH] sync --- firmware/lib/bughal.c | 13 ++++++ firmware/lib/bughal.h | 1 + firmware/main.c | 96 +++++++++++++++++++++++++------------------ 3 files changed, 70 insertions(+), 40 deletions(-) diff --git a/firmware/lib/bughal.c b/firmware/lib/bughal.c index dcff0cf..ed6309e 100644 --- a/firmware/lib/bughal.c +++ b/firmware/lib/bughal.c @@ -56,6 +56,19 @@ void init_buzzr(void){ return; } + +void init_mic(void){ + //its on B2 and C5, for reasons + // + DDRC |= (1 << PORTC5); + DDRB |= (1 << PORTB2); + //switch it off + buzzr_off(); + return; +} + + + void buzzr_up(void){ PORTC &= ~(1 << PORTC5); PORTB |= (1 << PORTB2); diff --git a/firmware/lib/bughal.h b/firmware/lib/bughal.h index d3d875f..c3aa099 100644 --- a/firmware/lib/bughal.h +++ b/firmware/lib/bughal.h @@ -45,6 +45,7 @@ void led_on(int); void led_off(int); void init_buzzr(void); +void init_mic(void); void buzzr_up(void); void buzzr_down(void); void buzzr_off(void); diff --git a/firmware/main.c b/firmware/main.c index b3f5ce1..bdca4c8 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -17,7 +17,7 @@ #define MODE1 1 #define MODE2 2 #define MODE3 3 -#define MODE3 4 +#define MODE4 4 #define NUM_MODES 5 @@ -42,52 +42,26 @@ void modeswitch_poll(void){ }; void do_mode0(void){ - - -return; -} - -void do_mode4(void){ - uint8_t max = 200; - uint8_t min = 10; - static timer_t mytimer; - static bool blink; + static uint16_t maxval; if (ModeChanged){ - music_setNote(NOTE_PAUSE,0); + timer_set(&mytimer, 10); + maxval=0; ModeChanged = false; - timer_set(&mytimer, 10); - blink = false; + buzzr_up(); }; if(timer_expired(&mytimer)){ - if (!blink) { - //lets blink - int i = (rand() % 3); - switch(i) { - case 0 : led_on(LED_L); break; - case 1 : led_on(LED_R); break; - default : led_on(LED_L|LED_R); - }; - if (rand()%10>8) set_motor(MOTOR_ON); - music_setNote(NOTE_C,5); - timer_set(&mytimer, 2); - blink=true; - } else { - //stop blink - led_off(LED_L|LED_R); - set_motor(MOTOR_OFF); - music_setNote(NOTE_PAUSE,0); - timer_set(&mytimer, (rand() % (max-min)) + min); + //USART0_put_uint16(maxval); + //USART0_crlf(); + timer_set(&mytimer, 10); + maxval=0; + buzzr_inv(); + }; //end if timer_expired + maxval++; - blink=false; - } + - } //end if timer_expired - - - - -}; +}; //end do_mode0 void do_mode1(void){ @@ -190,6 +164,48 @@ void do_mode3(void){ +}; + +void do_mode4(void){ + uint8_t max = 200; + uint8_t min = 10; + + static timer_t mytimer; + static bool blink; + if (ModeChanged){ + music_setNote(NOTE_PAUSE,0); + ModeChanged = false; + timer_set(&mytimer, 10); + blink = false; + }; + if(timer_expired(&mytimer)){ + if (!blink) { + //lets blink + int i = (rand() % 3); + switch(i) { + case 0 : led_on(LED_L); break; + case 1 : led_on(LED_R); break; + default : led_on(LED_L|LED_R); + }; + if (rand()%10>8) set_motor(MOTOR_ON); + music_setNote(NOTE_C,5); + timer_set(&mytimer, 2); + blink=true; + } else { + //stop blink + led_off(LED_L|LED_R); + set_motor(MOTOR_OFF); + music_setNote(NOTE_PAUSE,0); + timer_set(&mytimer, (rand() % (max-min)) + min); + + blink=false; + } + + } //end if timer_expired + + + + };