Skip to content

Commit d881293

Browse files
committed
software debounce
1 parent ac65493 commit d881293

File tree

6 files changed

+41
-17
lines changed

6 files changed

+41
-17
lines changed

platformio.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@ build_flags =
4646
-DOLED_LCD=true
4747
; -DFORCE_KEEPALIVE=true
4848

49-
debug_tool = esp-prog
5049
monitor_speed = 115200
5150
lib_deps = ${common_env_data.lib_deps_external}
5251

5352
upload_port = /dev/cu.SLAB_USBtoUART
5453

54+
debug_tool = esp-prog
55+
debug_port = /dev/cu.usbserial-00001014A
5556

5657
[env:classic]
5758
platform = espressif8266@~2.2.0

src/BPLSettings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,10 @@ String BPLSettings::jsonBeerProfile(void)
637637
DBG_PRINTF(" sg:%d \n",s_step->gravity.sg);
638638
if(_data.gdc.usePlato){
639639
jstep["g"]= GravityToPlato(s_step->gravity.sg);
640+
#if SerialDebug
640641
Serial.print("SG:");
641642
Serial.println(GravityToPlato(s_step->gravity.sg));
643+
#endif
642644
}else{
643645
jstep["g"]= GravityToSG(s_step->gravity.sg);
644646
}

src/DisplayLcd.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
#include "TemperatureFormats.h"
3030
#include "Pins.h"
3131

32-
33-
3432
uint8_t LcdDisplay::stateOnDisplay;
3533
uint8_t LcdDisplay::flags;
3634

src/FSEepromAccess.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class FSEepromAccess
4949
return false;
5050
}
5151
static bool writeToFile(const char* filename,const uint8_t* source,size_t size){
52-
File file = SPIFFS.open(filename, "w+b");
52+
File file = SPIFFS.open(filename, "w");
5353
if (file) {
5454
file.write(source, size);
5555
file.close();

src/IicOledLcd.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,13 @@ class IICOledLcd : public Print {
5858
#ifdef print_P_inline
5959
// print a string stored in PROGMEM
6060
void print_P(const char * str) {
61-
char buf[21]; // create buffer in RAM
61+
#if ESP32
62+
print((char*)str);
63+
#else
64+
char buf[21]; // create buffer in RAM
6265
strcpy_P(buf, str); // copy string to RAM
6366
print(buf); // print from RAM
67+
#endif
6468
}
6569
#else
6670
void print_P(const char * str);

src/RotaryEncoder.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#include "Brewpi.h"
2828
#include "TempControl.h"
2929

30+
#if ESP32
31+
#include "rom/gpio.h"
32+
#endif
33+
3034
#if ButtonViaPCF8574
3135
#include <pcf8574_esp.h>
3236
#endif
@@ -573,8 +577,9 @@ int16_t RotaryEncoder::read(void){
573577
#define HS_R_START_M 0x3
574578
#define HS_R_CW_BEGIN_M 0x4
575579
#define HS_R_CCW_BEGIN_M 0x5
576-
#if ESP32
577-
const uint8_t hs_ttable[7][4] = {
580+
#if ESP32
581+
// this table is accessed in ISR, needed to stay in RAM
582+
uint8_t hs_ttable[7][4] = {
578583
#else
579584
const uint8_t PROGMEM hs_ttable[7][4] = {
580585
#endif
@@ -600,8 +605,9 @@ const uint8_t PROGMEM hs_ttable[7][4] = {
600605
#define R_CCW_BEGIN 0x4
601606
#define R_CCW_FINAL 0x5
602607
#define R_CCW_NEXT 0x6
603-
#if ESP32
604-
const uint8_t ttable[7][4] = {
608+
#if ESP32
609+
// this table is accessed in ISR, needed to stay in RAM
610+
uint8_t ttable[7][4] = {
605611
#else
606612
const uint8_t PROGMEM ttable[7][4] = {
607613
#endif
@@ -629,14 +635,22 @@ const uint8_t PROGMEM ttable[7][4] = {
629635

630636
#ifdef ESP32
631637

632-
ICACHE_RAM_ATTR static void isr_rotary(void) {
638+
#define GPIO_READ(pin) (((pin)>31)? (gpio_input_get_high() & (1<<(pin-32))):(gpio_input_get() & (1<<pin)))
639+
640+
static void IRAM_ATTR isr_rotary(void) {
633641
rotaryEncoder.process();
634642
}
635643

636-
ICACHE_RAM_ATTR static void isr_push(void) {
644+
#define MINIMUM_PUSH_GAP 200000
637645

638-
if(! digitalRead(rotarySwitchPin))
646+
static void IRAM_ATTR isr_push(void) {
647+
// using software debouncing.
648+
static uint32_t pushed_time=0;
649+
uint32_t now= micros();
650+
if(! GPIO_READ(rotarySwitchPin) && (now - pushed_time) > MINIMUM_PUSH_GAP ){
651+
pushed_time = now;
639652
rotaryEncoder.setPushed();
653+
}
640654
}
641655

642656
#else //#ifdef ESP32
@@ -677,14 +691,19 @@ ISR(PCINT0_vect){
677691
#endif //#ifdef ESP8266
678692

679693

680-
ICACHE_RAM_ATTR void RotaryEncoder::process(void){
694+
void IRAM_ATTR RotaryEncoder::process(void){
695+
681696
static uint8_t state=R_START;
682697
// Grab state of input pins.
683698

684699
#if ESP32
700+
/* uint8_t currPinA = !digitalRead(rotaryAPin);
701+
uint8_t currPinB = !digitalRead(rotaryBPin); */
702+
703+
// uint32_t input=gpio_input_get();
685704

686-
uint8_t currPinA = !digitalRead(rotaryAPin);
687-
uint8_t currPinB = !digitalRead(rotaryBPin);
705+
uint8_t currPinA = ! GPIO_READ(rotaryAPin);
706+
uint8_t currPinB = ! GPIO_READ(rotaryBPin);
688707

689708
#else // #ifdef ESP32
690709
#if BREWPI_STATIC_CONFIG == BREWPI_SHIELD_DIY
@@ -734,7 +753,7 @@ ICACHE_RAM_ATTR void RotaryEncoder::process(void){
734753
}
735754
#endif // BREWPI_ROTARY_ENCODER
736755

737-
ICACHE_RAM_ATTR void RotaryEncoder::setPushed(void){
756+
void IRAM_ATTR RotaryEncoder::setPushed(void){
738757
pushFlag = true;
739758

740759
// this goes too deep, and needed to put in ICACHE, also it is processed in outer loop
@@ -752,7 +771,7 @@ void RotaryEncoder::init(void){
752771
fastPinMode(rotarySwitchPin, BREWPI_INPUT_PULLUP);
753772
attachInterrupt(rotaryAPin, isr_rotary, CHANGE);
754773
attachInterrupt(rotaryBPin, isr_rotary, CHANGE);
755-
attachInterrupt(rotarySwitchPin, isr_push, CHANGE);
774+
attachInterrupt(rotarySwitchPin, isr_push, FALLING);
756775
#else //#ifdef ESP32
757776
#define BREWPI_INPUT_PULLUP (USE_INTERNAL_PULL_UP_RESISTORS ? INPUT_PULLUP : INPUT)
758777
fastPinMode(rotaryAPin, BREWPI_INPUT_PULLUP);

0 commit comments

Comments
 (0)