Loading Software-modul/module_code/main.c +63 −97 Original line number Diff line number Diff line Loading @@ -82,6 +82,7 @@ #include "nrf_log_ctrl.h" #include "nrf_log_default_backends.h" /* Defines exclusive per PCB ---------------------------------------------------------------- */ #define SECTION_NUMBER 8 #define DEVICE_NAME "NeokompSeksjon8" /**< Name of device. Will be included in the advertising data. */ Loading @@ -96,8 +97,8 @@ #define ENCODER2_B 28 #define ENCODER3_A 29 #define ENCODER3_B 30 #define ENCODER4_A 31 #define ENCODER4_B 32 #define ENCODER4_A 7 #define ENCODER4_B 8 #define LCD_SCREEN_LED 2 #define LCD_SCREEN_DC 0 Loading Loading @@ -138,9 +139,9 @@ static uint32_t background_color = WHITE; #define MAX_SCROLL 20 //Max value of both shelf, row, column anbd depth #define LINE_STEP 10 #define CIRCLE_RADIUS 10 #define CIRCLE_STEP ((2 * CIRCLE_RADIUS) + 1) #define BORDER 2 BLE_LBS_DEF(m_lbs); /**< LED Button Service instance. */ NRF_BLE_GATT_DEF(m_gatt); /**< GATT module instance. */ Loading Loading @@ -178,10 +179,9 @@ static int state; #define NORMAL_STATE 2 #define SLEEP_STATE 3 //Forward declarations //Forward declaration void text_print_large(char *test_text, uint16_t x, uint16_t y, uint16_t color, uint8_t side); void start_sleep_state(); APP_TIMER_DEF(screen_timer_id); APP_TIMER_DEF(send_timer_id); Loading Loading @@ -220,10 +220,15 @@ void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name) { */ static void leds_init(void) { bsp_board_init(BSP_INIT_LEDS); nrf_gpio_cfg_output(LCD_SCREEN_LED); nrf_gpio_cfg_output(LCD_SCREEN_DC); nrf_gpio_cfg_output(NOTIFICATION_LED); 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(LCD_SCREEN_LED); } static void timer_timeout(void *p_context); //Forward declaration /**@brief Function for the Timer initialization. * * @details Initializes the timer module. Loading @@ -232,8 +237,8 @@ static void timers_init(void) { // Initialize timer module, making it use the scheduler ret_code_t err_code = app_timer_init(); APP_ERROR_CHECK(err_code); app_timer_create(&screen_timer_id, APP_TIMER_MODE_SINGLE_SHOT, timer_timeout); app_timer_create(&send_timer_id, APP_TIMER_MODE_SINGLE_SHOT, timer_timeout); } /**@brief Function for the GAP initialization. Loading Loading @@ -358,6 +363,7 @@ static void nus_data_handler(ble_nus_evt_t *p_evt) { switch (p_evt->type) { case BLE_NUS_EVT_RX_DATA: NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART."); NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length); Loading Loading @@ -386,6 +392,7 @@ static void nus_data_handler(ble_nus_evt_t *p_evt) { nrf_gpio_pin_set(NOTIFICATION_LED); //Will send on notification enable. send_nus(); break; } } Loading Loading @@ -422,6 +429,7 @@ static void services_init(void) { nus_init.data_handler = nus_data_handler; err_code = ble_nus_init(&m_nus, &nus_init); APP_ERROR_CHECK(err_code); } Loading Loading @@ -508,6 +516,7 @@ static void advertising_stop(void) { } } /**@brief Function for handling BLE events. * * @param[in] p_ble_evt Bluetooth stack event. Loading Loading @@ -717,6 +726,7 @@ static void buttons_init(void) { 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_cfg_input(ENCODER4_B, NRF_GPIO_PIN_NOPULL); nrf_gpio_pin_clear(LCD_SCREEN_LED); nrf_gpio_pin_set(LCD_SCREEN_DC); Loading @@ -726,7 +736,6 @@ static void buttons_init(void) { {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}, {ENCODER4_A, false, NRF_GPIO_PIN_NOPULL, button_event_handler}, {BUTTON1, false, BUTTON_PULL, button_event_handler} }; Loading Loading @@ -806,55 +815,6 @@ void custom_background_draw(void) { APP_ERROR_CHECK(nrf_gfx_line_draw(p_lcd, &cross_horistontal_line_black, BLACK)); } static void line_draw(void) { nrf_gfx_line_t my_line = NRF_GFX_LINE(0, 0, 0, nrf_gfx_height_get(p_lcd), 2); nrf_gfx_line_t my_line_2 = NRF_GFX_LINE(nrf_gfx_width_get(p_lcd), nrf_gfx_height_get(p_lcd), 0, nrf_gfx_height_get(p_lcd), 2); for (uint16_t i = 0; i <= nrf_gfx_width_get(p_lcd); i += LINE_STEP) { my_line.x_end = i; APP_ERROR_CHECK(nrf_gfx_line_draw(p_lcd, &my_line, RED)); } my_line.x_end = nrf_gfx_width_get(p_lcd); for (uint16_t i = 0; i <= nrf_gfx_height_get(p_lcd); i += LINE_STEP) { my_line.y_end = (nrf_gfx_height_get(p_lcd) - i); APP_ERROR_CHECK(nrf_gfx_line_draw(p_lcd, &my_line, RED)); } for (uint16_t i = 0; i <= nrf_gfx_height_get(p_lcd); i += LINE_STEP) { my_line_2.y_end = (nrf_gfx_height_get(p_lcd) - i); APP_ERROR_CHECK(nrf_gfx_line_draw(p_lcd, &my_line_2, BLUE)); } my_line_2.y_end = 0; for (uint16_t i = 0; i <= nrf_gfx_width_get(p_lcd); i += LINE_STEP) { my_line_2.x_end = i; APP_ERROR_CHECK(nrf_gfx_line_draw(p_lcd, &my_line_2, BLUE)); } } static void circle_draw(void) { nrf_gfx_circle_t my_circle = NRF_GFX_CIRCLE(0, 0, CIRCLE_RADIUS); for (uint16_t j = 0; j <= nrf_gfx_height_get(p_lcd); j += CIRCLE_STEP) { my_circle.y = j; for (uint16_t i = 0; i <= nrf_gfx_width_get(p_lcd); i += CIRCLE_STEP) { my_circle.x = i; APP_ERROR_CHECK(nrf_gfx_circle_draw(p_lcd, &my_circle, BLUE, true)); } } for (uint16_t j = CIRCLE_RADIUS; j <= nrf_gfx_height_get(p_lcd) + CIRCLE_RADIUS; j += CIRCLE_STEP) { my_circle.y = j; for (uint16_t i = CIRCLE_RADIUS; i <= nrf_gfx_width_get(p_lcd) + CIRCLE_RADIUS; i += CIRCLE_STEP) { my_circle.x = i; APP_ERROR_CHECK(nrf_gfx_circle_draw(p_lcd, &my_circle, RED, false)); } } } void rect_draw(nrf_lcd_t const *p_instance, uint16_t x, uint16_t y, Loading Loading @@ -942,7 +902,6 @@ void start_sleep_state() { state = SLEEP_STATE; advertising_stop(); nrf_gpio_pin_clear(LCD_SCREEN_LED); idle_state_handle(); } } Loading @@ -969,8 +928,15 @@ int main(void) { services_init(); advertising_init(); conn_params_init(); // Start execution. app_button_enable(); gfx_initialization(); app_timer_create(&screen_timer_id, APP_TIMER_MODE_SINGLE_SHOT, timer_timeout); app_timer_create(&send_timer_id, APP_TIMER_MODE_SINGLE_SHOT, timer_timeout); // Set up screen default text start_sleep_state(); // Enter main loop. for (;;) { Loading Loading
Software-modul/module_code/main.c +63 −97 Original line number Diff line number Diff line Loading @@ -82,6 +82,7 @@ #include "nrf_log_ctrl.h" #include "nrf_log_default_backends.h" /* Defines exclusive per PCB ---------------------------------------------------------------- */ #define SECTION_NUMBER 8 #define DEVICE_NAME "NeokompSeksjon8" /**< Name of device. Will be included in the advertising data. */ Loading @@ -96,8 +97,8 @@ #define ENCODER2_B 28 #define ENCODER3_A 29 #define ENCODER3_B 30 #define ENCODER4_A 31 #define ENCODER4_B 32 #define ENCODER4_A 7 #define ENCODER4_B 8 #define LCD_SCREEN_LED 2 #define LCD_SCREEN_DC 0 Loading Loading @@ -138,9 +139,9 @@ static uint32_t background_color = WHITE; #define MAX_SCROLL 20 //Max value of both shelf, row, column anbd depth #define LINE_STEP 10 #define CIRCLE_RADIUS 10 #define CIRCLE_STEP ((2 * CIRCLE_RADIUS) + 1) #define BORDER 2 BLE_LBS_DEF(m_lbs); /**< LED Button Service instance. */ NRF_BLE_GATT_DEF(m_gatt); /**< GATT module instance. */ Loading Loading @@ -178,10 +179,9 @@ static int state; #define NORMAL_STATE 2 #define SLEEP_STATE 3 //Forward declarations //Forward declaration void text_print_large(char *test_text, uint16_t x, uint16_t y, uint16_t color, uint8_t side); void start_sleep_state(); APP_TIMER_DEF(screen_timer_id); APP_TIMER_DEF(send_timer_id); Loading Loading @@ -220,10 +220,15 @@ void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name) { */ static void leds_init(void) { bsp_board_init(BSP_INIT_LEDS); nrf_gpio_cfg_output(LCD_SCREEN_LED); nrf_gpio_cfg_output(LCD_SCREEN_DC); nrf_gpio_cfg_output(NOTIFICATION_LED); 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(LCD_SCREEN_LED); } static void timer_timeout(void *p_context); //Forward declaration /**@brief Function for the Timer initialization. * * @details Initializes the timer module. Loading @@ -232,8 +237,8 @@ static void timers_init(void) { // Initialize timer module, making it use the scheduler ret_code_t err_code = app_timer_init(); APP_ERROR_CHECK(err_code); app_timer_create(&screen_timer_id, APP_TIMER_MODE_SINGLE_SHOT, timer_timeout); app_timer_create(&send_timer_id, APP_TIMER_MODE_SINGLE_SHOT, timer_timeout); } /**@brief Function for the GAP initialization. Loading Loading @@ -358,6 +363,7 @@ static void nus_data_handler(ble_nus_evt_t *p_evt) { switch (p_evt->type) { case BLE_NUS_EVT_RX_DATA: NRF_LOG_DEBUG("Received data from BLE NUS. Writing data on UART."); NRF_LOG_HEXDUMP_DEBUG(p_evt->params.rx_data.p_data, p_evt->params.rx_data.length); Loading Loading @@ -386,6 +392,7 @@ static void nus_data_handler(ble_nus_evt_t *p_evt) { nrf_gpio_pin_set(NOTIFICATION_LED); //Will send on notification enable. send_nus(); break; } } Loading Loading @@ -422,6 +429,7 @@ static void services_init(void) { nus_init.data_handler = nus_data_handler; err_code = ble_nus_init(&m_nus, &nus_init); APP_ERROR_CHECK(err_code); } Loading Loading @@ -508,6 +516,7 @@ static void advertising_stop(void) { } } /**@brief Function for handling BLE events. * * @param[in] p_ble_evt Bluetooth stack event. Loading Loading @@ -717,6 +726,7 @@ static void buttons_init(void) { 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_cfg_input(ENCODER4_B, NRF_GPIO_PIN_NOPULL); nrf_gpio_pin_clear(LCD_SCREEN_LED); nrf_gpio_pin_set(LCD_SCREEN_DC); Loading @@ -726,7 +736,6 @@ static void buttons_init(void) { {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}, {ENCODER4_A, false, NRF_GPIO_PIN_NOPULL, button_event_handler}, {BUTTON1, false, BUTTON_PULL, button_event_handler} }; Loading Loading @@ -806,55 +815,6 @@ void custom_background_draw(void) { APP_ERROR_CHECK(nrf_gfx_line_draw(p_lcd, &cross_horistontal_line_black, BLACK)); } static void line_draw(void) { nrf_gfx_line_t my_line = NRF_GFX_LINE(0, 0, 0, nrf_gfx_height_get(p_lcd), 2); nrf_gfx_line_t my_line_2 = NRF_GFX_LINE(nrf_gfx_width_get(p_lcd), nrf_gfx_height_get(p_lcd), 0, nrf_gfx_height_get(p_lcd), 2); for (uint16_t i = 0; i <= nrf_gfx_width_get(p_lcd); i += LINE_STEP) { my_line.x_end = i; APP_ERROR_CHECK(nrf_gfx_line_draw(p_lcd, &my_line, RED)); } my_line.x_end = nrf_gfx_width_get(p_lcd); for (uint16_t i = 0; i <= nrf_gfx_height_get(p_lcd); i += LINE_STEP) { my_line.y_end = (nrf_gfx_height_get(p_lcd) - i); APP_ERROR_CHECK(nrf_gfx_line_draw(p_lcd, &my_line, RED)); } for (uint16_t i = 0; i <= nrf_gfx_height_get(p_lcd); i += LINE_STEP) { my_line_2.y_end = (nrf_gfx_height_get(p_lcd) - i); APP_ERROR_CHECK(nrf_gfx_line_draw(p_lcd, &my_line_2, BLUE)); } my_line_2.y_end = 0; for (uint16_t i = 0; i <= nrf_gfx_width_get(p_lcd); i += LINE_STEP) { my_line_2.x_end = i; APP_ERROR_CHECK(nrf_gfx_line_draw(p_lcd, &my_line_2, BLUE)); } } static void circle_draw(void) { nrf_gfx_circle_t my_circle = NRF_GFX_CIRCLE(0, 0, CIRCLE_RADIUS); for (uint16_t j = 0; j <= nrf_gfx_height_get(p_lcd); j += CIRCLE_STEP) { my_circle.y = j; for (uint16_t i = 0; i <= nrf_gfx_width_get(p_lcd); i += CIRCLE_STEP) { my_circle.x = i; APP_ERROR_CHECK(nrf_gfx_circle_draw(p_lcd, &my_circle, BLUE, true)); } } for (uint16_t j = CIRCLE_RADIUS; j <= nrf_gfx_height_get(p_lcd) + CIRCLE_RADIUS; j += CIRCLE_STEP) { my_circle.y = j; for (uint16_t i = CIRCLE_RADIUS; i <= nrf_gfx_width_get(p_lcd) + CIRCLE_RADIUS; i += CIRCLE_STEP) { my_circle.x = i; APP_ERROR_CHECK(nrf_gfx_circle_draw(p_lcd, &my_circle, RED, false)); } } } void rect_draw(nrf_lcd_t const *p_instance, uint16_t x, uint16_t y, Loading Loading @@ -942,7 +902,6 @@ void start_sleep_state() { state = SLEEP_STATE; advertising_stop(); nrf_gpio_pin_clear(LCD_SCREEN_LED); idle_state_handle(); } } Loading @@ -969,8 +928,15 @@ int main(void) { services_init(); advertising_init(); conn_params_init(); // Start execution. app_button_enable(); gfx_initialization(); app_timer_create(&screen_timer_id, APP_TIMER_MODE_SINGLE_SHOT, timer_timeout); app_timer_create(&send_timer_id, APP_TIMER_MODE_SINGLE_SHOT, timer_timeout); // Set up screen default text start_sleep_state(); // Enter main loop. for (;;) { Loading