mirror of
https://github.com/scottbez1/smartknob.git
synced 2025-09-26 23:09:27 +08:00

- Firmware - Refactor all code to use a log interface rather than `Serial` directly - Moved platformio.ini to root, so you can load the entire repo in VS Code and still use platformio - Reduced graphic buffer bit depth to 8 bits (short on RAM :( ) - Implemented threadsafe log interface in interface_task (using a queue for posting log message) - Created serial protocol interface and 2 implementations - plaintext (default) and protobuf (selected by sending a NULL byte) - Protobuf protocol is roughly the same architecture as Splitflap's: - PacketSerial (cobs) framing with NULL delimiters - CRC32 checksums for packets - nanopb generated code for encoding/decoding (generated firmware code is checked in, since it should change less frequently and this reduces burden to build the project from scratch) - Software - Typescript example host-side code: - smartknobjs-proto - Autogenerated types/encoding/decoding protobuf code (using protobufjs) - smartknobjs - Helper library for interfacing the with smartknob via serial/protobuf. Implements basic outgoing queue (with retries and ACK checking) and message callback for responding to messages from the SmartKnob - example - Basic demo CLI app that uses smartknobjs to connect to the smartknob, send a haptic config, and print state changes and log messages to the console
29 lines
671 B
C++
29 lines
671 B
C++
#pragma once
|
|
|
|
#include <functional>
|
|
|
|
#include "../logger.h"
|
|
#include "../proto_gen/smartknob.pb.h"
|
|
|
|
#define SERIAL_PROTOCOL_LEGACY 0
|
|
#define SERIAL_PROTOCOL_PROTO 1
|
|
|
|
typedef std::function<void(uint8_t)> ProtocolChangeCallback;
|
|
|
|
class SerialProtocol : public Logger {
|
|
public:
|
|
SerialProtocol() : Logger() {}
|
|
virtual ~SerialProtocol(){}
|
|
|
|
virtual void loop() = 0;
|
|
|
|
virtual void handleState(const PB_SmartKnobState& state) = 0;
|
|
|
|
virtual void setProtocolChangeCallback(ProtocolChangeCallback cb) {
|
|
protocol_change_callback_ = cb;
|
|
}
|
|
|
|
protected:
|
|
ProtocolChangeCallback protocol_change_callback_;
|
|
};
|