Example #1
0
void menu_draw(void)
{
  unsigned y, i;
  
  if ( menu_o.current_dialog == CLOCK_DIALOG )
  {
	draw_hm(&oled_o, &clk_o);
  }
  else
  {
    const char *m = menu_dialog_list[menu_o.current_dialog];
    
    oled_set_font(&oled_o, helvR12small);
    
    y = 14;
    for( i = 0; i < menu_o.total; i++ )
    {
	if ( menu_o.curr == i )
	{
	  oled_draw_string(&oled_o, 0, y, ":");
	}
	oled_draw_string(&oled_o, 10, y, m+2); 
	if ( *m == 0xf3 || *m == 0xf2 )
	{
	  oled_draw_num(&oled_o, 100, y, 10, 1, menu_o.num[i]);    
	}
	
	y += 16;
	m = menu_get_entry(m, 1);
    }
  }
}
Example #2
0
void APP_Tasks(void) {

    /* Check if device is configured.  See if it is configured with correct
     * configuration value  */

    switch (appData.state) {
        case APP_STATE_INIT:



            /* Open the device layer */
            appData.usbDevHandle = USB_DEVICE_Open(USB_DEVICE_INDEX_0, DRV_IO_INTENT_READWRITE);

            if (appData.usbDevHandle != USB_DEVICE_HANDLE_INVALID) {
                /* Register a callback with device layer to get event notification (for end point 0) */
                USB_DEVICE_EventHandlerSet(appData.usbDevHandle, APP_USBDeviceEventHandler, 0);

                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            } else {
                /* The Device Layer is not ready to be opened. We should try
                 * again later. */
            }

            break;

        case APP_STATE_WAIT_FOR_CONFIGURATION:

            if (appData.deviceConfigured == true) {
                /* Device is ready to run the main task */
                appData.hidDataReceived = false;
                appData.hidDataTransmitted = true;
                appData.state = APP_STATE_MAIN_TASK;

                /* Place a new read request. */
                USB_DEVICE_HID_ReportReceive(USB_DEVICE_HID_INDEX_0,
                        &appData.rxTransferHandle, appData.receiveDataBuffer, 64);
            }
            break;

        case APP_STATE_MAIN_TASK:

            if (!appData.deviceConfigured) {
                /* Device is not configured */
                appData.state = APP_STATE_WAIT_FOR_CONFIGURATION;
            } else if (appData.hidDataReceived) {
                /* Look at the data the host sent, to see what
                 * kind of application specific command it sent. */

                switch (appData.receiveDataBuffer[0]) {
                    case 0x80:

                        /* Toggle on board LED1 to LED2. */
                        BSP_LEDToggle(APP_USB_LED_1);
                        BSP_LEDToggle(APP_USB_LED_2);



                        setRTR();
                        break;

                    case 0x81:
                        if (appData.hidDataTransmitted) {
                            /* Echo back to the host PC the command we are fulfilling in
                             * the first byte.  In this case, the Get Push-button State
                             * command. */

                            appData.transmitDataBuffer[0] = 0x81;

                            appData.transmitDataBuffer[1] = 0b1 & BSP_SwitchStateGet(APP_USB_SWITCH_1);

                            appData.transmitDataBuffer[2] = 111;


                            setRTS();
                            setRTR();
                        }
                        break;


                    case 0x82:
                        if (!appData.numTX || _CP0_GET_COUNT() > 200000) {

                            //prepare new data to send
                            acc_read_register(OUT_X_L_A, (unsigned char *) appData.accels, 6);
                            appData.transmitDataBuffer[0] = 1; //we have data to send
                            appData.transmitDataBuffer[1] = appData.accels[0] >> 8; //x high byte
                            appData.transmitDataBuffer[2] = appData.accels[0] & 0xFF; //x low byte
                            appData.transmitDataBuffer[3] = appData.accels[1] >> 8; //y high byte
                            appData.transmitDataBuffer[4] = appData.accels[1] & 0xFF; //y low byte
                            appData.transmitDataBuffer[5] = appData.accels[2] >> 8; //z high byte
                            appData.transmitDataBuffer[6] = appData.accels[2] & 0xFF; //z low byte

                            // reset core timer for 100 hz
                            _CP0_SET_COUNT(0);
                            appData.numTX++;
                        }
                        else {
                            appData.transmitDataBuffer[0] = 0;  // we don't have new data
                        }

                        setRTS();
                        setRTR();
                        break;

                    case 0x83:
                        // prepare for a bout of sending accel data
                        //parse incoming data to screen
                        oled_clear_buffer();
                        int row = appData.receiveDataBuffer[1];
                        char * msg;
                        msg = &appData.receiveDataBuffer[2];

                        oled_draw_string(0, row, msg, 1);
                        oled_update();


                        // clear buffered accel data so we read new data to send
                        acc_read_register(OUT_X_L_A, (unsigned char *) appData.accels, 6);

                        appData.numTX = 0; //we're starting over

                        setRTR();
                        break;

                    case 0x84:
                        // done asking for data
                        oled_draw_string(0, 55, "Done!", 1);
                        oled_update();

                        setRTR();
                        break;

                    default:
                        setRTR();
                        break;
                }
            }