2019-10-18 01:55:16 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the "bluetoothheater" distribution
|
|
|
|
* (https://gitlab.com/mrjones.id.au/bluetoothheater)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2019 Ray Jones <ray@mrjones.id.au>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "128x64OLED.h"
|
|
|
|
#include "TempSensorScreen.h"
|
|
|
|
#include "KeyPad.h"
|
|
|
|
#include "fonts/Icons.h"
|
|
|
|
#include "fonts/MiniFont.h"
|
|
|
|
#include "../Utility/TempSense.h"
|
|
|
|
|
|
|
|
|
|
|
|
CTempSensorScreen::CTempSensorScreen(C128x64_OLED& display, CScreenManager& mgr) : CPasswordScreen(display, mgr)
|
|
|
|
{
|
|
|
|
_bHasBME280 = false;
|
2019-10-18 22:58:19 +00:00
|
|
|
_nDS18B20 = 0;
|
2019-10-18 01:55:16 +00:00
|
|
|
_bPrimary = false;
|
|
|
|
_Offset = 0;
|
|
|
|
_initUI();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CTempSensorScreen::onSelect()
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
CPasswordScreen::onSelect();
|
2019-10-18 01:55:16 +00:00
|
|
|
_initUI();
|
|
|
|
_bHasBME280 = getTempSensor().getBME280().getCount() != 0;
|
2019-10-18 22:58:19 +00:00
|
|
|
_nDS18B20 = getTempSensor().getDS18B20().getNumSensors();
|
2019-10-18 01:55:16 +00:00
|
|
|
_bPrimary = NVstore.getHeaterTuning().BME280probe.bPrimary;
|
|
|
|
_readNV();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CTempSensorScreen::_initUI()
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
CPasswordScreen::_initUI();
|
2019-10-18 01:55:16 +00:00
|
|
|
_keyHold = -1;
|
|
|
|
_scrollChar = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CTempSensorScreen::show()
|
|
|
|
{
|
|
|
|
char msg[32];
|
|
|
|
|
|
|
|
_display.clearDisplay();
|
|
|
|
|
|
|
|
if(!CPasswordScreen::show()) { // for showing "saving settings"
|
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
if(_colSel == 0)
|
|
|
|
_showTitle("Temp Sensor Role");
|
|
|
|
else
|
|
|
|
_showTitle("Temp Sensor Offset");
|
2019-10-18 01:55:16 +00:00
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
// force BME280 as primary if the only sensor
|
|
|
|
if(!_nDS18B20 && _bHasBME280)
|
|
|
|
_bPrimary = true;
|
2019-10-18 01:55:16 +00:00
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
strcpy(msg, "Nul");
|
2019-10-18 01:55:16 +00:00
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
if(_bHasBME280) {
|
|
|
|
if(!_bPrimary && _nDS18B20) {
|
|
|
|
strcpy(msg, "Lst");
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
|
|
|
else {
|
2019-11-10 04:44:54 +00:00
|
|
|
strcpy(msg, "Pri");
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
}
|
|
|
|
int baseLine = 36;
|
|
|
|
_printMenuText(border, baseLine, msg, _rowSel == 1 && _colSel == 0);
|
|
|
|
|
|
|
|
_printMenuText(27, baseLine, "BME280");
|
|
|
|
if(_colSel == 0) {
|
|
|
|
float temperature;
|
|
|
|
getTempSensor().getBME280().getTemperature(temperature, false);
|
|
|
|
sprintf(msg, "%.01f`C", temperature + _Offset);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sprintf(msg, "%+.01f", _Offset);
|
|
|
|
}
|
|
|
|
_printMenuText(90, baseLine, msg, _rowSel == 1 && _colSel == 1);
|
2019-10-18 01:55:16 +00:00
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
if(_nDS18B20) {
|
|
|
|
if(_bPrimary) {
|
|
|
|
strcpy(msg, "Nxt"); // BME280 is primary
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
strcpy(msg, "Pri"); // DS18B20(s) are primary
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
int baseLine = 24;
|
|
|
|
_printMenuText(border, baseLine, msg, _rowSel == 2 && _colSel == 0);
|
2019-10-18 01:55:16 +00:00
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
_printMenuText(27, baseLine, "DS18B20");
|
2020-01-09 01:50:54 +00:00
|
|
|
if(_nDS18B20 > 1) {
|
|
|
|
sprintf(msg, "x%d", _nDS18B20);
|
|
|
|
_printMenuText(72, baseLine, msg);
|
|
|
|
}
|
|
|
|
if(_colSel == 0) {
|
|
|
|
// get temperature of primary DS18B20
|
|
|
|
float temperature;
|
|
|
|
getTempSensor().getDS18B20().getTemperature(0, temperature, false);
|
|
|
|
sprintf(msg, "%.01f`C", temperature + _OffsetDS18B20);
|
|
|
|
}
|
|
|
|
else {
|
2019-11-10 04:44:54 +00:00
|
|
|
sprintf(msg, "%+.01f", _OffsetDS18B20);
|
|
|
|
}
|
2020-01-09 01:50:54 +00:00
|
|
|
_printMenuText(90, baseLine, msg, _rowSel == 2 && _colSel == 1);
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
CTempSensorScreen::animate()
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
if(_saveBusy() || isPasswordBusy()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* pMsg = NULL;
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 0:
|
|
|
|
_printMenuText(_display.xCentre(), 53, " \021 \030Edit Exit \020 ", true, eCentreJustify);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if(_colSel == 0)
|
|
|
|
pMsg = " Hold Right to adjust probe offset. ";
|
|
|
|
else
|
|
|
|
pMsg = " Hold Left to select probe's priority. ";
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if(_nDS18B20 > 1)
|
|
|
|
pMsg = " Press UP to adjust DS18B20 priorities. ";
|
|
|
|
else if(_nDS18B20 == 1) {
|
|
|
|
if(_colSel == 0)
|
|
|
|
pMsg = " Hold Right to adjust probe offset. ";
|
|
|
|
else
|
|
|
|
pMsg = " Hold Left to select probe's priority. ";
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
2019-11-21 08:25:14 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
break;
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
2019-11-21 08:25:14 +00:00
|
|
|
if(pMsg != NULL) {
|
|
|
|
_display.drawFastHLine(0, 52, 128, WHITE);
|
|
|
|
_scrollMessage(56, pMsg, _scrollChar);
|
|
|
|
}
|
|
|
|
return true;
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
CTempSensorScreen::keyHandler(uint8_t event)
|
|
|
|
{
|
2019-11-21 08:25:14 +00:00
|
|
|
if(CPasswordScreen::keyHandler(event)) { // manage password collection and NV save confirm
|
2019-10-18 01:55:16 +00:00
|
|
|
if(_isPasswordOK()) {
|
|
|
|
_rowSel = 1;
|
|
|
|
_keyHold = -1;
|
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
return true;
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-11-21 08:25:14 +00:00
|
|
|
if(CUIEditScreen::keyHandler(event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
sUserSettings us;
|
|
|
|
if(event & keyPressed) {
|
|
|
|
_keyHold = 0;
|
|
|
|
// DOWN press
|
|
|
|
if(event & key_Down) {
|
|
|
|
_rowSel--;
|
|
|
|
LOWERLIMIT(_rowSel, 0);
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
}
|
2019-10-18 01:55:16 +00:00
|
|
|
|
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
if(event & keyRepeat) {
|
|
|
|
if(_keyHold >= 0) {
|
|
|
|
_keyHold++;
|
|
|
|
if(_keyHold == 2) {
|
|
|
|
if(event & key_Up) {
|
|
|
|
}
|
|
|
|
if(event & key_Left) {
|
|
|
|
_colSel = 0;
|
|
|
|
_scrollChar = 0;
|
|
|
|
}
|
|
|
|
if(event & key_Right) {
|
|
|
|
if(_nDS18B20 == 1 || _rowSel == 1)
|
|
|
|
_colSel = 1;
|
|
|
|
_scrollChar = 0;
|
|
|
|
}
|
|
|
|
if(event & key_Centre) {
|
|
|
|
if(_colSel == 1)
|
|
|
|
_Offset = 0;
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
_keyHold = -1;
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
}
|
2019-10-18 01:55:16 +00:00
|
|
|
|
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
if(event & keyReleased) {
|
|
|
|
if(_keyHold == 0) {
|
|
|
|
// UP release
|
|
|
|
if(event & key_Up) {
|
|
|
|
if(_rowSel == 1 && _colSel == 1 && _nDS18B20 != 1)
|
|
|
|
_colSel = 0;
|
|
|
|
if(_rowSel == 0) {
|
|
|
|
_getPassword();
|
|
|
|
if(_isPasswordOK()) {
|
|
|
|
_rowSel = 1;
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
else {
|
|
|
|
_rowSel++;
|
|
|
|
if(_rowSel == 3 && _nDS18B20 > 1)
|
|
|
|
_ScreenManager.selectMenu(CScreenManager::BranchMenu, CScreenManager::DS18B20UI); // force return to main menu
|
|
|
|
|
|
|
|
UPPERLIMIT(_rowSel, _nDS18B20 ? 2 : 1);
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
}
|
|
|
|
// LEFT release
|
|
|
|
if(event & key_Left) {
|
|
|
|
if(_rowSel == 0)
|
|
|
|
_ScreenManager.prevMenu();
|
|
|
|
else
|
|
|
|
adjust(-1);
|
|
|
|
}
|
|
|
|
// RIGHT release
|
|
|
|
if(event & key_Right) {
|
|
|
|
if(_rowSel == 0)
|
|
|
|
_ScreenManager.nextMenu();
|
|
|
|
else
|
|
|
|
adjust(+1);
|
|
|
|
}
|
|
|
|
// CENTRE release
|
|
|
|
if(event & key_Centre) {
|
|
|
|
if(_rowSel == 0) {
|
|
|
|
_ScreenManager.selectMenu(CScreenManager::RootMenuLoop); // force return to main menu
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
else {
|
2019-11-21 08:25:14 +00:00
|
|
|
_confirmSave(); // enter save confirm mode
|
|
|
|
_rowSel = 0;
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-10 04:44:54 +00:00
|
|
|
_keyHold = -1;
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
_ScreenManager.reqUpdate();
|
|
|
|
|
2019-10-18 01:55:16 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CTempSensorScreen::adjust(int dir)
|
|
|
|
{
|
2019-10-18 22:58:19 +00:00
|
|
|
if(_colSel == 0) {
|
|
|
|
_bPrimary = !_bPrimary;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch(_rowSel) {
|
|
|
|
case 1:
|
2019-10-18 01:55:16 +00:00
|
|
|
_Offset += dir * 0.1;
|
|
|
|
BOUNDSLIMIT(_Offset, -10, +10);
|
2019-10-18 22:58:19 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
_OffsetDS18B20 += dir * 0.1;
|
|
|
|
BOUNDSLIMIT(_OffsetDS18B20, -10, +10);
|
|
|
|
break;
|
|
|
|
}
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CTempSensorScreen::_readNV()
|
|
|
|
{
|
|
|
|
const sHeaterTuning& tuning = NVstore.getHeaterTuning();
|
|
|
|
|
|
|
|
_bPrimary = tuning.BME280probe.bPrimary;
|
|
|
|
_Offset = tuning.BME280probe.offset;
|
2019-10-18 22:58:19 +00:00
|
|
|
_OffsetDS18B20 = tuning.DS18B20probe[0].offset;
|
2019-10-18 01:55:16 +00:00
|
|
|
}
|
|
|
|
|
2019-11-10 04:44:54 +00:00
|
|
|
void
|
|
|
|
CTempSensorScreen::_saveNV()
|
2019-10-18 01:55:16 +00:00
|
|
|
{
|
|
|
|
sHeaterTuning tuning = NVstore.getHeaterTuning();
|
|
|
|
|
|
|
|
tuning.BME280probe.bPrimary = _bPrimary;
|
|
|
|
tuning.BME280probe.offset = _Offset;
|
2019-10-18 22:58:19 +00:00
|
|
|
tuning.DS18B20probe[0].offset = _OffsetDS18B20;
|
2019-10-18 01:55:16 +00:00
|
|
|
|
|
|
|
NVstore.setHeaterTuning(tuning);
|
2019-11-10 04:44:54 +00:00
|
|
|
NVstore.save();
|
|
|
|
}
|