Skip to content

Commit

Permalink
[๐Ÿ“บ] First version of the IR Dump feature.
Browse files Browse the repository at this point in the history
the ๐“ฏ๐“ป๐“ฎ๐“ช๐“ด๐”‚ feature is almost ready ๐Ÿ‘…๐Ÿ‘…๐Ÿ‘…
  • Loading branch information
Niximkk committed Aug 3, 2024
1 parent c373b34 commit cb7d60f
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/core/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "modules/others/qrcode_menu.h"
#include "modules/others/mic.h"
#include "modules/ir/TV-B-Gone.h"
#include "modules/ir/IRReceiver.h"
#include "modules/ir/IRDump.h"
#include "modules/rf/rf.h"
#include "modules/rfid/tag_o_matic.h"
#include "modules/rfid/mfrc522_i2c.h"
Expand Down Expand Up @@ -130,7 +130,7 @@ void irOptions(){
options = {
{"TV-B-Gone", [=]() { StartTvBGone(); }},
{"Custom IR", [=]() { otherIRcodes(); }},
{"IR Receiver", [=]() { recvReceive(); }},
{"IR Dump", [=]() { recvReceive(); }},
{"Main Menu", [=]() { backToMenu(); }}
};
delay(200);
Expand Down
106 changes: 67 additions & 39 deletions src/modules/ir/IRReceiver.cpp โ†’ src/modules/ir/IRDump.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
/* This code is ass, feel free to delete everthing and redo it from scratch <3 */
/* Author: @im.nix - even tho im not proud of this code :P */
/**
* @file IRDump.cpp
* @author @im.nix (https://github.com/Niximkk)
* @version 0.2
* @date 2024-08-03
*
* This code is ass, feel free to delete everthing and redo it from scratch <3
* Code from Fuck-Nemo...
* No wait, fuck that firmware, the code is originally from https://github.com/FlasherTwelve/IR_Replay ^^
*/

#include "core/display.h"
#include "core/mykeyboard.h"
#include "core/sd_functions.h"
#include "IRReceiver.h"
#include "IRDump.h"

/* Dont touch this */
#define MAX_RAWBUF_SIZE 100
#define MAX_RAWBUF_SIZE 300
#define IR_FREQUENCY 38000
#define DUTY_CYCLE 0.330000

decode_results results;
uint16_t* rawcode;

int rawDataLen;
int signalCount;
String signalName;
String signalCode;

Expand All @@ -24,33 +32,41 @@ void initializeIRReceiver(IRrecv &irrecv) {
}

void displayWaitingMessage() {
tft.fillScreen(BGCOLOR);
tft.setTextSize(4);
tft.setCursor(0, 0);
tft.println("Receiver");
tft.setTextSize(3);
tft.println("Waiting...");
drawMainBorder();
tft.setCursor(10, 28);
tft.setTextSize(FP);
tft.println("Waiting for signal.");
}

void displayRecordedMessage() {
tft.fillScreen(BGCOLOR);
tft.setTextSize(4);
tft.setCursor(0, 0);
tft.println("Receiver");
tft.setTextSize(3);
tft.println("Recorded!");
tft.print(results.value, HEX);
drawMainBorder();
tft.setCursor(10, 28);
tft.setTextSize(FP);
tft.println("Signal found!");
tft.setCursor(10, tft.getCursorY());
tft.print("HEX: 0x");
tft.println(results.value, HEX);
tft.setCursor(10, tft.getCursorY());
tft.println("");
tft.setCursor(10, tft.getCursorY());
tft.println("M5 To save");
tft.setCursor(10, tft.getCursorY());
tft.println("Nxt To discard");
tft.setCursor(10, tft.getCursorY());
tft.println("Esc To exit");
}

// TODO: Remove bloat
void processRawData() {
rawcode = new uint16_t[MAX_RAWBUF_SIZE];
memset(rawcode, 0, MAX_RAWBUF_SIZE * sizeof(uint16_t));
rawDataLen = results.rawlen;

signalCode = "";
Serial.print("Raw Data ");
Serial.print(rawDataLen);
Serial.print(" : ");
/* I HAVE NO FUCKING IDEA WHY WE NEED TO MULTIPLY BY 2, BUT DO. */

/* I HAVE NO FUCKING IDEA WHY WE NEED TO MULTIPLY BY 2, BUT WE DO. */
for (int i = 1; i < rawDataLen; i++) {
signalCode += String(results.rawbuf[i] * 2);
Serial.print(results.rawbuf[i], DEC);
Expand All @@ -63,24 +79,30 @@ void processRawData() {
Serial.println();
Serial.print("Hex: ");
Serial.println(results.value, HEX);
delete[] rawcode;
rawcode = nullptr;
}

// TODO: Make this less shitty, implement a better way of selecting options.
void recvReceive() {
IRrecv irrecv(IrRx);
initializeIRReceiver(irrecv);

displayWaitingMessage();

while (true) {
if (irrecv.decode(&results)) {
displayRecordedMessage();
processRawData();
recv_save();
irrecv.resume();
delay(1000);
break;
initializeIRReceiver(irrecv);
displayWaitingMessage();
while (true) {
if (irrecv.decode(&results)) {
displayRecordedMessage();
processRawData();
while(true){
if (checkSelPress()) { saveController(); break; }
if (checkNextPress()) break;
if (checkEscPress()) return;
}
irrecv.resume();
break;
}
}
if (checkEscPress()) break;
if (checkEscPress()) return;
}
}

Expand All @@ -89,7 +111,7 @@ void selectFileSystem(FS* &fs) {
if (checkLittleFsSize()) options.push_back({"LittleFS", [&]() { fs=&LittleFS; }});
if (setupSdCard()) options.push_back({"SD Card", [&]() { fs=&SD; }});
if (options.size() == 0) {
displayRedStripe("No space, womp womp", TFT_WHITE, BGCOLOR);
displayRedStripe("No space, womp womp", TFT_WHITE, FGCOLOR);
delay(1000);
backToMenu();
}
Expand All @@ -109,6 +131,7 @@ String generateUniqueFilename(FS* fs, String baseName) {
return filename;
}

// TODO: Add a way to save multiple signals before closing the file.
void saveSignalToFile(FS* fs, String filename) {
if (!(*fs).exists("/BruceInfrared")) (*fs).mkdir("/BruceInfrared");
filename = generateUniqueFilename(fs, filename);
Expand All @@ -120,25 +143,30 @@ void saveSignalToFile(FS* fs, String filename) {
file.println("#");
file.println("# " + filename);
file.println("#");
file.println("name: Captured");
file.println("name: CoolSignal");
file.println("type: raw");
file.println("frequency: " + String(IR_FREQUENCY));
file.println("duty_cycle: " + String(DUTY_CYCLE));
file.println("data: " + signalCode);
file.println("#");
file.close();
displayRedStripe("Saved!", TFT_WHITE, FGCOLOR);
delay(1000);
}
signalCode = "";
}

void recv_save() {
// TODO: Only call this to close the file and save the controller.
void saveController() {
FS *fs = NULL;
String filename = keyboard("", 30, "File name:");

String filename = keyboard("MyController", 30, "File name:");
drawMainBorder();
selectFileSystem(fs);

if (fs) {
saveSignalToFile(fs, filename);
delay(100);
}
}
recvReceive();
}

// TODO: Make a saveSignal(); function to only store the signal without closing the file.
13 changes: 7 additions & 6 deletions src/modules/ir/IRReceiver.h โ†’ src/modules/ir/IRDump.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
#include <SD.h>
#include "core/globals.h"

void initializeIRReceiver(IRrecv &irrecv);
String generateUniqueFilename(FS* fs, String baseName);

void recvReceive();
void processRawData();
void saveController();
void displayWaitingMessage();
void displayRecordedMessage();
void processRawData();
void recvReceive();
void selectFileSystem(FS* &fs);
String generateUniqueFilename(FS* fs, String baseName);
void saveSignalToFile(FS* fs, String filename);
void recv_save();
void initializeIRReceiver(IRrecv &irrecv);
void saveSignalToFile(FS* fs, String filename);

0 comments on commit cb7d60f

Please sign in to comment.