Skip to content

Commit

Permalink
Override TFT displays without MISO from web interface. (#42)
Browse files Browse the repository at this point in the history
* Display starts from web interface.

* TFT override only goes from AUTO to FORCED.
To reset this, reset the device.

* Cleanup.

* Cleanup.

* Fixes.

* Cleanup.

* Change from slider to button.

* Removed value update code.

Set sensor search time-out to 1500ms.

* Fixed the convoluted logic.

* Add probable error cause.

* Update README.md.

* A lot shorter.

* Shorter.
  • Loading branch information
CelliesProjects authored Mar 9, 2020
1 parent 222a5e2 commit e9eda86
Show file tree
Hide file tree
Showing 6 changed files with 1,245 additions and 1,247 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ Toggle the `GIT_TAG` option in `deviceSetup.h` to enable or disable version info
<br>To be on the safe side, I use a BC547 transistor (and a 100R resistor) between the ESP32 pin and the LED connector on the tft board.
<br>If you connect the LED directly to a ESP32 pin, connect it through a 100R resistor in series to prevent burning up your ESP32.

To override the device detection for ILI9341 displays you can use the `ILI9341 force` button in the `setup` page of the web interface. This will force a ILI9341 display until the device reboots.

#### Lunar cycle night light

- Moon light settings can be adjusted in the `channels` area of the web-interface.
Expand Down
38 changes: 13 additions & 25 deletions aquacontrol32.ino
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,18 @@ const char * threeDigitPercentage( char * buffer, const uint8_t &bufferSize, con
return buffer;
}

const TaskHandle_t startTFT() {
xTaskCreatePinnedToCore(
tftTask, /* Function to implement the task */
"tftTask", /* Name of the task */
4000, /* Stack size in words */
NULL, /* Task input parameter */
tftTaskPriority, /* Priority of the task */
&xTftTaskHandle, /* Task handle. */
1);
return xTftTaskHandle;
}

void setup()
{
pinMode( LED0_PIN, OUTPUT );
Expand Down Expand Up @@ -277,31 +289,7 @@ void setup()
tft.begin( TFT_SPI_CLOCK );

if ( TFT_HAS_NO_MISO || tft.readcommand8( ILI9341_RDSELFDIAG ) == 0xE0 ) {
tft.setTextSize( 2 );
tft.fillScreen( TFT_BACK_COLOR );

/* setup backlight pwm */
ledcAttachPin( TFT_BACKLIGHT_PIN, TFT_BACKLIGHT_CHANNEL );
double backlightFrequency = ledcSetup( TFT_BACKLIGHT_CHANNEL , LEDC_MAXIMUM_FREQ, TFT_BACKLIGHT_BITDEPTH );

tftBrightness = preferences.getFloat( "tftbrightness", tftBrightness );
ledcWrite( TFT_BACKLIGHT_CHANNEL, map( tftBrightness, 0, 100, 0, TFT_BACKLIGHT_MAXPWM ) );

( preferences.getString( "tftorientation", "normal" ).equals( "normal" ) ) ? tftOrientation = TFT_ORIENTATION_NORMAL : tftOrientation = TFT_ORIENTATION_UPSIDEDOWN;
tft.setRotation( tftOrientation );

touch.begin();

tft.println( "Aquacontrol32");
ESP_LOGI( TAG, "%s an ILI9341 display on SPI.", TFT_HAS_NO_MISO ? "Forced" : "Found" );
xTaskCreatePinnedToCore(
tftTask, /* Function to implement the task */
"tftTask", /* Name of the task */
4000, /* Stack size in words */
NULL, /* Task input parameter */
tftTaskPriority, /* Priority of the task */
&xTftTaskHandle, /* Task handle. */
1); /* Core where the task should run */
if (!startTFT()) ESP_LOGE(TAG,"Could not start TFT task.");
}
else ESP_LOGI( TAG, "No ILI9341 found" );

Expand Down
19 changes: 19 additions & 0 deletions tfttask.ino
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ void drawSensors();
void tftTask( void * pvParameters ) {
const TickType_t tftTaskdelayTime = ( 1000 / UPDATE_FREQ_TFT) / portTICK_PERIOD_MS;

tft.setTextSize( 2 );
tft.fillScreen( TFT_BACK_COLOR );

//* setup backlight pwm *
ledcAttachPin( TFT_BACKLIGHT_PIN, TFT_BACKLIGHT_CHANNEL );
double backlightFrequency = ledcSetup( TFT_BACKLIGHT_CHANNEL , LEDC_MAXIMUM_FREQ, TFT_BACKLIGHT_BITDEPTH );

tftBrightness = preferences.getFloat( "tftbrightness", tftBrightness );
ledcWrite( TFT_BACKLIGHT_CHANNEL, map( tftBrightness, 0, 100, 0, TFT_BACKLIGHT_MAXPWM ) );

( preferences.getString( "tftorientation", "normal" ).equals( "normal" ) ) ? tftOrientation = TFT_ORIENTATION_NORMAL : tftOrientation = TFT_ORIENTATION_UPSIDEDOWN;
tft.setRotation( tftOrientation );

touch.begin();

tft.println( "Aquacontrol32");

ESP_LOGI( TAG, "started a ILI9341 display on SPI." );

while ( !xDimmerTaskHandle ) vTaskDelay( 10 / portTICK_PERIOD_MS );

ledcWrite( TFT_BACKLIGHT_CHANNEL, 0 );
Expand Down
67 changes: 39 additions & 28 deletions webif/setup.htm
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ <h3>SENSORS</h3>
<div class="shadowedBox collapsable">
<h3>DISPLAYS</h3>
<div class="settingsBox">
<p class="item tftBar" id="tftOverrideBar"><span class="itemName">ILI9341 force</span><span id="tftOverrideValue" class="itemValue">&nbsp;</span><input type="button" id="tftOverrideButton" value="Force"></p>
<p class="item tftBar"><span class="itemName">ILI9341 orientation</span><span id="tftOrientation" class="itemValue">&nbsp;</span><input type="range" id="tftOrientationSlider" min="0" max="1"></p>
<p class="item tftBar"><span class="itemName">ILI9341 max brightness</span><span id="tftBrightnessValue" class="itemValue">&nbsp;</span><input type="range" id="tftBrightnessSlider" value="11" min="0" max="100" step="1"></p>
<p class="item oledBar"><span class="itemName">SSD1306 orientation</span><span id="oledOrientationValue" class="itemValue">&nbsp;</span><input type="range" id="oledOrientationSlider" min="0" max="1"></p>
Expand All @@ -190,25 +191,22 @@ <h3>STATUS</h3>
var getAllValues;
$(document).ready(function(){
getAllValues=true;
$('#deviceStatus').html("hostname...");
$.get("/api/getdevice?hostname=")
.done(function(data){
$('#hostNameInput').val(data);
$('#hostName').html(data);
document.title=data+" setup";
})
.fail(function(){$('#deviceStatus').html("Problem getting hostname.");})
.fail(function(){$('#deviceStatus').html("Problem getting hostname");})
.always(function(){if(getAllValues)getBootlog();})
});
function getBootlog(){
$('#deviceStatus').html("reset reason...");
$.get("/api/getdevice?bootlog=")
.done(function(data){$('#bootlog').val(data.toUpperCase());})
.fail(function(){})
.always(function(){if(getAllValues)getOledOrientation();});
}
function getOledOrientation(){
$('#deviceStatus').html("oled orientation...");
$.get("/api/getdevice?oledorientation=")
.done(function(data){
$('.oledBar').show();
Expand All @@ -220,7 +218,6 @@ <h3>STATUS</h3>
.always(function(){if(getAllValues)getOledContrast();});
}
function getOledContrast(){
$('#deviceStatus').html("oled contrast...");
$.get("/api/getdevice?oledcontrast=")
.done(function(data){
$('#oledContrastValue').html(data);
Expand All @@ -230,50 +227,56 @@ <h3>STATUS</h3>
.always(function(){if(getAllValues)getTftOrientation();});
}
function getTftOrientation(){
$('#deviceStatus').html("9341 orientation...");
$.get("/api/getdevice?tftorientation=")
.done(function(data){
$('.tftBar').show();
$('#tftOverrideBar').hide();
$('#tftOrientation').html(data);
if(data=='normal'){$('#tftOrientationSlider').val(0);}
if(data=='upsidedown'){$('#tftOrientationSlider').val(1);}
})
.fail(function(data){if(data.status!=501)$('#deviceStatus').html("Error getting tft orientation.");})
.fail(function(data){
if(data.status==501){
$('#tftOverrideBar').show();
$('#tftOverrideButton').val("Force");
$('#tftOverrideValue').html("AUTO");
}
else{
$('#deviceStatus').html("Error getting tft orientation");
}
})
.always(function(){if(getAllValues)getSensorLoggingStatus();});
}

function getSensorLoggingStatus(){
$('#deviceStatus').html("sensor logging...");
$.get("/api/getdevice?sensorlogging=")
.done( function(data){
$('#sensorLogging').prop('value',data);
$('.sensorbutton').show();
})
.fail(function(data){if(data.status!=501)$('#deviceStatus').html("Error getting sensor status.");})
.fail(function(data){if(data.status!=501)$('#deviceStatus').html("Error getting sensor status");})
.always(function(){if(getAllValues)getSensorErrorLoggingStatus();});
}
function getSensorErrorLoggingStatus(){
$('#deviceStatus').html("sensor error logging...");
$.get("/api/getdevice?sensorerrorlogging=")
.done(function(data){$('#sensorErrorLogging').prop('value',data);})
.fail(function(data){if(data.status!=501)$('#deviceStatus').html("Error getting sensor status.");})
.fail(function(data){if(data.status!=501)$('#deviceStatus').html("Error getting sensor status");})
.always(function(){if(getAllValues)getTftMaxBrightness();});
}
function getTftMaxBrightness(){
$('#deviceStatus').html("tft brightness...");
$.get("/api/getdevice?tftbrightness=")
.done(function(data){
$('#tftBrightnessValue').html( parseInt(data)+"%");
$('#tftBrightnessSlider').val(data);
})
.fail(function(data){if(data.status!=501)$('#deviceStatus').html("Error getting tft brightness.");})
.fail(function(data){if(data.status!=501)$('#deviceStatus').html("Error getting tft brightness");})
.always(function(){if(getAllValues)getTimeZone();});
}
function getTimeZone(){
$('#deviceStatus').html("time zone...");
$.get("/api/getdevice?timezone=")
.done(function(data){$('#timeZoneTextBox').val(data);})
.fail(function(data){$('#deviceStatus').html(data.statusText);})
.always(function(){if(getAllValues){$('#deviceStatus').html("loading lightstatus...");getLightStatus();}});
.always(function(){if(getAllValues)getLightStatus();});
}
function getLightStatus(){
$.get("/api/getdevice?status=")
Expand All @@ -290,11 +293,10 @@ <h3>STATUS</h3>
}
});
})
.fail(function(){$('#deviceStatus').html("Error getting lightstatus.");})
.fail(function(){$('#deviceStatus').html("Error getting lightstatus");})
.always(function(){if(getAllValues)getSensors();});
}
function getSensors(){
$('#deviceStatus').html("loading sensors...");
$.get("/api/getdevice?sensors")
.done(function(data){
var item=data.split('\n');var sensor=0;
Expand All @@ -309,29 +311,29 @@ <h3>STATUS</h3>
$('.sensorname .itemName').eq(sensor).html(String(sensorid).toUpperCase()+" - "+temp);
$('.sensorNameInput').eq(sensor).val(name);
$('.sensorname').eq(sensor).show();
$('.sensorbutton').show();
sensor++;
}
getSensorLoggingStatus();
getSensorErrorLoggingStatus()
$('#deviceStatus').html("");
})
.fail(function(){$('#deviceStatus').html("Error getting sensors.");})
.fail(function(data){if(!getAllValues)$('#deviceStatus').html("No sensors found");})
.always(function(){if(getAllValues)getWifiSSID()});
}
function getWifiSSID(){
$('#deviceStatus').html("WiFi ssid...");
$.get("/api/getdevice?wifissid=")
.done(function(data){$('#wifissid').html("WiFi network: "+data);})
.fail(function(data){$('#wifissid').html("Error getting wifi SSID: "+data.statusText);})
.always(function(){if(getAllValues)getBootTime();});
}
function getBootTime(){
$('#deviceStatus').html("system start...");
$.get("/api/getdevice?boottime=")
.done(function(data){$('#bootTime').html(data);})
.fail(function(data){$('#deviceStatus').html("Error getting boottime: "+data.statusText);})
.always(function(){if(getAllValues)getDiskSpace();});
}
function getDiskSpace(){
$('#deviceStatus').html("disk space...");
$.get("/api/getdevice?diskspace=")
.done(function(data){
var tmp=data.split(',');
Expand All @@ -342,14 +344,12 @@ <h3>STATUS</h3>
.always(function(){if(getAllValues)getPwmDepth();});
}
function getPwmDepth(){
$('#deviceStatus').html("pwm depth...");
$.get("/api/getdevice?pwmdepth=")
.done(function(data){$('#pwmStatus').html(data+"bit - ");})
.fail(function(data){$('#deviceStatus').html("Error getting pwmdepth "+data.responseText);})
.always(function(){if(getAllValues)getVersion();});
}
function getVersion(){
$('#deviceStatus').html("firmware version...");
$.get("/api/getdevice?version=")
.done(function(data){
$('#version').html(data);
Expand All @@ -364,7 +364,6 @@ <h3>STATUS</h3>
.always(function(){if(getAllValues)getPwmFrequency();});
}
function getPwmFrequency(){
$('#deviceStatus').html("pwm frequency...");
$.get("/api/getdevice?pwmfrequency=")
.done(function(data){$('#pwmStatus').append(data+"Hz");})
.fail(function(data){$('#deviceStatus').html("Error getting pwmfrequency: "+data.responseText);})
Expand Down Expand Up @@ -400,7 +399,7 @@ <h3>STATUS</h3>
.fail(function(){$('#passwordInput').css({'background':'red'});});
});
$('#oledOrientationSlider').on('change',function(){
$(this).val()==1?$('#oledOrientationValue').html('upsidedown'):$('#oledOrientationValue').html('normal');
$('#oledOrientationValue').html($(this).val()==1?'upsidedown':'normal');
$.post("/api/setdevice",{oledorientation:$('#oledOrientationValue').html()})
.done(function(data){$('#oledOrientationValue').html(data);})
.fail(function(){getOledOrientation();});
Expand Down Expand Up @@ -457,6 +456,17 @@ <h3>STATUS</h3>
.done(function(data){$('#tftBrightnessSlider').val(data);})
.fail(function(){getTftMaxBrightness();});
});
$('#tftOverrideButton').on('click',function(){
$.post("/api/setdevice",{tftstate:"forcetft"})
.done(function(){
getTftOrientation();
getTftMaxBrightness();
$('#deviceStatus').html("TFT forced until reboot");
})
.fail(function(data){
$('#deviceStatus').html(data.statusText);
});
})
$('#timeZoneTextBox').on('change',function(){
$.post('/api/setdevice',{timezone:$(this).val()})
.done(function(data){
Expand Down Expand Up @@ -492,11 +502,12 @@ <h3>STATUS</h3>
});
$('#sensorScan').on('click',function(){
$.post("/api/setdevice",{sensorscan:true})
.done(function(data){
var updateSensors=setTimeout(getSensors,800);
.done(function(){
var updateSensors=setTimeout(getSensors,1500);
$('p.item.sensorname').hide();
$('.sensorbutton').hide();
})
.fail(function(data){console.log(data);});
.fail(function(){$('#deviceStatus').html("Error scanning sensors");});
});
$('.collapsable').on('click',function(){
$('.collapsable').css('height','45px').css('cursor','pointer').css('background-color','beige').css('opacity',0.3);
Expand Down
Loading

0 comments on commit e9eda86

Please sign in to comment.