Skip to content

Commit

Permalink
Inclusion of the RF433R and the Spectrum option.
Browse files Browse the repository at this point in the history
On Spectrum it is possible to visualize the signal wave, this code was adapted for Cardputer and was based on the @aat440hz project.
  • Loading branch information
IncursioHack authored May 9, 2024
1 parent 2ffdb91 commit 5078a19
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ TFT_eSprite draw = TFT_eSprite(&tft);
#include "evil_portal.h"
#include "clients.h"
#include "arp.h"
#include "rf.h"


#ifdef CARDPUTER
Expand Down Expand Up @@ -200,7 +201,7 @@ void loop() {
options = {
{"Scan/copy", [=]() { displayRedStripe("Scan/Copy"); }},
{"Replay", [=]() { displayRedStripe("Replay"); }},
{"Spectrum", [=]() { displayRedStripe("Spectrum"); }},
{"Spectrum", [=]() { rf_spectrum(); }}, //@IncursioHack
{"Main Menu", [=]() { backToMenu(); }},
};
delay(200);
Expand All @@ -209,7 +210,7 @@ void loop() {
break;
case 3: // RFID
options = {
{"Scan/copy", [=]() { rfid_setup(); }},
{"Scan/copy", [=]() { rfid_setup(); }}, //@IncursioHack
{"Replay", [=]() { displayRedStripe("Replay"); }},
{"Main Menu", [=]() { backToMenu(); }},
};
Expand Down
79 changes: 79 additions & 0 deletions src/rf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//@IncursioHack - github.com/IncursioHack

#include "rf.h"
#include "globals.h"
#include "mykeyboard.h"
#include "display.h"
#include "PCA9554.h"
#include "sd_functions.h"
#include <driver/rmt.h>

// Cria um objeto PCA9554 com o endereço I2C do PCA9554PW
// PCA9554 extIo1(pca9554pw_address);

#define RMT_RX_CHANNEL RMT_CHANNEL_6
#define RMT_BLOCK_NUM 1

#define RMT_CLK_DIV 80 /*!< RMT counter clock divider */
#define RMT_1US_TICKS (80000000 / RMT_CLK_DIV / 1000000)
#define RMT_1MS_TICKS (RMT_1US_TICKS * 1000)

#define SIGNAL_STRENGTH_THRESHOLD 1500 // Adjust this threshold as needed

#define DISPLAY_HEIGHT 130 // Height of the display area for the waveform
#define DISPLAY_WIDTH 240 // Width of the display area
#define LINE_WIDTH 2 // Adjust line width as needed

void initRMT() {
rmt_config_t rxconfig;
rxconfig.rmt_mode = RMT_MODE_RX;
rxconfig.channel = RMT_RX_CHANNEL;
rxconfig.gpio_num = gpio_num_t(GROVE_SCL);
rxconfig.mem_block_num = RMT_BLOCK_NUM;
rxconfig.clk_div = RMT_CLK_DIV;
rxconfig.rx_config.filter_en = true;
rxconfig.rx_config.filter_ticks_thresh = 200 * RMT_1US_TICKS;
rxconfig.rx_config.idle_threshold = 3 * RMT_1MS_TICKS;

ESP_ERROR_CHECK(rmt_config(&rxconfig));
ESP_ERROR_CHECK(rmt_driver_install(rxconfig.channel, 2048, 0));
}

void rf_spectrum() { //@IncursioHack - https://github.com/IncursioHack ----thanks @aat440hz - RF433ANY-M5Cardputer

tft.fillScreen(TFT_BLACK);
tft.setTextSize(1);
tft.println("");
tft.println(" RF433 - Spectrum");
pinMode(GROVE_SCL, INPUT);
initRMT();

RingbufHandle_t rb = nullptr;
rmt_get_ringbuf_handle(RMT_RX_CHANNEL, &rb);
rmt_rx_start(RMT_RX_CHANNEL, true);
while (rb) {
size_t rx_size = 0;
rmt_item32_t* item = (rmt_item32_t*)xRingbufferReceive(rb, &rx_size, 500);
if (item != nullptr) {
if (rx_size != 0) {
// Clear the display area
tft.fillRect(0, 20, DISPLAY_WIDTH, DISPLAY_HEIGHT, TFT_BLACK);
// Draw waveform based on signal strength
for (size_t i = 0; i < rx_size; i++) {
int lineHeight = map(item[i].duration0 + item[i].duration1, 0, SIGNAL_STRENGTH_THRESHOLD, 0, DISPLAY_HEIGHT/2);
int lineX = map(i, 0, rx_size - 1, 0, DISPLAY_WIDTH - 1); // Map i to within the display width
// Ensure drawing coordinates stay within the box bounds
int startY = constrain(20 + DISPLAY_HEIGHT / 2 - lineHeight / 2, 20, 20 + DISPLAY_HEIGHT);
int endY = constrain(20 + DISPLAY_HEIGHT / 2 + lineHeight / 2, 20, 20 + DISPLAY_HEIGHT);
tft.drawLine(lineX, startY, lineX, endY, TFT_PURPLE);
}
}
vRingbufferReturnItem(rb, (void*)item);
}
}
// Checks para sair do while

rmt_rx_stop(RMT_RX_CHANNEL);
delay(10);

}
16 changes: 16 additions & 0 deletions src/rf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @IncursioHack - https://github.com/IncursioHack
#include <Wire.h>
#include <SD.h>
#include "PCA9554.h" // Biblioteca para PCA9554

// Define o endereço I2C do PCA9554PW
const int pca9554pw_address = 0x27;

// Cria um objeto PCA9554 com o endereço I2C do PCA9554PW
extern PCA9554 extIo1;

// Define os pinos para o receptor e transmissor
const int PCA9554RSX_PIN = 4;
const int PCA9554TRX_PIN = 0;

void rf_spectrum();

0 comments on commit 5078a19

Please sign in to comment.