Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: C/C++ CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y build-essential
- name: Build
run: make
- name: Run tests
run: make check
- name: Clean
run: make clean
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
dist/
virtual_keyboard
keyboard_writer
virtusdev
*.o
devices/*.o
176 changes: 176 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Migration Guide

## Upgrading from Previous Versions

### Changes in VirtUSDev 2.0

VirtUSDev has been significantly enhanced to support multiple device types. Here's what changed:

#### Renamed Files
- `keyboard_writer` β†’ `virtusdev` (binary name)
- `keyboard_writer.c` β†’ `virtusdev.c` (source file, legacy file kept for reference)

**Backward Compatibility:** A symlink `keyboard_writer` β†’ `virtusdev` is created for backward compatibility.

#### New Features
1. **Multi-device support**: Choose from barcode, USB keyboard, mouse jiggler, or RS232
2. **Interactive menu**: Run without parameters to select device
3. **Configuration file**: Set default device in `/etc/virtusdev/config`
4. **Colored output**: Better readability with ANSI colors
5. **System installation**: Install to `/usr/local/bin` with `make install`
6. **Systemd service**: Auto-start on boot

#### Updated Commands

**Old way:**
```bash
sudo ./virtual_keyboard # Only barcode scanner
sudo ./keyboard_writer /dev/input/event25
```

**New way (recommended):**
```bash
sudo ./virtual_keyboard barcode # Select device type
sudo ./virtusdev /dev/input/event25
```

**New way (backward compatible):**
```bash
sudo ./virtual_keyboard # Still works (shows menu)
sudo ./keyboard_writer /dev/input/event25 # Symlink still works
```

#### Device Architecture

Previous version:
- Single barcode scanner device hardcoded in `virtual_keyboard.c`

Current version:
- Modular device system in `devices/` directory
- Each device type in separate file
- Easy to add new devices

```
devices/
β”œβ”€β”€ barcode.c # Barcode scanner (original functionality)
β”œβ”€β”€ usb_keyboard.c # USB keyboard
β”œβ”€β”€ mouse_jiggle.c # Mouse jiggler
β”œβ”€β”€ rs232.c # RS232 serial port
└── device_interface.h
```

#### Configuration File

New in version 2.0, you can set a default device:

Create `/etc/virtusdev/config`:
```bash
# VirtUSDev Configuration
DEVICE=barcode
```

Priority:
1. Command-line argument (highest)
2. Config file
3. Interactive menu (lowest)

#### Installation

**Old way:**
```bash
make
sudo cp virtual_keyboard /usr/local/bin/
sudo cp keyboard_writer /usr/local/bin/
```

**New way:**
```bash
make
sudo make install
```

This installs:
- `/usr/local/bin/virtual_keyboard`
- `/usr/local/bin/virtusdev`
- `/usr/local/bin/keyboard_writer` (symlink)
- `/etc/virtusdev/config` (if doesn't exist)
- `/etc/systemd/system/virtusdev.service`

#### Systemd Service

New feature - auto-start on boot:

```bash
# Edit config
sudo nano /etc/virtusdev/config

# Enable service
sudo systemctl enable virtusdev
sudo systemctl start virtusdev

# Check status
sudo systemctl status virtusdev
```

### Upgrading Scripts

If you have scripts using the old commands, they should continue to work due to backward compatibility.

**Example - No changes needed:**
```bash
#!/bin/bash
# This script still works unchanged
sudo ./keyboard_writer /dev/input/event25 "BARCODE123"
```

**Example - Updated to use new features:**
```bash
#!/bin/bash
# Modern version with colors and error handling
if ! virtusdev /dev/input/event25 "BARCODE123"; then
echo "Error: Failed to send barcode"
exit 1
fi
```

### Breaking Changes

None! All existing functionality is preserved and backward compatible.

### Deprecated Features

- `keyboard_writer.c` source file (replaced by `virtusdev.c`, but kept for reference)
- Building with old script method (use Makefile instead)

### Recommendations

1. **Use new command names** in new scripts: `virtusdev` instead of `keyboard_writer`
2. **Use `make install`** for system-wide installation
3. **Set up systemd service** if you need auto-start
4. **Use config file** to avoid typing device name repeatedly
5. **Update documentation** to reference new tool names

### Getting Help

```bash
# Device emulator help
./virtual_keyboard --help

# Barcode writer help
./virtusdev --help

# Check version
git log --oneline | head -1
```

### Rollback

If you need to rollback to the previous version:

```bash
git checkout <previous-commit>
make clean
make
```

The original `keyboard_writer.c` is still in the repository for reference.
79 changes: 67 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,89 @@
CC = gcc
CFLAGS = -Wall -Wextra -O2
TARGETS = virtual_keyboard keyboard_writer
TARGETS = virtual_keyboard virtusdev
DEVICE_OBJS = devices/barcode.o devices/usb_keyboard.o devices/mouse_jiggle.o devices/rs232.o
PREFIX ?= /usr/local
SYSCONFDIR ?= /etc

all: $(TARGETS)

virtual_keyboard: virtual_keyboard.c device_config.h
$(CC) $(CFLAGS) -o virtual_keyboard virtual_keyboard.c
devices/%.o: devices/%.c devices/%.h devices/device_interface.h device_config.h
$(CC) $(CFLAGS) -c -o $@ $<

keyboard_writer: keyboard_writer.c device_config.h
$(CC) $(CFLAGS) -o keyboard_writer keyboard_writer.c
virtual_keyboard: virtual_keyboard.c device_config.h $(DEVICE_OBJS)
$(CC) $(CFLAGS) -o virtual_keyboard virtual_keyboard.c $(DEVICE_OBJS)

virtusdev: virtusdev.c device_config.h
$(CC) $(CFLAGS) -o virtusdev virtusdev.c

# Legacy keyboard_writer target for compatibility
keyboard_writer: virtusdev
ln -sf virtusdev keyboard_writer

check: $(TARGETS)
@echo "Running basic checks..."
@echo "[1/4] Checking virtual_keyboard binary..."
@test -f virtual_keyboard || (echo "ERROR: virtual_keyboard not built" && exit 1)
@echo "[2/4] Checking virtusdev binary..."
@test -f virtusdev || (echo "ERROR: virtusdev not built" && exit 1)
@echo "[3/4] Checking file permissions..."
@test -x virtual_keyboard || (echo "ERROR: virtual_keyboard not executable" && exit 1)
@test -x virtusdev || (echo "ERROR: virtusdev not executable" && exit 1)
@echo "[4/4] Checking device modules..."
@test -f devices/barcode.o || (echo "ERROR: device modules not built" && exit 1)
@echo "βœ… All checks passed!"

clean:
rm -f $(TARGETS)
rm -f $(TARGETS) keyboard_writer
rm -f devices/*.o

install: all
@echo "Run with sudo:"
@echo " sudo ./virtual_keyboard # Terminal 1"
@echo " sudo ./keyboard_writer # Terminal 2"
@echo "Installing binaries..."
install -d $(PREFIX)/bin
install -m 755 virtual_keyboard $(PREFIX)/bin/
install -m 755 virtusdev $(PREFIX)/bin/
ln -sf virtusdev $(PREFIX)/bin/keyboard_writer
@echo "Creating config directory..."
install -d $(SYSCONFDIR)/virtusdev
@if [ ! -f $(SYSCONFDIR)/virtusdev/config ]; then \
echo "# VirtUSDev Configuration" > $(SYSCONFDIR)/virtusdev/config; \
echo "# Select device: barcode, usb_keyboard, mouse_jiggle, rs232" >> $(SYSCONFDIR)/virtusdev/config; \
echo "DEVICE=barcode" >> $(SYSCONFDIR)/virtusdev/config; \
echo "Created default config at $(SYSCONFDIR)/virtusdev/config"; \
fi
@echo "Installing systemd service..."
@if [ -d /etc/systemd/system ]; then \
install -m 644 virtusdev.service /etc/systemd/system/; \
echo "Systemd service installed. Enable with: sudo systemctl enable virtusdev"; \
fi
@echo ""
@echo "Installation complete!"
@echo " Binaries: $(PREFIX)/bin/{virtual_keyboard,virtusdev,keyboard_writer}"
@echo " Config: $(SYSCONFDIR)/virtusdev/config"

uninstall:
rm -f $(PREFIX)/bin/virtual_keyboard
rm -f $(PREFIX)/bin/virtusdev
rm -f $(PREFIX)/bin/keyboard_writer
rm -f /etc/systemd/system/virtusdev.service
@echo "Uninstalled. Config files preserved in $(SYSCONFDIR)/virtusdev/"

help:
@echo "Virtual Barcode Reader - Build Targets:"
@echo "VirtUSDev - Virtual Device Emulator - Build Targets:"
@echo ""
@echo " make - Build all binaries"
@echo " make clean - Remove compiled binaries"
@echo " make install - Show installation instructions"
@echo " make install - Install to system (requires root)"
@echo " make uninstall - Remove from system (requires root)"
@echo " make help - Show this help message"
@echo ""
@echo "Usage:"
@echo " sudo ./virtual_keyboard [device_type] # Start device emulator"
@echo " sudo ./virtusdev [/dev/input/eventX] # Send barcode data"
@echo ""
@echo "For more information:"
@echo " README.md - General usage"
@echo " TESTING.md - Testing procedures"
@echo ""

.PHONY: all clean install help
.PHONY: all check clean install uninstall help
Loading