mirror of
https://github.com/niellun/FastCarPlay.git
synced 2026-06-07 09:38:25 +02:00
Updated emulator and keylistener
This commit is contained in:
+25
-18
@@ -1,8 +1,9 @@
|
||||
// lgpio_blink.cpp
|
||||
#include <iostream>
|
||||
#include <csignal>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <pigpiod_if2.h>
|
||||
#include <lgpio.h>
|
||||
|
||||
bool running = true;
|
||||
|
||||
@@ -11,37 +12,43 @@ void signal_handler(int signum) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
const int PIN_HOLD = 17; // stays ON
|
||||
const int PIN_BLINK = 27; // toggles
|
||||
const double ON_INTERVAL = 0.2; // seconds ON
|
||||
const double OFF_INTERVAL = 0.8; // seconds OFF
|
||||
const int PIN_HOLD = 17; // stays ON
|
||||
const int PIN_BLINK = 27; // toggles
|
||||
const double ON_INTERVAL = 0.2; // seconds
|
||||
const double OFF_INTERVAL = 0.8; // seconds
|
||||
|
||||
signal(SIGINT, signal_handler);
|
||||
|
||||
int pi = pigpio_start(NULL, NULL);
|
||||
if (pi < 0) {
|
||||
std::cerr << "Failed to connect to pigpiod daemon.\n";
|
||||
// Open the GPIO chip (0 = /dev/gpiochip0 on every Pi)
|
||||
int h = lgGpiochipOpen(0);
|
||||
if (h < 0) {
|
||||
std::cerr << "Failed to open gpiochip0 (error " << h << ")\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Claim pins as outputs
|
||||
int rc1 = lgGpioClaimOutput(h, 0, PIN_HOLD, 1); // 1 = initial HIGH
|
||||
int rc2 = lgGpioClaimOutput(h, 0, PIN_BLINK, 0); // 0 = initial LOW
|
||||
if (rc1 < 0 || rc2 < 0) {
|
||||
std::cerr << "Failed to claim pins (rc1=" << rc1 << ", rc2=" << rc2 << ")\n";
|
||||
lgGpiochipClose(h);
|
||||
return 1;
|
||||
}
|
||||
|
||||
set_mode(pi, PIN_HOLD, PI_OUTPUT);
|
||||
set_mode(pi, PIN_BLINK, PI_OUTPUT);
|
||||
|
||||
gpio_write(pi, PIN_HOLD, 1);
|
||||
std::cout << "GPIO " << PIN_HOLD << " ON (constant), toggling GPIO " << PIN_BLINK << "...\n";
|
||||
std::cout << "GPIO " << PIN_HOLD << " ON (constant), toggling GPIO " << PIN_BLINK << ".\n";
|
||||
|
||||
while (running) {
|
||||
gpio_write(pi, PIN_BLINK, 1);
|
||||
lgGpioWrite(h, PIN_BLINK, 1);
|
||||
std::this_thread::sleep_for(std::chrono::duration<double>(ON_INTERVAL));
|
||||
gpio_write(pi, PIN_BLINK, 0);
|
||||
|
||||
lgGpioWrite(h, PIN_BLINK, 0);
|
||||
std::this_thread::sleep_for(std::chrono::duration<double>(OFF_INTERVAL));
|
||||
}
|
||||
|
||||
std::cout << "\nStopping...\n";
|
||||
gpio_write(pi, PIN_HOLD, 0);
|
||||
gpio_write(pi, PIN_BLINK, 0);
|
||||
pigpio_stop(pi);
|
||||
lgGpioWrite(h, PIN_HOLD, 0);
|
||||
lgGpioWrite(h, PIN_BLINK, 0);
|
||||
|
||||
lgGpiochipClose(h);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user