pull/71/head^2
Hansi, dl9rdz 2021-03-02 12:47:46 +01:00
rodzic a051b069bb
commit a7a642332f
7 zmienionych plików z 84 dodań i 8 usunięć

Wyświetl plik

@ -108,6 +108,7 @@ int readLine(Stream &stream, char *buffer, int maxlen) {
return n;
}
// Replaces placeholder with LED state value
String processor(const String& var) {
Serial.println(var);
@ -564,6 +565,7 @@ struct st_configitems config_list[] = {
{"tft_rs", "TFT RS", 0, &sonde.config.tft_rs},
{"tft_cs", "TFT CS", 0, &sonde.config.tft_cs},
{"tft_orient", "TFT orientation (0/1/2/3), OLED flip: 3", 0, &sonde.config.tft_orient},
{"tft_modeflip", "TFT modeflip (usually 0)", 0, &sonde.config.tft_modeflip},
{"button_pin", "Button input port", -4, &sonde.config.button_pin},
{"button2_pin", "Button 2 input port", -4, &sonde.config.button2_pin},
{"button2_axp", "Use AXP192 PWR as Button 2", 0, &sonde.config.button2_axp},
@ -790,6 +792,55 @@ const char *handleControlPost(AsyncWebServerRequest *request) {
return "";
}
int streamEditForm(int &state, File &file, String filename, char *buffer, size_t maxlen, size_t index) {
Serial.printf("streamEdit: state=%d max:%d idx:%d\n", state, maxlen, index);
int i=0;
switch(state) {
case 0: // header
{
// we optimistically assume that on first invocation, maxlen is large enough to handle the header.....
strncpy(buffer, "<html><head><title>Editor</title></head><body><p>Edit: ", maxlen);
i = strlen(buffer);
strncpy(buffer+i, filename.c_str(), maxlen-i);
i += strlen(buffer+i);
strncpy(buffer+i, "</p><form action=\"edit.html?file=", maxlen-i);
i += strlen(buffer+i);
strncpy(buffer+i, filename.c_str(), maxlen-i);
i += strlen(buffer+i);
strncpy(buffer+i, "\" method=\"post\" enctype=\"multipart/form-data\"><textarea name=\"text\" cols=\"80\" rows=\"40\">", maxlen-i);
i += strlen(buffer+i);
if(i>=maxlen) {
strncpy(buffer, "Out of memory", maxlen);
state = 3;
return strlen(buffer);
}
state++;
Serial.printf("Wrote %d bytes. Header finished", i);
return i;
break;
}
case 1: // file content
while(file.available()) {
int cnt = readLine(file, buffer+i, maxlen-i-1);
i += cnt;
buffer[i++] = '\n';
buffer[i] = 0;
if(i+256 > maxlen) break; // max line length in file 256 chars
}
if(i>0) return i;
file.close();
state++; // intentional fall-through
case 2: // footer
Serial.println("Appending footer\n");
strncpy(buffer, "</textarea><input type=\"submit\" value=\"Save\"></input></form></body></html>", maxlen);
state++;
return strlen(buffer);
case 3: // end
return 0;
}
return 0;
}
// bad idea. prone to buffer overflow. use at your own risk...
const char *createEditForm(String filename) {
Serial.println("Creating edit form");
@ -999,14 +1050,27 @@ void SetupAsyncServer() {
});
server.on("/edit.html", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/html", createEditForm(request->getParam(0)->value()));
// new version:
// Open file
// store file object in request->_tempObject
//request->send(200, "text/html", createEditForm(request->getParam(0)->value()));
const String filename = request->getParam(0)->value();
File file = SPIFFS.open("/" + filename, "r");
int state = 0;
request->send("text/html", 0, [state,file,filename](uint8_t *buffer, size_t maxLen, size_t index) mutable -> size_t {
Serial.printf("******* send callback: %d %d %d\n", state, maxLen, index);
return streamEditForm(state, file, filename, (char *)buffer, maxLen, index);
});
});
server.on("/edit.html", HTTP_POST, [](AsyncWebServerRequest * request) {
const char *ret = handleEditPost(request);
if (ret == NULL)
request->send(200, "text/html", "<html><head>ERROR</head><body><p>Something went wrong. Uploaded file is empty.</p></body></hhtml>");
else
request->send(200, "text/html", createEditForm(request->getParam(0)->value()));
else {
String f = request->getParam(0)->value();
request->redirect("/edit.html?file="+f);
//request->send(200, "text/html", createEditForm(request->getParam(0)->value()));
}
},
NULL,
[](AsyncWebServerRequest * request, uint8_t *data, size_t len, size_t index, size_t total) {

Wyświetl plik

@ -25,6 +25,7 @@
#tft_rs=2
#tft_cs=0
tft_orient=1
#tft_modeflip=0
#gps_rxd=-1
#gps_txd=-1
# Show AFC value (for RS41 and M10/M20, maybe also DFM, but not useful for RS92)

Wyświetl plik

@ -1,4 +1,4 @@
const char *version_name = "rdzTTGOsonde";
const char *version_id = "devel20210226";
const char *version_id = "devel20210302";
const int SPIFFS_MAJOR=2;
const int SPIFFS_MINOR=10;

Wyświetl plik

@ -87,6 +87,7 @@ void Sonde::defaultConfig() {
config.button2_axp = 0;
config.norx_timeout = 20;
config.screenfile = 1;
config.tft_modeflip = 0;
if(initlevels[16]==0) {
config.oled_sda = 4;
config.oled_scl = 15;
@ -258,6 +259,8 @@ void Sonde::setConfig(const char *cfg) {
config.tft_cs = atoi(val);
} else if(strcmp(cfg,"tft_orient")==0) {
config.tft_orient = atoi(val);
} else if(strcmp(cfg,"tft_modeflip")==0) {
config.tft_modeflip = atoi(val);
} else if(strcmp(cfg,"gps_rxd")==0) {
config.gps_rxd = atoi(val);
} else if(strcmp(cfg,"gps_txd")==0) {

Wyświetl plik

@ -186,6 +186,7 @@ typedef struct st_rdzconfig {
int tft_rs; // TFT RS pin
int tft_cs; // TFT CS pin
int tft_orient; // TFT orientation (default: 1)
int tft_modeflip; // Hack for Joerg's strange display
int gps_rxd; // GPS module RXD pin. We expect 9600 baud NMEA data.
int gps_txd; // GPS module TXD pin
// software configuration

Wyświetl plik

@ -342,10 +342,12 @@ void TFT22_ILI9225::begin()
endWrite();
delay(50);
#define OCTLFLIP(m) ((m&0xff)<<8)
#define EMODEFLIP(m) ((m>>8)<<3)
startWrite();
_writeRegister(ILI9225_DRIVER_OUTPUT_CTRL, 0x011C); // set the display line number and display direction
_writeRegister(ILI9225_DRIVER_OUTPUT_CTRL, OCTLFLIP(_modeFlip) ^ 0x011C); // set the display line number and display direction
_writeRegister(ILI9225_LCD_AC_DRIVING_CTRL, 0x0100); // set 1 line inversion
_writeRegister(ILI9225_ENTRY_MODE, 0x1038); // set GRAM write direction and BGR=1.
_writeRegister(ILI9225_ENTRY_MODE, EMODEFLIP(_modeFlip) ^ 0x1038); // set GRAM write direction and BGR=1.
_writeRegister(ILI9225_DISP_CTRL1, 0x0000); // Display off
_writeRegister(ILI9225_BLANK_PERIOD_CTRL1, 0x0808); // set the back porch and front porch
_writeRegister(ILI9225_FRAME_CYCLE_CTRL, 0x1100); // set the clocks number per line
@ -482,7 +484,7 @@ void TFT22_ILI9225::_setWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y
startWrite();
// autoincrement mode
if ( _orientation > 0 ) mode = modeTab[_orientation-1][mode];
_writeRegister(ILI9225_ENTRY_MODE, 0x1000 | ( mode<<3) );
_writeRegister(ILI9225_ENTRY_MODE, EMODEFLIP(_modeFlip) ^ (0x1000 | ( mode<<3)) );
_writeRegister(ILI9225_HORIZONTAL_WINDOW_ADDR1,x1);
_writeRegister(ILI9225_HORIZONTAL_WINDOW_ADDR2,x0);
@ -582,6 +584,9 @@ void TFT22_ILI9225::setDisplay(boolean flag) {
}
}
void TFT22_ILI9225::setModeFlip(uint8_t m) {
_modeFlip = m;
}
void TFT22_ILI9225::setOrientation(uint8_t orientation) {

Wyświetl plik

@ -393,6 +393,8 @@ class TFT22_ILI9225 {
void getGFXCharExtent(uint8_t c, int16_t *gw, int16_t *gh, int16_t *xa);
void setModeFlip(uint8_t m);
private:
void _spiWrite(uint8_t v);
@ -436,7 +438,7 @@ class TFT22_ILI9225 {
int8_t _rst, _rs, _cs, _sdi, _clk, _led;
#endif
uint8_t _orientation, _brightness;
uint8_t _orientation, _brightness, _modeflip;
// correspondig modes if orientation changed:
const autoIncMode_t modeTab [3][8] = {