Exemple #1
0
/******************************************************************************
 * @fn          sendReport
 *
 * @brief       Send sensor report
 *
 * @param       none
 *
 * @return      none
 */
static void sendReport(void)
{
  uint8 pData[SENSOR_REPORT_LENGTH];
  static uint8 reportNr = 0;
  uint8 txOptions;

  // Read and report temperature value
  pData[SENSOR_TEMP_OFFSET] = readTemp();

  // Read and report voltage value
  pData[SENSOR_VOLTAGE_OFFSET] = readVoltage();

  pData[SENSOR_PARENT_OFFSET] =  HI_UINT16(parentShortAddr);
  pData[SENSOR_PARENT_OFFSET + 1] =  LO_UINT16(parentShortAddr);
  pData[BUTTON_PARENT_OFFSET+1] = MCU_IO_GET(0,1);
 // HalUARTWrite(HAL_UART_PORT_0,pData,SENSOR_REPORT_LENGTH);
 // HalUARTWrite(HAL_UART_PORT_1,pData,SENSOR_REPORT_LENGTH);
  int test = MCU_IO_GET(0,1);
  if( MCU_IO_GET(0,1) > 0){
    MCU_IO_SET_LOW(0, 0);
  } else {
    MCU_IO_SET_HIGH(0, 0);
  }
  MCU_IO_SET_LOW(0, 1);
  // Set ACK request on each ACK_INTERVAL report
  // If a report failed, set ACK request on next report
  if ( ++reportNr<ACK_REQ_INTERVAL && reportFailureNr == 0 )
  {
    txOptions = AF_TX_OPTIONS_NONE;
  }
  else
  {
    txOptions = AF_MSG_ACK_REQUEST;
    reportNr = 0;
  }
  // Destination address 0xFFFE: Destination address is sent to previously
  // established binding for the commandId.
  //printf("%i %i",pData[SENSOR_TEMP_OFFSET],oldValue);
  if(timeDone >= 60000){
     timeDone += 1;
  }
  if(pData[SENSOR_TEMP_OFFSET] != oldValue && timeDone >= 60000){
    oldValue = pData[SENSOR_TEMP_OFFSET];
    zb_SendDataRequest( 0xFFFE, SENSOR_REPORT_CMD_ID, SENSOR_REPORT_LENGTH, pData, 0, txOptions, 0 );
    timeDone = 0;
  } else {
    timeDone += myReportPeriod;
  }
}
Exemple #2
0
/************************************************************************************
* @fn  halJoystickPushed
*
* @brief
*      This function detects if the joystick is being pushed. The function
*      implements software debounce. Return true only if previuosly called
*      with joystick not pushed. Return true only once each time the joystick
*      is pressed.
*
* Parameters:
*
* @param  void
*
* @return uint8
*          1: Button is being pushed
*          0: Button is not being pushed
*
******************************************************************************/
uint8 halJoystickPushed(void)
{
  uint8 value, active;
  uint8 i;
  static uint8 prevValue = 0;
  uint16 adcValue;

  // Criterion for button pushed:
  // 3 times joystick active and in center position
  value = 1;
  for (i=0; i<3; i++) {
    active = MCU_IO_GET(HAL_BOARD_IO_JOY_MOVE_PORT, HAL_BOARD_IO_JOY_MOVE_PIN);
    adcValue = adcSampleSingle(ADC_REF_AVDD, ADC_9_BIT, \
        HAL_BOARD_IO_JOYSTICK_ADC_CH);
    // Only use 7 out of the 9 bits
    adcValue = (adcValue & 0x7FC0) >> 8;
    if (! active || adcValue < 0x54) {
      // Joystick not active or not in center position
      value = 0;
      break;
    }
    halMcuWaitUs(3);
  }

  if (value){
    if (!prevValue){
      value = prevValue = 1;
      halMcuWaitMs(100);

    }
    else {
      value = 0;
    }
  }
  else{
    prevValue = 0;
  }

  return value;
}