Skip to content

Commit

Permalink
Misc:
Browse files Browse the repository at this point in the history
- Format code
- Changes from PR

Notifications:
- Improve scrolling
- Add option to add notifications when notification app is active

BLE:

Signed-off-by: Daniel Kampert <DanielKampert@kampis-elektroecke.de>
  • Loading branch information
Kampi committed Nov 21, 2023
1 parent 75458fc commit d339979
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,4 @@ CONFIG_PINCTRL=y

CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=y
# Ensure GPIO P0.01 and P0.00 can be used
CONFIG_SOC_ENABLE_LFXO=n

CONFIG_BT_DIS=y
CONFIG_BT_DIS_HW_REV=y
CONFIG_BT_DIS_MODEL="ZSWatch"
CONFIG_SOC_ENABLE_LFXO=n
6 changes: 5 additions & 1 deletion app/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ CONFIG_BT_SMP=y
CONFIG_BT_PERIPHERAL=y
CONFIG_BT_DIS=y
CONFIG_BT_DIS_PNP=n
CONFIG_BT_DIS_HW_REV=y
CONFIG_BT_DIS_MODEL="ZSWatch"
CONFIG_BT_BAS=y
CONFIG_BT_HRS=n
CONFIG_BT_DEVICE_NAME="ZSWatch"
Expand Down Expand Up @@ -197,4 +199,6 @@ CONFIG_BMI270_PLUS_TRIGGER_GLOBAL_THREAD=y

# Uncomment for BME688 IAQ using Bosch BSEC
#CONFIG_BME680=n
#CONFIG_EXTERNAL_USE_BOSCH_BSEC=y
#CONFIG_EXTERNAL_USE_BOSCH_BSEC=y

CONFIG_RESET_ON_FATAL_ERROR=n
41 changes: 35 additions & 6 deletions app/src/applications/notification/notification_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "managers/zsw_notification_manager.h"
#include "managers/zsw_app_manager.h"

// Functions needed for all applications
static void notification_app_start(lv_obj_t *root, lv_group_t *group);
static void notification_app_stop(void);

Expand All @@ -16,26 +15,56 @@ static application_t app = {
.stop_func = notification_app_stop
};

static lv_group_t *notification_group;

// Test
void my_work_handler(struct k_work *work);
void my_timer_handler(struct k_timer *timer_id);
K_WORK_DEFINE(my_work, my_work_handler);
K_TIMER_DEFINE(my_timer, my_timer_handler, NULL);
zsw_not_mngr_notification_t not = {
.id = 0,
.title = "Hallo",
.body = "Test"
};


void my_work_handler(struct k_work *work)
{
sprintf(not.body, "Test: %u", not.id);
not.id++;
notifications_ui_add_notification(&not, notification_group);
}

void my_timer_handler(struct k_timer *dummy)
{
k_work_submit(&my_work);
}
//

static void on_notification_page_notification_close(uint32_t not_id)
{
// TODO send to phone that the notification was read.
zsw_notification_manager_remove(not_id);
}


static void notification_app_start(lv_obj_t *root, lv_group_t *group)
{
int num_unread;
zsw_not_mngr_notification_t notifications[NOTIFICATION_MANAGER_MAX_STORED];

notification_group = group;

zsw_notification_manager_get_all(notifications, &num_unread);
notifications_page_init(on_notification_page_notification_close);
notifications_page_create(notifications, num_unread, group);
notifications_ui_page_init(on_notification_page_notification_close);
notifications_ui_page_create(notifications, num_unread, notification_group);

k_timer_start(&my_timer, K_SECONDS(10), K_SECONDS(2));
}

static void notification_app_stop(void)
{
notifications_page_close();
notifications_ui_page_close();
}

static int notification_app_add(void)
Expand All @@ -45,4 +74,4 @@ static int notification_app_add(void)
return 0;
}

SYS_INIT(notification_app_add, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
SYS_INIT(notification_app_add, APPLICATION, CONFIG_APPLICATION_INIT_PRIORITY);
35 changes: 20 additions & 15 deletions app/src/applications/notification/notification_ui.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
#include <notification/notification_ui.h>
#include <lvgl.h>

#include "notification/notification_ui.h"

static void not_button_pressed(lv_event_t *e);
static void scroll_event_cb(lv_event_t *e);
static void build_notification_entry(lv_obj_t *parent, zsw_not_mngr_notification_t *not, lv_group_t *input_group);
static void build_notification_entry(lv_obj_t *parent, zsw_not_mngr_notification_t *not, lv_group_t *group);

static on_notification_remove_cb_t not_removed_callback;

static lv_obj_t *main_page;
static lv_group_t *group;

void notifications_page_init(on_notification_remove_cb_t not_removed_cb)
void notifications_ui_page_init(on_notification_remove_cb_t not_removed_cb)
{
not_removed_callback = not_removed_cb;
}

void notifications_page_create(zsw_not_mngr_notification_t *notifications, uint8_t num_notifications,
lv_group_t *input_group)
void notifications_ui_page_create(zsw_not_mngr_notification_t *notifications, uint8_t num_notifications,
lv_group_t *group)
{
group = input_group;

main_page = lv_obj_create(lv_scr_act());
lv_obj_set_scrollbar_mode(lv_scr_act(), LV_SCROLLBAR_MODE_OFF);

Expand All @@ -34,22 +32,29 @@ void notifications_page_create(zsw_not_mngr_notification_t *notifications, uint8
lv_obj_add_event_cb(main_page, scroll_event_cb, LV_EVENT_SCROLL, NULL);

for (int i = 0; i < num_notifications; i++) {
build_notification_entry(main_page, &notifications[i], input_group);
build_notification_entry(main_page, &notifications[i], group);
}

/* Update the notifications position manually firt time */
// Update the notifications position manually firt time
lv_event_send(main_page, LV_EVENT_SCROLL, NULL);

/* Be sure the fist notification is in the middle */
lv_obj_scroll_to_view(lv_obj_get_child(main_page, 0), LV_ANIM_OFF);
// Be sure the fist notification is in the middle
lv_obj_scroll_to_view(lv_obj_get_child(main_page, -1), LV_ANIM_OFF);
}

void notifications_page_close(void)
void notifications_ui_page_close(void)
{
lv_obj_del(main_page);
}

static void build_notification_entry(lv_obj_t *parent, zsw_not_mngr_notification_t *not, lv_group_t *input_group)
void notifications_ui_add_notification(zsw_not_mngr_notification_t *not, lv_group_t *group)
{
build_notification_entry(main_page, not, group);
lv_obj_scroll_to_view(lv_obj_get_child(main_page, -1), LV_ANIM_OFF);
lv_obj_update_layout(main_page);
}

static void build_notification_entry(lv_obj_t *parent, zsw_not_mngr_notification_t *not, lv_group_t *group)
{
lv_obj_t *title;
lv_obj_t *cont;
Expand Down Expand Up @@ -77,7 +82,7 @@ static void build_notification_entry(lv_obj_t *parent, zsw_not_mngr_notification
lv_obj_add_style(cont, &outline_focused, LV_STATE_FOCUS_KEY);

lv_obj_add_event_cb(cont, not_button_pressed, LV_EVENT_CLICKED, (void *)not->id);
lv_group_add_obj(input_group, cont);
lv_group_add_obj(group, cont);
lv_obj_add_flag(cont, LV_OBJ_FLAG_SCROLL_ON_FOCUS);

LV_FONT_DECLARE(lv_font_montserrat_14_full)
Expand Down
12 changes: 6 additions & 6 deletions app/src/applications/notification/notification_ui.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef __NOTIFICATION_UI_H
#define __NOTIFICATION_UI_H
#pragma once

#include <inttypes.h>
#include <lvgl.h>
Expand All @@ -8,10 +7,11 @@

typedef void(*on_notification_remove_cb_t)(uint32_t id);

void notifications_page_init(on_notification_remove_cb_t not_removed_cb);
void notifications_ui_page_init(on_notification_remove_cb_t not_removed_cb);

void notifications_page_create(zsw_not_mngr_notification_t *notifications, uint8_t num_notifications,
void notifications_ui_page_create(zsw_not_mngr_notification_t *notifications, uint8_t num_notifications,
lv_group_t *input_group);

void notifications_page_close(void);
#endif // __NOTIFICATION_UI_H
void notifications_ui_page_close(void);

void notifications_ui_add_notification(zsw_not_mngr_notification_t *not, lv_group_t *group);
2 changes: 1 addition & 1 deletion app/src/ble/ble_ancs.c
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ static int parse_notify(const struct bt_ancs_attr *attr)

// the last message is Negative action label, send only when all data is received;
case ATTR_ID_NEGATIVE_ACTION_LABEL:
struct ble_data_event evt;
static struct ble_data_event evt;

cb.type = BLE_COMM_DATA_TYPE_NOTIFY;

Expand Down
2 changes: 1 addition & 1 deletion app/src/ble/gadgetbridge/ble_gadgetbridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#include <zephyr/bluetooth/hci.h>
#include <zephyr/logging/log.h>
#include <zephyr/kernel.h>
#include <zephyr/zbus/zbus.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <errno.h>
#include <math.h>
#include <zephyr/zbus/zbus.h>

#include "ui/zsw_ui.h"
#include "ble/ble_comm.h"
Expand Down
30 changes: 15 additions & 15 deletions app/src/ble/gadgetbridge/ble_gadgetbridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@

#define MAX_GB_PACKET_LENGTH 1000

/** @brief
* @param key
* @param data
* @param value_lem
* @return
/** @brief
* @param key
* @param data
* @param value_lem
* @return
*/
char *extract_value_str(char *key, char *data, int *value_len);

/** @brief
* @param data
* @param len
* @return
/** @brief
* @param data
* @param len
* @return
*/
int parse_data(char *data, int len);

/** @brief
* @param data
* @return
/** @brief
* @param data
* @return
*/
void parse_time(char *data);

/** @brief
* @param data
* @param len
/** @brief
* @param data
* @param len
*/
void parse_remote_control(char *data, int len);
3 changes: 1 addition & 2 deletions app/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,7 @@ int main(void)
// it has the required amount of stack.
k_work_submit(&init_work);

while(1)
{
while (1) {
const struct zbus_channel *chan;

if (!zbus_sub_wait(&ble_data_subscriber, &chan, K_FOREVER)) {
Expand Down

0 comments on commit d339979

Please sign in to comment.