-
Notifications
You must be signed in to change notification settings - Fork 1
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
add blind spot #11
Open
parahybaja-punchClock
wants to merge
5
commits into
v5
Choose a base branch
from
develop-blind_spot
base: v5
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add blind spot #11
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f694c0b
add blind spot
parahybaja-punchClock ad74cf3
Modify in process
parahybaja-punchClock 16bdb57
add project IDE
Flaviano-Junior 566c1f1
Insert project for accelerometer
Flaviano-Junior 51cef18
Delete project test_i2c
Flaviano-Junior File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
idf_component_register( | ||
SRCS "src/blind_spot.c" | ||
INCLUDE_DIRS "include" | ||
REQUIRES system driver | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version: "0.1.0" | ||
description: "task example" | ||
url: "https://github.com/Parahybaja/firmware" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/** | ||
* @file task_blind_spot.h | ||
* @author Flaviano Medeiros da Silva Júnior ([email protected]) | ||
* @brief task blind spot | ||
* @version 0.1 | ||
* @date 2024-01-22 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
* Version Modified By Date Comments | ||
* ------- ------------- ---------- ----------- | ||
* 0.1.0 Flaviano Jr. 22/01/2024 first version | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "system.h" | ||
#include "driver/gpio.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#define TASK_BLIND_SPOT_SEND_RATE_Hz 1 // RPM task send rate in hertz | ||
|
||
#define ACTIVE_LOW false | ||
#define BLIND_SPOT_AVERAGE_POINTS 5 | ||
#define THRESHOLD 1 // to be calibrated | ||
|
||
void task_blind_spot(void*); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <Arduino.h> | ||
|
||
#define RX_PIN 3 // GPIO3 (RX0) como RX (pino de recepção) | ||
#define TX_PIN 1 // GPIO1 como TX (pino de transmissão) | ||
#define SERIAL_BAUD 9600 // Taxa de baud para comunicação serial | ||
|
||
void setup() { | ||
Serial.begin(SERIAL_BAUD); | ||
} | ||
|
||
void loop() { | ||
getDistance(); | ||
delay(100); // Adiciona um pequeno atraso entre leituras | ||
} | ||
|
||
void getDistance() { | ||
unsigned int distance; | ||
byte startByte, h_data, l_data, sum = 0; | ||
byte buf[3]; | ||
|
||
// Espera até que pelo menos 3 bytes estejam disponíveis | ||
while (Serial.available() < 3) { | ||
delay(10); | ||
} | ||
|
||
Serial.readBytes(buf, 3); | ||
startByte = buf[0]; | ||
h_data = buf[1]; | ||
l_data = buf[2]; | ||
sum = h_data + l_data; | ||
|
||
if (startByte == 255 && sum == buf[2]) { | ||
distance = (h_data << 8) + l_data; | ||
Serial.print("Distância [mm]: "); | ||
Serial.println(distance); | ||
} else { | ||
Serial.println("Resultado inválido"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "task/blind_spot.h" | ||
|
||
static const char *TAG = "blind_spot"; | ||
|
||
void task_blind_spot(void *arg){ | ||
(void)arg; | ||
|
||
const gpio_num_t gpio_pin = (gpio_num_t)arg; | ||
|
||
// -----config gpio----- | ||
//zero-initialize the config structure. | ||
gpio_config_t io_conf = {}; | ||
io_conf.intr_type = GPIO_INTR_DISABLE; | ||
io_conf.mode = GPIO_MODE_INPUT; | ||
io_conf.pin_bit_mask = (1ULL<<gpio_pin); | ||
io_conf.pull_down_en = false; | ||
io_conf.pull_up_en = false; | ||
ESP_ERROR_CHECK(gpio_config(&io_conf)); | ||
|
||
const int send_rate_ms = (int)(1000.0 / (float)(TASK_BLIND_SPOT_SEND_RATE_Hz)); | ||
uint32_t timer_send_ms; | ||
float sum; | ||
int last_value = 0; | ||
sensor_t blind_sr = {TILT_Z, 0.0}; | ||
// sensor_t blind_sl = {TILT_X, 0.0}; | ||
|
||
task_remaining_space(); | ||
|
||
timer_send_ms = esp_log_timestamp(); | ||
|
||
for (;;) | ||
{ | ||
if ((esp_log_timestamp() - timer_send_ms) >= send_rate_ms) | ||
{ | ||
// -----add to timer----- | ||
timer_send_ms += send_rate_ms; | ||
|
||
// -----calculate----- | ||
sum = 0; // clean sum buffer | ||
for (int i=0; i < BLIND_SPOT_AVERAGE_POINTS; i++) { | ||
if (ACTIVE_LOW) | ||
sum += !gpio_get_level(gpio_pin); | ||
else | ||
sum += gpio_get_level(gpio_pin); | ||
} | ||
blind_sr.value = sum / (float)(BLIND_SPOT_AVERAGE_POINTS); | ||
|
||
// ----- define high or low level ----- | ||
// comment out to send raw data fuel average | ||
if (blind_sr.value <= THRESHOLD){ // low fuel level | ||
blind_sr.value = 0; // active low fuel emergency flag | ||
} | ||
else { | ||
blind_sr.value = 1; | ||
} | ||
|
||
// ----- send data just when is changed ----- | ||
if (blind_sr.value != last_value) { | ||
// -----send fuel data through esp-now to receiver----- | ||
ESP_LOGD(TAG, "Blind Spot, detected"); | ||
printf("Pin Level: %f\n",sum); | ||
// esp_now_send(mac_address_ECU_rear, (uint8_t *) &blind_spot_right, sizeof(blind_spot_right)); | ||
// esp_now_send(mac_address_ECU_rear, (uint8_t *) &blind_spot_left, sizeof(blind_spot_left)); | ||
}; | ||
|
||
// ----- update last value ----- | ||
last_value = blind_sr.value; | ||
} | ||
|
||
vTaskDelay(pdMS_TO_TICKS(10)); // free up the processor | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
update description