Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Updated for NCS314-6 v2.3 05/05/2020 model. Added signal handling to …
…shut off Nixie tubes upon exit.
  • Loading branch information
UberEclectic committed Feb 20, 2021
commit 6f2c53ecf2d0b603f77498a312eec1014854c6c2
22 changes: 19 additions & 3 deletions DisplayNixie/src/DisplayNixie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <wiringPiI2C.h>
#include <softTone.h>
#include <softPwm.h>
#include <signal.h>

using namespace std;
#define R5222_PIN 22
Expand Down Expand Up @@ -54,7 +55,6 @@ bool HV5222;
#define RIGHT_REPR_START 2
#define RIGHT_BUFFER_START 4


uint16_t SymbolArray[10]={1, 2, 4, 8, 16, 32, 64, 128, 256, 512};

int fileDesc;
Expand Down Expand Up @@ -285,10 +285,26 @@ uint32_t addBlinkTo32Rep(uint32_t var) {
return var;
}

// Interrupt handler to turn off Nixie upon SIGINT(2), SIGQUIT(3), SIGTERM(15), but not SIGKILL(9)
void signal_handler (int sig_received)
{
printf("Received Signal %d; Exiting.\n", sig_received);
resetFireWorks();
digitalWrite(LEpin, LOW);
wiringPiI2CWrite(fileDesc, I2CFlush);
exit(sig_received);
}

//uint64_t* reverseBit(uint64_t num);
uint64_t reverseBit(uint64_t num);

int main(int argc, char* argv[]) {

// Setup signal handlers
signal(SIGINT, signal_handler);
signal(SIGQUIT, signal_handler);
signal(SIGTERM, signal_handler);

printf("Nixie Clock v%s \n\r", _VERSION);

wiringPiSetup();
Expand Down Expand Up @@ -341,9 +357,9 @@ int main(int argc, char* argv[]) {

// Tell the user the fireworks mode
if (doFireworks)
puts("Firworks ENABLED at start.");
puts("Fireworks ENABLED at start.");
else
puts("Firworks DISABLED at start.");
puts("Fireworks DISABLED at start.");

// Further setup...
initPin(UP_BUTTON_PIN);
Expand Down