Example #1
0
void halInitLed(void)
{
  /* Set GPIO pins for Led D1 and Led D3  */
  halGpioConfig(LED_D1, GPIOCFG_OUT);
  halGpioConfig(LED_D3, GPIOCFG_OUT);
  /* Switch off Led D1,D3 */
  halClearLed(LED_D1);
  halClearLed(LED_D3);
}
//
// Function Name: bootloadGpioInit
// Description:   This function selects the chip's GPIO configuration. These
//                settings are the minimum base configuration needed to
//                support the bootloader functionality. These settings can
//                be modified for custom applications as long as the base
//                settings are preserved.
// Parameters:    none
// Returns:       none
//
void bootloadGpioInit(void)
{
  halInternalEnableWatchDog();

  #ifdef BTL_HAS_RADIO
    if (paIsPresent()) {
      // The PHY_CONFIG token indicates that a power amplifier is present.
      // Not all power amplifiers require both TX_ACTIVE and nTX_ACTIVE.  If
      // your design does not require TX_ACTIVE or nTX_ACTIVE, you can remove
      // the GPIO configuration for the unused signal to save a bit of flash.

      // Configure GPIO PC5 to support TX_ACTIVE alternate output function.
      halGpioSetConfig(PORTC_PIN(5),GPIOCFG_OUT_ALT);

      // Configure GPIO PC6 to support nTX_ACTIVE alternate output function.
      halGpioSetConfig(PORTC_PIN(6),GPIOCFG_OUT_ALT);
    }
  #endif

  #ifndef NO_LED
    halGpioSetConfig(BOARD_ACTIVITY_LED, GPIOCFG_OUT);
    halClearLed(BOARD_ACTIVITY_LED);
    halGpioSetConfig(BOARD_HEARTBEAT_LED, GPIOCFG_OUT);
    halSetLed(BOARD_HEARTBEAT_LED);
  #endif

  CONFIGURE_EXTERNAL_REGULATOR_ENABLE();
}
Example #3
0
void halStackIndicateActivity(bool turnOn)
{
 #if     NO_LED
  // Don't touch LEDs when built with NO_LED
 #else//!NO_LED
  if(turnOn) {
    halSetLed(BOARD_ACTIVITY_LED);
  } else {
    halClearLed(BOARD_ACTIVITY_LED);
  }
 #endif//NO_LED
}
// bootloadStateIndicator
//
// Called by the bootloader state macros (in bootloader-gpio.h). Used to blink
// the LED's or otherwise signal bootloader activity.
//
// Current settings:
// Enabled: Turn on yellow activity LED on bootloader up and successful bootload
//          Turn off yellow activity LED on bootload failure
// Disabled: Blink red heartbeat LED during idle polling.
void bootloadStateIndicator(enum blState_e state)
{
  // sample state indication using LEDs
  #ifndef NO_LED
    static uint16_t pollCntr = 0;

    switch(state) {
      case BL_ST_UP:                      // bootloader up
        halSetLed(BOARD_ACTIVITY_LED);
        break;

      case BL_ST_DOWN:                    // bootloader going down
        break;

      case BL_ST_POLLING_LOOP:            // Polling for serial or radio input in
                                          // standalone bootloader.
        if(0 == pollCntr--) {
          halToggleLed(BOARD_HEARTBEAT_LED);
          pollCntr = 10000;
        }
        break;

      case BL_ST_DOWNLOAD_LOOP:           // processing download image
        halClearLed(BOARD_HEARTBEAT_LED);
        halToggleLed(BOARD_ACTIVITY_LED);
        break;

      case BL_ST_DOWNLOAD_SUCCESS:
        halSetLed(BOARD_ACTIVITY_LED);
        break;

      case BL_ST_DOWNLOAD_FAILURE:
        halClearLed(BOARD_ACTIVITY_LED);
        break;

      default:
        break;
    }
  #endif
}
/** @brief Pairing Complete
 *
 * This function is called by the RF4CE ZRC plugin when the push-button
 * pairing operation completes.  If status is ::EMBER_SUCCESS, pairing was
 * successful and pairingIndex indicates the index in the pairing table for
 * the remote node while eui64, vendorInfo, and applicationInfo contain
 * information about the remote node itself.  Otherwise, status indicates the
 * reason for failure and the other arguments are meaningless.
 *
 * @param status The status of the push-button pairing operation.  Ver.:
 * always
 * @param pairingIndex The index of the pairing entry.  Ver.: always
 * @param eui64 The ::EmberEUI64 of the remote node.  Ver.: always
 * @param vendorInfo The vendor information of the remote node.  Ver.: always
 * @param applicationInfo The application information of the remote node.
 * Ver.: always
 */
void emberAfPluginRf4ceZrc11PairingCompleteCallback(EmberStatus status,
                                                    int8u pairingIndex,
                                                    const EmberEUI64 eui64,
                                                    const EmberRf4ceVendorInfo *vendorInfo,
                                                    const EmberRf4ceApplicationInfo *applicationInfo)
{
  if (status == EMBER_SUCCESS) {
    emberAfCorePrintln("Pairing %p: 0x%x", "complete", pairingIndex);
    halPlayTune_P(happyTune, TRUE);
  } else {
    emberAfCorePrintln("Pairing %p: 0x%x", "failed", status);
    halPlayTune_P(sadTune, TRUE);
  }
  halClearLed(LED);
}
void identifyEventHandler(void)
{
  if (identifyDurationMs == 0) {
    halClearLed(LED);
    emberEventControlSetInactive(identifyEventControl);
  } else {
    halToggleLed(LED);
    if (identifyDurationMs >= MILLISECOND_TICKS_PER_QUARTERSECOND) {
      identifyDurationMs -= MILLISECOND_TICKS_PER_QUARTERSECOND;
    } else {
      identifyDurationMs = 0;
    }
    emberEventControlSetDelayMS(identifyEventControl,
                                MILLISECOND_TICKS_PER_QUARTERSECOND);
  }
}
/** @brief Server Attribute Changed
 *
 * On/off cluster, Server Attribute Changed
 *
 * @param endpoint Endpoint that is being initialized  Ver.: always
 * @param attributeId Attribute that changed  Ver.: always
 */
void emberAfOnOffClusterServerAttributeChangedCallback(int8u endpoint,
                                                       EmberAfAttributeId attributeId)
{
  // When the on/off attribute changes, set the LED appropriately.  If an error
  // occurs, ignore it because there's really nothing we can do.
  if (attributeId == ZCL_ON_OFF_ATTRIBUTE_ID) {
    boolean onOff;
    if (emberAfReadServerAttribute(endpoint,
                                   ZCL_ON_OFF_CLUSTER_ID,
                                   ZCL_ON_OFF_ATTRIBUTE_ID,
                                   (int8u *)&onOff,
                                   sizeof(onOff))
        == EMBER_ZCL_STATUS_SUCCESS) {
      if (onOff) {
        halSetLed(LED);
      } else {
        halClearLed(LED);
      }
    }
  }
}
// Cluster: On/off, server
EmberAfStatus emberAfOnOffClusterServerCommandParse(EmberAfClusterCommand *cmd) {
	boolean wasHandled = FALSE;
	int8u OnOfffCmdBeforeNumber;
	if (!cmd->mfgSpecific) {
		switch (cmd->apsFrame->destinationEndpoint){
			case 1 : OnOfffCmdBeforeNumber = 1;
			break;
			case 3 : OnOfffCmdBeforeNumber = 2;
			break;
			case 5 : OnOfffCmdBeforeNumber = 3;
			break;
			case 7 : OnOfffCmdBeforeNumber = 4;
			break;
			case LedLightOptionEndpoint:
					 OnOfffCmdBeforeNumber = 5;
			break;
		}
		if (CommonGetDurationTime(OnOffCmdBeforeTimer[OnOfffCmdBeforeNumber]) > 1000){
			OnOffCmdBeforeTimer[OnOfffCmdBeforeNumber] = (int16u)halCommonGetInt32uMillisecondTick();
			switch (cmd->commandId) {
				case ZCL_OFF_COMMAND_ID: {
					// Command is fixed length: 0
					wasHandled = emberAfOnOffClusterOffCallback();
					break;
				}
				case ZCL_ON_COMMAND_ID: {
					// Command is fixed length: 0
					wasHandled = emberAfOnOffClusterOnCallback();
					break;
				}
				case ZCL_TOGGLE_COMMAND_ID: {
					// Command is fixed length: 0
					wasHandled = emberAfOnOffClusterToggleCallback();
					break;
				}
			}



		//	User Controller Command
			int8u CurrentState;
			emberAfReadServerAttribute(cmd->apsFrame->destinationEndpoint,
						ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, &CurrentState,
						sizeof(CurrentState));
			if (status(wasHandled, cmd->mfgSpecific) == EMBER_ZCL_STATUS_SUCCESS) {
				if (cmd->apsFrame->destinationEndpoint == LedLightOptionEndpoint) {
					if (CurrentState == 1) {
						halClearLed(LED_LIGHT);
					}
					else{
						halSetLed(LED_LIGHT);
					}
				}
				else {
					if (CurrentState == 1) {
						UartSendSwitchControlNumber(
								(((cmd->apsFrame->destinationEndpoint) >> 1) + 1),
								OnRelay);
					} else {
						UartSendSwitchControlNumber(
								(((cmd->apsFrame->destinationEndpoint) >> 1) + 1),
								OffRelay);
					}

					//	 	Send to Bind Device

					SendViaBindingTable(cmd->apsFrame->destinationEndpoint,
							CurrentState, OnOffType);

					//		Send On-Off AttributeResponse, Zipato stupid update :D-----------------------------//
					SendOnOffControlReadAttribute(cmd->apsFrame->destinationEndpoint,
							CurrentState);

					// on-off led

					if (CurrentState == 1) {
						CommonSetLed(cmd->apsFrame->destinationEndpoint >> 1);
					} else {