Skip to content

Commit

Permalink
Dev/28 (#29)
Browse files Browse the repository at this point in the history
* fix: Interrupt (#28)
  • Loading branch information
Pyojihwan authored Dec 12, 2024
1 parent d78b55a commit 4a56394
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 58 deletions.
Binary file added Client/RSP5(Buzzer)/buzzer
Binary file not shown.
2 changes: 1 addition & 1 deletion Client/RSP5(Buzzer)/inc/CANCommunicationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CANCommunicationManager {
struct ifreq ifr{};
LEDController& ledController;
SoundManager& soundManager;
std::atomic<int> failCounter{0};
std::atomic<int> failCounter{1};
std::thread soundThread;
std::thread ledThread;

Expand Down
11 changes: 11 additions & 0 deletions Client/RSP5(Buzzer)/inc/Configure.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef CONFIGURE_H
#define CONFIGURE_H

#define RLED 1
#define GLED 2
#define BLED 28
#define YLED 29
#define SPKR 27
#define SW 25

#endif
39 changes: 20 additions & 19 deletions Client/RSP5(Buzzer)/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,40 @@
#include "inc/SoundManager.h"
#include "inc/LEDController.h"
#include "inc/CANCommunicationManager.h"
#include "inc/Configure.h"

#define SW 5

// 전역 포인터를 사용해 인터럽트 핸들러에서 접근
CANCommunicationManager* globalCanManager = nullptr;
volatile bool interruptFlag = false;

void switchInterrupt() {
if (globalCanManager) {
SoundManager sound;
globalCanManager->sendCANMessage(0x002, 0b00000101);
std::cout << "dingdong" << std::endl;
}
interruptFlag = true;
}

int main() {
wiringPiSetup();
int main() {
wiringPiSetup();

SoundManager soundManager;
LEDController ledController;
soundManager.initialize();
ledController.initialize();
CANCommunicationManager canManager(ledController, soundManager);
globalCanManager = &canManager;

pinMode(SW, INPUT);
pullUpDnControl(SW, PUD_UP);
wiringPiISR(SW, INT_EDGE_FALLING, switchInterrupt);

while(1) {
canManager.initializeCANSocket();

while(true) {
canManager.processCANMessage();
canManager.initializeCANSocket();

while (1) {
if (interruptFlag) {
interruptFlag = false;
soundManager.playDingDongTone();
canManager.sendCANMessage(0x002, 0b00000101);
std::cout << "dingdong" << std::endl;
}

canManager.processCANMessage();
}


soundManager.playResetTone();
return 0;
}
}
Binary file modified Client/RSP5(Buzzer)/obj/CANCommunicationManager.o
Binary file not shown.
Binary file modified Client/RSP5(Buzzer)/obj/SoundManager.o
Binary file not shown.
Binary file modified Client/RSP5(Buzzer)/obj/main.o
Binary file not shown.
8 changes: 4 additions & 4 deletions Client/RSP5(Buzzer)/src/CANCommunicationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ bool CANCommunicationManager::processCANMessage() {
std::cout << "Open" << std::endl;
soundThread = std::thread(&SoundManager::playOpenTone, &soundManager);
ledThread = std::thread(&LEDController::setGreenLED, &ledController);
failCounter = 0;
failCounter = 1;
}
else if(frame.data[0] == 4) {
std::cout << "Closed" << std::endl;
ledThread = std::thread(&LEDController::setGreenLED, &ledController);
soundThread = std::thread(&SoundManager::playCloseTone, &soundManager);
failCounter = 0;
failCounter = 1;
}
else {
if ((failCounter == 3)||(frame.data[0] == 0)||(frame.data[0]==2)) {
std::cout << "Alarm" << std::endl;
ledThread = std::thread(&LEDController::setRedLED, &ledController);
soundThread = std::thread(&SoundManager::playAlarmTone, &soundManager);
failCounter = 0;
failCounter = 1;
}
else if (frame.data[0]==1){
std::cout << "Retry password" << std::endl;
Expand Down Expand Up @@ -125,4 +125,4 @@ void CANCommunicationManager::closeCANSocket() {
close(socketFd);
socketFd = -1;
}
}
}
6 changes: 2 additions & 4 deletions Client/RSP5(Buzzer)/src/LEDController.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#include "../inc/LEDController.h"
#include "../inc/Configure.h"
#include <wiringPi.h>

#define RLED 1
#define GLED 2
#define BLED 28
#define YLED 29


void LEDController::initialize() {
pinMode(RLED, OUTPUT);
Expand Down
2 changes: 1 addition & 1 deletion Client/RSP5(Buzzer)/src/SoundManager.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "../inc/SoundManager.h"
#include "../inc/Configure.h"
#include <wiringPi.h>
#include <softTone.h>

#define SPKR 6

void SoundManager::initialize() {
pinMode(SPKR, OUTPUT);
Expand Down
29 changes: 0 additions & 29 deletions Client/RSP5(Buzzer)/src/switch-handler.cpp

This file was deleted.

0 comments on commit 4a56394

Please sign in to comment.