Ejemplo n.º 1
0
void pickTempSetting(ReadTemp readTemp, WriteTemp writeTemp, const char* tempName, PrintAnnotation printAnnoation, int row) {
	
	temperature oldSetting = readTemp();
	temperature startVal = oldSetting;
	if(oldSetting == INVALID_TEMP){	 // previous temperature was not defined, start at 20C
		startVal = intToTemp(20);
	}
	
	rotaryEncoder.setRange(fixedToTenths(oldSetting), fixedToTenths(tempControl.cc.tempSettingMin), fixedToTenths(tempControl.cc.tempSettingMax));

	uint8_t blinkTimer = 0;
	uint16_t lastChangeTime = ticks.seconds();
	while(ticks.timeSince(lastChangeTime) < MENU_TIMEOUT){ // time out at 10 seconds
		if(rotaryEncoder.changed()){
			lastChangeTime = ticks.seconds();
			blinkTimer = 0;
			startVal = tenthsToFixed(rotaryEncoder.read());
			display.printTemperatureAt(12, row, startVal);

			if( rotaryEncoder.pushed() ){
				rotaryEncoder.resetPushed();
				writeTemp(startVal);
				char tempString[9];				
				printAnnoation(PSTR("%S temp set to %s in Menu."), tempName, tempToString(tempString,startVal,1,9));
				return;
			}
		}	
		else{
			if(blinkTimer == 0){
				display.printTemperatureAt(12, row, startVal);
			}
			if(blinkTimer == 128){
				display.printAt_P(12, row, STR_6SPACES); // only 5 needed, but 6 is okay to and lets us re-use the string
			}
			blinkTimer++;
			wait.millis(3); // delay for blinking
		}
	}
	// Time Out. Setting is not written
}
Ejemplo n.º 2
0
#include "TemperatureFormats.h"
#include "TempControl.h"
#include <cstring>

ControlConstants TempControl::cc;

// Disable some warning about converting string constant
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wwrite-strings"

TEST_CASE("Test conversion between internal format and stirng", "[tempconversion]") {

    // intToTemp is a macro to initialize temperatures in Celsius

    SECTION("Storing 0 as internal temperature gets C_OFFSET added") {
        REQUIRE(C_OFFSET == intToTemp(0));
    }

    SECTION("Conversion from int to temp and back") {
        REQUIRE(20 == tempToInt(intToTemp(20)));
        REQUIRE(-20 == tempToInt(intToTemp(-20)));
    }

    SECTION("Storing 0 as internal temperature difference is stored without offset") {
        REQUIRE(0 == intToTempDiff(0));
    }

    SECTION("Conversion from int to tempdiff and back") {
        REQUIRE(20 == tempDiffToInt(intToTempDiff(20)));
        REQUIRE(-20 == tempDiffToInt(intToTempDiff(-20)));
    }