fixed init for objs

This commit is contained in:
oloturia 2024-05-29 00:33:51 +02:00
parent 493d051bcf
commit adcad61878
4 changed files with 38 additions and 8 deletions

View file

@ -58,7 +58,10 @@ AnalogControl::AnalogControl(int pin, byte effect, int middle) {
this->pin = pin;
this->effect = effect;
this->middle = middle;
pinMode(pin,INPUT);
}
void AnalogControl::init() {
pinMode(pin,INPUT);
}
void AnalogControl::checkStatus() {
@ -83,9 +86,11 @@ DigitalButton::DigitalButton(int pin, byte effect, byte effect_toggle, byte effe
this->effect_long = effect_long;
this->effect_long_toggle = effect_long_toggle;
this->pin = pin;
pinMode(pin,INPUT_PULLUP);
}
void DigitalButton::init() {
pinMode(pin,INPUT_PULLUP);
}
void DigitalButton::checkStatus() {
if (digitalRead(pin) == LOW && pressed == false) {
@ -129,24 +134,26 @@ void DigitalButton::checkStatus() {
Mux::Mux(int pinSIG, int effects[16], int mid_deadzone[16]) {
this->pinSIG = pinSIG;
pinMode(pinSIG,INPUT);
pinMode(pinS0,OUTPUT);
pinMode(pinS1,OUTPUT);
pinMode(pinS2,OUTPUT);
pinMode(pinS3,OUTPUT);
for (int i = 0; i < 16; i++) {
this->effects[i] = effects[i];
this->mid_deadzone[i] = effects[i];
}
}
void Mux::init() {
pinMode(pinSIG,INPUT);
pinMode(pinS0,OUTPUT);
pinMode(pinS1,OUTPUT);
pinMode(pinS2,OUTPUT);
pinMode(pinS3,OUTPUT);
}
void Mux::checkStatus(byte selector){
digitalWrite(pinS0, bitRead(selector,0));
digitalWrite(pinS1, bitRead(selector,1));
digitalWrite(pinS2, bitRead(selector,2));
digitalWrite(pinS3, bitRead(selector,3));
int value = analogRead(pinSIG);
if (value < STICKYNESS) {
value = 0;
} else if (value > 1023-STICKYNESS) {

View file

@ -29,6 +29,7 @@ class AnalogControl {
int prev_value;
public:
AnalogControl(int pin, byte effect, int middle);
void init();
void checkStatus();
};
@ -47,6 +48,7 @@ class DigitalButton {
bool long_pressed;
public:
DigitalButton(int pin, byte effect, byte effect_toggle, byte effect_long, byte effect_long_toggle);
void init();
void checkStatus();
};
@ -69,6 +71,7 @@ class Mux {
static int pinS2;
static int pinS3;
Mux(int pinSIG, int effects[16], int mid_deadzone[16]);
void init();
void checkStatus(byte selector);
};

View file

@ -98,6 +98,14 @@ void setup() {
Serial.println("RDY");
#endif
for (int i = 0; i < active_analog_controls; i++) {
analog_controls[i].init();
}
for (int i = 0; i < active_buttons; i++) {
active_buttons[i].init();
}
for (int i = 0; i < active_encoders; i++) {
rotary_encoders[i].rotary_encoder.setUserId(rotary_encoders[i].effect);
rotary_encoders[i].rotary_encoder.setEncoderHandler(eb_Encoder);

View file

@ -113,6 +113,18 @@ void setup() {
Serial.println("RDY");
#endif
for (int i = 0; i < active_analog_controls; i++) {
analog_controls[i].init();
}
for (int i = 0; i < active_buttons; i++) {
active_buttons[i].init();
}
for (int i = 0; i < active_mux_inputs; i++) {
mux_inputs[i].init();
}
for (int i = 0; i < active_encoders; i++) {
rotary_encoders[i].rotary_encoder.setUserId(rotary_encoders[i].effect);
rotary_encoders[i].rotary_encoder.setEncoderHandler(eb_Encoder);