Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect breaks task #15

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions Core/Src/interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,32 @@
#include "interrupts.h"
#include "ApplicationTypes.h"
#include "data_aggregator.h"
#include "CANDriver.h"

/**
* Brakes are connected to GPIO 0
*/
const uint BRAKE_PIN = 0;

void brakes_callback(uint gpio, uint32_t events) {
bool brake_pressed = (events & GPIO_IRQ_EDGE_RISE);
data_aggregator_set_breaks_pressed(brake_pressed);
iCommsMessage_t brakeMsg;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in UOSM-core there is function to create CAN message directly. Those are the standard in our code currently but in the end it does the same thing (IComms_CreateMessage) feel free to look at it and change your function if you want

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// Sending the brake signal through CAN
if (brake_pressed) {
brakeMsg.standardMessageID = 0x123; // Brake message ID
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to add this message to UOSM-core

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

brakeMsg.dataLength = 1;
brakeMsg.data[0] = brake_pressed;

uint8_t result = CANSPI_Transmit(&brakeMsg);

if (result == 1) {
DebugPrint("Brake signal sent successfully\n");
} else {
DebugPrint(("Brake signal sent failed\n"));
}

data_aggregator_set_breaks_pressed(events & GPIO_IRQ_EDGE_RISE);
}

Expand Down