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

T-Embed Keyboard fix and RF .sub with multiple RAW_Data #641

Merged
merged 8 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
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
21 changes: 6 additions & 15 deletions boards/lilygo-t-embed-cc1101/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,38 +464,29 @@ String keyboard(String mytext, int maxSize, String msg) {
/* Down Btn to move in X axis (to the right) */
if(checkNextPress())
{
// To handle Encoder devices such as T-EMBED
#ifdef T_EMBED_1101
if(digitalRead(BK_BTN) == BTN_ACT) { y++; }
else
#endif
if(x==3 && y<0) {y++; x=0;}
else if(x==11) { y++; x++; }
if ((x >= 3 && y < 0) || x == 11) { y++; x = 0; }
else x++;

if(y>3) { y=-1; }
else if(y<-1) y=3;

if(y<0 && x>3) x=0;
if(x>11) x=0;
else if (x<0) x=11;
if (y > 3) y = -1;
redraw = true;
}
/* UP Btn to move in Y axis (Downwards) */
if(checkPrevPress()) {
// To handle Encoder devices such as T-EMBED
#ifdef T_EMBED_1101
if(digitalRead(BK_BTN) == BTN_ACT) { y--; }
else
#endif
if(x==0) { y--; x--; }
else x--;

if(y<0 && x<0) x=11;
if(x>11) x=0;
if(y<-1) { y=3; x=11; }
else if(y<0 && x<0) x=3;
else if (x<0) x=11;

// To handle Encoder devices such as T-EMBED
if(y>3) { y=-1; }
else if(y<-1) y=3;
redraw = true;
}

Expand Down
1 change: 1 addition & 0 deletions boards/lilygo-t-embed.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ lib_deps =
${env.lib_deps}
lewisxhe/XPowersLib @0.2.6
mathertel/RotaryEncoder @1.5.3
fastled/FastLED @3.9.4
91 changes: 71 additions & 20 deletions src/modules/rf/rf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void rf_SquareWave() { //@Pirata
// Draw waveform based on signal strength
for (int i = 0; i < RCSWITCH_RAW_MAX_CHANGES-1; i+=2) {
if(raw[i]==0) break;
#define TIME_DIVIDER tftWidth/8
#define TIME_DIVIDER tftWidth/30
if(raw[i]>20000) raw[i]=20000;
if(raw[i+1]>20000) raw[i+1]=20000;
if(line_w+(raw[i]+raw[i+1])/TIME_DIVIDER>tftWidth) { line_w=10; line_h+=10; }
Expand Down Expand Up @@ -961,7 +961,7 @@ void RCSwitch_RAW_send(int * ptrtransmittimings) {
return;

bool currentlogiclevel = true;
int nRepeatTransmit = 5; // repeats RAW signal twice!
int nRepeatTransmit = 1; // repeats RAW signal twice!
//HighLow pulses ;

for (int nRepeat = 0; nRepeat < nRepeatTransmit; nRepeat++) {
Expand Down Expand Up @@ -1232,6 +1232,10 @@ void otherRFcodes() {
bool txSubFile(FS *fs, String filepath) {
struct RfCodes selected_code;
File databaseFile;
String line;
String txt;
int total=0;
int sent=0;

if(!fs) return false;

Expand All @@ -1247,28 +1251,75 @@ bool txSubFile(FS *fs, String filepath) {
selected_code.filepath = filepath.substring( 1 + filepath.lastIndexOf("/") );

// format specs: https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/file_formats/SubGhzFileFormats.md
String line;
String txt;
while (databaseFile.available() ) {

// Count the number of signals present in the .sub file
displaySomething("Reading File..");
while (databaseFile.available()) {
line = databaseFile.readStringUntil('\n');
if( line.startsWith("Bit_RAW:") ||
line.startsWith("Key:") ||
line.startsWith("RAW_Data:") ||
line.startsWith("Data_RAW:"))
{
total++;
}
}
databaseFile.close();
Serial.printf("\nFound a total of %d code(s)\n", total);
databaseFile = fs->open(filepath, FILE_READ);
if(!databaseFile) Serial.println("Fail opening file again");
// Analyse and send the signals
while (databaseFile.available()) {
line = databaseFile.readStringUntil('\n');
txt=line.substring(line.indexOf(":") + 1);
if(txt.endsWith("\r")) txt.remove(txt.length() - 1);
txt.trim();
if(line.startsWith("Protocol:")) selected_code.protocol = txt;
if(line.startsWith("Preset:")) selected_code.preset = txt;
if(line.startsWith("Frequency:")) selected_code.frequency = txt.toInt();
if(line.startsWith("TE:")) selected_code.te = txt.toInt();
if(line.startsWith("Bit:")) selected_code.Bit = txt.toInt();
if(line.startsWith("Bit_RAW:")) selected_code.BitRAW = txt.toInt();
if(line.startsWith("RAW_Data:") || line.startsWith("Data_RAW:")) selected_code.data +=" " + txt; // add a space at the end, some files have more than one RAW_Data. This initial space will be trimmed
if(line.startsWith("Key:")) selected_code.key = hexStringToDecimal(txt.c_str());
if(line.startsWith("RAW_Data:") || line.startsWith("Data_RAW:")) {
selected_code.data = txt;
}

// If the signal is complete, send it and reset the signal to send the next command in the file, in case it has more RAW_Data
if(selected_code.protocol!="" && selected_code.preset!="" && selected_code.frequency>0 && (selected_code.BitRAW>0 || selected_code.data!="" || selected_code.key>0)) {
selected_code.data.trim(); // remove initial and final spaces and special characters
addToRecentCodes(selected_code);

// To send the signal using CC1101 sharing the SPI Bus with SDCard, we need to close the file first
// Does not apply for Smoochiee board and StickCPlus for now.
if(bruceConfig.rfModule==CC1101_SPI_MODULE) {
#if SDCARD_MOSI==CC1101_MOSI_PIN
size_t point = databaseFile.position(); // Save the last position read
databaseFile.close(); // Close the File
#endif
sendRfCommand(selected_code);
#if SDCARD_MOSI==CC1101_MOSI_PIN
databaseFile = fs->open(filepath, FILE_READ); // Open the file
databaseFile.seek(point); // Head back to where we were
#endif
}
else sendRfCommand(selected_code);

selected_code.BitRAW=0;
selected_code.data="";
selected_code.key=0;
sent++;
displaySomething("Sent " + String(sent) + "/" + String(total));
Serial.print(".");
delay(50);
}

if(checkEscPress()) break;
}
selected_code.data.trim(); // remove initial and final spaces and special characters
Serial.printf("\nSent %d of %d signals\n", sent, total);

databaseFile.close();

addToRecentCodes(selected_code);
sendRfCommand(selected_code);

//digitalWrite(bruceConfig.rfTx, LED_OFF);
delay(1000);
deinitRfModule();
return true;
}
Expand All @@ -1294,7 +1345,7 @@ static const float subghz_frequency_list[] = {
906.400f, 915.000f, 925.000f, 928.000f
};

#define _MAX_TRIES 3
#define _MAX_TRIES 5

struct FreqFound {
float freq;
Expand Down Expand Up @@ -1375,7 +1426,7 @@ void rf_scan_copy() {
int signals = 0, idx = range_limits[bruceConfig.rfScanRange][0];
float found_freq = 0.f, frequency = 0.f;
int rssi=-80, rssiThreshold = -55;
FreqFound _freqs[_MAX_TRIES]; // get the best RSSI out of 3 tries
FreqFound _freqs[_MAX_TRIES]; // get the best RSSI out of 5 tries
bool ReadRAW=true;

RestartScan:
Expand Down Expand Up @@ -1578,21 +1629,21 @@ void rf_scan_copy() {
options.push_back({ "Save Signal", [&]() { option = 2; } });
options.push_back({ "Reset Signal", [&]() { option = 3; } });
}
if(bruceConfig.rfModule==CC1101_SPI_MODULE) options.push_back({ "Range", [&]() { option = 1; } });


if(ReadRAW) options.push_back({ "Stop RAW", [&]() { ReadRAW=false; } });
else options.push_back({ "Read RAW", [&]() { ReadRAW=true; } });
if(bruceConfig.devMode && !OnlyRAW) options.push_back({ "[D]Only RAW", [&]() { ReadRAW=true; OnlyRAW=true; } });
else if(bruceConfig.devMode && OnlyRAW) options.push_back({ "[D]RAW+Decode",[&]() { ReadRAW=true; OnlyRAW=false; } });
if(bruceConfig.devMode && !OnlyRAW) options.push_back({ "Only RAW", [&]() { ReadRAW=true; OnlyRAW=true; } });
else if(bruceConfig.devMode && OnlyRAW) options.push_back({ "RAW+Decode", [&]() { ReadRAW=true; OnlyRAW=false; } });
options.push_back({ "Close Menu", [&]() { option =-1; } });
options.push_back({ "Main Menu", [=]() { returnToMenu=true; } });
options.push_back({ "Main Menu", [&]() { returnToMenu=true; } });

delay(200);
loopOptions(options);

if(option==-1) goto RestartScan;

if(returnToMenu) break;
if(returnToMenu) goto END;

if(option ==0 ) { // Replay signal
ReplaySignal:
Expand Down Expand Up @@ -1660,6 +1711,6 @@ void rf_scan_copy() {
}
++idx;
}

END:
deinitRfModule();
}
Loading