|
|
@ -33,12 +33,13 @@ TouchWheel::TouchWheel() { |
|
|
|
WriteRegister(Register::RESET, 1); |
|
|
|
WriteRegister(Register::RESET, 1); |
|
|
|
// TODO(daniel): do we need this? how long does reset take?
|
|
|
|
// TODO(daniel): do we need this? how long does reset take?
|
|
|
|
vTaskDelay(pdMS_TO_TICKS(1)); |
|
|
|
vTaskDelay(pdMS_TO_TICKS(1)); |
|
|
|
|
|
|
|
ReadRegister(Register::FIRMWARE_VERSION); |
|
|
|
WriteRegister(Register::SLIDER_OPTIONS, 0b11000000); |
|
|
|
WriteRegister(Register::SLIDER_OPTIONS, 0b11000000); |
|
|
|
WriteRegister(Register::CALIBRATE, 1); |
|
|
|
//WriteRegister(Register::CALIBRATE, 1);
|
|
|
|
// Confusingly-named; this sets to max-power max-response-time.
|
|
|
|
// Confusingly-named; this sets to max-power max-response-time.
|
|
|
|
WriteRegister(Register::LOW_POWER, 1); |
|
|
|
//WriteRegister(Register::LOW_POWER, 1);
|
|
|
|
// TODO(jacqueline): Temp to debug touchwheel responsiveness.
|
|
|
|
// TODO(jacqueline): Temp to debug touchwheel responsiveness.
|
|
|
|
WriteRegister(Register::CHARGE_TIME, 8); |
|
|
|
//WriteRegister(Register::CHARGE_TIME, 8);
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TouchWheel::~TouchWheel() {} |
|
|
|
TouchWheel::~TouchWheel() {} |
|
|
@ -63,9 +64,10 @@ uint8_t TouchWheel::ReadRegister(uint8_t reg) { |
|
|
|
transaction.start() |
|
|
|
transaction.start() |
|
|
|
.write_addr(kTouchWheelAddress, I2C_MASTER_WRITE) |
|
|
|
.write_addr(kTouchWheelAddress, I2C_MASTER_WRITE) |
|
|
|
.write_ack(reg) |
|
|
|
.write_ack(reg) |
|
|
|
|
|
|
|
.stop() |
|
|
|
.start() |
|
|
|
.start() |
|
|
|
.write_addr(kTouchWheelAddress, I2C_MASTER_READ) |
|
|
|
.write_addr(kTouchWheelAddress, I2C_MASTER_READ) |
|
|
|
.read(&res, I2C_MASTER_NACK) |
|
|
|
.read(&res, I2C_MASTER_ACK) |
|
|
|
.stop(); |
|
|
|
.stop(); |
|
|
|
ESP_ERROR_CHECK(transaction.Execute()); |
|
|
|
ESP_ERROR_CHECK(transaction.Execute()); |
|
|
|
return res; |
|
|
|
return res; |
|
|
@ -73,13 +75,14 @@ uint8_t TouchWheel::ReadRegister(uint8_t reg) { |
|
|
|
|
|
|
|
|
|
|
|
void TouchWheel::Update() { |
|
|
|
void TouchWheel::Update() { |
|
|
|
// Read data from device into member struct
|
|
|
|
// Read data from device into member struct
|
|
|
|
bool has_data = !gpio_get_level(GPIO_NUM_25); |
|
|
|
//bool has_data = !gpio_get_level(GPIO_NUM_25);
|
|
|
|
if (!has_data) { |
|
|
|
//if (!has_data) {
|
|
|
|
return; |
|
|
|
// return;
|
|
|
|
} |
|
|
|
//}
|
|
|
|
uint8_t status = ReadRegister(Register::DETECTION_STATUS); |
|
|
|
uint8_t status = ReadRegister(Register::DETECTION_STATUS); |
|
|
|
if (status & 0b10000000) { |
|
|
|
if (status & 0b10000000) { |
|
|
|
// Still calibrating.
|
|
|
|
// Still calibrating.
|
|
|
|
|
|
|
|
ESP_LOGW(kTag, "awaiting calibration"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (status & 0b01000000) { |
|
|
|
if (status & 0b01000000) { |
|
|
@ -88,13 +91,16 @@ void TouchWheel::Update() { |
|
|
|
} |
|
|
|
} |
|
|
|
if (status & 0b10) { |
|
|
|
if (status & 0b10) { |
|
|
|
// Slider detect.
|
|
|
|
// Slider detect.
|
|
|
|
|
|
|
|
ESP_LOGW(kTag, "wheel changed"); |
|
|
|
data_.wheel_position = ReadRegister(Register::SLIDER_POSITION); |
|
|
|
data_.wheel_position = ReadRegister(Register::SLIDER_POSITION); |
|
|
|
|
|
|
|
ESP_LOGW(kTag, "new pos: %d", data_.wheel_position); |
|
|
|
} |
|
|
|
} |
|
|
|
if (status & 0b1) { |
|
|
|
if (status & 0b1) { |
|
|
|
// Key detect.
|
|
|
|
// Key detect.
|
|
|
|
// TODO(daniel): implement me
|
|
|
|
// TODO(daniel): implement me
|
|
|
|
// Ensure we read all status registers -- even if we're not using them -- to
|
|
|
|
// Ensure we read all status registers -- even if we're not using them -- to
|
|
|
|
// ensure that INT can float high again.
|
|
|
|
// ensure that INT can float high again.
|
|
|
|
|
|
|
|
ESP_LOGW(kTag, "button changed"); |
|
|
|
ReadRegister(Register::KEY_STATUS_A); |
|
|
|
ReadRegister(Register::KEY_STATUS_A); |
|
|
|
ReadRegister(Register::KEY_STATUS_B); |
|
|
|
ReadRegister(Register::KEY_STATUS_B); |
|
|
|
} |
|
|
|
} |
|
|
|