2023-08-06 11:40:50 +02:00
|
|
|
#pragma once
|
|
|
|
//
|
|
|
|
// FILE: m5rotate8.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2023-08-09 12:25:58 +02:00
|
|
|
// VERSION: 0.2.0
|
2023-08-06 11:40:50 +02:00
|
|
|
// PURPOSE: Arduino library for M5 8ROTATE 8x rotary encoders
|
|
|
|
// URL: https://github.com/RobTillaart/M5ROTATE8
|
|
|
|
|
|
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
#include "Wire.h"
|
|
|
|
|
2023-08-09 12:25:58 +02:00
|
|
|
#define M5ROTATE8_LIB_VERSION (F("0.2.0"))
|
2023-08-06 11:40:50 +02:00
|
|
|
|
|
|
|
#define M5ROTATE8_DEFAULT_ADDRESS 0x41
|
|
|
|
|
|
|
|
// prelim error handling
|
|
|
|
#define M5ROTATE8_OK 0x0000
|
|
|
|
#define M5ROTATE8_ERR_CHANNEL 0xFF00
|
|
|
|
#define M5ROTATE8_ERROR 0xFFFF
|
|
|
|
|
|
|
|
|
|
|
|
class M5ROTATE8
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
M5ROTATE8(uint8_t address = M5ROTATE8_DEFAULT_ADDRESS, TwoWire *wire = &Wire);
|
|
|
|
|
|
|
|
#if defined (ESP8266) || defined(ESP32)
|
|
|
|
bool begin(int sda, int scl);
|
|
|
|
#endif
|
|
|
|
bool begin();
|
|
|
|
bool isConnected();
|
|
|
|
|
|
|
|
bool setAddress(uint8_t address = M5ROTATE8_DEFAULT_ADDRESS);
|
|
|
|
uint8_t getAddress();
|
|
|
|
uint8_t getVersion();
|
|
|
|
|
2023-08-09 12:25:58 +02:00
|
|
|
// ROTARY ENCODER PART
|
2023-08-06 11:40:50 +02:00
|
|
|
// channel = 0..7
|
|
|
|
int32_t getAbsCounter(uint8_t channel);
|
|
|
|
bool setAbsCounter(uint8_t channel, int32_t value);
|
|
|
|
int32_t getRelCounter(uint8_t channel);
|
|
|
|
bool getKeyPressed(uint8_t channel);
|
|
|
|
bool resetCounter(uint8_t channel);
|
|
|
|
void resetAll();
|
|
|
|
|
2023-08-09 12:25:58 +02:00
|
|
|
// INPUT SWITCH PART
|
2023-08-06 11:40:50 +02:00
|
|
|
uint8_t inputSwitch();
|
2023-08-09 12:25:58 +02:00
|
|
|
|
|
|
|
// LED PART
|
2023-08-06 11:40:50 +02:00
|
|
|
// channel = 0..7
|
|
|
|
// R,G,B = 0..255
|
|
|
|
bool writeRGB(uint8_t channel, uint8_t R, uint8_t G, uint8_t B);
|
2023-08-09 12:25:58 +02:00
|
|
|
bool setAll(uint8_t R, uint8_t G, uint8_t B);
|
2023-08-06 11:40:50 +02:00
|
|
|
bool allOff();
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint8_t _address;
|
|
|
|
|
|
|
|
int _error;
|
|
|
|
|
|
|
|
TwoWire* _wire;
|
|
|
|
|
|
|
|
bool write8(uint8_t reg, uint8_t value);
|
|
|
|
uint8_t read8(uint8_t reg);
|
|
|
|
bool write24(uint8_t reg, uint8_t R, uint8_t G, uint8_t B);
|
|
|
|
bool write32(uint8_t reg, uint32_t value);
|
|
|
|
uint32_t read32(uint8_t reg);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -- END OF FILE --
|