Exemplo n.º 1
0
/*====================================================================================================*/
int main( void )
{
  u8 i = 0;

  GPIO_Config();
  TIMER_Config();

  nrf_gpio_pin_set(LED_0);
  nrf_gpio_pin_clear(LED_1);

  while(1) {

//    nrf_gpio_pin_toggle(LED_0);
    nrf_gpio_pin_toggle(LED_1);
    for(i = 0; i<7; i++) {
      LED_PORT = ~(0x01<<i);
      Delay_1ms(DELAY_TIME);
    }
//    nrf_gpio_pin_toggle(LED_0);
    nrf_gpio_pin_toggle(LED_1);
    for(i = 7; i>0; i--) {
      LED_PORT = ~(0x01<<i);
      Delay_1ms(DELAY_TIME);
    }
  }
}
static void termdev_priv_btnPress(void *bD, BTNS_EventType evType) {
    dbg_debugModule("BTNPress\n");
    start_waiting_for_edge();
    nrf_gpio_pin_set(12);
    nrf_gpio_pin_toggle(TRIGGER_GPIO_PIN_NO);
    nrf_gpio_pin_toggle(LED_GPIO_NO);
}
Exemplo n.º 3
0
/** @brief: Function for handling the RTC0 interrupts.
 * Triggered on TICK and COMPARE0 match.
 */
static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
{
    if (int_type == NRF_DRV_RTC_INT_COMPARE0)
    {
        nrf_gpio_pin_toggle(COMPARE_EVENT_OUTPUT);
    }
    else if (int_type == NRF_DRV_RTC_INT_TICK)
    {
        nrf_gpio_pin_toggle(TICK_EVENT_OUTPUT);
    }
}
Exemplo n.º 4
0
/*====================================================================================================*/
int main( void )
{
  uint8_t Count = 0;
  uint8_t State = 0;

  GPIO_Config();
  SF595_Config();
  SF595_Init();

  while(1) {
    nrf_gpio_pin_toggle(LED_1);
    nrf_gpio_pin_toggle(LED_2);
    Delay_10ms(10);

    Count++;

    switch(State) {

        case 0:
          if (Count == 8) {
            SF595_Shift(0);
            State = 1;
          }
          else {
            SF595_Shift(0);
          }
          break;

        case 1:
          if (Count == 16) {
            SF595_Shift(1);
            State = 2;
          }
          else {
            SF595_Shift(1);
          }
          break;

        case 2:
          for(; State>0; State--) {
            SF595_SendByte(0x00);
            Delay_100ms(2);
            SF595_SendByte(0xFF);
            Delay_100ms(2);
          }
          Count = 0;
          break;
    }
  }
}
/**
 * main function
 * \return 0. int return type required by ANSI/ISO standard.
 */
int main(void)
{
    int i;

    gpio_init();
    gpiote_init();
    wdt_init();

    //Write the value of RESETREAS to pins 9-15 (LEDs 1-7)
    nrf_gpio_pin_write(LED_1, NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk); //Bit A in RESETREAS
    nrf_gpio_pin_write(LED_2, NRF_POWER->RESETREAS & POWER_RESETREAS_DOG_Msk);      //Bit B in RESETREAS
    nrf_gpio_pin_write(LED_3, NRF_POWER->RESETREAS & POWER_RESETREAS_SREQ_Msk);     //Bit C in RESETREAS
    nrf_gpio_pin_write(LED_4, NRF_POWER->RESETREAS & POWER_RESETREAS_LOCKUP_Msk);   //Bit D in RESETREAS
    nrf_gpio_pin_write(LED_5, NRF_POWER->RESETREAS & POWER_RESETREAS_OFF_Msk);      //Bit E in RESETREAS
    nrf_gpio_pin_write(LED_6, NRF_POWER->RESETREAS & POWER_RESETREAS_LPCOMP_Msk);   //Bit F in RESETREAS
    nrf_gpio_pin_write(LED_7, NRF_POWER->RESETREAS & POWER_RESETREAS_DIF_Msk);      //Bit G in RESETREAS    

    NRF_POWER->RESETREAS = 0xFFFFFFFF;   //Clear the RESETREAS register

    for(i=0;i<STARTUP_TOGGLE_ITERATIONS;i++)
    {
        nrf_gpio_pin_toggle(LED_0);
        nrf_delay_us(DELAY);
    }

    while (true)
    {
        //Blink LED 0 fast until watchdog triggers reset
        nrf_gpio_pin_toggle(LED_0);
        nrf_delay_us(DELAY/3);

        // If SYSTEM_OFF_BUTTON is pressed.. enter System Off mode
        if(nrf_gpio_pin_read(SYSTEM_OFF_BUTTON) == BTN_PRESSED)
        {
            // Clear PORT 1 (pins 8-15)
            nrf_gpio_port_clear(NRF_GPIO_PORT_SELECT_PORT1, 0xFF);

            // Enter system OFF. After wakeup the chip will be reset, and the program will run from the top 
            NRF_POWER->SYSTEMOFF = 1;
        }

        // If SOFTWARE_RESET_BUTTON is pressed.. soft-reset
        if(nrf_gpio_pin_read(SOFTWARE_RESET_BUTTON) == BTN_PRESSED)
        {
            NVIC_SystemReset();
        }
    }
}
/**@brief Timeout handler that is responsible for toggling the Advertisement LED.
 *
 * @details This function will be called each time the timer that was started for the sake of
 *          blinking the Advertisement LED expires. This function toggle the state of the
 *          Advertisement LED.
 *
 * @param[in]   p_context   Pointer used for passing some arbitrary information (context) from the
 *                          app_start_timer() call to the timeout handler.
 */
static void adv_led_blink_timeout_handler(void * p_context)
{
    if (m_is_adv_led_blinking)
    {
        bool *          p_is_led_on;
        uint32_t        next_timer_interval;
        uint32_t        err_code;
    
        APP_ERROR_CHECK_BOOL(p_context != NULL);

        nrf_gpio_pin_toggle(ADVERTISING_LED_PIN_NO);

        p_is_led_on = (bool *)(p_context);

        *p_is_led_on = !(*p_is_led_on);

        if(*p_is_led_on )
        {
            // The toggle operation above would have resulted in an ON state. So start a timer that
            // will expire after ADV_LED_ON_TIME.
            next_timer_interval = ADV_LED_ON_TIME;
        }
        else
        {
            // The toggle operation above would have resulted in an OFF state. So start a timer that
            // will expire after ADV_LED_OFF_TIME.
            next_timer_interval = ADV_LED_OFF_TIME;
        }

        err_code = app_timer_start(m_adv_led_blink_timer_id,
                                   next_timer_interval,
                                   p_is_led_on );
        APP_ERROR_CHECK(err_code);
    }
}
Exemplo n.º 7
0
bool PingModule::TerminalCommandHandler(string commandName, vector<string> commandArgs)
{
	if(commandArgs.size() >= 2 && commandArgs[1] == moduleName)
	{
		//React on commands, return true if handled, false otherwise
		if(commandName == "pingmod"){
			//Get the id of the target node
			nodeID targetNodeId = atoi(commandArgs[0].c_str());
			logt("PINGMOD", "Trying to ping node %u", targetNodeId);
			nrf_gpio_pin_toggle(18);

			//Send ping packet to that node
			connPacketModuleAction packet;
			packet.header.messageType = MESSAGE_TYPE_MODULE_TRIGGER_ACTION;
			packet.header.sender = node->persistentConfig.nodeId;
			packet.header.receiver = targetNodeId;
			packet.moduleId = moduleId;
			packet.actionType = PingModuleTriggerActionMessages::TRIGGER_PING;
			packet.data[0] = 123;


			cm->SendMessageToReceiver(NULL, (u8*)&packet, SIZEOF_CONN_PACKET_MODULE_ACTION + 1, true);

			return true;
		}
	}


	//Must be called to allow the module to get and set the config
	return Module::TerminalCommandHandler(commandName, commandArgs);
}
Exemplo n.º 8
0
/**@brief Timer callback used for periodic changing of LED state.
 */
static void iot_timer_client_four_callback(iot_timer_time_in_ms_t elapsed_time)
{
    UNUSED_PARAMETER(elapsed_time);
    LEDS_INVERT(DISPLAY_LED_3);
    nrf_gpio_pin_toggle(13);
    printf("------------------------- %4d ms\r\n", IOT_TIMER_CLIENT_FOUR_CB_INTERVAL);
}
Exemplo n.º 9
0
/**@brief Function for application main entry. Does not return.
 */ 
int main(void)
{
    bool is_test_success;
    
    // Configure all LEDs as outputs. 
    nrf_gpio_range_cfg_output(LED_START, LED_STOP);
        
    // Set LED_0 high to indicate that the application is running. 
    nrf_gpio_pin_set(LED_0);    
    
    for (;;)
    {
        is_test_success = test_spi_tx_rx();
        if (!is_test_success)        
        {
            // Set LED2 high to indicate that error has occurred. 
            nrf_gpio_pin_set(LED_2);            
            for (;;)
            {
                // No implementation needed.           
            }
        }
        
        nrf_gpio_pin_toggle(LED_1);
        nrf_delay_ms(DELAY_MS);   
    }
}
Exemplo n.º 10
0
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    ret_code_t ret_code;
    nrf_gpio_cfg_output(LED_1);
    nrf_gpio_pin_set(LED_1);
    nrf_gpio_cfg_output(LED_2);
    nrf_gpio_pin_set(LED_2);
    uart_config();
    printf("\033[2J\033[;H\r\n* Example to find TWI devices connected to \r\n* the TWI bus and their addresses\r\n\r\n");
    twi_init();
    
    uint8_t dummy_data = 0x55;
    // Itterate through all possible 7-bit TWI addresses
    for(uint8_t i = 0; i <= 0x7F; i++)
    {
        device_address = i;
        // Send dummy data. If a device is present on this particular address a TWI EVT_DONE event is 
        // received in the twi event handler and a message is printed to UART
        ret_code = nrf_drv_twi_tx(&twi_instance, i, &dummy_data, 1, false);
        APP_ERROR_CHECK(ret_code);
        // Delay 10 ms to allow TWI transfer to complete and UART to print messages before starting new transfer
        nrf_delay_ms(10);
    }
    if(device_found)
    {
        // Blinke LED_1 rapidly if device is found
        while(true)
        {
            nrf_gpio_pin_toggle(LED_1);
            nrf_delay_ms(1000);
        }
    }
    else
    {
        // Disable LED_1 if device is NOT found
        nrf_gpio_cfg_default(LED_1);
        printf("*****************\n\rNO DEVICES FOUND!\r\n*****************\n\r");
        while(true)
        {
            nrf_gpio_pin_toggle(LED_2);
            nrf_delay_ms(100);;
        }      
    }
}
Exemplo n.º 11
0
/** @brief Function for handling the GPIOTE interrupt which is triggered on pin 0 change.
 */
void GPIOTE_IRQHandler(void)
{
    // Event causing the interrupt must be cleared.
    if ((NRF_GPIOTE->EVENTS_IN[0] == 1) && 
        (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN0_Msk))
    {
        NRF_GPIOTE->EVENTS_IN[0] = 0;
    }
    nrf_gpio_pin_toggle(8);
}
Exemplo n.º 12
0
int main(void)
{
        // Configure green LED-pin as output
        nrf_gpio_cfg_output(BLE_DEV_BOARD_LED_GREEN);

        while(true)
        {
                nrf_gpio_pin_toggle(BLE_DEV_BOARD_LED_GREEN);
                nrf_delay_ms(100);
        }
}
Exemplo n.º 13
0
/**@brief LED0 task entry function.
 *
 * @param[in] pvParameter   Pointer that will be used as the parameter for the task.
 */
static void vLed0Function (void *pvParameter)
{
    UNUSED_PARAMETER(pvParameter);
    for( ;; )
    {
        nrf_gpio_pin_toggle(BSP_LED_0);
        vTaskDelay(TASK_DELAY); // Delay a task for a given number of ticks

        // Tasks must be implemented to never return...
    }
}
Exemplo n.º 14
0
/**
 * @brief Function for main application entry.
 */
int main(void)
{
    // Configure pins 8 to 15 as outputs.
    nrf_gpio_cfg_output(GPIO_TOGGLE_PIN);

    while (true)
    {
        nrf_gpio_pin_toggle(GPIO_TOGGLE_PIN);
        // use Timer 0 peripheral to generate 100 ms delay.
        nrf_timer_delay_ms(TIMER0, TIMER_DELAY_MS);
    
        nrf_gpio_pin_toggle(GPIO_TOGGLE_PIN);
        // use Timer 1 peripheral to generate 100 ms delay.
        nrf_timer_delay_ms(TIMER1, TIMER_DELAY_MS);
    
        nrf_gpio_pin_toggle(GPIO_TOGGLE_PIN);
        // use Timer 2 peripheral to generate 100 ms delay.
        nrf_timer_delay_ms(TIMER2, TIMER_DELAY_MS);
    } 
}
/** GPIOTE interrupt handler.
 * Triggered on WATCHDOG_RELOAD_BUTTON change
 */
void GPIOTE_IRQHandler(void)
{
    // Event causing the interrupt must be cleared
    if ((NRF_GPIOTE->EVENTS_IN[0] == 1) && (NRF_GPIOTE->INTENSET & GPIOTE_INTENSET_IN0_Msk))
    {
        NRF_GPIOTE->EVENTS_IN[0] = 0;
        
        NRF_WDT->RR[0] = WATCHDOG_RELOAD_CONSTANT; 
        
        nrf_gpio_pin_toggle(LED_0);
    }
}
Exemplo n.º 16
0
/** RTC0 interrupt handler.
 * Triggered on TICK and COMPARE0 match.
 */
void RTC0_IRQHandler()
{
  if ((NRF_RTC0->EVENTS_TICK != 0) && ((NRF_RTC0->INTENSET & RTC_INTENSET_TICK_Msk) != 0))
  {
    NRF_RTC0->EVENTS_TICK = 0;
    nrf_gpio_pin_toggle(GPIO_TOGGLE_TICK_EVENT);
  }
  if ((NRF_RTC0->EVENTS_COMPARE[0] != 0) && ((NRF_RTC0->INTENSET & RTC_INTENSET_COMPARE0_Msk) != 0))
  {
    NRF_RTC0->EVENTS_COMPARE[0] = 0;
    nrf_gpio_pin_write(GPIO_TOGGLE_COMPARE_EVENT, 1);
  }
}
Exemplo n.º 17
0
/*
 * Handler to be called when button is pushed.
 * param[in]   pin_no 			The pin number where the event is genereated
 * param[in]   button_action 	Is the button pushed or released
 */
static void button_handler(uint8_t pin_no, uint8_t button_action)
{
    if(button_action == APP_BUTTON_PUSH)
    {
        switch(pin_no)
        {
            case BUTTON_1:
                nrf_gpio_pin_toggle(LED_1);
                break;
            case BUTTON_2:
                nrf_gpio_pin_toggle(LED_2);
                break;
            case BUTTON_3:
                nrf_gpio_pin_toggle(LED_3);
                break;
            case BUTTON_4:
                nrf_gpio_pin_toggle(LED_4);
                break;
            default:
                break;
        }
    }
}
Exemplo n.º 18
0
void PingModule::ConnectionPacketReceivedEventHandler(connectionPacket* inPacket, Connection* connection, connPacketHeader* packetHeader, u16 dataLength)
{
	//Must call superclass for handling
	Module::ConnectionPacketReceivedEventHandler(inPacket, connection, packetHeader, dataLength);

	//Filter trigger_action messages
	if(packetHeader->messageType == MESSAGE_TYPE_MODULE_TRIGGER_ACTION){
		connPacketModuleAction* packet = (connPacketModuleAction*)packetHeader;

		//Check if our module is meant and we should trigger an action
		if(packet->moduleId == moduleId){
			//It's a ping message
			if(packet->actionType == PingModuleTriggerActionMessages::TRIGGER_PING){
				nrf_gpio_pin_toggle(18);
				//Inform the user
				logt("PINGMOD", "Ping request received with data: %d", packet->data[0]);

				//Send PING_RESPONSE
				connPacketModuleAction outPacket;
				outPacket.header.messageType = MESSAGE_TYPE_MODULE_ACTION_RESPONSE;
				outPacket.header.sender = node->persistentConfig.nodeId;
				outPacket.header.receiver = packetHeader->sender;

				outPacket.moduleId = moduleId;
				outPacket.actionType = PingModuleActionResponseMessages::PING_RESPONSE;
				outPacket.data[0] = packet->data[0];
				outPacket.data[1] = 111;

				cm->SendMessageToReceiver(NULL, (u8*)&outPacket, SIZEOF_CONN_PACKET_MODULE_ACTION + 2, true);

			}
		}
	}

	//Parse Module action_response messages
	if(packetHeader->messageType == MESSAGE_TYPE_MODULE_ACTION_RESPONSE){

		connPacketModuleAction* packet = (connPacketModuleAction*)packetHeader;

		//Check if our module is meant and we should trigger an action
		if(packet->moduleId == moduleId)
		{
			//Somebody reported its connections back
			if(packet->actionType == PingModuleActionResponseMessages::PING_RESPONSE){
				logt("PINGMOD", "Ping came back from %u with data %d, %d", packet->header.sender, packet->data[0], packet->data[1]);
			}
		}
	}
}
Exemplo n.º 19
0
/**
 * @brief Function for application main entry.
 */
int main(void)
{
    gpio_init();
	interrupt_init();
	LTC2492_Init();
	nrf_gpio_pin_set(LED_1);
	
	simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);
	
	
	int size = 128; 
	double storage[128];
	memset(storage, 0, sizeof(*storage) * size);
	//double * storage = malloc(sizeof(*storage) * size ); 
	int i = 0; 
    while (true)
    {	
		
		nrf_delay_ms(150); 
		
		nrf_gpio_pin_toggle(LED_1);
		uint32_t output = SPI0_LTC2492_Read();
		
		uint8_t chuncks_8bit[4];
		chuncks_8bit[0] = (output & 0xFF000000) >> 24; ;
		chuncks_8bit[1] = (output & 0x00FF0000) >> 16; 
		chuncks_8bit[2] = (output & 0x0000FF00) >> 8; 
		chuncks_8bit[3] = (output & 0x000000FF) >> 0; 
		
		int count; 
		for (count = 0; count < 4; count++) {
			simple_uart_put(chuncks_8bit[count]);
		}
		
		
		
		storage[i] = output; 
		i++; 
		
		if (i == 128) {
			i = 0; 
		}
		
			
	}
	
		
}
Exemplo n.º 20
0
static void rtc1_handler(nrf_drv_rtc_int_type_t int_type) {
//    uint32_t err_code;

    if (int_type == NRF_DRV_RTC_INT_COMPARE0) {   // Interrupt from COMPARE0 event.
        nrf_gpio_pin_set(led_pin1);
        nrf_drv_rtc_int_enable(&rtc1, RTC_CHANNEL_INT_MASK(0));
    } else if (int_type == NRF_DRV_RTC_INT_COMPARE1) {   // Interrupt from COMPARE1 event.
        nrf_gpio_pin_clear(led_pin1);
        nrf_drv_rtc_int_enable(&rtc1, RTC_CHANNEL_INT_MASK(1));
    } else if (int_type == NRF_DRV_RTC_INT_COMPARE2) {   // Interrupt from COMPARE2 event.
        nrf_drv_rtc_counter_clear(&rtc1);
        nrf_drv_rtc_int_enable(&rtc1, RTC_CHANNEL_INT_MASK(2));
    } else if (int_type == NRF_DRV_RTC_INT_TICK) {       // Tick off
        nrf_gpio_pin_toggle(led_pin1);
    }
}
Exemplo n.º 21
0
static void rtc1_handler(nrf_drv_rtc_int_type_t int_type) {
//    uint32_t err_code;

    NRF_LOG_DEBUG("rtc1_handler %d %u\n\r",int_type,pos);
    if (int_type == NRF_DRV_RTC_INT_COMPARE0) {   // Interrupt from COMPARE0 event.
    	uint16_t temp;
        nrf_gpio_pin_toggle(led_pin1);
        if (pos%2==0) {
        	max6675_prepare(&max6675_config);
        } else {
        	temp=max6675_readcelsius(&max6675_config);
            NRF_LOG_INFO("rtc1_handler temp \x1B[1;32m%u\x1B[0m,\x1B[1;31m%d\x1B[0m    \r",temp>>2,(temp&0x0003)*25);
        }
        nrf_drv_rtc_int_enable(&rtc1, RTC_CHANNEL_INT_MASK(0));
        nrf_drv_rtc_counter_clear(&rtc1);


    }
Exemplo n.º 22
0
static void inline display_toggle_COM()
{
	// check if VCOM Inversion is inhibited by display write
	if( !VCOM_inhibit )
  {
		// raise DISP_CS
		// nrf_gpio_pin_set( PIN_DISP_CS );
		// raise EXTCOMIN
		// nrf_gpio_pin_set( PIN_VCOM );
		// wait 2 us
		// nrf_delay_us( 2 );
		// lower EXTCOMIN
		// lower CS
		// nrf_gpio_pin_clear( PIN_VCOM );
		// nrf_gpio_pin_clear( PIN_DISP_CS );
		
		nrf_gpio_pin_toggle( PIN_VCOM );
  }
}
Exemplo n.º 23
0
/**
 * @brief Function for application main entry.
 */
int main(void) {

    uint8_t pos=0;
    // setup
    // Configure LED-pin as outputs and clear.
    for (pos=0;pos<LEDPINS;pos++) {
    	nrf_gpio_cfg_output(led_pin[pos]);
    	nrf_gpio_pin_clear(led_pin[pos]);
    }

    // loop
    // Toggle LED.
    pos=0;
    while (true) {
        nrf_gpio_pin_toggle(led_pin[pos]);
        nrf_delay_ms(1000);
        pos++;
		if (pos>=LEDPINS) {
			pos=0;
		}
    }
}
Exemplo n.º 24
0
static void read_all(void)
{
    // Signal on LED that something is going on.
    nrf_gpio_pin_toggle(READ_ALL_INDICATOR);

    // [these structures have to be "static" - they cannot be placed on stack
    //  since the transaction is scheduled and these structures most likely
    //  will be referred after this function returns]
    static app_twi_transfer_t const transfers[] =
    {
        LM75B_READ_TEMP(&m_buffer[0])
        ,
        MMA7660_READ_XYZ_AND_TILT(&m_buffer[2])
    };
    static app_twi_transaction_t const transaction =
    {
        .callback            = read_all_cb,
        .p_user_data         = NULL,
        .p_transfers         = transfers,
        .number_of_transfers = sizeof(transfers) / sizeof(transfers[0])
    };

    APP_ERROR_CHECK(app_twi_schedule(&m_app_twi, &transaction));
}


static void print_data(char const * name,
                       uint8_t const * p_buffer, uint8_t length)
{
    printf("\r\n%s", name);

    do {
        printf(" %02X", *p_buffer++);
    } while (--length);

    printf("\r\n\r\n");
}
Exemplo n.º 25
0
void LED2_Toggle(void)
{
  nrf_gpio_pin_toggle(LED_1);
}
Exemplo n.º 26
0
void led_toggle(board_led_obj_t * led_obj) {
    nrf_gpio_pin_toggle(led_obj->hw_pin);
}
Exemplo n.º 27
0
/**
 * @brief Timer routine for fall & step detection.
 */
void process_step_count(void * p_context)
{
  //timer_stop(m_app_timer_id);
	
	reset_wdt();
	
	nrf_gpio_pin_toggle(LED_RESETTING); 
	
	if (NRF_NVMC->READY == NVMC_READY_READY_Busy)
  {
        // Do not interfere if flash write is ongoing.
			return;
  }

  
	
	if (SaveSnapshot == 1)
	{
		nrf_gpio_pin_set(LED_RESETTING);
		return;
	}
	
	if (ReadBigSnapshot == 1)
		return;

    
    // store snapshot
		readSensorsAndStore(); 
	
	//process activity levels
		updateAverages();
		curr_sv = latestResultant();

	
	if (BLESessionActive == 1)
		return;
	
		if (curr_sv < getPerso()->freefall_threshold) {
			zero_g_detected = true;	
		}
	
//		if ( checkOrientation() == ORIENTATION_STANDING){
//			if (curr_sv < getPerso()->freefall_threshold){
//					zero_g_detected = true;
//				}
//			}
//		else if (checkOrientation() == ORIENTATION_NOT_STANDING)
//		{
//			if (curr_sv < NOT_STANDING_FREEFALL_THRESHOLD_DEFAULT){
//				zero_g_detected = true;
//			}
//		}
		else {
			zero_g_detected = false;
			
		}
    
    //zero_g_detected = fd_check_zero_g();    
    if (zero_g_detected == true) 
    {        
      nrf_gpio_pin_write(LED_OTHER,1);
			
//			if (count == 0) 
				accel_get_angles(&xAngleBeforeImpact, &yAngleBeforeImpact);			
			
			count = getPerso()->fall_detection_window;
		}
			
			if (count > 0)
			{
				count--;
					
				fall_detected = fd_check_for_impact(curr_sv);
					if (fall_detected == 0xFF) 
					{
							accel_get_angles(&xAngleAfterImpact, &yAngleAfterImpact);
						
	//						if (abs(xAngleAfterImpact - xAngleBeforeImpact) >= getPerso()->x_angle_threshold && 
	//								abs(yAngleAfterImpact - yAngleBeforeImpact) >= getPerso()->y_angle_threshold)
							{                   
									ClearDataBuffer = ClearSnapshots = SetTimestamp = 0;
								
							//		backupRawData();
								
									do_post_processing = true;
									
									emergencyCall = 1;

									zero_g_detected = false;
									fall_detected = 0;
									count = 0;
									
							}
							
					}
					
			}

			if (count == 0)
				nrf_gpio_pin_write(LED_OTHER,0);
 /*   
			else 
			{
				// detect if step occurred
				if (detect_step(xRaw,yRaw,zRaw)==1) 
						{
								nSteps++;
						}
			}
*/
 
}
Exemplo n.º 28
0
/**
 * @brief Function for application main entry.
 */
int main(void)
{
    // Configure pins 8-15 (Port1) as outputs
    nrf_gpio_range_cfg_output(8, 15);
    nrf_gpio_port_clear(NRF_GPIO_PORT_SELECT_PORT1, 0XFF);

    // Configure motion interrupt pin
    nrf_gpio_cfg_input(MOTION_INTERRUPT_PIN_NUMBER, NRF_GPIO_PIN_PULLDOWN);

    gpiote_init();

    if (adns2080_init() != ADNS2080_OK)
    {
        // ADNS2080 init failed, set rightmost LED on.
        nrf_gpio_pin_write(15, 1);
        while (true)
        {
            //  Do nothing.
        }
    }

    // By default, ADNS2080 motion interrupt output is active low, edge sensitive; make it active high.
    if (adns2080_motion_interrupt_set(ADNS2080_MOTION_OUTPUT_POLARITY_HIGH, ADNS2080_MOTION_OUTPUT_SENSITIVITY_LEVEL) != ADNS2080_OK)
    {
        nrf_gpio_pin_write(14, 1);
        while (true)
        {
            // Do nothing.
        }
    }

    // Read out movement to clear ADNS2080 interrupt flags.
    if (adns2080_is_motion_detected())
    {
        int16_t dummy;
        adns2080_movement_read(&dummy, &dummy);
    }

    // Enable GPIOTE interrupt in Nested Vector Interrupt Controller.
    NVIC_EnableIRQ(GPIOTE_IRQn);

    // Enable global interrupts.
    __enable_irq();

    while(true)
    {
        if (motion_interrupt_detected)
        {
            // Toggle pin 12 to indicate that we've detected motion interrupt.
            nrf_gpio_pin_toggle(12);
            
            motion_interrupt_detected = false;

            // On our Nordic reference design PCB, the chip orientation is not the same as in the ADNS2080
            // datasheet diagram, so X and Y axis are reversed. This is corrected by passing the pointer
            // parameters in reversed order. */
            adns2080_movement_read(&m_delta_y, &m_delta_x);

            // If movement delta_x is above the threshold, the LEDs light up accordingly. When the mouse is moved
            // to the left, LEDs 1 through 4 are lit and when the mouse is moved right, LEDs 5 through 8 are lit.
            if (m_delta_x > MOUSE_MOVEMENT_THRESHOLD)
            {
                nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, 0xF0);
            }
            else if (m_delta_x < (-MOUSE_MOVEMENT_THRESHOLD))
            {
                nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, 0x0F);
            }
            else
            {
                nrf_gpio_port_clear(NRF_GPIO_PORT_SELECT_PORT1,  0xFF);
            }
        }
    }
}
Exemplo n.º 29
0
static void timer_timeout_handler(void * p_context)
{
    UNUSED_PARAMETER(p_context);
    nrf_gpio_pin_toggle(BSP_LED_1);
    nrf_adc_start();
}
Exemplo n.º 30
0
void LED1_Toggle(void)
{
  nrf_gpio_pin_toggle(LED_0);
}