-
Notifications
You must be signed in to change notification settings - Fork 3
/
tpms_monitor.c
75 lines (60 loc) · 2.59 KB
/
tpms_monitor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <furi.h>
#include <furi-hal.h>
#include <gui/gui.h>
#include <gui/view_port.h>
#include <subghz/subghz.h>
// Define the plugin state
typedef struct {
SubGhzProtocolCommon* protocol;
uint8_t tire_pressure;
uint16_t model_year;
} TpmsMonitorState;
void subghz_protocol_common_load(SubGhzProtocolCommon* instance, const SubGhzProtocolCommonEncoder* encoder) {
furi_assert(instance);
furi_assert(encoder);
instance->common_encoder = encoder;
// Set modulation settings
instance->modulation = FuriHalSubGhzModulationFSK;
instance->real_frequency = 433.92f; // Carrier frequency
instance->real_bitrate = 125.0f; // Data rate
instance->real_frequency_deviation = 10.0f; // Frequency deviation
instance->real_packet_duration = 1000.0f / instance->real_bitrate; // Packet duration
}
// The main function for the plugin
int32_t tpms_monitor_app(void* p) {
// Allocate and initialize the plugin state
TpmsMonitorState* state = furi_alloc(sizeof(TpmsMonitorState));
// Initialize the Sub-GHz module
state->protocol = subghz_protocol_common_alloc();
subghz_protocol_load(state->protocol, "TPMS Ford"); // Load the Ford TPMS protocol
// Set the frequency based on the model year
if (state->model_year >= 2003 && state->model_year <= 2004) {
subghz_protocol_set_frequency(state->protocol, 433000000); // Set frequency to 433 MHz
} else if (state->model_year >= 2005) {
subghz_protocol_set_frequency(state->protocol, 315000000); // Set frequency to 315 MHz
}
// Create a view port for the plugin
ViewPort* view_port = view_port_alloc();
// Set up the input and render callbacks
// You will need to implement these functions
view_port_input_callback_set(view_port, tpms_monitor_input_callback, state);
view_port_draw_callback_set(view_port, tpms_monitor_render_callback, state);
// Register the view port with the GUI
Gui* gui = furi_record_open("gui");
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
// Main loop
while(1) {
// Handle input and update the state here
// Analyze the TPMS signal
uint32_t signal = subghz_protocol_get_raw_data(state->protocol);
state->tire_pressure = (uint8_t)(signal & 0xFF); // Extract the tire pressure from the signal
// Trigger a screen update
view_port_update(view_port);
}
// Clean up
view_port_free(view_port);
furi_record_close("gui");
subghz_protocol_free(state->protocol);
free(state);
return 0;
}