Commit b15810de authored by siguhe's avatar siguhe

Encoders functional

parent 8c5f9cc2
......@@ -72,10 +72,17 @@
#define ADVERTISING_LED BSP_BOARD_LED_0 /**< Is on when device is advertising. */
#define CONNECTED_LED BSP_BOARD_LED_1 /**< Is on when device has connected. */
#define LEDBUTTON_LED BSP_BOARD_LED_2 /**< LED to be toggled with the help of the LED Button Service. */
#define LEDBUTTON_BUTTON0 BSP_BUTTON_0 /**< Button that will trigger the notification event with the LED Button Service */
#define LEDBUTTON_BUTTON1 BSP_BUTTON_1 /**< Button that will trigger the notification event with the LED Button Service */
#define LEDBUTTON_BUTTON2 BSP_BUTTON_2 /**< Button that will trigger the notification event with the LED Button Service */
#define LEDBUTTON_BUTTON3 BSP_BUTTON_3 /**< Button that will trigger the notification event with the LED Button Service */
#define LEDBUTTON_BUTTON0 BSP_BUTTON_0 /**< Button that will trigger the notification event with the LED Button Service */
#define LEDBUTTON_BUTTON1 BSP_BUTTON_1 /**< Button that will trigger the notification event with the LED Button Service */
#define LEDBUTTON_BUTTON2 BSP_BUTTON_2 /**< Button that will trigger the notification event with the LED Button Service */
#define LEDBUTTON_BUTTON3 BSP_BUTTON_3 /**< Button that will trigger the notification event with the LED Button Service */
#define ENCODER1_A 25
#define ENCODER1_B 26
#define ENCODER2_A 27
#define ENCODER2_B 28
#define ENCODER3_A 29
#define ENCODER3_B 30
#define DEVICE_NAME "Testurd" /**< Name of device. Will be included in the advertising data. */
......@@ -95,7 +102,7 @@
#define NEXT_CONN_PARAMS_UPDATE_DELAY APP_TIMER_TICKS(5000) /**< Time between each call to sd_ble_gap_conn_param_update after the first call (5 seconds). */
#define MAX_CONN_PARAMS_UPDATE_COUNT 3 /**< Number of attempts before giving up the connection parameter negotiation. */
#define BUTTON_DETECTION_DELAY APP_TIMER_TICKS(50) /**< Delay from a GPIOTE event until a button is reported as pushed (in number of timer ticks). */
#define BUTTON_DETECTION_DELAY APP_TIMER_TICKS(4) /**< Delay from a GPIOTE event until a button is reported as pushed (in number of timer ticks). */
#define DEAD_BEEF 0xDEADBEEF /**< Value used as error code on stack dump, can be used to identify stack location on stack unwind. */
......@@ -110,6 +117,10 @@ static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
static uint8_t m_enc_advdata[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; /**< Buffer for storing an encoded advertising set. */
static uint8_t m_enc_scan_response_data[BLE_GAP_ADV_SET_DATA_SIZE_MAX]; /**< Buffer for storing an encoded scan data. */
static uint8_t advertising_now=0;
static uint8_t counter_encoder1=0;
static uint8_t counter_encoder2=0;
static uint8_t counter_encoder3=0;
/**@brief Struct that contains pointers to the encoded advertising data. */
......@@ -405,7 +416,7 @@ static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
NRF_LOG_INFO("Connected");
bsp_board_led_on(CONNECTED_LED);
bsp_board_led_off(ADVERTISING_LED);
//nrf_gpio_pin_set(2);
nrf_gpio_pin_set(2);
m_conn_handle = p_ble_evt->evt.gap_evt.conn_handle;
err_code = nrf_ble_qwr_conn_handle_assign(&m_qwr, m_conn_handle);
APP_ERROR_CHECK(err_code);
......@@ -416,7 +427,7 @@ static void ble_evt_handler(ble_evt_t const * p_ble_evt, void * p_context)
case BLE_GAP_EVT_DISCONNECTED:
NRF_LOG_INFO("Disconnected");
bsp_board_led_off(CONNECTED_LED);
//nrf_gpio_pin_clear(2);
nrf_gpio_pin_clear(2);
m_conn_handle = BLE_CONN_HANDLE_INVALID;
//err_code = app_button_disable();
//APP_ERROR_CHECK(err_code);
......@@ -512,66 +523,50 @@ static void button_event_handler(uint8_t pin_no, uint8_t button_action)
ret_code_t err_code;
uint8_t position[4];
position[0]=counter_encoder1;
position[1]=counter_encoder2;
position[2]=counter_encoder3;
position[3]=0;
switch (pin_no)
{
case LEDBUTTON_BUTTON0:
bsp_board_led_on(BSP_BOARD_LED_3);
position[0]=2;
position[1]=1;
position[2]=0;
position[3]=0;
NRF_LOG_INFO("Send button state change.");
err_code = ble_lbs_on_button_change(m_conn_handle, &m_lbs, position);
if (err_code != NRF_SUCCESS &&
err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
err_code != NRF_ERROR_INVALID_STATE &&
err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
{
APP_ERROR_CHECK(err_code);
case ENCODER1_A:
if(button_action){
if(nrf_gpio_pin_read(ENCODER1_B)){
counter_encoder1+=1;
}
else{
counter_encoder1-=1;
}
}
break;
case LEDBUTTON_BUTTON1:
bsp_board_led_off(BSP_BOARD_LED_3);
position[0]=2;
position[1]=1;
position[2]=1;
position[3]=0;
NRF_LOG_INFO("Send button state change.");
err_code = ble_lbs_on_button_change(m_conn_handle, &m_lbs, position);
if (err_code != NRF_SUCCESS &&
err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
err_code != NRF_ERROR_INVALID_STATE &&
err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
{
APP_ERROR_CHECK(err_code);
case ENCODER2_A:
if(button_action){
if(nrf_gpio_pin_read(ENCODER2_B)){
counter_encoder2+=1;
}
else{
counter_encoder2-=1;
}
}
break;
case LEDBUTTON_BUTTON2:
position[0]=2;
position[1]=1;
position[2]=2;
position[3]=0;
NRF_LOG_INFO("Send button state change.");
err_code = ble_lbs_on_button_change(m_conn_handle, &m_lbs, position);
if (err_code != NRF_SUCCESS &&
err_code != BLE_ERROR_INVALID_CONN_HANDLE &&
err_code != NRF_ERROR_INVALID_STATE &&
err_code != BLE_ERROR_GATTS_SYS_ATTR_MISSING)
{
APP_ERROR_CHECK(err_code);
case ENCODER3_A:
if(button_action){
if(nrf_gpio_pin_read(ENCODER3_B)){
counter_encoder3+=1;
}
else{
counter_encoder3-=1;
}
}
break;
case LEDBUTTON_BUTTON3:
position[0]=2;
position[1]=1;
position[2]=3;
position[3]=button_action;
NRF_LOG_INFO("Send button state change.");
err_code = ble_lbs_on_button_change(m_conn_handle, &m_lbs, position);
if (err_code != NRF_SUCCESS &&
......@@ -587,6 +582,7 @@ static void button_event_handler(uint8_t pin_no, uint8_t button_action)
APP_ERROR_HANDLER(pin_no);
break;
}
}
......@@ -599,10 +595,11 @@ static void buttons_init(void)
//The array must be static because a pointer to it will be saved in the button handler module.
static app_button_cfg_t buttons[] =
{
{LEDBUTTON_BUTTON0, false, BUTTON_PULL, button_event_handler},
{LEDBUTTON_BUTTON1, false, BUTTON_PULL, button_event_handler},
{LEDBUTTON_BUTTON2, false, BUTTON_PULL, button_event_handler},
{ENCODER1_A, false, NRF_GPIO_PIN_NOPULL, button_event_handler},
{ENCODER2_A, false, NRF_GPIO_PIN_NOPULL, button_event_handler},
{ENCODER3_A, false, NRF_GPIO_PIN_NOPULL, button_event_handler},
{LEDBUTTON_BUTTON3, false, BUTTON_PULL, button_event_handler}
};
err_code = app_button_init(buttons, ARRAY_SIZE(buttons),
......@@ -666,6 +663,9 @@ int main(void)
advertising_start();
nrf_gpio_cfg_output(20);
nrf_gpio_cfg_output(2);
nrf_gpio_cfg_input(ENCODER1_B,NRF_GPIO_PIN_NOPULL);
nrf_gpio_cfg_input(ENCODER2_B,NRF_GPIO_PIN_NOPULL);
nrf_gpio_cfg_input(ENCODER3_B,NRF_GPIO_PIN_NOPULL);
nrf_gpio_pin_clear(2);
// nrf_gpio_pin_toggle(6);
......
<!DOCTYPE CrossStudio_Session_File>
<session>
<Bookmarks/>
<Breakpoints groups="Breakpoints" active_group="Breakpoints">
<Exceptions set="MemManage;UsageFault_Coprocessor;UsageFault_CheckingError;UsageFault_StateError;BusFault;ExceptionEntryReturnFault;HardFault"/>
</Breakpoints>
<Breakpoints groups="Breakpoints" active_group="Breakpoints"/>
<ExecutionProfileWindow/>
<FrameBufferWindow>
<FrameBufferWindow bufferHeight="-1" addressSpace="" addressText="" bufferWidth="-1"/>
......@@ -63,14 +61,15 @@
</Watch4>
<Files>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="175" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/ble/nrf_ble_qwr/nrf_ble_qwr.c" selected="0" top="159" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="0" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/softdevice/s132/headers/ble.h" selected="0" top="132" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="646" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../main.c" selected="1" top="632" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="0" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/softdevice/s132/headers/ble.h" selected="0" top="0" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="572" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../main.c" selected="1" top="565" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="1845" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/softdevice/s132/headers/ble_gap.h" selected="0" top="1819" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="71" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/ble/ble_services/ble_lbs/ble_lbs.c" selected="0" top="57" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="199" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/boards/boards.h" selected="0" top="183" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="71" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/boards/boards.c" selected="0" top="47" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="120" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/ble/ble_services/ble_lbs/ble_lbs.c" selected="0" top="114" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="154" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/boards/boards.h" selected="0" top="142" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="64" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/boards/boards.c" selected="0" top="45" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="642" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../modules/nrfx/hal/nrf_gpio.h" selected="0" top="634" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="64" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/boards/pca10040.h" selected="0" top="64" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="76" useTextEdit="1" useBinaryEdit="0" left="0" path="../../../../../../components/boards/pca10040.h" selected="0" top="62" codecName="Default"/>
<SessionOpenFile windowGroup="DockEditLeft" x="0" y="7061" useTextEdit="1" useBinaryEdit="0" left="0" path="../config/sdk_config.h" selected="0" top="7047" codecName="Default"/>
</Files>
<ARMCrossStudioWindow activeProject="ble_app_blinky_pca10040_s132" fileDialogDefaultFilter="*.c" autoConnectTarget="J-Link" buildConfiguration="Release" debugSearchFileMap="" fileDialogInitialDirectory="/home/bruk/nRF5_SDK_15.3.0_59ac345/examples/peripheral/blinky" debugSearchPath="" autoConnectCapabilities="3711"/>
<ARMCrossStudioWindow activeProject="ble_app_blinky_pca10040_s132" fileDialogDefaultFilter="*.c" autoConnectTarget="J-Link" buildConfiguration="Release" debugSearchFileMap="" fileDialogInitialDirectory="/home/bruk/nRF5_SDK_15.3.0_59ac345/examples/peripheral/blinky" debugSearchPath="" autoConnectCapabilities="3199"/>
</session>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment