Skip to content

Commit 6284277

Browse files
committed
Library update
Modified the callback definition with the event proprietes.
1 parent 88aa321 commit 6284277

File tree

9 files changed

+485
-439
lines changed

9 files changed

+485
-439
lines changed

examples/I2CEncoderV2/Basic_with_Callbacks/Basic_with_Callbacks.ino

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,23 @@ i2cEncoderLibV2 Encoder(0x61); /* A0 is soldered */
2020

2121

2222
//Callback when the CVAL is incremented
23-
void encoder_increment(i2cEncoderLibV2* obj, SourceInt e) {
23+
void encoder_increment(i2cEncoderLibV2* obj) {
2424
Serial.print("Increment: ");
2525
Serial.println( Encoder.readCounterByte());
2626
}
2727

2828

2929

3030
//Callback when the CVAL is decremented
31-
void encoder_decrement(i2cEncoderLibV2* obj, SourceInt e) {
31+
void encoder_decrement(i2cEncoderLibV2* obj) {
3232
Serial.print("Decrement: ");
3333
Serial.println( Encoder.readCounterByte());
3434
}
3535

3636

3737

3838
//Callback when CVAL reach MAX
39-
void encoder_max(i2cEncoderLibV2* obj, SourceInt e) {
39+
void encoder_max(i2cEncoderLibV2* obj) {
4040
Serial.print("Maximum threshold: ");
4141
Serial.println( Encoder.readCounterByte());
4242
}
@@ -45,7 +45,7 @@ void encoder_max(i2cEncoderLibV2* obj, SourceInt e) {
4545

4646

4747
//Callback when CVAL reach MIN
48-
void encoder_min(i2cEncoderLibV2* obj, SourceInt e) {
48+
void encoder_min(i2cEncoderLibV2* obj) {
4949
Serial.print("Minimum threshold: ");
5050
Serial.println( Encoder.readCounterByte());
5151
}
@@ -54,21 +54,21 @@ void encoder_min(i2cEncoderLibV2* obj, SourceInt e) {
5454

5555

5656
//Callback when the encoder is pushed
57-
void encoder_push(i2cEncoderLibV2* obj, SourceInt e) {
57+
void encoder_push(i2cEncoderLibV2* obj) {
5858
Serial.println("Encoder is pushed!");
5959
}
6060

6161

6262

6363
//Callback when the encoder is released
64-
void encoder_released(i2cEncoderLibV2* obj, SourceInt e) {
64+
void encoder_released(i2cEncoderLibV2* obj) {
6565
Serial.println("Encoder is released");
6666
}
6767

6868

6969

7070
//Callback when the encoder is double pushed
71-
void encoder_double_push(i2cEncoderLibV2* obj, SourceInt e) {
71+
void encoder_double_push(i2cEncoderLibV2* obj) {
7272
Serial.println("Encoder is double pushed!");
7373
}
7474

@@ -100,15 +100,18 @@ void setup(void)
100100
Encoder.writeStep((int32_t)1); /* Set the step to 1*/
101101
Encoder.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
102102
Encoder.writeDoublePushPeriod(50); /*Set a period for the double push of 500ms */
103-
104-
Encoder.attachInterrupt(encoder_increment, ENCODER_INCREMENT);
105-
Encoder.attachInterrupt(encoder_decrement, ENCODER_DECREMENT);
106-
Encoder.attachInterrupt(encoder_max, ENCODER_MAX);
107-
Encoder.attachInterrupt(encoder_min, ENCODER_MIN);
108-
Encoder.attachInterrupt(encoder_push, BUTTON_PUSH);
109-
Encoder.attachInterrupt(encoder_released, BUTTON_RELEASE);
110-
Encoder.attachInterrupt(encoder_double_push, BUTTON_DOUBLE_PUSH);
111-
Encoder.autoconfigInterrupt(); /* Enable all the attached interrupt */
103+
104+
// Definition of the events
105+
Encoder.onIncrement = encoder_increment;
106+
Encoder.onDecrement = encoder_decrement;
107+
Encoder.onMax = encoder_max;
108+
Encoder.onMin = encoder_min;
109+
Encoder.onButtonPush = encoder_push;
110+
Encoder.onButtonRelease = encoder_released;
111+
Encoder.onButtonDoublePush = encoder_double_push;
112+
113+
/* Enable the I2C Encoder V2 interrupts according to the previus attached callback */
114+
Encoder.autoconfigInterrupt();
112115

113116
}
114117

@@ -117,4 +120,4 @@ void loop() {
117120
/* Check the status of the encoder and call the callback */
118121
Encoder.updateStatus();
119122
}
120-
}
123+
}

examples/I2CEncoderV2/ESP32_RGB_encoder/ESP32_RGB_encoder.ino

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const int IntPin = 23; /* Definition of the interrupt pin, change according to y
2121
i2cEncoderLibV2 Encoder(0b1100001); /* For make the address 0x61 only the jumpers A0, A5 and A6 are soldered.*/
2222

2323
//Callback when the encoder is rotated
24-
void encoder_rotated(i2cEncoderLibV2* obj, SourceInt e) {
25-
if (e == ENCODER_INCREMENT)
24+
void encoder_rotated(i2cEncoderLibV2* obj) {
25+
if ( obj->readStatus( RINC))
2626
Serial.print("Increment: ");
2727
else
2828
Serial.print("Decrement: ");
@@ -32,15 +32,15 @@ void encoder_rotated(i2cEncoderLibV2* obj, SourceInt e) {
3232

3333

3434
//Callback when the encoder is pushed
35-
void encoder_pushed(i2cEncoderLibV2* obj, SourceInt e) {
35+
void encoder_click(i2cEncoderLibV2* obj) {
3636
Serial.println("Push: ");
3737
obj->writeRGBCode(0x0000FF);
3838
}
3939

4040

4141
//Callback when the encoder reach the max or min
42-
void encoder_thresholds(i2cEncoderLibV2* obj, SourceInt e) {
43-
if (e == ENCODER_MAX)
42+
void encoder_thresholds(i2cEncoderLibV2* obj) {
43+
if ( obj->readStatus( RMAX))
4444
Serial.println("Max!");
4545
else
4646
Serial.println("Min!");
@@ -50,7 +50,7 @@ void encoder_thresholds(i2cEncoderLibV2* obj, SourceInt e) {
5050

5151

5252
//Callback when the fading process finish and set the RGB led off
53-
void encoder_fade(i2cEncoderLibV2* obj, SourceInt e) {
53+
void encoder_fade(i2cEncoderLibV2* obj) {
5454
obj->writeRGBCode(0x000000);
5555
}
5656

@@ -80,14 +80,13 @@ void setup(void)
8080
Encoder.writeMax((int32_t)10); /* Set the maximum threshold*/
8181
Encoder.writeMin((int32_t) - 10); /* Set the minimum threshold */
8282
Encoder.writeStep((int32_t)1); /* Set the step to 1*/
83-
Encoder.attachInterrupt(encoder_rotated, ENCODER_INCREMENT);
84-
/* attach the callback to the interrupt source */
85-
Encoder.attachInterrupt(encoder_rotated, ENCODER_DECREMENT);
86-
Encoder.attachInterrupt(encoder_pushed, BUTTON_RELEASE);
87-
Encoder.attachInterrupt(encoder_thresholds, ENCODER_MAX);
88-
Encoder.attachInterrupt(encoder_thresholds, ENCODER_MIN);
89-
Encoder.attachInterrupt(encoder_fade, FADE);
90-
/* Enable the interrupt according to the previus attached callback */
83+
/* Configure the events */
84+
Encoder.onChange = encoder_rotated;
85+
Encoder.onButtonRelease = encoder_click;
86+
Encoder.onMinMax = encoder_thresholds;
87+
Encoder.onFadeProcess = encoder_fade;
88+
89+
/* Enable the I2C Encoder V2 interrupts according to the previus attached callback */
9190
Encoder.autoconfigInterrupt();
9291

9392
Encoder.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
@@ -100,16 +99,16 @@ void setup(void)
10099
Encoder.writeRGBCode(0x0000FF);
101100
delay(250);
102101
Encoder.writeRGBCode(0x000000);
103-
102+
104103
Encoder.writeFadeRGB(3); //Fade enabled with 3ms step
105104

106105
}
107106

108107
void loop() {
109108

110-
/* Waith when the INT pin goes low */
109+
/* Waith when the INT pin goes low */
111110
if (digitalRead(IntPin) == LOW) {
112-
/* Check the status of the encoder and call the callback */
111+
/* Check the status of the encoder and call the callback */
113112
Encoder.updateStatus();
114113
}
115114
}

examples/I2CEncoderV2/Matrix_3x3_RGB_encoders/Matrix_3x3_RGB_encoders.ino

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ i2cEncoderLibV2 RGBEncoder[ENCODER_N] = {
3434

3535
uint8_t encoder_status, i;
3636

37-
void encoder_rotated(i2cEncoderLibV2* obj, SourceInt e) {
38-
if (e == ENCODER_INCREMENT)
37+
void encoder_rotated(i2cEncoderLibV2* obj) {
38+
if ( obj->readStatus( RINC))
3939
Serial.print("Increment ");
4040
else
4141
Serial.print("Decrement ");
@@ -45,22 +45,22 @@ void encoder_rotated(i2cEncoderLibV2* obj, SourceInt e) {
4545
obj->writeRGBCode(0x00FF00);
4646
}
4747

48-
void encoder_pushed(i2cEncoderLibV2* obj, SourceInt e) {
48+
void encoder_click(i2cEncoderLibV2* obj) {
4949
Serial.print("Push: ");
5050
Serial.println(obj->id);
5151
obj->writeRGBCode(0x0000FF);
5252
}
5353

54-
void encoder_thresholds(i2cEncoderLibV2* obj, SourceInt e) {
55-
if (e == ENCODER_MAX)
54+
void encoder_thresholds(i2cEncoderLibV2* obj) {
55+
if ( obj->readStatus( RMAX))
5656
Serial.print("Max: ");
5757
else
5858
Serial.print("Min: ");
5959
Serial.println(obj->id);
6060
obj->writeRGBCode(0xFF0000);
6161
}
6262

63-
void encoder_fade(i2cEncoderLibV2* obj, SourceInt e) {
63+
void encoder_fade(i2cEncoderLibV2* obj) {
6464
obj->writeRGBCode(0x000000);
6565
}
6666

@@ -77,7 +77,7 @@ void setup(void)
7777

7878

7979
pinMode(IntPin, INPUT);
80-
pinMode(LED_BUILTIN, OUTPUT);
80+
8181
Serial.begin(115200);
8282
Serial.print("Encoder Test!!\n");
8383

@@ -93,12 +93,14 @@ void setup(void)
9393
RGBEncoder[enc_cnt].writeFadeRGB(3); //Fade enabled with 3ms step
9494
RGBEncoder[enc_cnt].writeAntibouncingPeriod(25); //250ms of debouncing
9595
RGBEncoder[enc_cnt].writeDoublePushPeriod(0); //Set the double push period to 500ms
96-
RGBEncoder[enc_cnt].attachInterrupt(encoder_rotated, ENCODER_INCREMENT);
97-
RGBEncoder[enc_cnt].attachInterrupt(encoder_rotated, ENCODER_DECREMENT);
98-
RGBEncoder[enc_cnt].attachInterrupt(encoder_pushed, BUTTON_RELEASE);
99-
RGBEncoder[enc_cnt].attachInterrupt(encoder_thresholds, ENCODER_MAX);
100-
RGBEncoder[enc_cnt].attachInterrupt(encoder_thresholds, ENCODER_MIN);
101-
RGBEncoder[enc_cnt].attachInterrupt(encoder_fade, FADE);
96+
97+
/* Configure the events */
98+
RGBEncoder[enc_cnt].onChange = encoder_rotated;
99+
RGBEncoder[enc_cnt].onButtonRelease = encoder_click;
100+
RGBEncoder[enc_cnt].onMinMax = encoder_thresholds;
101+
RGBEncoder[enc_cnt].onFadeProcess = encoder_fade;
102+
103+
/* Enable the I2C Encoder V2 interrupts according to the previus attached callback */
102104
RGBEncoder[enc_cnt].autoconfigInterrupt();
103105
RGBEncoder[enc_cnt].id = enc_cnt;
104106
}

0 commit comments

Comments
 (0)