Пример #1
0
void termination_handler(int sig) {
	PRINT_DEBUG("**********Terminating *******");

	//shutdown all module threads in backwards order of startup
	//rtm_shutdown();

	udp_shutdown();
	tcp_shutdown();
	icmp_shutdown();
	ipv4_shutdown();
	arp_shutdown();

	interface_shutdown(); //TODO finish
	daemon_shutdown(); //TODO finish
	switch_shutdown(); //TODO finish

	//have each module free data & que/sem //TODO finish each of these
	//rtm_release();
	udp_release();
	tcp_release();
	icmp_release();
	ipv4_release();
	arp_release();

	interface_release();
	daemon_release();
	switch_release();

	PRINT_DEBUG("FIN");
	exit(-1);
}
Пример #2
0
int main(void)
{
    switch_init();
    switch_add_callback(SWITCH_ALL_EVENTS, print_hello);
    printf("Switch callback are now active for 15 seconds.\n");
    printf("Press a switch to print \"hello\" on screen.\n");
    sleep(15);
    switch_release();

    return 0;
}
unsigned char wavetype(void)
{
char msg1[16] =  "   START NOW?  ";// LCD line 1 message
char msg2[16] =  "  PRESS ANYKEY ";// LCD line 2 message
unsigned char choice = 0;// represents ADC convert value
LCD_Reset();// initiliaze LCD
sprintf(msg1,"----WAVE TYPE?---");// input to LCD line 1
LCD_Line1(msg1);
do{
	choice = (unsigned char)poten(2)+2;	// let adc convert value to choice	
	switch(choice)
	{
		case SINUSOIDAL:	
								sprintf(msg2,"---SINUSOIDAL---");
		                    	LCD_Line2(msg2);

								bo=1;// 1 represent sine wave
	    break;
		case TRIANGLE:
								sprintf(msg2,"----TRIANGLE----");
								LCD_Line2(msg2);

								bo=2;// 2 represents triangle wave
		break;
		case SAWTOOTH:
								sprintf(msg2,"----SAWTOOTH----");
								LCD_Line2(msg2);

								bo=3;// 3 represents sawtooth wave
		break;
		case SQUARE:
								sprintf(msg2,"-----SQUARE-----");
								LCD_Line2(msg2);

								bo=4;// 4 represents square wave
		break;
        default: 
		break;
	}
								

if (SWITCH_1==0)// if RA5 pressed exit wavetype function goto divice type menu 
 {
 while(SWITCH_1 == 0);// wait for RA5 release
	return 1; 
 }
	
}while(SWITCH_0 == 1);//end do  while RB0 pressed.
 switch_release();// wait for RB0 release
}
int main(void){
        /* Initialises the switches and LEDs using the LetMeCreate library */
        switch_init();
        led_init();
        
        /* The first parameter is the event for which a callback function will be triggered. The second is a pointer to the function that will run when the event occurs */
        switch_add_callback(SWITCH_1_PRESSED, led_toggle);
        switch_add_callback(SWITCH_2_PRESSED, end_program);
        
        /* running is true until switch 2 is pressed */
        while(running)
                ;
        /* The LEDs are no longer accessible by the program */
        led_release();
        /* Removes all of the callback functions */
        switch_release();
        
        return 0;
}
unsigned char frequencyrange(void)
{
unsigned char m;// represent adc convert value
unsigned int f;// represent frequency 
char msg1[16] =  "   START NOW?  ";//LCD LINE 1 message
char msg2[16] =  "  PRESS ANYKEY ";// LCD line 2 message
LCD_Reset();// initiliaze LCD

sprintf(msg1,"  Please choose  ");// chose frequency message
LCD_Line1(msg1);
sprintf(msg2,"Frequency");
LCD_Line2(msg2);
Delay10KTCYx(250);// delay 0.25s
Delay10KTCYx(250);//delay 0.25s
Delay10KTCYx(250);// delay0.25s
Delay10KTCYx(250);//delay0.25s



LCD_Reset();// initialize lCD
		switch(bo)
	{
		case 1:	
								do
								{
								sprintf(msg1,"Range:11~2277 Hz");
		                    	LCD_Line1(msg1);
								m=poten(8);// ADC convert value
								if (m==0) m=1;// let the least ADC value is 1 
								f=(unsigned int)1/(1/12600+m*0.00035+0.000089);;// caculate sine wave frequency
								if ((m<=60)&&(m>=30))f=f-1;// slightly adjust frequency
								if ((m<=20)&&(m>=10))f=f-4;// slightly adjust frequency
								if ((m>5)&&(m<10) )f=f-5;// slightly adjust frequency
								if(m==5) f=f-6;// slightly adjust frequency
								if(m==4) f=f-7;// slightly adjust frequency
								if(m==3) f=f-7;// slightly adjust frequency
								if (m==2) f=f+13;// slightly adjust frequency 
								sprintf(msg2,"%10d Hz",f);
								LCD_Line2(msg2);// show frequency
if (SWITCH_1==0)
{
switch_release();//wait for RA5 release
	return 2;// if RA5 pressed goto wavetype function
 }
								}
								while(SWITCH_0 == 1);
							    switch_release();//wait for RB0 release
								sinewave(m);//output sine wave
							    switch_release();//wait for RA5 release
								return 3;// if RA5 pressed goto frequency range function
	    break;
		case 2:
								do
								{
									sprintf(msg1,"Range:6~581 Hz");
		                    	LCD_Line1(msg1);
								m=poten(8);// ADC convert value
								if (m==0) m=1;// let the least ADC value is 1 
							 	f=(unsigned int) 1/ (1/847 + m*0.00057+0.001230); //caculate and slightly adjust triangle wave frequency
								if (m==1) f=f+26;//caculate and slightly adjust triangle wave frequency
								if (m==2) f=f+20;//caculate and slightly adjust triangle wave frequency
								if (m==3) f=f+12;//caculate and slightly adjust triangle wave frequency
								if (m==4) f=f+10;//caculate and slightly adjust triangle wave frequency
								if (m==5) f=f+7;//caculate and slightly adjust triangle wave frequency
								if ((m>=6)&&(m<=8)) f=f+5;//caculate and slightly adjust triangle wave frequency
								if (m==9) f=f+4;//caculate and slightly adjust triangle wave frequency
								if ((m>=10)&& (m<=13)) f=f+3;//caculate and slightly adjust triangle wave frequency
								if ((m>=13)&&(m<=17)) f=f+2;//caculate and slightly adjust triangle wave frequency
								if ((m>=18)&&(m<=50)) f=f+1;//caculate and slightly adjust triangle wave frequency
							sprintf(msg2,"%10d Hz",f);
								LCD_Line2(msg2);// show frequency
if (SWITCH_1==0)
{
	switch_release();//wait for RA5 release
	return 2;// if RA5 pressed goto wavetype function
 }
								}
								while(SWITCH_0 == 1);
								switch_release();//wait for RB0 release
								triwave(m);// output triangle wave
								switch_release();//wait for RA5 release
								return 3;// if RA5 pressed goto frequency range function
		break;
		case 3:
								do
								{
								sprintf(msg1,"Range:5~676 Hz");
		                    	LCD_Line1(msg1);
								m=poten(8);// ADC convert value
								if (m<=1) m=2;// let the least ADC value is 2
							 	f=(unsigned int) 1/ (1/15600 + m*0.000709+0.00007);//caculate  sawtooth wave frequency
								if ((m==2)||(m==3)) f=f+4;//caculate and slightly adjust sawtooth wave frequency
								if (m==4) f=f+1;//caculate and slightly adjust sawtooth wave frequency
							sprintf(msg2,"%10d Hz",f);
								LCD_Line2(msg2);// show frequency
							
if (SWITCH_1==0)
{
	switch_release();//wait for RA5 release
	return 2;// if RA5 pressed goto wavetype function
 }								
								}
								while(SWITCH_0 == 1);
								switch_release();//wait for RB0 release
								sawtooth(m);//output sawtooth wave
								switch_release();//wait for RA5 release
								return 3;// if RA5 pressed goto frequency range function
		break;
		case 4:
								do
								{
								sprintf(msg1,"Range:102~7690Hz");
		                    	LCD_Line1(msg1);
								m=poten(8);// adc convert value
								if (m==0) m=1;// let the least ADC value is 1
							 if ((m>=140)&&(m<=255)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-0.5;//caculate and slightly adjust square wave frequency
							 if ((m>=101)&&(m<=139)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-1.5;//caculate and slightly adjust square wave frequency
							if ((m>=70)&&(m<=100)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-2.5;//caculate and slightly adjust square wave frequency
							if ((m>=64)&&(m<=69)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-3.5;//caculate and slightly adjust square wave frequency
							if ((m>=55)&&(m<=63)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-4.5;//caculate and slightly adjust square wave frequency
							if ((m>=46)&&(m<=54)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-5.5;//caculate and slightly adjust square wave frequency
							if ((m>=45)&&(m<=43)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-6.5;//caculate and slightly adjust square wave frequency
							if ((m>=40)&&(m<=42)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-7.5;//caculate and slightly adjust square wave frequency
							if ((m>=30)&&(m<=40)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-9.5;//caculate and slightly adjust square wave frequency
							if ((m>=20)&&(m<=29)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-11.5;//caculate and slightly adjust square wave frequency
							if ((m>=10)&&(m<=19)) f=(unsigned int) 1/ (1/11400 + m*0.0000376+0.000075)-2.5*m;//caculate and slightly adjust square wave frequency
							if (m==10) f=2131;//caculate and slightly adjust square wave frequency
							if (m==9) f=2313;//caculate and slightly adjust square wave frequency
							if (m==8) f=2540;//caculate and slightly adjust square wave frequency
							if (m==7) f=2810;//caculate and slightly adjust square wave frequency
							if (m==6) f=3140;//caculate and slightly adjust square wave frequency
							if (m==5) f=3570;//caculate and slightly adjust square wave frequency
							if (m==4) f=4130;//caculate and slightly adjust square wave frequency
							if (m==3) f=4900;//caculate and slightly adjust square wave frequency
							if (m==2) f=6020;//caculate and slightly adjust square wave frequency
							if (m==1) f=7690;	//caculate and slightly adjust square wave frequency
							sprintf(msg2,"%10d Hz",f);
								LCD_Line2(msg2);// show frequency
if (SWITCH_1==0)
{
	switch_release();//wait for RA5 release
	return 2;// if RA5 pressed goto wavetype function
 }									
								}
								while(SWITCH_0 == 1);
								switch_release();//wait for RB0 release
								squarewave(m);//output square wave
								switch_release();//wait for RA5 release
								return 3;// if RA5 pressed goto frequency range function
		break;
        default: 
		break;
	}

}