Update ssdled.c
multiuse für heartbeat etc
This commit is contained in:
parent
9f56ca4e59
commit
c34800ce14
88
ssdled.c
88
ssdled.c
@ -65,7 +65,9 @@
|
||||
|
||||
|
||||
static unsigned int o_refresh = 20; /* milliseconds */
|
||||
static unsigned int o_gpiopin = 4; /* BCM numbering scheme */
|
||||
static unsigned int o_gpiopin = 20; /* BCM numbering scheme - gelbe LED*/
|
||||
static unsigned int o_gpiopin_kernel = 21; /* grüne LED */
|
||||
static unsigned int o_gpiopin_heartbeat = 26; /* blaue LED */
|
||||
static int o_detach = 0;
|
||||
|
||||
static volatile sig_atomic_t running = 1;
|
||||
@ -133,6 +135,67 @@ void led(int on) {
|
||||
current = on;
|
||||
}
|
||||
|
||||
/* Update the Kernel-LED */
|
||||
void kernel_led(int on) {
|
||||
static int kernel_current = 1; /* Ensure the LED turns off on first call */
|
||||
if (kernel_current == on)
|
||||
return;
|
||||
|
||||
if (on) {
|
||||
gpioWrite( o_gpiopin_kernel, PI_HIGH );
|
||||
} else {
|
||||
gpioWrite( o_gpiopin_kernel, PI_LOW );
|
||||
}
|
||||
|
||||
kernel_current = on;
|
||||
}
|
||||
|
||||
/* Update the Heartbeat-LED */
|
||||
void heartbeat_led(int on) {
|
||||
static int heartbeat_current = 1; /* Ensure the LED turns off on first call */
|
||||
if (heartbeat_current == on)
|
||||
return;
|
||||
|
||||
if (on) {
|
||||
gpioWrite( o_gpiopin_heartbeat, PI_HIGH );
|
||||
} else {
|
||||
gpioWrite( o_gpiopin_heartbeat, PI_LOW );
|
||||
}
|
||||
|
||||
heartbeat_current = on;
|
||||
}
|
||||
|
||||
int kernelloaded() {
|
||||
kernel_led( PI_HIGH );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int heartbeat() {
|
||||
/* gpioSetPWMfrequency(26, 1000);
|
||||
gpioSetPWMrange(26, 255);
|
||||
|
||||
while (1) {
|
||||
for (int i = 0; i < 255; i++) {
|
||||
gpioPWM(26, i);
|
||||
usleep(1E4);
|
||||
}
|
||||
|
||||
for (int i = 255; i > 0; i--) {
|
||||
gpioPWM(26, i);
|
||||
usleep(1E4);
|
||||
}
|
||||
}*/
|
||||
|
||||
if(0 == system("pgrep plexmediaserver > /dev/null") && 0 == system("pgrep smbd > /dev/null")) {
|
||||
heartbeat_led( PI_HIGH );
|
||||
}
|
||||
else {
|
||||
heartbeat_led( PI_LOW );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Signal handler -- break out of the main loop */
|
||||
void shutdown(int sig) {
|
||||
running = 0;
|
||||
@ -163,7 +226,7 @@ error_t parse_options(int key, char *arg, struct argp_state *state) {
|
||||
int main(int argc, char **argv) {
|
||||
struct argp_option options[] = {
|
||||
{ "detach", 'd', NULL, 0, "Detach from terminal" },
|
||||
{ "pin", 'p', "VALUE", 0, "GPIO pin where LED is connected (default: BCM 4, physical pin 7 on the P1 header)" },
|
||||
{ "pin", 'p', "VALUE", 0, "GPIO pin where SSD LED is connected (default: BCM 4, physical pin 7 on the P1 header)" },
|
||||
{ "refresh", 'r', "VALUE", 0, "Refresh interval (default: 20 ms)" },
|
||||
{ 0 },
|
||||
};
|
||||
@ -185,11 +248,13 @@ int main(int argc, char **argv) {
|
||||
delay.tv_nsec = 1000000 * (o_refresh % 1000);
|
||||
|
||||
/* If we can't set up pigpio, then just bail */
|
||||
if( gpioInitialise() < 0 ) {
|
||||
fprintf( stderr, "Unable to setup the piGPIO library. STOP." );
|
||||
return -1;
|
||||
}
|
||||
gpioSetMode( o_gpiopin, PI_OUTPUT );
|
||||
if( gpioInitialise() < 0 ) {
|
||||
fprintf( stderr, "Unable to setup the piGPIO library. STOP." );
|
||||
return -1;
|
||||
}
|
||||
gpioSetMode( o_gpiopin, PI_OUTPUT );
|
||||
gpioSetMode( o_gpiopin_kernel, PI_OUTPUT );
|
||||
gpioSetMode( o_gpiopin_heartbeat, PI_OUTPUT );
|
||||
|
||||
|
||||
/* Open the vmstat file */
|
||||
@ -201,6 +266,8 @@ int main(int argc, char **argv) {
|
||||
|
||||
/* Ensure the LED is off */
|
||||
led(0);
|
||||
kernel_led(0);
|
||||
heartbeat_led(0);
|
||||
|
||||
/* Save the current I/O stat values */
|
||||
if (activity(vmstat) < 0)
|
||||
@ -241,10 +308,16 @@ int main(int argc, char **argv) {
|
||||
if (a < 0)
|
||||
break;
|
||||
led(a);
|
||||
if( kernelloaded() < 0 )
|
||||
break;
|
||||
if( heartbeat() < 0 )
|
||||
break;
|
||||
}
|
||||
|
||||
/* Ensure the LED is off */
|
||||
led(0);
|
||||
kernel_led(0);
|
||||
heartbeat_led(0);
|
||||
|
||||
/* Halt any library functions */
|
||||
gpioTerminate();
|
||||
@ -256,4 +329,3 @@ out:
|
||||
if (vmstat) fclose(vmstat);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user