Exemplo n.º 1
0
void send_mesg_test_mode()
{
   	lcd_init();
	init_push_buttons();

	usart_init();
	txq_init();
	usart_drain_rx();

	lcd_puts("Send Mesg Test Mode");
	wait_ms(1000);
	lcd_clear();

	char echo_mesg[] = "foobar";  // Assumed to be less than DATA_FRAME_MAX_LEN.
 
	while (true)
	{
		switch (wait_button("Select Message")) {
		case mesg_ping:

			txq_enqueue(signal_start);
			txq_enqueue(mesg_ping);
			txq_enqueue(signal_stop);
			txq_drain();
			break;

		case mesg_echo:

			txq_enqueue(signal_start);
			txq_enqueue(mesg_echo);

			// Copy the echo message into the `control`:
			strcpy(control.data, echo_mesg);
			control.data_len = strlen(echo_mesg);

			// Enqueue the frame. No more frames coming.
			tx_frame(false);

			txq_enqueue(signal_start);
			txq_drain();
			break;

		default:
			wait_button("Invalid selection.");
			break;
		}
	}
}
Exemplo n.º 2
0
int main()
{
	setup_demo( buf, synth );
	
	// generate 1000 clocks of square wave
	int length = 1000;
	int amplitude = 1;
	for ( int time = 0; time < length; time += 10 )
	{
		synth.update( time, amplitude );
		amplitude = -amplitude;
	}
	
	// find out how many samples of sine wave to generate
	int count = buf.count_samples( length );
	blip_sample_t temp [4096];
	for ( int i = 0; i < count; i++ )
	{
		double y = sin( i * (3.14159 / 100) );
		temp [i] = y * 0.30 * blip_sample_max; // convert to blip_sample_t's range
	}
	
	// mix sine wave's samples into Blip_Buffer
	buf.mix_samples( temp, count );
	
	// end frame and show samples
	buf.end_frame( length );
	show_buffer( buf );
	wait_button();
	 
	return 0;
}
Exemplo n.º 3
0
int main()
{
	lcd_init();
	init_push_buttons();
	shaft_encoder_init();
	stepper_init();
	
	while (1) {
		char prog;
		
		lcd_clear();
		prog = wait_button("Choose program:");
		switch (prog) {
			case 1:
				part1();
				break;
			case 2:
				part2();
				break;
			case 3:
				part3(); 
				break;
			default:
				;  // do nothing
		}
	}
}
Exemplo n.º 4
0
void test_songs_mode(void)
{
	while (true) {
		uint8_t song_id = wait_button("Select song");
		songs_load(song_id);
	}
}
Exemplo n.º 5
0
/* keybell_handle()
 *==========================================================================
 * Turn on/off key or bell
 */
void
keybell_handle( int base, int *var )
{
  OBJECT *tree  = (OBJECT *)rs_trindex[GENERAL];
  
  *var ^= TRUE;
  (( *var ) ? ( Enable( base ) ) : ( Disable( base ) ) );
  Objc_draw( tree, base, MAX_DEPTH, NULL );
  Set_Keybell();
  wait_button( UP );
}
Exemplo n.º 6
0
/* Dclick_Select()
 *==========================================================================
 * Selects one of the 5 mouse double click objects possible
 */
void
Dclick_Select( int obj )
{
   OBJECT *tree = ( OBJECT *)rs_trindex[ GENERAL ];
   
   Deselect( cur_value.dclick + M0 );
   Objc_draw( tree, cur_value.dclick + M0, 0, NULL );
   Select( obj );
   cur_value.dclick = obj - M0;
   Objc_draw( tree, obj, 0, NULL );
   Set_Dclick();
   wait_button( UP );
}
Exemplo n.º 7
0
Arquivo: tree.c Projeto: pete0877/wpi
void main()
{
	/* initialize turtle graphics */
	init_turtle();

	/* draw 'V' */
	vee(40, 10);
	right(180);
	vee(40, 10);


	/* wait for user to click right mouse button */
	wait_button();

}
Exemplo n.º 8
0
/* Dclick_Handle()
 *==========================================================================
 * Handle the Double Click Routine
 * Select the Object IF a double click occurred
 */
void
Dclick_Handle( BOOLEAN flag, int obj )
{
   OBJECT *tree = ( OBJECT *)rs_trindex[ GENERAL ];
   
   if( flag )	/* double click? */
   {
      	XSelect( tree, DOUBLE );
/*       	Objc_draw( tree, obj, 0, NULL );*/
       	Evnt_timer( 250L );
       	XDeselect( tree, DOUBLE );
/*       	Objc_draw( tree, obj, 0, NULL );*/
   }
   wait_button( UP );
  
}
Exemplo n.º 9
0
void wd_hndlbutton(WINDOW *w, int x, int y, int n, int bstate,
				   int kstate)
{
	int item, m_state;

	if (selection.w != w)
		desel_old();

	m_state = xe_button_state();
	item = itm_find(w, x, y);

	if (item >= 0)
	{
		if (n == 2)
		{
			itm_select(w, item, 0, TRUE);
			itm_set_menu(w);

			wait_button();

			if (itm_open(w, item, kstate) == TRUE)
				itm_select(w, item, 2, TRUE);
		}
		else
		{
			if ((m_state == 0) || (itm_state(w, item) == FALSE))
			{
				itm_select(w, item, (kstate & 3) ? 1 : 0, TRUE);
				itm_set_menu(w);
			}

			if ((m_state != 0) && (itm_state(w, item) == TRUE))
				itm_move(w, item, x, y);
		}

		itm_set_menu(selection.w);
	}
	else if (in_window(w, x, y) == TRUE)
	{
		if (((m_state == 0) || ((kstate & 3) == 0)) && (selection.w == w))
			itm_select(w, -1, 0, TRUE);
		if (m_state)
			itm_rselect(w, x, y);
		itm_set_menu(w);
	}
}
Exemplo n.º 10
0
void readings_stream_mode()
{
	const uint8_t BUF_LENGTH = 100;
	char buf[BUF_LENGTH];

	enum {
		reading_ir = 1,
		reading_sonar = 2,
		reading_sonar_mode = 3
	} reading;

	init_push_buttons();
	lcd_init();

	ir_init();
	sonar_init();

	usart_init();
	usart_drain_rx();

	while (true) {
		switch (wait_button("Readings Stream")) {
		case reading_ir:
			snprintf(buf, BUF_LENGTH, "IR: %u\n", ir_raw_reading());
			break;

		case reading_sonar:
			snprintf(buf, BUF_LENGTH, "Sonar: %u\n", sonar_raw_reading());
			break;

		case reading_sonar_mode:
			while (true) {
				snprintf(buf, BUF_LENGTH, "Sonar: %u\n", sonar_raw_reading());
				usart_tx_buf(buf);
			}
			break;

		default:
			buf[0] = '\0';
		}

		usart_tx_buf(buf);
	}
}
Exemplo n.º 11
0
void main(){
  
    unsigned char digit,button;
    unsigned int len,i;
    unsigned int g_seed;
    unsigned int Xn_1;
    
    setup();
    
    set_all_leds(0,0,0);
    delay(5);
    set_all_leds(0,0,0);
    delay(5);   
    
    wait_button();      // Ожидание нажатия для начала раунда
    start_flash();      // Стартовое приветствие
    g_seed = get_seed(); // Захват стартового значения для ПСП
    delay(150);
    len = 1;            // Установка длинны последовательности
    

    while(1){
        ///////////////////////////////////////////////
        //   Демонстрация последовательности
        ///////////////////////////////////////////////
        Xn_1 = g_seed;
        for(i=0;i<len;i++){

            digit = get_next_psevdo_digit(&Xn_1);
            show_color(digit);

            delay(100); 
            sound_stop();
            set_all_leds(0,0,0);
            delay(50);
        }  // Показали Последовательность  

        /////////////////////////////////////////////////////// 
        //   ВВод и проверка последовательности
        ///////////////////////////////////////////////////////
        Xn_1 = g_seed;
        for(i=0;i<len;i++){
            
            digit = get_next_psevdo_digit(&Xn_1);
             button = wait_button();
            if(digit != button){
                error();            //  Ошибка
                break;      
            }else{                  // Ответ верен
                show_color(digit);  // Индикация правильного ответа
                delay(100); 
                sound_stop();
                set_all_leds(0,0,0);
                delay(10);
            }
        }//for   
        
        if(digit == button){        // Если Всё верно
            delay(30);          
            set_all_leds(10,10,10); // Индикация, что ответ был правильный
            delay(5);
            set_all_leds(0,0,0);
            delay(100);
            len++;                  // Увеличение длинны последовательности
            continue;
        }else{
            wait_button();          // Ожидание нажатия для начала следующего раунда
            start_flash();          // Стартовое приветствие
            g_seed = get_seed();    // Захват стартового значения для ПСП
            delay(10);
            len = 1;                // Установка длинны последовательности
        }
        
    
    }



}
Exemplo n.º 12
0
void view_inputs()
{
    char a[6][14]= {"Analog Port ","Digital Port ","Frob knob",
                    "Dip Switches","Motor Force","Quit"
                   };
    int sel,port,index;

    while(1)
    {
        if((index=select_string(a,6))==-1)
            return;

        if(index>-1 && index<2)
            port=select_int_value(a[index],0,27);

        if(index==0)  /* analog */
        {
            while(chosen_button()!=ESCAPE_B)
            {
                port=select_int_value(a[index],0,27);

                while(chosen_button()==NEITHER_B)
                {
                    printf("Port %d=%d\n",port,analog(port));
                    sleep(.1);
                }
            }

            wait_button(UP_B);
        }
        else if(index==1) /* digital */
            while(chosen_button()==NEITHER_B)
            {
                printf("Port %d=%d\n",port,digital(port));
                sleep(.1);
            }
        else if(index==2) /* frob knob */
        {
            if(select_int_value("Frob knob ",0,255)==-1)
                return;
        }
        else if(index==3) /* dip switches */
        {
            while(chosen_button()==NEITHER_B)
            {
                printf("Dips=%b\n",dip_switches());
                sleep(.1);
            }

            if(chosen_button()==ESCAPE_B)
                return;
        }
        else if(index==4)  /* motor force */
        {
            if((port=select_int_value("Motor ",0,3))==-1)
                return;

            motor(port,100);

            while(chosen_button()==NEITHER_B)
            {
                printf("Force=%d\n",motor_force(port));
                sleep(.1);
            }

            motor(port,0);

            if(chosen_button()==ESCAPE_B)
                return;
        }
        else  /* Quit */
            return;

        if(chosen_button()==ESCAPE_B)
            return;
    }
}
Exemplo n.º 13
0
static void itm_move(WINDOW *src_wd, int src_object, int old_x, int old_y)
{
	int x = old_x, y = old_y;
	WINDOW *cur_wd = src_wd, *new_wd;
	int cur_object = src_object, new_object;
	int clip[4];
	int ox, oy, kstate, *list, n, nv, i;
	boolean cur_state = TRUE, new_state, mreleased;
	ICND *icnlist;

	if (itm_type(src_wd, src_object) == ITM_PREVDIR)
	{
		wait_button();
		return;
	}

	if ((itm_list(src_wd, &n, &list) == FALSE) || (n == 0))
		return;

	for (i = 0; i < n; i++)
	{
		if (itm_type(src_wd, list[i]) == ITM_PREVDIR)
			itm_select(src_wd, list[i], 2, TRUE);
	}

	free(list);

	if (itm_xlist(src_wd, &n, &nv, &list, &icnlist, old_x, old_y) == FALSE)
		return;

	get_minmax(icnlist, nv, clip);

	wind_update(BEG_MCTRL);
	graf_mouse(FLAT_HAND, NULL);
	draw_icns(icnlist, nv, x, y, clip);

	do
	{
		ox = x;
		oy = y;
		mreleased = xe_mouse_event(0, &x, &y, &kstate);

		if ((x != ox) || (y != oy))
		{
			draw_icns(icnlist, nv, ox, oy, clip);
			find_newobj(x, y, &new_wd, &new_object, &new_state);

			if ((cur_wd != new_wd) || (cur_object != new_object))
			{
				if ((cur_state == FALSE) && (cur_object >= 0))
					select_object(cur_wd, cur_object, 2);

				cur_wd = new_wd;
				cur_object = new_object;
				cur_state = new_state;

				if ((cur_object >= 0) && (cur_state == FALSE))
					select_object(cur_wd, cur_object, 3);
			}
			if (mreleased == FALSE)
				draw_icns(icnlist, nv, x, y, clip);
		}
		else if (mreleased == TRUE)
			draw_icns(icnlist, nv, x, y, clip);
	}
	while (mreleased == FALSE);

	graf_mouse(ARROW, NULL);
	wind_update(END_MCTRL);


	if ((cur_state == FALSE) && (cur_object >= 0))
		select_object(cur_wd, cur_object, 2);

	if ((cur_wd != src_wd) || (cur_object != src_object))
	{
		if (cur_wd != NULL)
		{
			int cur_type = xw_type(cur_wd);

			if ((cur_type == DIR_WIND) || (cur_type == DESK_WIND))
			{
				/* Test if destination window is the desktop and if the
				   destination object is -1 (no object). If this is true,
				   clip the mouse coordinates. */

				if ((xw_type(cur_wd) == DESK_WIND) && (cur_object == -1) && (xw_type(src_wd) == DESK_WIND))
					clip_coords(clip, x, y, &x, &y);

				itm_copy(src_wd, n, list, cur_wd, cur_object, kstate, icnlist, x, y);
			}
			else
				alert_printf(1, MILLCOPY);
		}
		else
#if _MINT_
		if (mint)
			itm_drop(src_wd, n, list, kstate, icnlist, x, y);		/* HR 050203 drag & drop */
		else
#endif
			alert_printf(1, MILLCOPY);
	}

	free(list);
	free(icnlist);
}