Skip to content

Commit

Permalink
pre release 1.5 17Nov 20h
Browse files Browse the repository at this point in the history
Buttons tested
  • Loading branch information
karawin committed Nov 17, 2018
1 parent 5135273 commit afe2deb
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 73 deletions.
12 changes: 6 additions & 6 deletions lolin32pro.csv
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ P_ENC0_A,data,u8,18
P_ENC0_B,data,u8,19
P_ENC0_BTN,data,u8,4
P_ENC1_A,data,u8,255
P_ENC1_B,data,u8,17
P_ENC1_BTN,data,u8,5
P_BTN0_A,data,u8,255
P_BTN0_B,data,u8,255
P_BTN0_C,data,u8,255
P_ENC1_B,data,u8,19
P_ENC1_BTN,data,u8,255
P_BTN0_A,data,u8,32
P_BTN0_B,data,u8,33
P_BTN0_C,data,u8,35
P_BTN1_A,data,u8,255
P_BTN1_B,data,u8,255
P_BTN1_C,data,u8,255
Expand All @@ -30,7 +30,7 @@ P_IR_SIGNAL,data,u8,255
P_I2S_LRCK,data,u8,25
P_I2S_BCLK,data,u8,26
P_I2S_DATA,data,u8,27
P_ADC,data,u8,34
P_ADC,data,u8,255
custom_ir_space,namespace,,
K_UP,data,string,0xFF0047 0xFF0040
K_LEFT,data,string,0xFF0007
Expand Down
44 changes: 13 additions & 31 deletions main/ClickButtons.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,6 @@
#include "freertos/task.h"

// ----------------------------------------------------------------------------
/*
int8_t enc->pinA;
int8_t enc->pinB;
int8_t enc->pinBTN;
bool enc->pinsActive;
volatile int16_t enc->delta;
volatile int16_t enc->last;
volatile uint8_t enc->steps;
volatile uint16_t enc->acceleration;
bool enc->accelerationEnabled;
volatile enc->button enc->button;
bool enc->doubleClickEnabled;
bool buttonHeldEnabled;
bool enc->buttonOnPinZeroEnabled = false;
uint16_t enc->keyDownTicks = 0;
uint16_t enc->doubleClickTicks = 0;
uint16_t buttonHoldTime = BTN_HOLDTIME;
uint16_t buttonDoubleClickTime = BTN_DOUBLECLICKTIME;
unsigned long enc->lastButtonCheck = 0;
*/


#define TAG "ClickButton"

Expand All @@ -50,7 +29,8 @@ bool getpinsActives(Button_t *enc) {return enc->pinsActive;}
Button_t* ClickButtonsInit(int8_t A, int8_t B, int8_t C)
{
Button_t* enc = malloc(sizeof(Button_t));
enc->pinBTN[0] = A; enc->pinBTN[1] = B;
enc->pinBTN[0] = A;
enc->pinBTN[1] = B;
enc->pinBTN[2] = C;

enc->pinsActive = LOW;
Expand All @@ -63,28 +43,30 @@ Button_t* ClickButtonsInit(int8_t A, int8_t B, int8_t C)
}
enc->button[0] = Open;enc->button[1] = Open;enc->button[2] = Open;
enc->doubleClickEnabled = true; enc->buttonHeldEnabled = true;

gpio_config_t gpio_conf;
gpio_conf.mode = GPIO_MODE_INPUT;
gpio_conf.pull_up_en = (enc->pinsActive == LOW) ?GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE;
gpio_conf.pull_down_en = (enc->pinsActive == LOW) ?GPIO_PULLDOWN_DISABLE : GPIO_PULLDOWN_ENABLE;
gpio_conf.intr_type = GPIO_INTR_DISABLE;
if (enc->pinA >= 0)
gpio_conf.intr_type = GPIO_INTR_DISABLE;

if (enc->pinBTN[0] > 0)
{
gpio_conf.pin_bit_mask = BIT(enc->pinA);
gpio_conf.pin_bit_mask = BIT(enc->pinBTN[0]);
gpio_conf.pin_bit_mask = ((uint64_t)(((uint64_t)1)<<enc->pinBTN[0]));
ESP_ERROR_CHECK(gpio_config(&gpio_conf));
}
if (enc->pinB >= 0)
if (enc->pinBTN[1] > 0)
{
gpio_conf.pin_bit_mask = BIT(enc->pinB);
gpio_conf.pin_bit_mask = ((uint64_t)(((uint64_t)1)<<enc->pinBTN[1]));
ESP_ERROR_CHECK(gpio_config(&gpio_conf));
}
if (enc->pinC > 0)
if (enc->pinBTN[2] > 0)
{
gpio_conf.pin_bit_mask = BIT(enc->pinC);
gpio_conf.pin_bit_mask = ((uint64_t)(((uint64_t)1)<<enc->pinBTN[2]));
ESP_ERROR_CHECK(gpio_config(&gpio_conf));
}

return enc;
}

Expand Down
10 changes: 5 additions & 5 deletions main/ClickEncoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,19 @@ Encoder_t* ClickEncoderInit(int8_t A, int8_t B, int8_t BTN, bool initHalfStep)
gpio_conf.pull_down_en = (enc->pinsActive == LOW) ?GPIO_PULLDOWN_DISABLE : GPIO_PULLDOWN_ENABLE;
gpio_conf.intr_type = GPIO_INTR_DISABLE;

if (enc->pinA >= 0)
if (enc->pinA > 0)
{
gpio_conf.pin_bit_mask = BIT(enc->pinA);
gpio_conf.pin_bit_mask = ((uint64_t)(((uint64_t)1)<<enc->pinA));
ESP_ERROR_CHECK(gpio_config(&gpio_conf));
}
if (enc->pinB >= 0)
if (enc->pinB > 0)
{
gpio_conf.pin_bit_mask = BIT(enc->pinB);
gpio_conf.pin_bit_mask = ((uint64_t)(((uint64_t)1)<<enc->pinB));
ESP_ERROR_CHECK(gpio_config(&gpio_conf));
}
if (enc->pinBTN > 0)
{
gpio_conf.pin_bit_mask = BIT(enc->pinBTN);
gpio_conf.pin_bit_mask = ((uint64_t)(((uint64_t)1)<<enc->pinBTN));
ESP_ERROR_CHECK(gpio_config(&gpio_conf));
}

Expand Down
54 changes: 30 additions & 24 deletions main/addon.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void drawStation()
// draw the volume screen
void drawVolume()
{
printf("drawVolume. mTscreen: %d, Volume: %d\n",mTscreen,volume);
// printf("drawVolume. mTscreen: %d, Volume: %d\n",mTscreen,volume);
isColor?drawVolumeUcg(mTscreen):drawVolumeU8g2(mTscreen);
}

Expand Down Expand Up @@ -537,43 +537,43 @@ void adcLoop() {
}
if ((voltage0 >3700) || (voltage1 >3700)) return; // must be two valid voltage

if (voltage < 985) //ESP_LOGD(TAG,"Voltage: %i",voltage);
printf("VOLTAGE: %d\n",voltage);
if (voltage < 985) ESP_LOGD(TAG,"Voltage: %i",voltage);
// printf("VOLTAGE: %d\n",voltage);
if ((voltage >400) && (voltage < 590)) // volume +
{
setRelVolume(+5);
ESP_LOGI(TAG,"Volume+ : %i",voltage);
ESP_LOGD(TAG,"Volume+ : %i",voltage);
}
else if ((voltage >730) && (voltage < 836)) // volume -
else if ((voltage >730) && (voltage < 830)) // volume -
{
setRelVolume(-5);
ESP_LOGI(TAG,"Volume- : %i",voltage);
ESP_LOGD(TAG,"Volume- : %i",voltage);
}
else if ((voltage >835) && (voltage < 985)) // station+
else if ((voltage >838) && (voltage < 985)) // station+
{
evtStation(1);
// changeStation(+1);
ESP_LOGI(TAG,"station+: %i",voltage);
ESP_LOGD(TAG,"station+: %i",voltage);
}
else if ((voltage >590) && (voltage < 710)) // station-
{
evtStation(-1);
// changeStation(-1);
ESP_LOGI(TAG,"station-: %i",voltage);
ESP_LOGD(TAG,"station-: %i",voltage);
}
if (!inside)
{
if ((voltage >100) && (voltage < 220)) // toggle time/info old stop
{
inside = true;
toggletime();
ESP_LOGI(TAG,"toggle time: %i",voltage);
ESP_LOGD(TAG,"toggle time: %i",voltage);
}
else if ((voltage >278) && (voltage < 380)) //start stop toggle old start
{
inside = true;
startStop();
ESP_LOGI(TAG,"start stop: %i",voltage);
ESP_LOGD(TAG,"start stop: %i",voltage);
}

}
Expand All @@ -590,36 +590,42 @@ void adcLoop() {
{
int i;
Button state[3] ;
typeScreen stateS;
if (role) stateS = sstation; else stateS = svolume;
for (i=0;i<3;i++)
{
state[i] = getButtons(enc,i);
}

if (state[0] != Open)
{
wakeLcd();

// clicked = startstop
if (state[0] == Clicked) startStop();
// double click = toggle time
if (state[0] == DoubleClicked) toggletime();
if (state[0] == Held)
{
if (stateScreen != sstation) Screen(sstation);
if (stateScreen != stateS) Screen(stateS);
}
} else
{
if ((stateScreen != sstation))
if (stateScreen != stateS)
{
if (state[1] != Open)
role?setRelVolume(5):changeStation(1);
{ if (role) setRelVolume(5);
else changeStation(1);}
if (state[2] != Open)
role?setRelVolume(-5):changeStation(-1);
{ if (role) setRelVolume(-5);
else changeStation(-1);}
}
if ((stateScreen == sstation))
if (stateScreen == stateS)
{
if (state[1] != Open)
role?changeStation(1):setRelVolume(5);
{if (role) changeStation(1);else setRelVolume(5);}
if (state[2] != Open)
role?changeStation(-1):setRelVolume(-5);
{if (role) changeStation(-1); else setRelVolume(-5); }
}
}
}
Expand All @@ -640,6 +646,7 @@ void encoderCompute(Encoder_t *enc,bool role)
{
Button newButton ;
int16_t newValue;
typeScreen state;

newValue = - getValue(enc);
newButton = getButton(enc);
Expand All @@ -660,14 +667,14 @@ void encoderCompute(Encoder_t *enc,bool role)
} else
// no event on button switch
{
if ((stateScreen != sstation)&&(newValue != 0))
if (role) state = sstation; else state = svolume;
if ((stateScreen != state)&&(newValue != 0))
{
role?setRelVolume(newValue):changeStation(newValue);
if(role) setRelVolume(newValue);else changeStation(newValue);
}
if ((stateScreen == sstation)&&(newValue != 0))
if ((stateScreen == state)&&(newValue != 0))
{
// currentValue += newValue;
role?changeStation(newValue):setRelVolume(newValue);
if(role) changeStation(newValue); else setRelVolume(newValue);
}
}
}
Expand Down Expand Up @@ -846,7 +853,6 @@ void initButtonEncoder()
if (enca0 == GPIO_NONE) isButton0 = false; //no encoder
if (isButton0) button0 = ClickButtonsInit(enca0, encb0, encbtn0);
if (isButton1) button1 = ClickButtonsInit(enca1, encb1, encbtn1 );

}


Expand Down
4 changes: 1 addition & 3 deletions main/include/CLickButtons.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ typedef gpio_mode_t pinMode_t;

typedef struct {
int8_t pinBTN[3];
int8_t pinA;
int8_t pinB;
int8_t pinC;

bool pinsActive;

volatile Button button[3];
Expand Down
8 changes: 4 additions & 4 deletions main/include/gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@

// Encoder knob
//-------------
#define PIN_ENC0_A GPIO_NUM_16 // 0 if encoder not used
#define PIN_ENC0_B GPIO_NUM_17 // DT
#define PIN_ENC0_BTN GPIO_NUM_5 // SW
#define PIN_ENC1_A GPIO_NONE // 0 if encoder not used
#define PIN_ENC0_A GPIO_NUM_16 //16 // 255 if encoder not used
#define PIN_ENC0_B GPIO_NUM_17 //17 // DT
#define PIN_ENC0_BTN GPIO_NUM_5 //5// SW
#define PIN_ENC1_A GPIO_NONE // 255 if encoder not used
#define PIN_ENC1_B GPIO_NONE // DT
#define PIN_ENC1_BTN GPIO_NONE // SW

Expand Down

0 comments on commit afe2deb

Please sign in to comment.