Пример #1
0
int main(void) {

    static int hid_res = 0;

	hid.connect(); // do not block
 	
	//Fill the report
    for(int i = 0; i < 64; i++)
        send_report.data[i] = i;
    send_report.length = 64;

	
    tic.attach(tic_handler, 0.1);
	
    while (1)
	{
      if (hid.readNB(&recv_report)) 
	  {
	    read_res++;
    	send_report.data[1] = hid_res;		
      }
	  wait_ms(1);
	}
}
Пример #2
0
void tic_handler() {
    send_report.data[2] = counter++;
     send_res = hid.send(&send_report);	
}
Пример #3
0
int main() 
{
    Ticker Sample_Period;               // Is this some sort of timer interrupt? 
    send_report.length = 8;             // Data length for USB-HID communication. 
    
    char  buffer[DATABITS]; 
    int   bindex = 0; 
    int   played = 0; 
    float Anote  = 440.0; 
    float Bnote  = 493.9; 
    float Cnote  = 523.3; 
    float Dnote  = 587.3; 
    
    for(int k=0; k<128; k++) 
    { 
        // Scale wave from 0.0 to 1.0 - needed for AnalogOut argument. 
        Analog_out_data[k]=((1.0 + sin((float(k)/128.0*6.28318530717958)))/2.0); 
    } 
    
    while(1) 
    {
        if (hid.readNB(&recv_report))   // Try to get USB-HID data from computer. 
        {
            for(int i = 0; i < recv_report.length; i++)
            {
                buffer[i] = recv_report.data[i]; 
                if (buffer[i] == 'A' || buffer[i] == 'a' || buffer[i] == 'B' || buffer[i] == 'b' || buffer[i] == 'C' || buffer[i] == 'c' || buffer[i] == 'D' || buffer[i] == 'd') 
                    played++; 
            }
            // Send the number of notes played. 
            for (int i = 1; i < send_report.length; i++) send_report.data[i] = 0; 
            send_report.data[0] = played & 0xff; 
            hid.send(&send_report); 
            played = 0; 
        }
        
        for (bindex = 0; bindex < DATABITS; bindex++)
        {
            switch(buffer[bindex])
            {
                case 'A': case 'a':  
                    Sample_Period.attach(&Sample_timer_interrupt, 1.0/(Anote*128)); 
                    wait(DELAY); 
                    Sample_Period.detach(); 
                break; 
                
                case 'B': case 'b': 
                    Sample_Period.attach(&Sample_timer_interrupt, 1.0/(Bnote*128)); 
                    wait(DELAY); 
                    Sample_Period.detach(); 
                break;
                
                case 'C': case 'c': 
                    Sample_Period.attach(&Sample_timer_interrupt, 1.0/(Cnote*128)); 
                    wait(DELAY); 
                    Sample_Period.detach(); 
                break; 
                
                case 'D': case 'd': 
                    Sample_Period.attach(&Sample_timer_interrupt, 1.0/(Dnote*128)); 
                    wait(DELAY); 
                    Sample_Period.detach(); 
                break;
                
                default: break; 
            }
            wait(0.02); 
        }
        Sample_Period.detach(); 
        
        pc.printf("Notes played: %d. \r\n", played); 
        wait(0.1); 
        for (bindex = 0; bindex < DATABITS; bindex++) buffer[bindex] = '0'; 
    }
}