34 lines
1.3 KiB
C

#ifndef BT_UART_H
#define BT_UART_H
/*
* bt_uart — DX-BT24 Bluetooth module UART driver
*
* The DX-BT24 is a UART-transparent BLE module. Whatever is written to the
* serial port is forwarded verbatim over BLE to the connected iOS/Android app.
*
* Usage (normal operation — module already at 115200):
* bt_uart_init("/dev/ttyS1", 0) — do_at_probe=0: skip AT commands
* bt_uart_send_json(json_str) — every event, thread-safe
* bt_uart_close() — shutdown (optional)
*
* First-time / factory-reset setup (module at factory default 9600):
* bt_uart_init("/dev/ttyS1", 1) — do_at_probe=1: negotiate baud via AT
* After success, set bt_at_probe = 0 in INI — never probe again.
*/
/* Open and configure the UART to the BT module.
* dev: device path, e.g. "/dev/ttyS1" (NULL or "" = disabled).
* do_at_probe: 0 = open directly at 115200 (normal operation, no AT sent).
* 1 = run AT baud negotiation first (one-time setup only).
* Returns 0 on success, -1 on failure / disabled. */
int bt_uart_init(const char *dev, int do_at_probe);
/* Write JSON bytes to the BT module (no CRLF added). Thread-safe. No-op if not init'd. */
void bt_uart_send_json(const char *json);
/* Close the UART fd and release resources. */
void bt_uart_close(void);
#endif /* BT_UART_H */