Skip to content

Commit 09c9c89

Browse files
committed
Added support for vibration power on modulino Vibro
1 parent 53aa89e commit 09c9c89

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/Modulino.h

+27-6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@
1818
#define HardwareI2C TwoWire
1919
#endif
2020

21+
typedef enum {
22+
STOP = 0,
23+
GENTLE = 25,
24+
MODERATE = 30,
25+
MEDIUM = 35,
26+
INTENSE = 40,
27+
POWERFUL = 45,
28+
MAXIMUM = 50
29+
} VibroPowerLevel;
30+
2131
void __increaseI2CPriority();
2232

2333
class ModulinoClass {
@@ -226,28 +236,39 @@ class ModulinoVibro : public Module {
226236
public:
227237
ModulinoVibro(uint8_t address = 0xFF)
228238
: Module(address, "VIBRO") {}
229-
void on(size_t len_ms) {
230-
uint8_t buf[8];
231-
uint32_t freq = 100;
239+
void on(size_t len_ms, bool block, VibroPowerLevel power = MAXIMUM ) {
240+
uint8_t buf[12];
241+
uint32_t freq = 1000;
232242
memcpy(&buf[0], &freq, 4);
233243
memcpy(&buf[4], &len_ms, 4);
234-
write(buf, 8);
244+
memcpy(&buf[8], &power, 4);
245+
write(buf, 12);
246+
if (block) {
247+
delay(len_ms);
248+
off();
249+
}
250+
}
251+
void on(size_t len_ms) {
252+
on(len_ms, false);
253+
}
254+
void on(size_t len_ms, VibroPowerLevel power) {
255+
on(len_ms, false, power);
235256
}
236257
void off() {
237258
uint8_t buf[8];
238259
memset(&buf[0], 0, 8);
239260
write(buf, 8);
240261
}
241262
virtual uint8_t discover() {
242-
for (unsigned int i = 0; i < sizeof(match)/sizeof(match[0]); i++) {
263+
for (int i = 0; i < match.size(); i++) {
243264
if (scan(match[i])) {
244265
return match[i];
245266
}
246267
}
247268
return 0xFF;
248269
}
249270
protected:
250-
uint8_t match[1] = { 0x70 }; // same as fw main.c
271+
std::vector<uint8_t> match = { 0x70 }; // same as fw main.c
251272
};
252273

253274
class ModulinoColor {

0 commit comments

Comments
 (0)