Skip to content

Commit 1862fc3

Browse files
committed
I2CEncoderV2 enum redefinition
Moved the enum inside of the I2CEncoderV2 class.
1 parent 6284277 commit 1862fc3

File tree

13 files changed

+643
-668
lines changed

13 files changed

+643
-668
lines changed

examples/I2CEncoderV2/Basic/Basic.ino

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,87 +16,88 @@
1616

1717
const int IntPin = A3; /* Definition of the interrupt pin. You can change according to your board /*
1818
//Class initialization with the I2C addresses*/
19-
i2cEncoderLibV2 Encoder(0x61); /* A0 is solderedA */
19+
i2cEncoderLibV2 Encoder(0x01); /* A0 is soldered */
2020

21-
22-
void setup(void)
23-
{
21+
void setup(void) {
2422
pinMode(IntPin, INPUT);
2523
Wire.begin();
2624
Serial.begin(115200);
2725
Serial.println("**** I2C Encoder V2 basic example ****");
2826
/*
29-
INT_DATA= The register are considered integer.
30-
WRAP_DISABLE= The WRAP option is disabled
31-
DIRE_LEFT= Encoder left direction increase the value
32-
IPUP_ENABLE= INT pin have the pull-up enabled.
33-
RMOD_X1= Encoder configured as X1.
34-
RGB_ENCODER= type of encoder is RGB, change to STD_ENCODER in case you are using a normal rotary encoder.
27+
INT_DATA= The register are considered integer.
28+
WRAP_DISABLE= The WRAP option is disabled
29+
DIRE_LEFT= Encoder left direction increase the value
30+
IPUP_ENABLE= INT pin have the pull-up enabled.
31+
RMOD_X1= Encoder configured as X1.
32+
RGB_ENCODER= type of encoder is RGB, change to STD_ENCODER in case you are using a normal rotary encoder.
3533
*/
3634
Encoder.reset();
37-
Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER);
38-
// Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | STD_ENCODER); // try also this!
39-
// Encoder.begin(INT_DATA | WRAP_ENABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER); // try also this!
40-
41-
Encoder.writeCounter((int32_t)0); /* Reset the counter value */
42-
Encoder.writeMax((int32_t)10); /* Set the maximum threshold*/
35+
Encoder.begin(
36+
i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE
37+
| i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE
38+
| i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
39+
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | RMOD_X1 | STD_ENCODER); // try also this!
40+
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | RMOD_X1 | RGB_ENCODER); // try also this!
41+
42+
Encoder.writeCounter((int32_t) 0); /* Reset the counter value */
43+
Encoder.writeMax((int32_t) 10); /* Set the maximum threshold*/
4344
Encoder.writeMin((int32_t) - 10); /* Set the minimum threshold */
44-
Encoder.writeStep((int32_t)1); /* Set the step to 1*/
45+
Encoder.writeStep((int32_t) 1); /* Set the step to 1*/
4546
Encoder.writeInterruptConfig(0xff); /* Enable all the interrupt */
46-
Encoder.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
47-
Encoder.writeDoublePushPeriod(50); /*Set a period for the double push of 500ms */
47+
Encoder.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
48+
Encoder.writeDoublePushPeriod(50); /*Set a period for the double push of 500ms */
4849
}
4950

5051
void loop() {
5152

5253
if (digitalRead(IntPin) == LOW) {
53-
if ( Encoder.updateStatus()) {
54-
if ( Encoder.readStatus(RINC)) {
54+
if (Encoder.updateStatus()) {
55+
if (Encoder.readStatus(i2cEncoderLibV2::RINC)) {
5556
Serial.print("Increment: ");
56-
Serial.println( Encoder.readCounterByte());
57+
Serial.println(Encoder.readCounterByte());
5758

5859
/* Write here your code */
5960

6061
}
61-
if ( Encoder.readStatus(RDEC)) {
62+
if (Encoder.readStatus(i2cEncoderLibV2::RDEC)) {
6263
Serial.print("Decrement: ");
63-
Serial.println( Encoder.readCounterByte());
64+
Serial.println(Encoder.readCounterByte());
6465

6566
/* Write here your code */
6667

6768
}
6869

69-
if ( Encoder.readStatus(RMAX)) {
70+
if (Encoder.readStatus(i2cEncoderLibV2::RMAX)) {
7071
Serial.print("Maximum threshold: ");
71-
Serial.println( Encoder.readCounterByte());
72+
Serial.println(Encoder.readCounterByte());
7273

7374
/* Write here your code */
7475

7576
}
7677

77-
if ( Encoder.readStatus(RMIN)) {
78+
if (Encoder.readStatus(i2cEncoderLibV2::RMIN)) {
7879
Serial.print("Minimum threshold: ");
79-
Serial.println( Encoder.readCounterByte());
80+
Serial.println(Encoder.readCounterByte());
8081

8182
/* Write here your code */
8283

8384
}
8485

85-
if ( Encoder.readStatus(PUSHR)) {
86+
if (Encoder.readStatus(i2cEncoderLibV2::PUSHR)) {
8687
Serial.println("Push button Released");
8788

8889
/* Write here your code */
8990

9091
}
9192

92-
if ( Encoder.readStatus(PUSHP)) {
93+
if (Encoder.readStatus(i2cEncoderLibV2::PUSHP)) {
9394
Serial.println("Push button Pressed");
9495

9596
/* Write here your code */
9697

9798
}
9899

99-
if ( Encoder.readStatus(PUSHD)) {
100+
if (Encoder.readStatus(i2cEncoderLibV2::PUSHD)) {
100101
Serial.println("Double push!");
101102

102103
/* Write here your code */

examples/I2CEncoderV2/Basic_with_Callbacks/Basic_with_Callbacks.ino

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,91 +16,75 @@
1616

1717
const int IntPin = A3; /* Definition of the interrupt pin. You can change according to your board */
1818
//Class initialization with the I2C addresses
19-
i2cEncoderLibV2 Encoder(0x61); /* A0 is soldered */
20-
19+
i2cEncoderLibV2 Encoder(0x01); /* A0 is soldered */
2120

2221
//Callback when the CVAL is incremented
2322
void encoder_increment(i2cEncoderLibV2* obj) {
2423
Serial.print("Increment: ");
25-
Serial.println( Encoder.readCounterByte());
24+
Serial.println(Encoder.readCounterByte());
2625
}
2726

28-
29-
3027
//Callback when the CVAL is decremented
3128
void encoder_decrement(i2cEncoderLibV2* obj) {
3229
Serial.print("Decrement: ");
33-
Serial.println( Encoder.readCounterByte());
30+
Serial.println(Encoder.readCounterByte());
3431
}
3532

36-
37-
3833
//Callback when CVAL reach MAX
3934
void encoder_max(i2cEncoderLibV2* obj) {
4035
Serial.print("Maximum threshold: ");
41-
Serial.println( Encoder.readCounterByte());
36+
Serial.println(Encoder.readCounterByte());
4237
}
4338

44-
45-
46-
4739
//Callback when CVAL reach MIN
4840
void encoder_min(i2cEncoderLibV2* obj) {
4941
Serial.print("Minimum threshold: ");
50-
Serial.println( Encoder.readCounterByte());
42+
Serial.println(Encoder.readCounterByte());
5143
}
5244

53-
54-
55-
5645
//Callback when the encoder is pushed
5746
void encoder_push(i2cEncoderLibV2* obj) {
5847
Serial.println("Encoder is pushed!");
5948
}
6049

61-
62-
6350
//Callback when the encoder is released
6451
void encoder_released(i2cEncoderLibV2* obj) {
6552
Serial.println("Encoder is released");
6653
}
6754

68-
69-
7055
//Callback when the encoder is double pushed
7156
void encoder_double_push(i2cEncoderLibV2* obj) {
7257
Serial.println("Encoder is double pushed!");
7358
}
7459

75-
76-
77-
78-
void setup(void)
79-
{
60+
void setup(void) {
8061
pinMode(IntPin, INPUT);
8162
Wire.begin();
8263
Serial.begin(115200);
8364
Serial.println("**** I2C Encoder V2 basic example ****");
8465
/*
85-
INT_DATA= The register are considered integer.
86-
WRAP_DISABLE= The WRAP option is disabled
87-
DIRE_LEFT= Encoder left direction increase the value
88-
IPUP_ENABLE= INT pin have the pull-up enabled.
89-
RMOD_X1= Encoder configured as X1.
90-
RGB_ENCODER= type of encoder is RGB, change to STD_ENCODER in case you are using a normal rotary encoder.
66+
INT_DATA= The register are considered integer.
67+
WRAP_DISABLE= The WRAP option is disabled
68+
DIRE_LEFT= Encoder left direction increase the value
69+
IPUP_ENABLE= INT pin have the pull-up enabled.
70+
RMOD_X1= Encoder configured as X1.
71+
RGB_ENCODER= type of encoder is RGB, change to STD_ENCODER in case you are using a normal rotary encoder.
9172
*/
9273
Encoder.reset();
93-
Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER);
94-
// Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | STD_ENCODER); // try also this!
95-
// Encoder.begin(INT_DATA | WRAP_ENABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER); // try also this!
96-
97-
Encoder.writeCounter((int32_t)0); /* Reset the counter value */
98-
Encoder.writeMax((int32_t)10); /* Set the maximum threshold*/
74+
Encoder.begin(
75+
i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE
76+
| i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE
77+
| i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
78+
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | RMOD_X1 | STD_ENCODER); // try also this!
79+
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | RMOD_X1 | RGB_ENCODER); // try also this!
80+
81+
Encoder.writeCounter((int32_t) 0); /* Reset the counter value */
82+
Encoder.writeMax((int32_t) 10); /* Set the maximum threshold*/
9983
Encoder.writeMin((int32_t) - 10); /* Set the minimum threshold */
100-
Encoder.writeStep((int32_t)1); /* Set the step to 1*/
101-
Encoder.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
102-
Encoder.writeDoublePushPeriod(50); /*Set a period for the double push of 500ms */
103-
84+
Encoder.writeStep((int32_t) 1); /* Set the step to 1*/
85+
Encoder.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
86+
Encoder.writeDoublePushPeriod(50); /*Set a period for the double push of 500ms */
87+
10488
// Definition of the events
10589
Encoder.onIncrement = encoder_increment;
10690
Encoder.onDecrement = encoder_decrement;
@@ -109,9 +93,9 @@ void setup(void)
10993
Encoder.onButtonPush = encoder_push;
11094
Encoder.onButtonRelease = encoder_released;
11195
Encoder.onButtonDoublePush = encoder_double_push;
112-
96+
11397
/* Enable the I2C Encoder V2 interrupts according to the previus attached callback */
114-
Encoder.autoconfigInterrupt();
98+
Encoder.autoconfigInterrupt();
11599

116100
}
117101

@@ -120,4 +104,4 @@ void loop() {
120104
/* Check the status of the encoder and call the callback */
121105
Encoder.updateStatus();
122106
}
123-
}
107+
}

examples/I2CEncoderV2/ESP32_RGB_encoder/ESP32_RGB_encoder.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ i2cEncoderLibV2 Encoder(0b1100001); /* For make the address 0x61 only the jumper
2222

2323
//Callback when the encoder is rotated
2424
void encoder_rotated(i2cEncoderLibV2* obj) {
25-
if ( obj->readStatus( RINC))
25+
if ( obj->readStatus( i2cEncoderLibV2::RINC))
2626
Serial.print("Increment: ");
2727
else
2828
Serial.print("Decrement: ");
@@ -40,7 +40,7 @@ void encoder_click(i2cEncoderLibV2* obj) {
4040

4141
//Callback when the encoder reach the max or min
4242
void encoder_thresholds(i2cEncoderLibV2* obj) {
43-
if ( obj->readStatus( RMAX))
43+
if ( obj->readStatus( i2cEncoderLibV2::RMAX))
4444
Serial.println("Max!");
4545
else
4646
Serial.println("Min!");
@@ -72,9 +72,9 @@ void setup(void)
7272
Wire.begin();
7373
Encoder.reset();
7474

75-
Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER);
76-
// Encoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | STD_ENCODER); // try also this!
77-
// Encoder.begin(INT_DATA | WRAP_ENABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | RGB_ENCODER); // try also this!
75+
Encoder.begin(i2cEncoderLibV2::INT_DATA |i2cEncoderLibV2:: WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
76+
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::STD_ENCODER); // try also this!
77+
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER); // try also this!
7878

7979
Encoder.writeCounter((int32_t)0); /* Reset the counter value */
8080
Encoder.writeMax((int32_t)10); /* Set the maximum threshold*/

examples/I2CEncoderV2/GPs_ADC/GPs_ADC.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ void setup(void)
4141

4242
//Configure the Standard Encoder
4343
STDEncoder.reset();
44-
STDEncoder.begin(INT_DATA | WRAP_DISABLE | DIRE_LEFT | IPUP_ENABLE | RMOD_X1 | STD_ENCODER);
45-
STDEncoder.writeGP1conf(GP_AN | GP_PULL_EN | GP_INT_DI); // Configure the GP pins in analog mode
46-
STDEncoder.writeGP2conf(GP_AN | GP_PULL_EN | GP_INT_DI); // Configure the GP pins in analog mode
47-
STDEncoder.writeGP3conf(GP_AN | GP_PULL_EN | GP_INT_DI); // Configure the GP pins in analog mode
44+
STDEncoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::STD_ENCODER);
45+
STDEncoder.writeGP1conf(i2cEncoderLibV2::GP_AN | i2cEncoderLibV2::GP_PULL_EN | i2cEncoderLibV2::GP_INT_DI); // Configure the GP pins in analog mode
46+
STDEncoder.writeGP2conf(i2cEncoderLibV2::GP_AN | i2cEncoderLibV2::GP_PULL_EN | i2cEncoderLibV2::GP_INT_DI); // Configure the GP pins in analog mode
47+
STDEncoder.writeGP3conf(i2cEncoderLibV2::GP_AN | i2cEncoderLibV2::GP_PULL_EN | i2cEncoderLibV2::GP_INT_DI); // Configure the GP pins in analog mode
4848
STDEncoder.writeCounter((int32_t) 0);
4949
STDEncoder.writeMax((int32_t) 10);
5050
STDEncoder.writeMin((int32_t) 0);
5151
STDEncoder.writeStep((int32_t) 1);
52-
STDEncoder.writeInterruptConfig(INT2 | RINC | RDEC | RMAX | RMIN); //Enable all the interrupts
52+
STDEncoder.writeInterruptConfig(i2cEncoderLibV2::INT_2 | i2cEncoderLibV2::RINC | i2cEncoderLibV2::RDEC | i2cEncoderLibV2::RMAX | i2cEncoderLibV2::RMIN); //Enable all the interrupts
5353
STDEncoder.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
5454
STDEncoder.updateStatus();
5555

0 commit comments

Comments
 (0)