Files
carpibord/flip_monitor/README.md

279 lines
6.2 KiB
Markdown

# CAN Monitor for Flipper Zero
Dynamic multi-page monitor application for Raspberry Pi 5 via UART.
## Features
- **Dynamic Page System** - Pages are fully controlled by RPi5
- **Multiple Page Types**:
- **Info** - Read-only status display
- **Menu** - Selectable action items
- **Confirm** - Yes/No confirmation dialogs
- **Real-time Updates** - Content refreshes every second
- **Bidirectional Communication** - Send commands back to RPi5
- **Result Notifications** - Action results displayed as overlay
## Default Pages
When connected to the CAN Sniffer system:
| Page | Type | Description |
|------|------|-------------|
| CAN Statistics | Info | Frame counts, queue status, per-interface stats |
| UPS Status | Info | Battery level, voltage, charging state (X120x) |
| System Info | Info | CPU temperature, power consumption, fan RPM |
| Actions | Menu | Shutdown, Reboot, Cancel shutdown |
## Screen Layout
```
128x64 pixels (Flipper Zero display)
+----------------------------------+
| [1/4] Page Title (*) | <- Header: page indicator, title, connection dot
+----------------------------------+
| |
| Content Line 1 | <- Content area: 4-5 lines
| Content Line 2 |
| Content Line 3 |
| Content Line 4 |
| |
+----------------------------------+
| < Hint Text > | <- Footer: nav arrows, action hint
+----------------------------------+
```
## Controls
| Key | Info Page | Menu Page | Confirm Page |
|-----|-----------|-----------|--------------|
| **Left/Right** | Navigate pages | Navigate pages | Navigate pages |
| **Up/Down** | - | Select item | Switch Yes/No |
| **OK** | - | Execute action | Confirm selection |
| **Back** | Disconnect (pg 0) / Prev page | Same | Cancel dialog |
## Protocol
### RPi5 -> Flipper
```
PAGE:<idx>/<total>|<type>|<title>|<lines>|<actions>|<selected>
ACK:<device>,ip=<ip>
RESULT:<OK|ERROR>|<message>
```
**Examples:**
```
PAGE:0/4|info|CAN Statistics|Total: 12.3K;Processed: 12.1K;Queue: 142||0
PAGE:1/4|info|UPS Status|Bat: 85.2% [====];Voltage: 4.12V;Status: Charging||0
PAGE:2/4|info|System Info|CPU Temp: 52.1C;Power: 4.2W;Fan: 3200 RPM||0
PAGE:3/4|menu|Actions|Shutdown;Reboot;Cancel Shutdown||0
PAGE:3/4|confirm|Confirm Shutdown?|Are you sure?|Yes;No|1
ACK:rpi5,ip=192.168.1.100
RESULT:OK|Shutdown in 1 min
```
### Flipper -> RPi5
```
INIT:flipper - Start handshake
STOP:flipper - Disconnect
CMD:NAV:next - Next page
CMD:NAV:prev - Previous page
CMD:SELECT:<index> - Select menu item
CMD:CONFIRM - Confirm action
CMD:CANCEL - Cancel action
CMD:REFRESH - Request page update
```
## Hardware Connection
### Wiring Diagram
```
Flipper Zero Raspberry Pi 5
----------- ---------------
Pin 13 (TX) ----> GPIO 15 (RX) - Pin 10
Pin 14 (RX) <---- GPIO 14 (TX) - Pin 8
Pin 8/11/18 (GND) ---- GND - Pin 6
```
**Note:** Cross TX/RX connections (Flipper TX -> RPi RX)
### Flipper Zero GPIO Pinout
```
Pin 13 = TX (USART)
Pin 14 = RX (USART)
Pin 8/11/18 = GND
```
### RPI5 GPIO (using /dev/ttyAMA0)
```
GPIO 14 = TX (Pin 8)
GPIO 15 = RX (Pin 10)
GND = Pin 6, 9, 14, 20, 25, 30, 34, 39
```
## Building the Application
### Prerequisites
1. Clone Flipper Zero firmware:
```bash
git clone --recursive https://github.com/DarkFlippers/unleashed-firmware.git
cd unleashed-firmware
```
2. Copy the `flip_monitor` folder to `applications_user/`:
```bash
cp -r /path/to/carpibord/flip_monitor applications_user/can_monitor
```
### Build
```bash
# Build the FAP
./fbt fap_can_monitor
# Or build all external apps
./fbt fap_dist
```
The compiled `.fap` file will be in `build/f7-firmware-D/.extapps/can_monitor.fap`
### Install
Copy the `.fap` file to your Flipper Zero SD card:
```
SD Card/apps/GPIO/can_monitor.fap
```
## RPI5 Configuration
### 1. Enable UART
Add to `/boot/firmware/config.txt`:
```
enable_uart=1
dtoverlay=uart0
```
Disable serial console:
```bash
sudo raspi-config
# Interface Options -> Serial Port -> No (login shell) -> Yes (hardware)
```
Reboot after changes.
### 2. Install Dependencies
```bash
pip install pyserial smbus2 gpiozero
```
### 3. Configure CAN Sniffer
Add to `can_sniffer/src/config.json`:
```json
{
"flipper": {
"enabled": true,
"device": "/dev/ttyAMA0",
"baudrate": 115200,
"send_interval": 1.0
}
}
```
Or use environment variables:
```bash
export CAN_SNIFFER_FLIPPER__ENABLED=true
export CAN_SNIFFER_FLIPPER__DEVICE=/dev/ttyAMA0
```
### 4. Run CAN Sniffer
```bash
cd can_sniffer/src
python main.py
```
## Adding Custom Pages
On RPi5 side, create a new page class:
```python
from flipper.pages.base import InfoPage
class MyCustomPage(InfoPage):
def __init__(self):
super().__init__(
name="my_page",
title="My Page",
icon="custom"
)
def get_lines(self) -> list[str]:
return [
"Custom line 1",
"Custom line 2",
f"Value: {self.get_value()}"
]
```
Register in FlipperHandler:
```python
# In flipper_handler.py
from flipper.pages.my_custom import MyCustomPage
# In _setup_pages():
self._page_manager.register_page(MyCustomPage())
```
## Troubleshooting
### No connection
1. Check wiring (TX/RX crossed correctly)
2. Verify UART is enabled on RPI5: `ls -la /dev/ttyAMA0`
3. Check config: `flipper.enabled = true`
4. Test UART manually:
```bash
# On RPI5
echo "ACK:rpi5,ip=test" > /dev/ttyAMA0
```
### Permission denied on /dev/ttyAMA0
Add user to dialout group:
```bash
sudo usermod -a -G dialout $USER
# Then logout and login again
```
### Flipper shows "Waiting for data..."
- Data is sent every 1 second (configurable)
- Connection timeout is 5 seconds
- Check if CAN sniffer is running
- Check UART logs: `CAN_SNIFFER_LOGGING__LEVEL=DEBUG python main.py`
### UPS page shows "not available"
- X120x UPS must be connected via I2C
- Install smbus2: `pip install smbus2`
- Check I2C: `i2cdetect -y 1` (should show device at 0x36)
## Version History
- **v2.0** - Dynamic page system, bidirectional commands, UPS/System pages
- **v1.0** - Basic CAN statistics display
## License
MIT License