Example #1
0
/**
 * \brief Wait for button press and release
 *
 * Waits for the button connected to \ref BUTTON_PIN to be pressed and released.
 * Debouncing is done with an approximate 20 ms delay after both the press and
 * the release.
 */
static void wait_for_button(void)
{
	do {} while (ioport_pin_is_high(BUTTON_PIN));
	mdelay(20);
	do {} while (ioport_pin_is_low(BUTTON_PIN));
	mdelay(20);
}
static void wait_for_btn_press(void)
{
	do { } while (ioport_pin_is_high(NEXT_BUTTON));
	delay_ms(5);
	do { } while (ioport_pin_is_low(NEXT_BUTTON));
	delay_ms(5);
}
Example #3
0
int main(void)
{

	board_init();
    uint16_t count;
	// Insert application code here, after the board has been initialized.
	
	sysclk_init();
	spi_task_init();
	pmic_init();
	alarm_task_init();
	scheduler_init();
	alarm("Device Restarted");
    zigbee_init();

    PORTC.INT0MASK |= PIN3_bm;
	PORTC.INTCTRL |= PORT_INT0LVL_LO_gc;
	PORTC.PIN3CTRL |= (PORT_ISC1_bm);
	//PORTC.PIN3CTRL |= (PORT_ISC1_bm | PORT_ISC2_bm);
	
	sei();
	

	
	addr_t destShortTemp, destLongTemp;

	destShortTemp.PANid = 0xBABE;
	destShortTemp.shortAddr = 0x0000;
	destShortTemp.mode = MAC_SHORT_ADDRESS;
	
	destLongTemp.PANid = 0x1122;
	destLongTemp.extAddr = 0x9999999999999999;
	destLongTemp.mode = MAC_LONG_ADDRESS;
	
	security_t sec;

	

if(ioport_pin_is_high(ZIGBEE_COORD_GPIO))
	{
		nwk_nlme_nf_t nf;
		nf.beaconOrder = 0xf;
		nf.BatteryLifeExt = NO;
		nf.scanChannels = 0x00000800;
		nf.scanDuration = 0x2;
		nf.superframeOrder = 0xf;
		NWK_nlme_formNetworkReq(&nf);

	}
else{		
	nwk_join_t join;
	join.extedPANid = 0x0000222388894343;
	join.capabilityInfo.altPanCoord = NO;
	join.capabilityInfo.powerSource = 0;
	join.capabilityInfo.devType = 0;
	join.capabilityInfo.reserved2 = 0;
	join.capabilityInfo.secEnabled = 0;
	join.capabilityInfo.allocAddr = 0x01;
	join.duration = 2;
	join.scanChannels = 0x00000800;
	join.securityEnabled = NO;
	join.rejoinNetwork = JOINED_THRU_ASSOC;
	
	addr_t dest;
	dest.shortAddr = 0x0000;
	dest.PANid = 0x3ac6;
	dest.mode = 0x02;
	MAC_mlme_assocReq(&dest, DEFAULT_CHANNELPAGE, DEFAULT_CHANNEL, *((uint8_t *)&join.capabilityInfo), &sec);
}

	scheduler();
	

    return 0;
}
Example #4
0
void app_usb_task(void)
{
	static bool sw0_released = true;
	static bool usb_running = false;
	static bool cdc_running = false;
	static bool toggle = true;

	if (sw0_released && ioport_pin_is_low(GPIO_PUSH_BUTTON_0)) {
		/* A new press has been done */
		sw0_released = false;
		/* Switch USB state */
		if (usb_running) {
			udc_stop();
			gfx_mono_draw_filled_rect(DISPLAY_USB_STA_POS_X,
					DISPLAY_USB_STA_POS_Y,
					DISPLAY_USB_STA_SIZE_X,
					DISPLAY_USB_STA_SIZE_Y,
					GFX_PIXEL_CLR);
			app_microsd_start();
		} else {
			/* Stop FatFS on uSD card if enabled */
			app_microsd_stop();
			stdio_usb_init(); /* Start USB */
			gfx_mono_generic_put_bitmap(&bitmap_usb,
					DISPLAY_USB_STA_POS_X,
					DISPLAY_USB_STA_POS_Y);
		}

		usb_running = !usb_running;
		cdc_running = true;
	} else {
		/* Wait switch release */
		sw0_released = ioport_pin_is_high(GPIO_PUSH_BUTTON_0);
	}

	if (!usb_running) {
		return;
	}

	/* USB MSC task */
	while (udi_msc_process_trans()) {
	}

	if (app_usb_cdc_open && !cdc_running) {
		printf("\x0CSensor data logs:\r\n");
		cdc_running = true;
	}

	if (!app_usb_cdc_open && cdc_running) {
		cdc_running = false;
	}

	/* Toggle USB icon */
	if ((app_usb_cdc_open && app_usb_rec_toggle) ||
			(toggle && app_usb_rec_toggle)) {
		app_usb_rec_toggle = false;
		toggle = !toggle;
		gfx_mono_draw_rect(DISPLAY_USB_STACDC_POS_X,
				DISPLAY_USB_STACDC_POS_Y,
				DISPLAY_USB_STACDC_SIZE_X,
				DISPLAY_USB_STACDC_SIZE_Y,
				toggle ? GFX_PIXEL_SET : GFX_PIXEL_CLR);
	}
}