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

Fixed RF Replay, Reduced general Flickering on UI #89

Merged
merged 1 commit into from
Jul 26, 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
66 changes: 38 additions & 28 deletions src/core/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,34 +153,37 @@ void progressHandler(int progress, size_t total) {
***************************************************************************************/
void drawOptions(int index,const std::vector<std::pair<std::string, std::function<void()>>>& options, uint16_t fgcolor, uint16_t bgcolor) {
int menuSize = options.size();
if(options.size()>MAX_MENU_SIZE) menuSize = MAX_MENU_SIZE;

tft.fillRoundRect(WIDTH*0.15,HEIGHT/2-menuSize*(FM*8+4)/2 -5,WIDTH*0.7,(FM*8+4)*menuSize+10,5,bgcolor);
if(options.size()>MAX_MENU_SIZE) {
menuSize = MAX_MENU_SIZE;
}

if(index==0) tft.fillRoundRect(WIDTH*0.10,HEIGHT/2-menuSize*(FM*8+4)/2 -5,WIDTH*0.8,(FM*8+4)*menuSize+10,5,bgcolor);

tft.setTextColor(fgcolor,bgcolor);
tft.setTextSize(FM);
tft.setCursor(WIDTH*0.15+5,HEIGHT/2-menuSize*(FM*8+4)/2);

tft.setCursor(WIDTH*0.10+5,HEIGHT/2-menuSize*(FM*8+4)/2);
int i=0;
int init = 0;
int cont = 1;
if(index==0) tft.fillRoundRect(WIDTH*0.10,HEIGHT/2-menuSize*(FM*8+4)/2 -5,WIDTH*0.8,(FM*8+4)*menuSize+10,5,bgcolor);
menuSize = options.size();
if(index>=MAX_MENU_SIZE) init=index-MAX_MENU_SIZE+1;
for(i=0;i<menuSize;i++) {
if(i>=init) {
String text="";
if(i==index) text+=">";
else text +=" ";
text += String(options[i].first.c_str());
tft.setCursor(WIDTH*0.15+5,tft.getCursorY()+4);
tft.println(text.substring(0,13));
text += String(options[i].first.c_str()) + " ";
tft.setCursor(WIDTH*0.10+5,tft.getCursorY()+4);
tft.println(text.substring(0,(WIDTH*0.8 - 10)/(LW*FM) - 1));
cont++;
}
if(cont>MAX_MENU_SIZE) goto Exit;
}
Exit:
if(options.size()>MAX_MENU_SIZE) menuSize = MAX_MENU_SIZE;
tft.drawRoundRect(WIDTH*0.15,HEIGHT/2-menuSize*(FM*8+4)/2 -5,WIDTH*0.7,(FM*8+4)*menuSize+10,5,fgcolor);
tft.drawRoundRect(WIDTH*0.10,HEIGHT/2-menuSize*(FM*8+4)/2 -5,WIDTH*0.8,(FM*8+4)*menuSize+10,5,fgcolor);
}

/***************************************************************************************
Expand All @@ -189,7 +192,7 @@ void drawOptions(int index,const std::vector<std::pair<std::string, std::functio
***************************************************************************************/
void drawSubmenu(int index,const std::vector<std::pair<std::string, std::function<void()>>>& options, String system) {
int menuSize = options.size();
drawMainBorder();
if(index==0) drawMainBorder();
tft.setTextColor(FGCOLOR,BGCOLOR);
tft.fillRect(6,26,WIDTH-12,20,BGCOLOR);
tft.fillRoundRect(6,26,WIDTH-12,HEIGHT-32,5,BGCOLOR);
Expand Down Expand Up @@ -220,15 +223,17 @@ void drawSubmenu(int index,const std::vector<std::pair<std::string, std::functio
tft.setTextColor(FGCOLOR-0x2000);
tft.drawCentreString(options[0].first.c_str(),WIDTH/2, 102,SMOOTH_FONT);
}

tft.drawFastHLine(WIDTH/2 - options[index].first.size()*FG*LW/2, 67+FG*LH,options[index].first.size()*FG*LW,FGCOLOR);
tft.fillRect(tft.width()-5,0,5,tft.height(),BGCOLOR);
tft.fillRect(tft.width()-5,index*tft.height()/menuSize,5,tft.height()/menuSize,FGCOLOR);

}

void drawMainBorder() {
tft.fillScreen(BGCOLOR);
tft.fillScreen(BGCOLOR);
void drawMainBorder(bool clear) {
if(clear){
tft.fillScreen(BGCOLOR);
tft.fillScreen(BGCOLOR);
}
setTftDisplay(12, 12, FGCOLOR, 1, BGCOLOR);

// if(wifiConnected) {tft.print(timeStr);} else {tft.print("BRUCE 1.0b");}
Expand Down Expand Up @@ -325,35 +330,40 @@ void drawWireguardStatus(int x, int y) {
***************************************************************************************/
#define MAX_ITEMS 7
void listFiles(int index, String fileList[][3]) {
tft.fillScreen(BGCOLOR);
tft.fillScreen(BGCOLOR);
tft.drawRoundRect(5, 5, WIDTH - 10, HEIGHT - 10, 5, FGCOLOR);
if(index==0){
tft.fillScreen(BGCOLOR);
tft.fillScreen(BGCOLOR);
}
tft.setCursor(10,10);
tft.setTextSize(FM);
int i=0;
int arraySize = 0;
while(fileList[arraySize][2]!="" && arraySize < MAXFILES) arraySize++;
int i=0;
int start=0;
if(index>=MAX_ITEMS) {
start=index-MAX_ITEMS+1;
if(start<0) start=0;
}

int nchars = (WIDTH-20)/(6*tft.textsize);
String txt=">";
while(i<arraySize) {
if(i>=start && fileList[i][2]!="") {
tft.setCursor(10,tft.getCursorY());
if(fileList[i][2]=="folder") tft.setTextColor(FGCOLOR-0x1111);
else if(fileList[i][2]=="operator") tft.setTextColor(ALCOLOR);
else tft.setTextColor(FGCOLOR);

if (index==i) tft.print(">");
else tft.print(" ");
tft.println(fileList[i][0].substring(0,17));

if(fileList[i][2]=="folder") tft.setTextColor(FGCOLOR-0x1111, BGCOLOR);
else if(fileList[i][2]=="operator") tft.setTextColor(ALCOLOR, BGCOLOR);
else { tft.setTextColor(FGCOLOR,BGCOLOR); }

if (index==i) txt=">";
else txt=" ";
txt+=fileList[i][0] + " ";
tft.println(txt.substring(0,nchars));
}
i++;
if (i==(start+MAX_ITEMS) || fileList[i][2]=="") break;
}
}
tft.drawRoundRect(5, 5, WIDTH - 10, HEIGHT - 10, 5, FGCOLOR);
tft.drawRoundRect(5, 5, WIDTH - 10, HEIGHT - 10, 5, FGCOLOR);

}


Expand Down
2 changes: 1 addition & 1 deletion src/core/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void drawOptions(int index,const std::vector<std::pair<std::string, std::functio

void drawSubmenu(int index,const std::vector<std::pair<std::string, std::function<void()>>>& options, String system);

void drawMainBorder();
void drawMainBorder(bool clear = true);

void listFiles(int index, String fileList[][3]);

Expand Down
3 changes: 2 additions & 1 deletion src/core/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ void getMainMenuOptions(int index){
void drawMainMenu(int index) {
const char* texts[7] = { "WiFi", "BLE", "RF", "RFID", "IR", "Others", "Config" };

drawMainBorder();
drawMainBorder(false);
tft.setTextSize(FG);

switch(index) {
Expand Down Expand Up @@ -243,6 +243,7 @@ void drawMainMenu(int index) {
}

tft.setTextSize(FM);
tft.fillRect(10,tft.height()-(LH*FM+10), WIDTH-20,LH*FM, BGCOLOR);
tft.drawCentreString(texts[index],tft.width()/2, tft.height()-(LH*FM+10), SMOOTH_FONT);
tft.setTextSize(FG);
tft.drawChar('<',10,tft.height()/2+10);
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ void loop() {
/* Select and run function */
if (checkSelPress()) {
getMainMenuOptions(index);
drawMainBorder(true);
redraw=true;
}

Expand Down
34 changes: 22 additions & 12 deletions src/modules/rf/rf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,32 +279,37 @@ static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength) {

void RCSwitch_Read_Raw() {
RCSwitch rcswitch = RCSwitch();
RestartRec:
pinMode(RfRx, INPUT);
rcswitch.enableReceive(RfRx);
RfCodes received;

drawMainBorder();
tft.setCursor(10, 28);
tft.setTextSize(FP);
tft.println("Waiting for signal.");
char hexString[64];
RestartRec:
pinMode(RfRx, INPUT);
rcswitch.enableReceive(RfRx);
while(!checkEscPress()) {
if(rcswitch.available()) {
long value = rcswitch.getReceivedValue();
Serial.println("Available");
if(value) {
Serial.println("has value");
unsigned int* raw = rcswitch.getReceivedRawdata();

unsigned int* raw = rcswitch.getReceivedRawdata();
received.frequency=433920000;
received.key=rcswitch.getReceivedValue();
received.protocol=rcswitch.getReceivedProtocol();
received.protocol="RcSwitch";
received.preset=rcswitch.getReceivedProtocol();
received.te=rcswitch.getReceivedDelay();
received.Bit=rcswitch.getReceivedBitlength();
received.filepath="Last copied";

for(int i=0; i<received.te*2;i++) {
if(i>0) received.data+=" ";
received.data+=raw[i];
}
Serial.println(received.protocol);
Serial.println(received.data);
const char* b = dec2binWzerofill(received.key, received.Bit);
drawMainBorder();
Expand All @@ -320,11 +325,11 @@ void RCSwitch_Read_Raw() {
tft.println("PulseLenght: " + String(received.te) + "ms");
tft.setCursor(10, tft.getCursorY());
tft.println("Protocol: " + String(received.protocol));
tft.println("\n");
tft.setCursor(10, tft.getCursorY());
tft.setCursor(10, tft.getCursorY()+LH*2);
tft.println("Press " + String(BTN_ALIAS) + "for options.");
}
rcswitch.resetAvailable();
previousMillis = millis();
}
if(received.key>0) {
if(checkSelPress()) {
Expand All @@ -339,23 +344,28 @@ void RCSwitch_Read_Raw() {
rcswitch.disableReceive();
sendRfCommand(received);
addToRecentCodes(received);
displayRedStripe("Waiting Signal",TFT_WHITE, FGCOLOR);
goto RestartRec;
}
else if (chosen==2) {
int i=0;
File file;
String FS="";
if(SD.begin()) {
while(SD.exists("/bruce_" + String(i) + ".sub")) i++;
file = SD.open("/bruce_"+ String(i) +".sub", FILE_WRITE);
if (!SD.exists("/BruceRF")) SD.mkdir("/BruceRF");
while(SD.exists("/BruceRF/bruce_" + String(i) + ".sub")) i++;
file = SD.open("/BruceRF/bruce_"+ String(i) +".sub", FILE_WRITE);
FS="SD";
} else if(LittleFS.begin()) {
while(LittleFS.exists("/bruce_" + String(i) + ".sub")) i++;
file = LittleFS.open("/bruce_"+ String(i) +".sub", FILE_WRITE);
if (!LittleFS.exists("/BruceRF")) LittleFS.mkdir("/BruceRF");
while(LittleFS.exists("/BruceRF/bruce_" + String(i) + ".sub")) i++;
file = LittleFS.open("/BruceRF/bruce_"+ String(i) +".sub", FILE_WRITE);
FS="LittleFS";
}
if(file) {
file.println("Filetype: Bruce SubGhz RAW File\nVersion 1\nFrequency: 433920000");
if(received.protocol=="1") received.protocol="FuriHalSubGhzPresetOok270Async";
else if (received.protocol=="2") received.protocol="FuriHalSubGhzPresetOok650Async";
file.println("Preset: " + String(received.protocol));
file.println("Protocol: RcSwitch");
file.println("Bit: " + String(received.Bit));
Expand Down Expand Up @@ -464,7 +474,7 @@ void sendRfCommand(struct RfCodes rfcode) {
else if(preset == "FuriHalSubGhzPresetOok650Async") {
rcswitch_protocol_no = 2;
rcswitch_protocol = { 650, { 1, 10 }, { 1, 2 }, { 2, 1 }, false };
} else if(preset == "1" || preset == "2" || preset == "3" || preset == "4" || preset == "5" || preset == "6" || preset == "7" || preset == "8" || preset == "9" || preset == "10" || preset == "11" || preset == "12") {
} else if(preset == "1" || preset == "2" || preset == "3" || preset == "4" || preset == "5" || preset == "6" || preset == "7" || preset == "8" || preset == "9" || preset == "10" || preset == "11" || preset == "12"|| preset == "13" || preset == "14") {
rcswitch_protocol_no = preset.toInt();
}
else {
Expand Down
Loading