add long hold for trigger continuous ev reading

This commit is contained in:
interfisch 2018-05-03 10:01:41 +02:00
parent 22ac8c37aa
commit a1c03a3293
1 changed files with 25 additions and 5 deletions

View File

@ -49,6 +49,7 @@ BH1750 lightMeter;
#define INCIDENTDELAY 100 //minimum delay between incident sensor (BH1750) readings
#define DEBOUNCETIME 20 //time to not check for inputs after key press
#define BUTTONTIMEHOLD 750 //time for button hold
#define BUTTONTIMEHOLDLONG 3000 //time for button long hold
#define VOLTAGE_WARN 3.4 //voltage per cell //TODO implement warning
@ -102,6 +103,10 @@ boolean button_hold_left=false;
boolean button_hold_center=false;
boolean button_hold_right=false;
//even longer press
boolean button_hold_long_trigger=false;
long timebuttonpressed_trigger_long=0;
float vbat=100;
struct Settings {
@ -362,11 +367,16 @@ void handleInputs()
button_hold_center=false;
button_hold_right=false;
//even longer press
button_hold_long_trigger=false;
if (millis()-millis_lastinput>DEBOUNCETIME) //Button debouncing
{
//Trigger
if (timebuttonpressed_trigger == 0 && !digitalRead(PIN_TRIGGER)){ //first time pressed down. (low when pressed)
timebuttonpressed_trigger=loopmillis; //set time of button press
timebuttonpressed_trigger_long=loopmillis; //set time of button press, for long hold timing
}else if(timebuttonpressed_trigger != 0 && digitalRead(PIN_TRIGGER)){ //button released (was pressed)
if (loopmillis-timebuttonpressed_trigger < BUTTONTIMEHOLD){ //short press
button_trigger=true;
@ -377,6 +387,12 @@ void handleInputs()
timebuttonpressed_trigger=-1; //-1 as flag for hold triggered
}
if (timebuttonpressed_trigger_long>0 && loopmillis-timebuttonpressed_trigger_long >= BUTTONTIMEHOLDLONG && !digitalRead(PIN_TRIGGER)) { //button held down even longer, set hold long flag for as long as button is down
button_hold_long_trigger=true;
}else if(timebuttonpressed_trigger_long>0 && digitalRead(PIN_TRIGGER)){ //released
timebuttonpressed_trigger_long=0; //reset long hold timing
}
//Left
if (timebuttonpressed_left == 0 && !digitalRead(PIN_BTNLEFT)){ //first time pressed down. (low when pressed)
timebuttonpressed_left=loopmillis; //set time of button press
@ -645,7 +661,7 @@ void handleInputs_Lightmeter()
}
}
if (button_trigger) { //Trigger
if (button_trigger || button_hold_long_trigger) { //Trigger or very long hold
ev_last=ev;
ev=getEV(); //set ev to current measurement by selected mode
if (ev<ev_min || ev_min<-254){ //new ev is smaller than last or ev_min wasn set
@ -659,10 +675,13 @@ void handleInputs_Lightmeter()
//LED Brightness on trigger
uint8_t triggerblinkbrightness=255;
if (ev<4){ //dim led when dark
triggerblinkbrightness=map(ev,4,2,255,10);
triggerblinkbrightness=map(ev,2,4,5,255);
}
if (ev<2){
triggerblinkbrightness=10;
triggerblinkbrightness=5;
}
if (button_hold_long_trigger){ //low brightness on long hold
triggerblinkbrightness=5;
}
blinkLED(20,triggerblinkbrightness);
}
@ -679,6 +698,7 @@ void handleInputs_Lightmeter()
blinkLED(400,triggerblinkbrightness);
}
}
@ -1419,14 +1439,14 @@ void updateDisplay_Lightmeter() //Lightmeter display
display.setCursor(xpos_debug+50,ypos_debug-5);
if (ev_min>-254) { //ev min set
if (ev_min>-254 && ev>=ev_min) { //ev min set
display.print("-");
display.print(ev-ev_min,1);
}else{
display.print("/");
}
display.print(" <> ");
if (ev_max>-254){
if (ev_max>-254 && ev<=ev_max){
display.print("+");
display.print(ev_max-ev,1);
}else{