int main (void) { uint8_t i; CPU_PRESCALE(0); DDRB = 0xff; DDRD = 0xff; usb_init(); while(!usb_configured()); usb_buffer[0] = 0xab; usb_buffer[1] = 0xcd; usb_buffer[63] = 4; led(); /* controller_mode = probe;*/ controller_mode = poll; while(1){ switch(controller_mode){ case(probe): _delay_ms(12); controller_probe(); usb_rawhid_send(usb_buffer, 50); break; case(poll): controller_poll(); usb_rawhid_send(usb_buffer, 50); _delay_ms(6); break; } } return 0; }
uint16_t SD_NumberOfFiles(void) { uint16_t fileCount = 0; buffer[0] = 0x01; usb_rawhid_send(buffer, 100); while(file.openNext(sdf.vwd(), O_READ)) { fileCount++; buffer[0]++; usb_rawhid_send(buffer, 100); } file.close(); return fileCount; }
boolean SD_ReadFile(const char *filename) { uint32_t t_arrival = millis(); boolean retVal = false; sdf.chdir(); if (!file.open(filename, O_READ)) { sdf.errorHalt("opening FILE for read failed"); } else { uint32_t len = file.fileSize(); uint8_t index = 0; for(uint32_t i=0; i< len; i++) { int intData = file.read(); char byteData; int base = 10u; //itoa(intData,&byteData,base); // Convert to ASCII buffer[index] = (uint8_t)intData;//byteData; if(index < 63u) { index++; } else { usb_rawhid_send(buffer, 100u); index = 0; } } file.close(); uint32_t t_exit = millis() - t_arrival; buffer[62] = (uint8_t)((t_exit & 0x000000FF)>>8); buffer[63] = (uint8_t)t_exit; usb_rawhid_send(buffer,100u); } }
int main(void) { int8_t r; uint16_t count=0; // set for 16 MHz clock CPU_PRESCALE(0); // Initialize the USB, and then wait for the host to set configuration. // If the Teensy is powered without a PC connected to the USB port, // this will wait forever. usb_init(); while (!usb_configured()) /* wait */ ; // Wait an extra second for the PC's operating system to load drivers // and do whatever it does to actually be ready for input _delay_ms(1000); // Configure timer 0 to generate a timer overflow interrupt every // 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock TCCR0A = 0x00; TCCR0B = 0x05; TIMSK0 = (1<<TOIE0); eeprom_read_block(buffer, EEPROM_BUF_ADDR, RAWHID_TX_SIZE); while (1) { // if received data, do something with it r = usb_rawhid_recv(buffer, 0); if (r > 0) { // save received data into eeprom eeprom_update_block(buffer, EEPROM_BUF_ADDR, RAWHID_TX_SIZE); } // if time to send output, transmit whatever we received earlier if (do_output) { do_output = 0; // put a count in the last 2 bytes buffer[62] = count >> 8; buffer[63] = count & 255; // send the packet usb_rawhid_send(buffer, 50); count++; } } }
extern "C" int main(void) { //state == 0: IDLE wait for scan start signal //state == 1: INITIATE SCAN: reset all data and start new scan //state == 2; scanning... transmitting data //state == 3: scan complete cleanup and reset to state 0 int state = STATEIDLE; //Main loop while(1){ //IDLE //Wait for command to start scanning if (state == STATEIDLE){ if(checkIncomingCmd() == 1){ if(checkPCCmd() == 1){ sendPCStart(); state = STATEINITIATE; } } //INITIATE }else if(state == STATEINITIATE){ resetState(); state = STATESCAN; //SCANNING }else if (state == STATESCAN){ if(checkIncomingCmd() == 1){ if(checkPCCmd() == 1){ sendPCStart(); state = STATEINITIATE; } } if(packData() == 1){ usb_rawhid_send(data_out, 15); } if(rotation == MAXROTATION){ state = STATEEND; } //scan complete cleanup and reset to state 0 }else if (state == STATEEND){ resetState(); sendPCEnd(); state = STATEIDLE; }//STATEEND }//main loop }//main
/** * \brief Periodic process which will send any data currently loaded for transmission */ void CCOM_Task(void) { uint32_t u32GetAddr; uint8_t *pu8Data; uint8_t i; if(!rbuf_empty(&ccomBuf)) { rbuf_get(&ccomBuf,&u32GetAddr); pu8Data = (uint8_t *)u32GetAddr; //if(USB_isReady()){ USB.write(pu8Data,MAX_FRAME_SIZE); } usb_rawhid_send(pu8Data, MAX_FRAME_SIZE); //for(i=0;i<MAX_FRAME_SIZE;i++){ printf("%02x,",*pu8Data++); } printf("\n\r"); } //else{ printf("No Data...\n\r"); } }
int main(void) { int8_t r; // set for 16 MHz clock CPU_PRESCALE(0); // Initialize the USB, and then wait for the host to set configuration. // If the Teensy is powered without a PC connected to the USB port, // this will wait forever. usb_init(); while (!usb_configured()) /* wait */ ; // Wait an extra second for the PC's operating system to load drivers // and do whatever it does to actually be ready for input _delay_ms(1000); // configure LED as output DDRD |= LEDMASK; while (1) { // if received data, do something with it r = usb_rawhid_recv(buffer, 0); if (r > 0) { // turn on the LED PORTD |= LEDMASK; /* For the response packet, we add 1 to each byte of the * received packet. */ uint8_t i; for (i = 0; i < BUFLEN; i++) buffer[i]++; // send the packet usb_rawhid_send(buffer, 50); // turn off the LED PORTD &= ~LEDMASK; } } }
void send(struct teensy_msg msg) { uint8_t * buf = pack(msg); // send the packet usb_rawhid_send(buf, SEND_TIMEOUT); free(buf); }
int main(void) { int8_t r; // set for 16 MHz clock CPU_PRESCALE(0); // Initialize the USB, and then wait for the host to set configuration. // If the Teensy is powered without a PC connected to the USB port, // this will wait forever. usb_init(); while (!usb_configured()) /* wait */ ; // Wait an extra second for the PC's operating system to load drivers // and do whatever it does to actually be ready for input _delay_ms(1000); // Configure timer 0 to generate a timer overflow interrupt every // 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock // This interrupt is used to check for button presses (JBS) TCCR0A = 0x00; TCCR0B = 0x05; TIMSK0 = (1<<TOIE0); // set the default direction for all of the ports DDRD |= (1<<PORTD4); // set pin D4 to output, i.e. LED 1 pin 4, red DDRD |= (1<<PORTD6); // set pin D6 to output, i.e. LED 1 pin 1, green DDRD |= (1<<PORTD7); // set pin D7 to output, i.e. LED 1 pin 3, blue DDRD |= (1<<PORTD1); // set pin D1 to output, i.e. LED 2 pin 4, red DDRD |= (1<<PORTD2); // set pin D2 to output, i.e. LED 2 pin 3, blue DDRD |= (1<<PORTD3); // set pin D3 to output, i.e. LED 2 pin 1, green DDRD |= (0<<PORTC6); // set button 2 to input DDRD |= (0<<PORTC7); // set button 1 to input while (1) { // if received data, do something with it r = usb_rawhid_recv(buffer, 0); if (r > 0) { // PD4 --> Red 1 // PD6 --> Green 1 // PD7 --> Blue 1 switch(buffer[0]){ // set the default LED color to blue for LED 1 & 2 case 'g': PORTD &= ~(1<<PORTD1); PORTD &= ~(1<<PORTD2); PORTD &= ~(1<<PORTD3); PORTD &= ~(1<<PORTD4); PORTD &= ~(1<<PORTD6); PORTD &= ~(1<<PORTD7); PORTD |= (1<<PORTD7); PORTD |= (1<<PORTD3); //set initial vote to blue = A abstain buffer[0] = 'A'; continue; break; default: break; } } // if time to check for button press, do so if (do_output) { do_output = 0; if ( !(PINC & (1<<7)) ) // if button 1 is pressed { if ( PIND & (1<<7) ) // if LED is blue { PORTD &= ~(1<<PORTD7); // turn off blue PORTD |= (1<<PORTD6); // turn on green buffer[0] = 'Y'; // set buffer to green } else { if ( PIND & (1<<6) ) // if LED is green { // turn off green PORTD &= ~(1<<PORTD6); // turn on red PORTD |= (1<<PORTD4); // set buffer char to red buffer[0] = 'N'; } else { // if LED is red if ( PIND & (1<<4) ) { // turn off red PORTD &= ~(1<<PORTD4); // turn on blue PORTD |= (1<<PORTD7); buffer[0] = 'A'; } } } } if ( !(PINC & (1<<6)) ) // if button 2 is pressed { // if LED 2 is blue if ( PIND & (1<<3) ) { // send the packet usb_rawhid_send(buffer, 50); PORTD &= ~(1<<PORTD3); // turn off blue PORTD |= (1<<PORTD2); // turn on green } else { // if LED 2 is green if ( PIND & (1<<2) ) { // turn off green PORTD &= ~(1<<PORTD2); // turn on blue, i.e. ready // to vote PORTD |= (1<<PORTD3); } } } } } }
void usb_send(void) { usb_rawhid_send(usb_out_buffer, TIMEOUT_SEND); }
void sendPCEnd(){ data_out[0] = CMDEND; usb_rawhid_send(data_out, 15); }
void sendPCStart(){ data_out[0] = CMDSTART; usb_rawhid_send(data_out, 15); }