mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-10-17 10:55:06 +00:00
48 lines
1.2 KiB
C++
48 lines
1.2 KiB
C++
// SPDX-License-Identifier: Apache-2.0
|
|
#include <gps/module.h>
|
|
#include <gps/private/gps_ledger.h>
|
|
|
|
#include <tactility/device.h>
|
|
#include <tactility/device_listener.h>
|
|
#include <tactility/drivers/uart_controller.h>
|
|
#include <tactility/error.h>
|
|
#include <tactility/module.h>
|
|
|
|
extern "C" {
|
|
|
|
// UARTs can appear and disappear at runtime, so their GPS devices follow them
|
|
static void on_device_event(Device* device, DeviceEvent event, void*) {
|
|
if (device_get_type(device) != &UART_CONTROLLER_TYPE) {
|
|
return;
|
|
}
|
|
if (event == DEVICE_EVENT_STARTED) {
|
|
gps_ledger_sync();
|
|
} else if (event == DEVICE_EVENT_STOPPING) {
|
|
gps_ledger_remove_children_of(device);
|
|
}
|
|
}
|
|
|
|
static error_t start() {
|
|
// Materializes devices for configurations persisted in previous sessions.
|
|
gps_ledger_sync();
|
|
device_listener_add(on_device_event, nullptr);
|
|
return ERROR_NONE;
|
|
}
|
|
|
|
static error_t stop() {
|
|
device_listener_remove(on_device_event, nullptr);
|
|
gps_ledger_clear();
|
|
return ERROR_NONE;
|
|
}
|
|
|
|
Module gps_module = {
|
|
.name = "gps",
|
|
.start = start,
|
|
.stop = stop,
|
|
.drivers = nullptr,
|
|
.symbols = nullptr,
|
|
.internal = nullptr,
|
|
};
|
|
|
|
}
|