/*********************************************************************
 * @fn      DualImageConcept_processStateChangeEvt
 *
 * @brief   Process a pending GAP Role state change event.
 *
 * @param   newState - new state
 *
 * @return  None.
 */
static void DualImageConcept_processStateChangeEvt(gaprole_States_t newState)
{
  switch ( newState )
  {
    case GAPROLE_STARTED:
      {
        uint8_t ownAddress[B_ADDR_LEN];

        GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress);

        // Display device address
        Display_print0(dispHandle, 1, 0, Util_convertBdAddr2Str(ownAddress));
        Display_print0(dispHandle, 2, 0, "Initialized");
      }
      break;
      
    case GAPROLE_ADVERTISING:
        Display_print0(dispHandle, 2, 0, "Advertising");
      break;

    case GAPROLE_CONNECTED:
      {
        uint8_t peerAddress[B_ADDR_LEN];

        GAPRole_GetParameter(GAPROLE_CONN_BD_ADDR, peerAddress);

        Display_print0(dispHandle, 2, 0, "Connected");
        Display_print0(dispHandle, 3, 0, Util_convertBdAddr2Str(peerAddress));
      }
      break;

    case GAPROLE_WAITING: 
      Display_print0(dispHandle, 2, 0, "Disconnected");

      // Clear remaining lines
      Display_clearLines(dispHandle, 3, 5);
      break;
      
    case GAPROLE_WAITING_AFTER_TIMEOUT:
      Display_print0(dispHandle, 2, 0, "Timed Out");
      
      // Clear remaining lines
      Display_clearLines(dispHandle, 3, 5);
      break;
      
    case GAPROLE_ERROR:
      break;
      
    default:
      break;
  }
}
/*********************************************************************
 * @fn      SensorTagDisplay_processCharChangeEvt
 *
 * @brief   Process a change in the IO characteristics
 *
 * @return  none
 */
void SensorTagDisplay_processCharChangeEvt(uint8_t paramID)
{
    if (paramID == DISPLAY_CONF)
    {
        uint8_t config[DISPLAY_CONF_LEN];

        Display_getParameter(DISPLAY_CONF, config);

        // Execute the control sequence
        switch (config[DISPLAY_CMD_OFFSET])
        {
        case DISPLAY_CONF_OFF:
            if (handle != NULL)
            {
                // NB! Has no effect on SensorTag because LCD_ENABLE pin is
                // shared with UART_TX, causing the LCD to get enabled again
                // as soon as the PINs used by the LCD are released.
                Display_clear(handle);
                Display_print0(handle, DISPLAY_LINE_DEFAULT, 2, "Display off");

                Display_close(handle);
                handle = NULL;
            }
            break;

        case DISPLAY_CONF_ON:
            // Initialize LCD
            if (handle == NULL)
            {
                Display_Params params;
                Display_Params_init(&params);
                params.lineClearMode = DISPLAY_CLEAR_NONE;
                handle = Display_open(Display_Type_LCD, &params);

                // Update status
                SensorTagDisplay_showStatus();
            }
            break;

        case DISPLAY_CONF_CLR:
            // Clear display
            if (handle != NULL)
            {
                Display_clear(handle);
            }
            break;

        case DISPLAY_CONF_CLR_LINE:
            // Clear line
            pos.line = config[DISPLAY_LINE_OFFSET];
            if (handle != NULL)
            {
                Display_clearLines(handle, pos.line, pos.line);
            }
            break;

        case DISPLAY_CONF_INV:
            if (handle != NULL)
            {
                uint8_t tmp;

                // Swap foreground and background colors
                tmp = color.fg;
                color.fg = color.bg;
                color.bg = tmp;

                Display_control(handle, DISPLAYSHARP_CMD_SET_COLORS, &color);

                // Update status
                SensorTagDisplay_showStatus();
            }
            break;

        case DISPLAY_CONF_MOV:
            // Store active "cursor" position
            pos.line = config[DISPLAY_LINE_OFFSET];
            pos.column = config[DISPLAY_COL_OFFSET];

            break;

        default:
            break;
        }
    }

    if (paramID == DISPLAY_DATA && handle != NULL)
    {
        uint8_t data[DISPLAY_BUFFER_LEN];

        Display_getParameter(DISPLAY_DATA, data);
        Display_print0(handle, pos.line, pos.column, (const char*)data);
    }
}
Пример #3
0
/*********************************************************************
 * @fn      SimpleBLEPeripheral_processStateChangeEvt
 *
 * @brief   Process a pending GAP Role state change event.
 *
 * @param   newState - new state
 *
 * @return  None.
 */
static void SimpleBLEPeripheral_processStateChangeEvt(gaprole_States_t newState)
{
#ifdef PLUS_BROADCASTER
  static bool firstConnFlag = false;
#endif // PLUS_BROADCASTER

  switch ( newState )
  {
    case GAPROLE_STARTED:
      {
        uint8_t ownAddress[B_ADDR_LEN];
        uint8_t systemId[DEVINFO_SYSTEM_ID_LEN];

        GAPRole_GetParameter(GAPROLE_BD_ADDR, ownAddress);

        // use 6 bytes of device address for 8 bytes of system ID value
        systemId[0] = ownAddress[0];
        systemId[1] = ownAddress[1];
        systemId[2] = ownAddress[2];

        // set middle bytes to zero
        systemId[4] = 0x00;
        systemId[3] = 0x00;

        // shift three bytes up
        systemId[7] = ownAddress[5];
        systemId[6] = ownAddress[4];
        systemId[5] = ownAddress[3];

        DevInfo_SetParameter(DEVINFO_SYSTEM_ID, DEVINFO_SYSTEM_ID_LEN, systemId);

        // Display device address
        Display_print0(dispHandle, 1, 0, Util_convertBdAddr2Str(ownAddress));
        Display_print0(dispHandle, 2, 0, "Initialized");
      }
      break;

    case GAPROLE_ADVERTISING:
      Display_print0(dispHandle, 2, 0, "Advertising");
      break;

#ifdef PLUS_BROADCASTER
    /* After a connection is dropped a device in PLUS_BROADCASTER will continue
     * sending non-connectable advertisements and shall sending this change of
     * state to the application.  These are then disabled here so that sending
     * connectable advertisements can resume.
     */
    case GAPROLE_ADVERTISING_NONCONN:
      {
        uint8_t advertEnabled = FALSE;

        // Disable non-connectable advertising.
        GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8_t),
                           &advertEnabled);

        advertEnabled = TRUE;

        // Enabled connectable advertising.
        GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
                             &advertEnabled);

        // Reset flag for next connection.
        firstConnFlag = false;

        SimpleBLEPeripheral_freeAttRsp(bleNotConnected);
      }
      break;
#endif //PLUS_BROADCASTER

    case GAPROLE_CONNECTED:
      {
        linkDBInfo_t linkInfo;
        uint8_t numActive = 0;

        Util_startClock(&periodicClock);

        numActive = linkDB_NumActive();

        // Use numActive to determine the connection handle of the last
        // connection
        if ( linkDB_GetInfo( numActive - 1, &linkInfo ) == SUCCESS )
        {
          Display_print1(dispHandle, 2, 0, "Num Conns: %d", (uint16_t)numActive);
          Display_print0(dispHandle, 3, 0, Util_convertBdAddr2Str(linkInfo.addr));
        }
        else
        {
          uint8_t peerAddress[B_ADDR_LEN];

          GAPRole_GetParameter(GAPROLE_CONN_BD_ADDR, peerAddress);

          Display_print0(dispHandle, 2, 0, "Connected");
          Display_print0(dispHandle, 3, 0, Util_convertBdAddr2Str(peerAddress));
        }

        #ifdef PLUS_BROADCASTER
          // Only turn advertising on for this state when we first connect
          // otherwise, when we go from connected_advertising back to this state
          // we will be turning advertising back on.
          if (firstConnFlag == false)
          {
            uint8_t advertEnabled = FALSE; // Turn on Advertising

            // Disable connectable advertising.
            GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t),
                                 &advertEnabled);

            // Set to true for non-connectabel advertising.
            advertEnabled = TRUE;

            // Enable non-connectable advertising.
            GAPRole_SetParameter(GAPROLE_ADV_NONCONN_ENABLED, sizeof(uint8_t),
                                 &advertEnabled);
            firstConnFlag = true;
          }
        #endif // PLUS_BROADCASTER
      }
      break;

    case GAPROLE_CONNECTED_ADV:
      Display_print0(dispHandle, 2, 0, "Connected Advertising");
      break;

    case GAPROLE_WAITING:
      Util_stopClock(&periodicClock);
      SimpleBLEPeripheral_freeAttRsp(bleNotConnected);

      Display_print0(dispHandle, 2, 0, "Disconnected");

      // Clear remaining lines
      Display_clearLines(dispHandle, 3, 5);
      break;

    case GAPROLE_WAITING_AFTER_TIMEOUT:
      SimpleBLEPeripheral_freeAttRsp(bleNotConnected);

      Display_print0(dispHandle, 2, 0, "Timed Out");

      // Clear remaining lines
      Display_clearLines(dispHandle, 3, 5);

      #ifdef PLUS_BROADCASTER
        // Reset flag for next connection.
        firstConnFlag = false;
      #endif //#ifdef (PLUS_BROADCASTER)
      break;

    case GAPROLE_ERROR:
      Display_print0(dispHandle, 2, 0, "Error");
      break;

    default:
      Display_clearLine(dispHandle, 2);
      break;
  }

  // Update the state
  //gapProfileState = newState;
}