Пример #1
0
int main( void )
{
    mInit();
    mUSBInit();
    mBusInit();

    // Set up usb interface
    bQueue in_q;
    bQueue out_q;
    usbIface usb( &in_q, &out_q );
    
//    picker_setup();
    stepper_setup();
//    set_timer5 (60000,30000,1200);
    
    setMode( STEP_8TH);
    setSpeedLimits( 65, 500 );
    set_speed(m_speed_min);
    setAccelerationLimit(100); //5000 is good
    
    uint8_t cmd; 
    uint16_t pos = 0;
    while(1)
    {
        usb.readBytes();

        // Handle bytes 
        if (!in_q.isempty() ) {
          mBlueTOGGLE;
          in_q.dequeue(&cmd);
          if ( cmd == 'l' ) {
            pos += 10;
          } else if ( cmd == 'h' ) {
            pos -= 10;
          }
        }
        update(pos);
    }
    return(0);
}
Пример #2
0
int main( void )
{
    // Initialize m4 things
    mInit();
    //mBusInit();
    mUSBInit();

    // Set up usb interface
    bQueue in_q;
    bQueue out_q;
    usbIface usb( &in_q, &out_q );
    
    // Initialize midi interface
    midiParser midi( &in_q );
    midiMsg msg;

    mYellowON;
    
    while(1)
    {
      usb.readBytes();
      /*
      mWaitms(500);
      mGreenON;
      usb.printf( "hello world\n" );
      mWaitms(500);
      mGreenOFF;
      */
      if ( midi.hasMsg(&msg) ) {
        mGreenTOGGLE;
        usb.printf("msg: %02x\n", msg.status);
        usb.printf("channel: %02x\n", msg.channel);
        usb.printf("data[0]: %02x\n", msg.data[0]);
        usb.printf("data[1]: %02x\n", msg.data[1]);
      }
      // Write data out 
      usb.writeBytes();
    }
}
Пример #3
0
int main( void )
{
    mInit();
    mUSBInit();
    //mBusInit();
    
    bQueue in_q;
    bQueue out_q;
    bQueueInit( &in_q );
    bQueueInit( &out_q );
    usbIface usb;
    usbIfaceInit( &usb, &in_q, &out_q );
    
    // Set up midi parser
    midiParser parser;
    midiParserInit( &parser, &in_q );
    midiMsg msg;
    
    picker_setup();
    stepper_setup();
    set_timer5 (60000,30000,1200);
   
    setMode( STEP_HALF );
    setSpeedLimits( 65, 200 );
    set_speed(m_speed_min);
    setAccelerationLimit(200);
    
    int test=0;
    
    //    uint16_t pos[]={0,-180,0,-360,0,-540,0,-720,-900,0};
    //    uint16_t dur[]={1000,1000,1000,1000};
    
    uint16_t pos=0;
    /*
    //set_speed(m_speed_min);
    int i=0;
    update(0);
    //    TIM_Cmd(TIM5, DISABLE);
    accStop();
    setPosition(0);
    */
    int Sflag=0;
    
    
    //strum_delay(1);
    while(1)
    {
        //        test = update(pos);
        //        if(test==1){
        //            if(Sflag==1){
        //                strum();
        //                Sflag=0;
        //            }
        //        }
        update(pos);    
        
        usbIfaceReadBytes(&usb);
        if(midiParserHasMsg(&parser,&msg)){
            mGreenTOGGLE;
            usbIfacePrintf(&usb, "status  %02x\n",msg.status);
            usbIfacePrintf(&usb, "channel %02x\n",msg.channel);
            usbIfacePrintf(&usb, "data[0] %02x\n",msg.data[0]);
            usbIfacePrintf(&usb, "data[1] %02x\n\n",msg.data[1]);
            if(msg.channel == INSTRUMENT_CHANNEL || msg.channel == BOTH_CHANNEL) {
              if(msg.status==NOTE_ON){
                  strum();
                  Sflag=1;
                  switch(msg.data[0]){
                      case 40:
                        pos = E2;
                        break;
                      case 41:
                        pos = F2;
                        break;
                      case 42:
                        pos = FS2;
                        break;
                      case 43:
                        pos = G2;
                        break;
                      case 44:
                        pos = GS2;
                        break;
                      case 45:
                        pos = A2;
                        break;
                      case 46:
                        pos = AS2;
                        break;
                      case 47:
                        pos = B2;
                        break;
                      case 48:
                        pos = C3;
                        break;
                      case 49:
                        pos = CS3;
                        break;
                      case 50:
                        pos = D3;
                        break;
                      case 51:
                        pos = DS3;
                        break;
                      case 52:
                        pos = E3;
                        break;
                      case 53:
                        pos = F3;
                        break;
                      case 54:
                        pos = FS3;
                        break;
                      case 55:
                        pos = G3;
                        break;
                      case 56:
                        pos = GS3;
                        break;
                      case 57:
                        pos = A3;
                        break;
                      case 58:
                        pos = AS3;
                        break;
                      case 59:
                        pos = B3;
                        break;
                      case 60:
                        pos = C4;
                        break;
                      default:
                        break;

                    /*
                    case 57:
                        pos=A3;
                        break;
                    case 59:
                        pos=B3;
                        break;
                    case 60:
                        pos=C4;
                        break;
                    case 62:
                        pos=D4;
                        break;
                    case 64:
                        pos=E4;
                        break;
                        pos=F4;
                        break;
                    case 67:
                        pos=G4;
                        break;
                    case 69:
                        pos=A4;
                        break;
                    case 71:
                        pos=B4;
                        break;
                    case 72:
                        pos=C5;
                        break;
                    default:
                        break;
                    */
                  }
               }
            }
        }
        usbIfaceWriteBytes(&usb);
    }
}
Пример #4
0
int main (void)
{
    mInit();
    mBusInit();
    mUSBInit();
    
    mWhiteOFF;
    mRedOFF;
    mGreenON;
    
    for (uint8_t i = 0; i < COMMAND_SIZE + 1; i++)
        command_buffer[i] = '\0';  // initialize command buffer
    
    bool sd_initialized = false;
    
reconnect:
    while (bDeviceState != CONFIGURED);
    
    sd_initialized = m_sd_init();
    
    mWaitms (1000);
    welcome_screen();
    
    if (!sd_initialized)
        printf ("ERROR: Could not initialize microSD card\r\n");
    
    printf ("> ");
    
    for (;;)
    {
        if (bDeviceState != CONFIGURED)
        {
            goto reconnect;
        }
        
        const int rchar = getchar();
        if (rchar < 0)
            continue;
        
        const char c = (char)rchar;
        
        if (c == '\n' || c == '\r')
        {  // received 'enter'
            printf ("\r\n");
            
            if (sd_initialized)
            {
                process_command();
                
                if (fatal_error)
                    sd_initialized = false;
            }
            else
            {
                if (m_sd_init())
                {
                    fatal_error = false;
                    sd_initialized = true;
                    
                    process_command();
                    
                    if (fatal_error)
                        sd_initialized = false;
                }
                else
                {
                    printf ("ERROR: Could not initialize microSD card: error code %d\r\n", m_sd_error_code);
                }
            }
            
            command_ptr = command_buffer;  // reset the current command length to 0
            
            printf ("> ");
        }
        else if (c == 8 || c == 127)
        {  // received backspace (or delete)
            if (command_ptr > command_buffer)
            {
                command_ptr--;
                
                putchar (27);  // escape
                printf ("[1D");  // move the cursor back 1 character
                putchar (27);
                printf ("[K");  // erase from the cursor position to the end of the line
            }
        }
        else if (c >= 32 && c < 127)
        {  // received a printable character or escape
            if (command_ptr < command_buffer + COMMAND_SIZE)
            {
                *command_ptr = c;
                command_ptr++;
                
                putchar (c);
            }
            else
            {  // out of command space: send bell
                putchar (7);
            }
        }
    }
    
    return 0;
}