2020-10-25 08:14:16 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef EVENT_H
|
|
|
|
#define EVENT_H
|
|
|
|
|
|
|
|
#include "divemode.h"
|
|
|
|
#include "gas.h"
|
|
|
|
#include "units.h"
|
|
|
|
|
2024-05-04 20:17:07 +00:00
|
|
|
#include <string>
|
2020-10-25 08:14:16 +00:00
|
|
|
#include <libdivecomputer/parser.h>
|
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
struct divecomputer;
|
|
|
|
|
2024-02-14 20:29:48 +00:00
|
|
|
enum event_severity {
|
|
|
|
EVENT_SEVERITY_NONE = 0,
|
|
|
|
EVENT_SEVERITY_INFO,
|
|
|
|
EVENT_SEVERITY_WARN,
|
|
|
|
EVENT_SEVERITY_ALARM
|
|
|
|
};
|
|
|
|
|
2020-10-25 08:14:16 +00:00
|
|
|
/*
|
|
|
|
* Events are currently based straight on what libdivecomputer gives us.
|
|
|
|
* We need to wrap these into our own events at some point to remove some of the limitations.
|
|
|
|
*/
|
2024-05-04 17:15:47 +00:00
|
|
|
|
2020-10-25 08:14:16 +00:00
|
|
|
struct event {
|
|
|
|
duration_t time;
|
|
|
|
int type;
|
|
|
|
/* This is the annoying libdivecomputer format. */
|
|
|
|
int flags, value;
|
|
|
|
/* .. and this is our "extended" data for some event types */
|
|
|
|
union {
|
|
|
|
enum divemode_t divemode; // for divemode change events
|
|
|
|
/*
|
|
|
|
* NOTE! The index may be -1, which means "unknown". In that
|
|
|
|
* case, the get_cylinder_index() function will give the best
|
|
|
|
* match with the cylinders in the dive based on gasmix.
|
|
|
|
*/
|
|
|
|
struct { // for gas switch events
|
|
|
|
int index;
|
|
|
|
struct gasmix mix;
|
|
|
|
} gas;
|
|
|
|
};
|
2024-02-19 08:04:14 +00:00
|
|
|
bool hidden;
|
2024-05-04 20:17:07 +00:00
|
|
|
std::string name;
|
2024-05-04 17:15:47 +00:00
|
|
|
event();
|
2024-05-25 06:16:57 +00:00
|
|
|
event(unsigned int time, int type, int flags, int value, const std::string &name);
|
2024-05-04 17:15:47 +00:00
|
|
|
~event();
|
2024-05-25 06:16:57 +00:00
|
|
|
|
|
|
|
bool operator==(const event &b2) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
class event_loop
|
|
|
|
{
|
|
|
|
std::string name;
|
|
|
|
size_t idx;
|
|
|
|
public:
|
|
|
|
event_loop(const char *name);
|
|
|
|
struct event *next(struct divecomputer &dc); // nullptr -> end
|
|
|
|
const struct event *next(const struct divecomputer &dc); // nullptr -> end
|
2020-10-25 08:14:16 +00:00
|
|
|
};
|
|
|
|
|
2024-05-25 06:16:57 +00:00
|
|
|
/* Get gasmixes at increasing timestamps. */
|
|
|
|
class gasmix_loop {
|
|
|
|
const struct dive &dive;
|
|
|
|
const struct divecomputer &dc;
|
|
|
|
struct gasmix last;
|
|
|
|
event_loop loop;
|
|
|
|
const struct event *ev;
|
|
|
|
public:
|
|
|
|
gasmix_loop(const struct dive &dive, const struct divecomputer &dc);
|
|
|
|
gasmix next(int time);
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Get divemodes at increasing timestamps. */
|
|
|
|
class divemode_loop {
|
|
|
|
const struct divecomputer &dc;
|
|
|
|
divemode_t last;
|
|
|
|
event_loop loop;
|
|
|
|
const struct event *ev;
|
|
|
|
public:
|
|
|
|
divemode_loop(const struct divecomputer &dc);
|
|
|
|
divemode_t next(int time);
|
|
|
|
};
|
|
|
|
|
|
|
|
extern bool event_is_gaschange(const struct event &ev);
|
|
|
|
extern bool event_is_divemodechange(const struct event &ev);
|
|
|
|
extern enum event_severity get_event_severity(const struct event &ev);
|
|
|
|
|
|
|
|
extern const struct event *get_first_event(const struct divecomputer &dc, const std::string &name);
|
|
|
|
extern struct event *get_first_event(struct divecomputer &dc, const std::string &name);
|
2020-10-25 08:14:16 +00:00
|
|
|
|
|
|
|
#endif
|