-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprotocols.h
More file actions
64 lines (53 loc) · 1.71 KB
/
Copy pathprotocols.h
File metadata and controls
64 lines (53 loc) · 1.71 KB
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
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
typedef enum {
ShockerModelCaiXianlin,
ShockerModelPetrainer,
ShockerModelPetrainer998DR,
ShockerModelT330,
ShockerModelD80,
ShockerModelCount,
} ShockerModel;
typedef enum {
ShockerCmdShock,
ShockerCmdVibrate,
ShockerCmdSound,
ShockerCmdLight,
ShockerCmdCount,
} ShockerCommand;
// An OOK pulse: carrier on for high_us microseconds, then off for low_us microseconds.
typedef struct {
uint16_t high_us;
uint16_t low_us;
} OokPulse;
// Maximum pulse buffer size (dual TX concatenates two packets + gap; CaiXianlin is 44 each)
#define OPENSHOCK_MAX_PULSES 160
// Decoded shocker command (result of RX decoding).
typedef struct {
ShockerModel model;
uint16_t shocker_id;
uint8_t channel;
ShockerCommand command;
uint8_t intensity;
} DecodedShocker;
// Returns the display name for a shocker model.
const char* openshock_model_name(ShockerModel model);
// Returns the display name for a command type.
const char* openshock_command_name(ShockerCommand command);
// Returns whether a command is supported by the given model.
bool openshock_command_supported(ShockerModel model, ShockerCommand command);
// Try to decode OOK pulses into a shocker command.
// Tries all protocols with a sliding window. Returns true on first match.
bool openshock_decode(const OokPulse* pulses, size_t count, DecodedShocker* result);
// Encode a command into OOK pulse timings.
// Returns number of pulses written, or 0 on error.
size_t openshock_encode(
ShockerModel model,
uint16_t shocker_id,
ShockerCommand command,
uint8_t intensity,
uint8_t channel,
OokPulse* buffer,
size_t buffer_size);