2026-03-11 18:30:24 +08:00
|
|
|
#ifndef BATTERY_STATUS_EVENT_H
|
|
|
|
|
#define BATTERY_STATUS_EVENT_H
|
|
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
|
|
#include <app_event_manager.h>
|
|
|
|
|
#include <app_event_manager_profiler_tracer.h>
|
|
|
|
|
|
|
|
|
|
struct battery_status_event
|
|
|
|
|
{
|
|
|
|
|
struct app_event_header header;
|
2026-03-18 13:41:36 +08:00
|
|
|
uint8_t flags;
|
2026-03-11 18:30:24 +08:00
|
|
|
uint8_t soc;
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-18 13:41:36 +08:00
|
|
|
#define BATTERY_STATUS_FLAG_CHARGING (1U << 0)
|
|
|
|
|
#define BATTERY_STATUS_FLAG_FULL (1U << 1)
|
|
|
|
|
|
|
|
|
|
#define BATTERY_STATUS_IS_CHARGING(flags) (((flags) & BATTERY_STATUS_FLAG_CHARGING) != 0U)
|
|
|
|
|
#define BATTERY_STATUS_IS_FULL(flags) (((flags) & BATTERY_STATUS_FLAG_FULL) != 0U)
|
|
|
|
|
|
2026-03-11 18:30:24 +08:00
|
|
|
APP_EVENT_TYPE_DECLARE(battery_status_event);
|
|
|
|
|
|
2026-03-18 13:41:36 +08:00
|
|
|
static inline void battery_status_event_submit(bool charging, bool full, uint8_t soc)
|
|
|
|
|
{
|
|
|
|
|
struct battery_status_event *event = new_battery_status_event();
|
|
|
|
|
|
|
|
|
|
event->flags = 0U;
|
|
|
|
|
if (charging) {
|
|
|
|
|
event->flags |= BATTERY_STATUS_FLAG_CHARGING;
|
|
|
|
|
}
|
|
|
|
|
if (full) {
|
|
|
|
|
event->flags |= BATTERY_STATUS_FLAG_FULL;
|
|
|
|
|
}
|
|
|
|
|
event->soc = soc;
|
|
|
|
|
|
|
|
|
|
APP_EVENT_SUBMIT(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint8_t battery_status_event_get_flags(const struct battery_status_event *event)
|
|
|
|
|
{
|
|
|
|
|
return event->flags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool battery_status_event_is_charging(const struct battery_status_event *event)
|
|
|
|
|
{
|
|
|
|
|
return BATTERY_STATUS_IS_CHARGING(event->flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline bool battery_status_event_is_full(const struct battery_status_event *event)
|
|
|
|
|
{
|
|
|
|
|
return BATTERY_STATUS_IS_FULL(event->flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline uint8_t battery_status_event_get_soc(const struct battery_status_event *event)
|
|
|
|
|
{
|
|
|
|
|
return event->soc;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-11 18:30:24 +08:00
|
|
|
#endif
|