full version of beta including resources and binary
This commit is contained in:
113
include/mightywatt_controller.h
Normal file
113
include/mightywatt_controller.h
Normal file
@ -0,0 +1,113 @@
|
||||
#ifndef MIGHTYWATT_CONTROLLER_H
|
||||
#define MIGHTYWATT_CONTROLLER_H
|
||||
|
||||
#include "mightywatt_app.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MW_CONTROLLER_PORT_PATH_MAX 255
|
||||
#define MW_CONTROLLER_ERROR_MAX 255
|
||||
|
||||
typedef struct mw_controller mw_controller;
|
||||
|
||||
typedef enum {
|
||||
MW_CONTROLLER_STOPPED = 0,
|
||||
MW_CONTROLLER_CONNECTING = 1,
|
||||
MW_CONTROLLER_CONNECTED = 2,
|
||||
MW_CONTROLLER_RECONNECT_WAIT = 3,
|
||||
} mw_controller_connection_state;
|
||||
|
||||
typedef enum {
|
||||
MW_CTRL_CMD_NONE = 0,
|
||||
MW_CTRL_CMD_SET_TARGET,
|
||||
MW_CTRL_CMD_LOAD_ON,
|
||||
MW_CTRL_CMD_LOAD_OFF,
|
||||
MW_CTRL_CMD_RESTORE_TARGET,
|
||||
MW_CTRL_CMD_SAFE,
|
||||
MW_CTRL_CMD_SET_REMOTE,
|
||||
MW_CTRL_CMD_SET_SERIES_RESISTANCE,
|
||||
MW_CTRL_CMD_REFRESH_CAPABILITIES,
|
||||
MW_CTRL_CMD_GET_SERIES_RESISTANCE,
|
||||
} mw_controller_command_kind;
|
||||
|
||||
typedef struct {
|
||||
const char *port_path;
|
||||
int settle_ms;
|
||||
int poll_interval_ms;
|
||||
int reconnect_ms;
|
||||
size_t queue_capacity;
|
||||
bool safe_on_shutdown;
|
||||
} mw_controller_config;
|
||||
|
||||
typedef struct {
|
||||
bool running;
|
||||
bool connected;
|
||||
mw_controller_connection_state connection_state;
|
||||
uint64_t snapshot_seq;
|
||||
uint64_t connect_attempts;
|
||||
uint64_t reconnect_count;
|
||||
uint64_t poll_success_count;
|
||||
uint64_t poll_error_count;
|
||||
uint64_t command_success_count;
|
||||
uint64_t command_error_count;
|
||||
uint64_t last_queued_command_id;
|
||||
uint64_t last_completed_command_id;
|
||||
int last_completed_result;
|
||||
mw_controller_command_kind last_completed_kind;
|
||||
size_t pending_commands;
|
||||
char port_path[MW_CONTROLLER_PORT_PATH_MAX + 1];
|
||||
char last_error[MW_CONTROLLER_ERROR_MAX + 1];
|
||||
char last_completed_error[MW_CONTROLLER_ERROR_MAX + 1];
|
||||
bool app_state_valid;
|
||||
mw_app_state app_state;
|
||||
bool series_resistance_valid;
|
||||
uint16_t series_resistance_milliohm;
|
||||
} mw_controller_snapshot;
|
||||
|
||||
void mw_controller_config_init(mw_controller_config *config);
|
||||
|
||||
int mw_controller_start(mw_controller **out_controller, const mw_controller_config *config);
|
||||
void mw_controller_stop(mw_controller *controller);
|
||||
|
||||
int mw_controller_get_snapshot(mw_controller *controller, mw_controller_snapshot *out_snapshot);
|
||||
int mw_controller_wait_for_update(mw_controller *controller,
|
||||
uint64_t last_seen_snapshot_seq,
|
||||
int timeout_ms,
|
||||
uint64_t *out_snapshot_seq);
|
||||
|
||||
int mw_controller_queue_set_target(mw_controller *controller,
|
||||
mw_mode mode,
|
||||
uint32_t milli_units,
|
||||
uint64_t *out_command_id);
|
||||
int mw_controller_queue_load_on(mw_controller *controller,
|
||||
mw_mode mode,
|
||||
uint32_t milli_units,
|
||||
uint64_t *out_command_id);
|
||||
int mw_controller_queue_load_off(mw_controller *controller, uint64_t *out_command_id);
|
||||
int mw_controller_queue_restore_target(mw_controller *controller, uint64_t *out_command_id);
|
||||
int mw_controller_queue_safe(mw_controller *controller, uint64_t *out_command_id);
|
||||
int mw_controller_queue_set_remote(mw_controller *controller,
|
||||
bool enable,
|
||||
uint64_t *out_command_id);
|
||||
int mw_controller_queue_set_series_resistance(mw_controller *controller,
|
||||
uint16_t milliohm,
|
||||
uint64_t *out_command_id);
|
||||
int mw_controller_queue_refresh_capabilities(mw_controller *controller,
|
||||
uint64_t *out_command_id);
|
||||
int mw_controller_queue_get_series_resistance(mw_controller *controller,
|
||||
uint64_t *out_command_id);
|
||||
|
||||
const char *mw_controller_connection_state_name(mw_controller_connection_state state);
|
||||
const char *mw_controller_command_kind_name(mw_controller_command_kind kind);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user