Exemple #1
0
int main(void){ // Real Lab13 
	// for the real board grader to work 
	// you must connect PD3 to your DAC output
  TExaS_Init(SW_PIN_PE3210, DAC_PIN_PB3210,ScopeOn); // activate grader and set system clock to 80 MHz
// PortE used for piano keys, PortB used for DAC        
  Sound_Init(); // initialize SysTick timer and DAC
  Piano_Init();
  EnableInterrupts();  // enable after all initialization are done
	DAC_Init();
	
  while(1){ volatile unsigned long current_switch;
	current_switch = Piano_In();
	if (current_switch == 0x01){
	EnableInterrupts();
	Sound_Tone(4780);
	}
	else if (current_switch == 0x02){
	EnableInterrupts();
	Sound_Tone(4259);
	}
	else if (current_switch == 0x04){
	EnableInterrupts();
	Sound_Tone(3794);
	}
	else if (current_switch == 0x08){
  EnableInterrupts();
	Sound_Tone(3189);
	}
//	else if (current_switch == 0x00){
//	Sound_Off();
//	DisableInterrupts();
//	}
	delay(10);
  }  
}	
Exemple #2
0
// *************************** Capture image dimensions out of BMP**********
int main(void){
  TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
  Output_Init();
	ADC0_Init();
	DAC_Init();
	SysTick_Init();
	Menu_Init();
	Sound_Init();
	UART1_Init();
	
	Button0_Init();
	Timer0_Init(Play, 80000000/11025);	// 11.025 kHz 80000000/11025
	Timer1_Init(Master_Funk,  80000000/60);
	//Timer2_Init(SomeUART function, high speed); //for UART

 /* ST7735_FillScreen(0x0000);            // set screen to black
  ST7735_SetCursor(1, 1);
  ST7735_OutString("GAME OVER");
  ST7735_SetCursor(1, 2);
  ST7735_OutString("Nice try,");
  ST7735_SetCursor(1, 3);
  ST7735_OutString("Earthling!");
  ST7735_SetCursor(2, 4);
  LCD_OutDec(1234);	 */
  while(1){							
  } 
}
void gli_initialize_sound(void)
{
    if (gli_conf_sound == 1)
    {
        if (SDL_Init(SDL_INIT_AUDIO) == -1)
        {
            gli_strict_warning("SDL init failed\n");
            gli_strict_warning(SDL_GetError());
            gli_conf_sound = 0;
            return;
        }
        if (Sound_Init() == -1)
        {
            gli_strict_warning("SDL Sound init failed\n");
            gli_strict_warning(Sound_GetError());
            gli_conf_sound = 0;
            return;
        }
        Sound_AudioInfo *audio;
        audio = malloc(sizeof(Sound_AudioInfo));
        audio->format = MIX_DEFAULT_FORMAT;
        audio->channels = 2;
        audio->rate = 44100;
        output = audio;
        if (Mix_OpenAudio(output->rate, output->format, output->channels, 4096) == -1)
        {
            gli_strict_warning("SDL Mixer init failed\n");
            gli_strict_warning(Mix_GetError());
            gli_conf_sound = 0;
            return;
        }
        int channels = Mix_AllocateChannels(SDL_CHANNELS);
        Mix_GroupChannels(0, channels - 1 , FREE);
    }
}
Exemple #4
0
bool initialize()
{
    if (_sdlInitialized)
        return true;

    do {
        // First initialize the mothership.
        bool audioInitDone =
            ((SDL_WasInit(SDL_INIT_AUDIO) & SDL_INIT_AUDIO) == SDL_INIT_AUDIO);
        if (!audioInitDone && SDL_Init(SDL_INIT_AUDIO) != 0)
            break;
        // Then it's allied forces.
        if (!Sound_Init()) {
            SDL_Quit();
            break;
        }
        // We register shutdown() via atexit, so that even if the user forgets
        // about calling shutdown() explicitly, we still perform a nice
        // cleanup.
        if (!_exitHookRegistered) {
            _exitHookRegistered = (atexit(shutdown) == 0) ? 1 : 0;
        }
        // Done.
        _sdlInitialized = true;
        return true;
    } while (false);

    // Once we get to this point, an error has occured.
    return false;
}
  void Audio_Init(void) {
    Sound_Init(); // Init SDL_Sound
    // output_decoders();

    SDL_AudioSpec* spec = new SDL_AudioSpec;
    spec->freq = 22050;
    spec->format = AUDIO_S16SYS;
    spec->channels = 2;
    spec->samples = 1024;

    sound = new Sound::System(spec);

    spec->userdata = sound;
    spec->callback = sound->GetCallback();

		SDL_AudioSpec obtained;

    if(SDL_OpenAudio( spec, &obtained ) != 0) {
      fprintf(stderr, "[error] %s\n", SDL_GetError());
      sound->SetStatus(Sound::eUninitialized);
    } else {
      sound->SetStatus(Sound::eInitialized);
			/*
			fprintf(stderr, "[sound] frequency: %d\n", obtained.freq);
			fprintf(stderr, "[sound] format: %d\n", obtained.format);
			fprintf(stderr, "[sound] channels: %d\n", obtained.channels);
			fprintf(stderr, "[sound] silence: %d\n", obtained.silence);
			fprintf(stderr, "[sound] buffer in samples: %d\n", obtained.samples);
			fprintf(stderr, "[sound] buffer in bytes: %d\n", obtained.size);
			*/
    }
    sound->SetMixMusic(gSettingsCache.playMusic);
    sound->SetMixFX(gSettingsCache.playEffects);
  }
int main(void){
	DisableInterrupts();
  TExaS_Init(SSI0_Real_Nokia5110_Scope);  // set system clock to 80 MHz
	Random_Init(1);
  Nokia5110_Init();
	PF1Init();
  //SysTick_Init(2666666); //Initialize SysTick with 30 Hz interrupts
	SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed
  Nokia5110_ClearBuffer();
	Nokia5110_DisplayBuffer();      // draw buffer
	ADC0_Init();
	Game_Init();
	SwitchLed_Init();
	Sound_Init();
	Timer2_Init(&Sound_Play,7256); //11.025 kHz. 80,000,000/11,025 cycles, which is about 7256
	GameOverFlag = 0;
	EnableInterrupts();
	
  while(1){
		while(Semaphore==0){};
    Semaphore = 0;
		if(GameOverFlag){
			State_GameOver();
		}
		else{
			Draw_GameFrame(); // update the LCD
		}	
		if((GameOverFlag == 0) && (Check_GameOver())){ //just detected game over
			Delay100ms(2);//Delay 200ms
			GameOverFlag = Check_GameOver();
			//SysTick_Init(2666666);//Re-initialize with 30 Hz interrupt
			SysTick_Init(2666666*4); //Increased period by 4 for actual hardware to make the game run at a playable speed
		}
	}
}
int main(void){// activate grader and set system clock to 80 MHz
	unsigned long NumberOfPresses = 0;   // store the number of presses
  unsigned long LastInput = 0; // store the last input of Switch here
	
  TExaS_Init(SW_PIN_PA3, HEADPHONE_PIN_PA2,ScopeOn); 
  Sound_Init();         
  EnableInterrupts();   // enable after all initialization are done
		
  while(1){
    // main program is free to perform other tasks
    // do not use WaitForInterrupt() here, it may cause the TExaS to crash
    // perform other tasks - Read the input over and over again:
    Switch = GPIO_PORTA_DATA_R & 0x08;  // read the switch from PA3
    if (Switch != 0 && Switch != LastInput) {
      // if the switch is pressed, and last time it was released:
      NumberOfPresses++;    
      // the number of the ACTUAL press increase by 1
    }
    LastInput = Switch;       // save the current input for next time
    if (NumberOfPresses%2 == 0) {
      // if the number of press is even
      // (those presses at the 0, 2nd, 4th, 6th,... time)
      GPIO_PORTA_DATA_R &= ~0x04;
      // then turn off PA2
    } else {
    // if the number of press is odd
    // (those presses at the 1st, 3rd, 5th, 7th,... time)
    WaitForInterrupt(); 
    // then periodically interrupt the system each 880 Hz
    // the SysTick will automatically
    // trigger itself every (1 s)/(880 Hz) = 1.13636 ms
    }
  }
}
Exemple #8
0
int main(void)
{ 
 	unsigned long input= 0;     
  
	PLL_Init();
	Sound_Init(); // initialize SysTick timer and DAC
  Piano_Init();
	EnableInterrupts();  // enable after all initialization are done

  while(1)
	{                
// input from keys to select tone
		input= Piano_In();

		switch (input)
		{
			case 0x01:
				Sound_Tone(C);
				break;
			case 0x10:
				Sound_Tone(D);
				break;
		  case 0x04:
				Sound_Tone(E);
				break;
			case 0x08:
				Sound_Tone(G);
				break;
			default:
				Sound_Off();
				break;
		}
  }       
}
Exemple #9
0
int main(void){      
  TExaS_Init(SW_PIN_PE3210,DAC_PIN_PB3210,ScopeOn);    // bus clock at 80 MHz
	//Timer0A_Init(&songTask, F80HZ);
  Piano_Init();
  Sound_Init(0);
	DAC_Init();
	Heartbeat_Init();
  // other initialization
  EnableInterrupts();
	uint32_t input;
  while(1){  
			GPIO_PORTF_DATA_R ^= 0x04;
			input = Piano_In();
			if (input == 0x04){
				Sound_Play(A);
			}
			else if (input == 0x02){
				Sound_Play(C);
			}
			else if (input == 0x01){
				Sound_Play(Eb);
			}
			else if (input == 0x07){
				Sound_Play(A);
			}
			else {
				Sound_Play(0);
			}
				
  }         
} 
Exemple #10
0
int main(void){ // for the real board grader to work, you must connect PD3 to your DAC output
  int piano; // to read current piano keys
	int prevPiano; // to store piano keys in prev cycle
	
	TExaS_Init(SW_PIN_PE3210, DAC_PIN_PB3210,ScopeOn); // activate grader and set system clock to 80 MHz  
  Sound_Init(); // initialize SysTick timer and DAC
  Piano_Init();
  EnableInterrupts();  // enable after all initialization are done
	
	while(1){ 
		piano = Piano_In();
	
		if(piano != prevPiano){ // only react if piano keys pressed
			if(piano == 0x00)
				Sound_Off();
			else if(piano == 0x01)
				Sound_Tone(2389);
			else if(piano == 0x02)
				Sound_Tone(2128);
			else if(piano == 0x04)
				Sound_Tone(1896);
			else if(piano == 0x08)
				Sound_Tone(1594);
			delay(10);
		}
		
		prevPiano = piano;
	}
}
Exemple #11
0
// 3. Subroutines Section
// MAIN: Mandatory for a C Program to be executable
int main(void){
  PLL_Init();                 // 80 MHz
  Sound_Init();               // initialize output and interrupts
  EnableInterrupts();
  while(1){                   // interrupts every 500us
    WaitForInterrupt();
  }
}
Exemple #12
0
void *sound_init(void)
{
static sstate data;

	if (!Sound_Init())
	{
		fprintf(stderr, "Sound_Init() failed: %s.\n", Sound_GetError());
		SDL_Quit();
	}

	memset(&data, 0, sizeof(data));
	return &data;
}
Exemple #13
0
int main(void){ // Real Lab13 
	// for the real board grader to work 
	// you must connect PD3 to your DAC output
  TExaS_Init(SW_PIN_PE3210, DAC_PIN_PB3210,ScopeOn); // activate grader and set system clock to 80 MHz
// PortE used for piano keys, PortB used for DAC        
  Sound_Init(); // initialize SysTick timer and DAC
  Piano_Init();
  EnableInterrupts();  // enable after all initialization are done
  while(1){                
// input from keys to select tone

  }
            
}
bool Sound_initialization(void)
{
    char SoundcardName[256];
	int audio_rate = 44100;
	int audio_channels = 2;
	int audio_bufsize = AUDIO_BUFFER;
	Uint16 audio_format = AUDIO_S16;
	SDL_version compile_version;

	sound_enabled=true;
	fprintf (stderr, "Initializing SDL_mixer.\n");

	int flags = MIX_INIT_OGG | MIX_INIT_MOD;
	int initted = Mix_Init(flags);
	if (initted & flags != flags) {
		printf("Mix_Init: Failed to init required ogg and mod support!\n");
		printf("Mix_Init: %s\n", Mix_GetError());
		sound_enabled = false;
		return false;
	}

	if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_bufsize))  {
	  fprintf (stderr, "Unable to open audio: %s\n", Mix_GetError());
	  sound_enabled=false;
	  fprintf (stderr, "Running the game without audio.\n");
	  return false;	
	} /* if */ 

	SDL_AudioDriverName (SoundcardName, sizeof (SoundcardName));
	Mix_QuerySpec (&audio_rate, &audio_format, &audio_channels);
	fprintf (stderr, "    opened %s at %d Hz %d bit %s, %d bytes audio buffer\n",
			 SoundcardName, audio_rate, audio_format & 0xFF,
			 audio_channels > 1 ? "stereo" : "mono", audio_bufsize);
	MIX_VERSION (&compile_version);
	fprintf (stderr, "    compiled with SDL_mixer version: %d.%d.%d\n",
			 compile_version.major,
			 compile_version.minor,
			 compile_version.patch);
	fprintf (stderr, "    running with SDL_mixer version: %d.%d.%d\n",
			 Mix_Linked_Version()->major,
			 Mix_Linked_Version()->minor,
			 Mix_Linked_Version()->patch);

	Sound_Init();
	Mix_HookMusic(myMusicPlayer, 0);

	return true;
} /* Sound_init */ 
void startTune(char tune)
{

	int song = atoi(&tune) - 1;
 
	stopTune();
	Tone = 0;
	Tempo = 0;
	Duration = 0;

	sendFString(TEXT_SONG_TBL[song]);     // Send the song title to the PC
	sendChar('\r');
            
	pSong=(int*)pgm_read_word(&Songs[song]); // looks too complicated..

	Sound_Init();
}
Exemple #16
0
int main(void)
{
	PLL_Init();   // 80 MHz
	ADCTimerINT_Init(7999);		// 10KHz
	EnableInterrupts(); // Enable global interrupt register flag 
	UART0_Init();
	TLV5618_Init();
	Sound_Init();
	UART0_TxString("Hi, Sir");
	ToggleDebug();
	//Sound_Tone(4780);
	while(1)
	{
		 //delay(20);
		WaitForInterrupt();
	}
}
Exemple #17
0
int main(void){ // Real Lab13 
	// for the real board grader to work 
	// you must connect PD3 to your DAC output
  TExaS_Init(SW_PIN_PE3210, DAC_PIN_PB3210,ScopeOn); // activate grader and set system clock to 80 MHz
// PortE used for piano keys, PortB used for DAC        
  Sound_Init(); // initialize SysTick timer and DAC
  Piano_Init();
  EnableInterrupts();  // enable after all initialization are done
  while(1){         
		
		/*DAC_Out(wave[n]);     // your code to output to the DAC
    delay(1000); // wait 1s (later change this to 1ms)
    n = (n+1)&0x1F;*/
		
		switch(Piano_In()) {
			case C:
				delay(delayValue);
				//EnableInterrupts();
				//Sound_Tone(523.251);
				Sound_Tone(C0);
				break;
			case D:
				//EnableInterrupts();
				delay(delayValue);
				Sound_Tone(D0);
				break;
			case E:
				//EnableInterrupts();
				delay(delayValue);
				Sound_Tone(E0);
				break;
			case G:
				//EnableInterrupts();
				delay(delayValue);
				Sound_Tone(G0);
				break;
			default:
				delay(delayValue);
				Sound_Off();
				//DisableInterrupts();
				break;
		}
	
	}
            
}
int main(void) {
	
	Clock_Init();
	PortG_Init();
	Sound_Init();	
	OLED_Init();	
	LED_Blink();
	SysTickInt_Init();	
	IntMasterEnable();

	

	while(1) { 
		// SLEEP 
		}
	
}
Exemple #19
0
void main(void) {

  PLL_Init();   // Engaging PLL allows use to run 9S12 at 24MHz even in RUN mode
  DAC_Init(); 
  Piano_Init();
  Sound_Init();
  EnableInterrupts;
  Data = 0;
  for(ever) {
     Piano_In();
     PTP ^= 0x80;     // Heartbeat
  } 
  
  /* for(;;) {
    DAC_Out(Data); 
    Data = 0x0F&(Data+1);  
  }   */ 
}
int main(int argc, char **argv)
{
    int i;

    if (!Sound_Init())  /* this calls SDL_Init(SDL_INIT_AUDIO) ... */
    {
        fprintf(stderr, "Sound_Init() failed: %s.\n", Sound_GetError());
        SDL_Quit();
        return(42);
    } /* if */

    for (i = 1; i < argc; i++)  /* each arg is an audio file to play. */
        playOneSoundFile(argv[i]);

    /* Shutdown the libraries... */
    Sound_Quit();
    SDL_Quit();
    return(0);
} /* main */
Exemple #21
0
// PE=Switch controls (input), PB=DAC output
int main(void){      
  TExaS_Init(SW_PIN_PE3210,DAC_PIN_PB3210,ScopeOn);    // bus clock at 80 MHz
	

	/*unsigned long Data; // 0 to 15 DAC output
	//PLL_Init(); // like Program 4.6 in the book, 80 MHz
	DAC_Init();
	for(;;) {
		DAC_Out(Data);
		Data = 0x0F&(Data+1); // 0,1,2...,14,15,0,1,2,...
	}*/

	Piano_Init();
	EnableInterrupts();
	Sound_Init(0);
  // other initialization

	Sound_Play(0);
	while(1){}
}
/*----------------------------------------------------------------------------
  MAIN function
 *----------------------------------------------------------------------------*/
int main (void) {

	Init_Debug_Signals();
	Init_RGB_LEDs();
	Sound_Init();	
	// Sound_Disable_Amp();
	Play_Tone();
	
	TFT_Init();
	TFT_Text_Init(1);
	TFT_Erase();
	TFT_Text_PrintStr_RC(0,0, "Test Code");

/*
	Graphics_Test();
	while (1) 
		;
*/
	
//	TFT_TS_Calibrate();
//	TFT_TS_Test();

	TFT_Text_PrintStr_RC(1,0, "Accel...");

	i2c_init();											// init I2C peripheral
	if (!init_mma()) {							// init accelerometer
		Control_RGB_LEDs(1,0,0);			// accel initialization failed, so turn on red error light
		while (1)
			;
	}
	TFT_Text_PrintStr_RC(1,9, "Done");

	Play_Waveform_with_DMA();

	Delay(70);

	os_sys_init(&Task_Init);

	while (1)
		;
}
Exemple #23
0
int main(int argc, char *argv[])
{
    if (argc != 2) {
        fprintf(stderr, "usage: %s <filename>\n", argv[0]);
        return 1;
    }

    if (SDL_Init(SDL_INIT_AUDIO) != 0) {
        fprintf(stderr, "Error: %s\n", SDL_GetError());
        return 1;
    }

    if (Sound_Init() == 0) {
        fprintf(stderr, "Error: %s\n", Sound_GetError());
        return 1;
    }

    SDL_RWops* rw = SDL_RWFromFile(argv[1], "r");
    if (rw == NULL) {
        fprintf(stderr, "Error: %s\n", SDL_GetError());
        return 1;
    }

    Sound_AudioInfo wantedFormat;
    wantedFormat.channels = 2;
    wantedFormat.rate = 44100;
    wantedFormat.format = AUDIO_S16LSB;

    Sound_Sample* sample = Sound_NewSample(rw, 0, &wantedFormat, 8192);
    if (sample == 0) {
        fprintf(stderr, "Error: %s\n", Sound_GetError());
        return 1;
    }

    Sound_DecodeAll(sample);
    printf("Format: %s\n", sample->decoder->description);
    printf("Decoded %d bytes of data.\n", sample->buffer_size);
    Sound_FreeSample(sample);

    return 0;
}
void main()
{
     Sound_Init(&PORTC, 0);        // Init Sound
     while(PORTA.F4==1);
     Sound_Play(2000,50);           // 2 kHz sound ON RC0
     Forward(255);                 // Call Forward
     Delay_ms(2000);

     Sound_Play(2000,50);           // 2 kHz sound ON RC0
     S_Left(255);                  // Call Spin Left
     Delay_ms(800);

     Sound_Play(2000,50);           // 2 kHz sound ON RC0
     Forward(255);                 // Call Forward
     Delay_ms(2000);

     Sound_Play(2000,50);           // 2 kHz sound ON RC0
     S_Right(255);                 // Call Spin Right
     Delay_ms(800);

     Sound_Play(2000,50);           // 2 kHz sound ON RC0
     Forward(255);                 // Call Forward
     Delay_ms(2000);

     Sound_Play(2000,50);           // 2 kHz sound ON RC0
     S_Left(255);                  // Call Spin Left
     Delay_ms(800);

     Sound_Play(2000,50);           // 2 kHz sound ON RC0
     Backward(255);                // Call Backward
     Delay_ms(1000);

     Sound_Play(2000,50);           // 2 kHz sound ON RC0
     Motor_Stop();                 // Stop all

}
Exemple #25
0
int main()
{
    char carac;
    
    TRISD = 0;
    TRISE = 0;
    TRISA = 0;
    TRISB = 0b00000111;
    TRISC = 0b00000001;

    I2C1_Init(100000);
    Delay_ms(100);
    UART1_Init(19200);
    Delay_ms(100);

    escreve(0,11);

    init_timer();//começa a escutar as teclas

    adcon1 = 0x0F;

    preenche_mapa_digitos();
    limpa_display();
        
    Sound_Init(&PORTC, 2);//PORTC.F2

    limpa_display();
    popula_displays_palavra("CLIC");
    carac = le_carac();
    while(carac == 255)
    {
       semente++;
       carac = le_carac();
    }
    limpa_display();

    if (carac == '1')
    {
       escreve(127, 0);
       pontuacao_record = 0;
       popula_displays_palavra("NO");
       Delay_ms(1000);
       popula_displays_palavra("RECO");
       Delay_ms(1500);
    }
    else
    {
       pontuacao_record = le(127);
       popula_displays_palavra("RECO");
       Delay_ms(1000);
       limpa_display();
       Delay_ms(500);
       popula_displays_num(pontuacao_record);
       Delay_ms(1500);
    }
    
    srand(semente);
    limpa_display();
    Delay_ms(500);
    popula_displays_palavra("PLAY");
    Delay_ms(1500);
       
    while(!errou)
    {
       sequencia_num[nivel_atual] = rand() & 0b00000011;
       imprime_sequencia_num();
       errou = !le_sequencia_jogador();

       if (errou)
       {
         limpa_display();
         popula_displays_palavra("FAIL");
         toca_som(300, 450);
         toca_som(600, 450);
         Delay_ms(2000);
         
         popula_displays_palavra("SCOR");
         Delay_ms(1500);
         popula_displays_num(nivel_atual);
         Delay_ms(1500);
         limpa_display();
         
         if (nivel_atual > pontuacao_record)
         {
          escreve(127, nivel_atual);//novo record
          popula_displays_palavra("UHUL");
          Delay_ms(1000);
          popula_displays_palavra("NOVO");
          Delay_ms(1000);
          popula_displays_palavra("RECO");
          Delay_ms(1000);
          limpa_display();
         }
       }
       else
       {
         nivel_atual++;
         limpa_display();
         popula_displays_palavra("GOOD");
         Delay_ms(1000);
       }
    }
}
Exemple #26
0
void GlobalInitialize()
{
    InitCommonControls(); 

/*	if(SDL_WasInit(SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_VIDEO) == 0)
	{
		if (SDL_InitSubSystem(SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_VIDEO) < 0)
			report_error("Couldn't init SDL");
	}
*/
		
	if(SDL_Init(SDL_INIT_EVERYTHING)<0) 
        report_error("Couldn't init SDL");
	
   if (!Sound_Init()) report_error("Couldn't init SDL_Sound");


	if(SDLNet_Init()<0)	report_error("Couldn't init SDL_Net");

	GLOBAL.os_version=check_OS();


    TTY.ThreadExitEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
    if (TTY.ThreadExitEvent == NULL)
        report_error("CreateEvent (Thread exit event)");       

	init_devicetype();
	TTY.COMDEV=INVALID_HANDLE_VALUE;
	TTY.CONNECTED=FALSE;
	TTY.read_pause=TRUE;
	TTY.amount_to_write=0;
	TTY.writeMutex=	CreateMutex( NULL, FALSE, NULL ); 

	TTY.FLOW_CONTROL=0;

	PACKET.readstate=0;
	PACKET.info=0;
	PACKET.requestedinfo=0;

	GLOBAL.objects=0;	actobject=NULL; actconnect=NULL;
	GLOBAL.tool_left=400;GLOBAL.tool_top=100;
	GLOBAL.tool_right=800;GLOBAL.tool_bottom=400;
	GLOBAL.anim_left=20;GLOBAL.anim_right=420;
	GLOBAL.anim_top=350;GLOBAL.anim_bottom=700;
	GLOBAL.design_left=20;GLOBAL.design_right=500;
	GLOBAL.design_top=20;GLOBAL.design_bottom=400;
	GLOBAL.startup=0; GLOBAL.autorun=0; GLOBAL.configfile[0]=0;
	GLOBAL.syncloss=0;
	GLOBAL.dialog_interval=DIALOG_UPDATETIME;
	GLOBAL.draw_interval=DRAW_UPDATETIME;
	GLOBAL.neurobit_available=0;
	GLOBAL.emotiv_available=0;
	GLOBAL.use_cv_capture=0;
	strcpy(GLOBAL.emotivpath,"C:\\Program Files (x86)\\Emotiv Development Kit_v1.0.0.3-PREMIUM");

	GLOBAL.loading=false;
	GLOBAL.read_tcp=0;
	GLOBAL.packet_parsed=0;
	GLOBAL.actcolumn=0;
	GLOBAL.running=false;
	GLOBAL.showdesign=TRUE;
	GLOBAL.showtoolbox=-1;
	GLOBAL.session_length=0;
	GLOBAL.session_start=0;
	GLOBAL.session_end=0;
	GLOBAL.session_loop =0 ;
	GLOBAL.session_sliding=0;

	GLOBAL.main_maximized=0;
	GLOBAL.minimized=0;
	GLOBAL.run_exception=0;
	GLOBAL.fly=0;

	GLOBAL.P3ALC1=12;
	GLOBAL.P3ALC2=12;

	TIMING.timerid=0;

	CAPTFILE.filetype=FILE_INTMODE;
	CAPTFILE.filehandle=INVALID_HANDLE_VALUE;
	CAPTFILE.file_action=0;
	CAPTFILE.do_read=0;
	CAPTFILE.do_write=0;
	CAPTFILE.length=0;
	CAPTFILE.start=0;
	strcpy(CAPTFILE.filename,"none");

	ghWndAnimation=NULL;
    ghWndToolbox=NULL;
    ghWndSettings=NULL;
    ghWndDesign=NULL;
	copy_object=NULL;

	init_draw();
	init_midi();

	load_settings();
	
	TIMING.timerid=0;
	TIMING.pause_timer=0;
	init_system_time();

	write_logfile("application init successful.");
    return ;
}
Exemple #27
0
//GAME
int main(void){unsigned long i=64,j=0;
  PLL_Init();  // Set the clocking to run at 80MHz from the PLL.
  LCD_Init();  // Initialize LCD
	Piano_Init();
	Sound_Init();
	ADC_Init();		//initialize ADC
	ADC_SetChannel(1); //PE2
	
	Missile_Init();
	Enemy1_Init();
	
  LCD_Goto(10,0);
  LCD_SetTextColor(255,0,0); // yellow= red+green, no blue
  printf("Welcome to Pokemon Capture!");
	delay_long();
	LCD_DrawFilledRect(0,0,320,80,0x00);
	delay_short();
	
	while((GPIO_PORTE_DATA_R&0x01)==0){
		LCD_Goto(10,0);
		printf("Press any button to begin...");
		delay_blink();
		LCD_DrawFilledRect(0,0,320,80,0x00);
		delay_blink();
	}
	delay_short();
	
	LCD_SetTextColor(255,255,0);
	LCD_Goto(0,0);
	printf("Tragedy has struck Pallet Town! Four Pokemon have    escaped from their Pokeballs, and it's your job to   put them back where they belong.");
	delay_long();
	delay_long();
	delay_long();
	LCD_DrawFilledRect(0,0,320,80,0x00);
	delay_short();
	
	LCD_Goto(0,0);
	printf("Use the slider to aim, and when you think you have a shot, press the button to throw your Pokeball.");
	delay_long();
	delay_long();
	delay_long();
	LCD_DrawFilledRect(0,0,320,80,0x00);
	delay_blink();
	
	LCD_Goto(0,0);
	printf("You only have so many Pokeballs, so be smart where   you throw them!");
	delay_long();
	delay_long();
	LCD_DrawFilledRect(0,0,320,80,0x00);
	delay_short();
	
	LCD_Goto(0,0);
	printf("Good luck!");
	delay_long();
	LCD_DrawFilledRect(0,0,320,80,0x00);
	delay_short();
	
	LCD_SetTextColor(255,0,0);
	LCD_Goto(0,0);
	printf("Captured:");
	
	LCD_SetTextColor(0,255,0);
	LCD_Goto(14,0);
	printf("Pokeballs Left:");
	
	LCD_SetTextColor(0,0,255);
	LCD_Goto(35,0);
	printf("Accuracy:");
  LCD_DrawLine(10,16,310,16,BURNTORANGE);
  
  Timer2_Init(7256); // 11kHz
	SysTick_Init(2666667);	//30 Hz
  EnableInterrupts();
	
	Pokeballs = 25;
  while(1){
		if((25-(hits+misses))==0){
			if(kill!=4){
				DisableInterrupts();
				LCD_SetTextColor(255,0,0);
				
				LCD_DrawFilledRect(0,0,320,80,0x00);
				delay_short();
				
				LCD_Goto(0,0);
				printf("Sorry, you were not able to catch all the Pokemon.");
				delay_long();
				delay_long();
				LCD_DrawFilledRect(0,0,320,80,0x00);
				delay_short();
				
				LCD_Goto(0,0);
				printf("Try again.");
				delay_long();
				LCD_DrawFilledRect(0,0,320,80,0x00);
				delay_short();
				
				while(1){
				LCD_Goto(0,0);
				printf("Press RESET to play again.");
				delay_blink();
				LCD_DrawFilledRect(0,0,320,80,0x00);
				delay_blink();
				}
			}
		}
				
		if(kill==4){
			DisableInterrupts();
			LCD_SetTextColor(0,255,255);
			
			LCD_DrawFilledRect(0,0,320,80,0x00);
			delay_short();
			
			LCD_Goto(0,0);
			printf("Congratulations! You have captured all the Pokemon!");
			delay_long();
			delay_long();
			LCD_DrawFilledRect(0,0,320,80,0x00);
			delay_short();
			
			LCD_Goto(0,0);
			printf("You are now a Pokemon Master!");
			delay_long();
			delay_long();
			LCD_DrawFilledRect(0,0,320,80,0x00);
			delay_short();
			
			while(1){
				LCD_Goto(0,0);
				printf("Press RESET to play again.");
				delay_blink();
				LCD_DrawFilledRect(0,0,320,80,0x00);
				delay_blink();
			}
		}
		
		
    if(Semaphore){
			
			LCD_SetTextColor(255,0,0);
			LCD_Goto(10,0);
			LCD_PrintInteger(kill);
			
			LCD_SetTextColor(0,255,0);
			LCD_Goto(30,0);
			LCD_PrintInteger(25-(hits+misses));
			if((25-(hits+misses))<10){
				LCD_Goto(31,0);
				printf(" ");
			}
			
			LCD_SetTextColor(0,0,255);
			LCD_Goto(45,0);
			LCD_PrintInteger(hits/(hits+misses));
			
			//draw ship
			if(Ship_Position>288){
				Ship_Position=288;
			}
      LCD_DrawBMP(PlayerShip,Ship_Position,220);
			LCD_DrawFilledRect(0,220,Ship_Position,9,0x00);
			LCD_DrawFilledRect(Ship_Position+32,220,320-(Ship_Position+32),9,0x00);
			
			
      for(j=0;j<1;j++){
				if(Missile[j].life==1){
					LCD_DrawBMP(Missile[j].image, Missile[j].x, Missile[j].y);
				} else{
					LCD_DrawFilledRect(Missile[j].x,Missile[j].y,16,18,0x00);
				}
				if(Missile[j].y<=18){
					LCD_DrawFilledRect(Missile[j].x,Missile[j].y,16,18,0x00);
					Missile[j].life=0;
					misses++;
				}
			}
			
      for(i=0;i<4;i++){
				if(Enemy1[i].life!=0){
					LCD_DrawBMP(Enemy1[i].image,Enemy1[i].x,Enemy1[i].y);
				}
				else{
					LCD_DrawFilledRect(Enemy1[i].x,Enemy1[i].y,32,32,0x00);
				}
			}
			
			LCD_DrawFilledRect(0,17,320,4,0x00);
			
      Semaphore = 0;
    }
  }
}
void WavePlayBack(uint32_t AudioFreq)
{ 
  /*
  Normal mode description:
  Start playing the audio file (using DMA stream) .
  Using this mode, the application can run other tasks in parallel since 
  the DMA is handling the Audio Transfer instead of the CPU.
  The only task remaining for the CPU will be the management of the DMA 
  Transfer Complete interrupt or the Half Transfer Complete interrupt in 
  order to load again the buffer and to calculate the remaining data.  
  Circular mode description:
  Start playing the file from a circular buffer, once the DMA is enabled it 
  always run. User has to fill periodically the buffer with the audio data 
  using Transfer complete and/or half transfer complete interrupts callbacks 
  (EVAL_AUDIO_TransferComplete_CallBack() or EVAL_AUDIO_HalfTransfer_CallBack()...
  In this case the audio data file is smaller than the DMA max buffer 
  size 65535 so there is no need to load buffer continuously or manage the 
  transfer complete or Half transfer interrupts callbacks. */  

  AUDIO_PlaybackBuffer_Status Sound_BufferStatus;

  printf("WavePlayBack start\n");
  /* Start playing */

  audioBuffer = Sound_Get_AudioBuffer();
  Sound_Init();
  AudioPlayStart = 1;
  RepeatState =0;

  /* Initialize wave player (Codec, DMA, I2C) */
  WavePlayerInit(AudioFreq);
  AudioRemSize   = 0;

  STOPWATCH_START
  /* Get Data from USB Key */
  f_lseek(&fileR, WaveCounter);
  //f_read (&fileR, audioBuffer, _MAX_SS, &BytesRead);
  STOPWATCH_STOP
  CycleCounter_Print(0,0,0);

  /* Start playing wave */
  Audio_MAL_Play((uint32_t)audioBuffer, 2*_MAX_SS);
  LED_Toggle = 6;
  PauseResumeStatus = 2;
  Count = 0;

  while(HCD_IsDeviceConnected(&USB_OTG_Core))
  {
    /* Test on the command: Playing */
    if (Command_index == 0)
    {

      /* wait for DMA transfer complete */
      while((AUDIO_PlaybackBuffer_GetStatus(0) == FULL) &&  HCD_IsDeviceConnected(&USB_OTG_Core))
      {
#ifdef WAV_OLDCODE
        if (PauseResumeStatus == 0)
        {
          /* Pause Playing wave */
          LED_Toggle = 0;
          WavePlayerPauseResume(PauseResumeStatus);
          PauseResumeStatus = 2;
        }
        else if (PauseResumeStatus == 1)
        {
          LED_Toggle = 6;
          /* Resume Playing wave */
          WavePlayerPauseResume(PauseResumeStatus);
          PauseResumeStatus = 2;
        }
#else
        if(PauseResumeStatus != 2)
        {
          WAV_OpenNextFile();
          f_lseek(&fileR, WaveCounter);
          Sound_Init();
          PauseResumeStatus = 2;
        }
#endif
      }

      //#define SOUND_DIRECT_TEST
#ifndef	SOUND_DIRECT_TEST
      Sound_FillBuffer(&fileR);
#else
      Sound_BufferStatus = AUDIO_PlaybackBuffer_GetStatus(0);
      if(Sound_BufferStatus & LOW_EMPTY)
      {
        f_read (&fileR, audioBuffer, _MAX_SS, &BytesRead);
        Sound_BufferStatus = AUDIO_PlaybackBuffer_GetStatus(LOW_EMPTY);
      }
      if(Sound_BufferStatus & HIGH_EMPTY)
      {
        f_read (&fileR, audioBuffer+_MAX_SS/2, _MAX_SS, &BytesRead);
        Sound_BufferStatus = AUDIO_PlaybackBuffer_GetStatus(HIGH_EMPTY);
      }
#endif
    }
    else
    {
      WavePlayerStop();
      WaveDataLength = 0;
      RepeatState =0;
      break;
    }
    if(WaveDataLength == 0) {
      WaveDataLength = WAVE_Format.DataSize;
      f_lseek(&fileR, 44);
    }
  }
#if defined PLAY_REPEAT_OFF 
  RepeatState = 1;
  WavePlayerStop();
  if (Command_index == 0)
    LED_Toggle = 4;
#else 
  LED_Toggle = 7;
  RepeatState = 0;
  AudioPlayStart = 0;
  WavePlayerStop();
#endif

}
Exemple #29
0
void Hardware_Init() 
{
    HAL_Init();

    SystemClock_Config();

    __GPIOA_CLK_ENABLE();
    __GPIOB_CLK_ENABLE();
    __GPIOC_CLK_ENABLE();
    __GPIOD_CLK_ENABLE();
    __GPIOE_CLK_ENABLE();
    __GPIOF_CLK_ENABLE();
    __GPIOG_CLK_ENABLE();
    __DMA1_CLK_ENABLE();        // Для DAC1 (бикалка)
    
    __TIM6_CLK_ENABLE();        // Для отсчёта миллисекунд
    __TIM2_CLK_ENABLE();        // Для тиков
    __TIM7_CLK_ENABLE();        // Для DAC1 (бикалка)
    __DAC_CLK_ENABLE();         // Для бикалки
    __PWR_CLK_ENABLE();

    __SYSCFG_CLK_ENABLE();

    HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

    // Timer  /////////////////////////////////////////////////////////////////
    //RCC_PCLK1Config(RCC_HCLK_Div1);

    // Таймер для мс
    HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 2, 0);
    HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);

    if (HAL_TIM_Base_Init(&handleTIM6forTimer) != HAL_OK)
    {
        HARDWARE_ERROR
    }

    if (HAL_TIM_Base_Start_IT(&handleTIM6forTimer) != HAL_OK)
    {
        HARDWARE_ERROR
    }

    // Таймер для тиков
    TIM_HandleTypeDef tim2handle =
    {
        TIM2,
        {
            0,
            TIM_COUNTERMODE_UP,
            0xffffffff,
            TIM_CLOCKDIVISION_DIV1
        }
    };

    if (HAL_TIM_Base_Init(&tim2handle) != HAL_OK)
    {
        HARDWARE_ERROR
    }

    if (HAL_TIM_Base_Start(&tim2handle) != HAL_OK)
    {
        HARDWARE_ERROR
    }

    Sound_Init();
    
#ifdef SPI_ENABLE
    Panel_Init();
#endif

    FSMC_Init();

    ADC_Init();

    FDrive_Init();
    
// Analog and DAC programmable SPI ////////////////////////////////////////

    GPIO_InitTypeDef isGPIOG =
    {
        GPIO_PIN_2 | GPIO_PIN_3 | GPIO_PIN_5 | GPIO_PIN_7,     // GPIO_PIN_1 - для работы с дисплеем
        GPIO_MODE_OUTPUT_PP,
        GPIO_NOPULL,
        GPIO_SPEED_HIGH,
        GPIO_AF0_MCO
    };
    HAL_GPIO_Init(GPIOG, &isGPIOG);

    isGPIOG.Pin = GPIO_PIN_1;
    isGPIOG.Mode = GPIO_MODE_OUTPUT_PP;
    isGPIOG.Pull = GPIO_NOPULL;

    HAL_GPIO_Init(GPIOG, &isGPIOG);
    
    HAL_GPIO_WritePin(GPIOG, GPIO_PIN_1, GPIO_PIN_RESET);                   // PG1 - когда равен 1, чтение дисплея, в остальных случаях 0

    RTC_Init();
}
Exemple #30
0
/*
 * main.c
 */
int main(void) {
    //WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
	Clock_Init();
    WDT_Init();
    WX315_Init();
	led_init();
	Init_HC05();
	TimerA_Init();
	Key_Init();
	MQ2_Init();
	Ir_Init();
	Sound_Init();

//	//__bis_SR_register(LPM0_bits + GIE);
	_EINT();

	led0_off();//默认开蓝牙使能
	delay_ms(1000);

	while(1){
		if(temp_tx_flag==1){
			for(i=0;i<8;i++){
				UartPutchar(ch[i]);
			}
			temp_tx_flag=0;
		}
		if(flag_mq2==1){
			flag_mq2=0;
			UartPutchar('V');//Vapour 烟雾传感器 有漏气 向APP发送指令'V'
		}
		if(flag_ir==1){
			flag_ir=0;
			UartPutchar('I');//Ir 红外传感器 有漏气 向APP发送指令'I'
		}
		if(flag_sound==1){
			flag_sound=0;
			UartPutchar('S');//Sound 声音传感器 有大风 向APP发送指令'S'
		}
		switch(uart_temp){

			 		//color
			 		case 'r':
			 			RGB_r();
			 			uart_temp=' ';
			 			break;
			 		case 'o':
			 			RGB_o();
			 			uart_temp=' ';
			 			break;
			 		case 'y':
			 			RGB_y();
			 			uart_temp=' ';
			 			break;
			 		case 'g':
			 			RGB_g();
			 			uart_temp=' ';
			 			break;
			 		case 'b':
			 			RGB_b();
			 			uart_temp=' ';
			 			break;
			 		case 'p':
			 			RGB_p();
			 			uart_temp=' ';
			 			break;
			 		case 'w':
			 			RGB_w();
			 			uart_temp=' ';
			 			break;
			 		case 'd'://关灯 dieout
			 			RGB_d();
			 			uart_temp=' ';
			 			break;
			 			//***********************************************************
			 		case 'm'://开窗 m motor
			 			Window_m();
			 			uart_temp=' ';
			 			break;
			 		case 'n'://关窗
			 			Window_n();
			 			uart_temp=' ';
			 			break;
			 			//***********************************************************
			 		case 'u'://加热 u up
			 			TempNew_u();
			 			uart_temp=' ';
			 			break;
			 		case 'v'://制冷
			 			TempNew_v();
			 			uart_temp=' ';
			 			break;
			 		case 'x'://停止加热
			 			TempNew_x();
			 			uart_temp=' ';
			 			break;
			 		case 'z'://停止制冷
			 			TempNew_z();
			 			uart_temp=' ';
			 			break;
			 			//************************************************************
			 		case 'c'://回家模式
			 			Home_Mode_Backhome();
			 			break;
			 		case 'e'://浪漫模式
			 			Home_Mode_Romatic();
			 			break;
			 		case 'f'://离家模式
			 			Home_Mode_Awayhome();
			 			break;


			 		default:break;
			 		}
	}

	
	//return 0;
}