setDPI getDPI

This commit is contained in:
Denis Manherz 2024-09-02 14:33:45 +02:00
parent 342b8098ed
commit c1fc9140a7
3 changed files with 69 additions and 16 deletions

View file

@ -115,7 +115,7 @@ POLLING_RATE A811::getUSBPollingRate()
return POLLING_RATE(_conf12->c1.polling_rate); return POLLING_RATE(_conf12->c1.polling_rate);
} }
ssize_t A811::setDPI(DPI_MODE mode, unsigned char color[3], int dpi) ssize_t A811::setDPI(DPI_MODE mode, unsigned char color[3], int dpi, int active)
{ {
if ((uint8_t)mode < (uint8_t)DPI_MODE::DPI_1 || if ((uint8_t)mode < (uint8_t)DPI_MODE::DPI_1 ||
@ -129,21 +129,27 @@ ssize_t A811::setDPI(DPI_MODE mode, unsigned char color[3], int dpi)
logError("ERROR: Invalid dpi.", __FILE__, __LINE__, __func__); logError("ERROR: Invalid dpi.", __FILE__, __LINE__, __func__);
return ssize_t(2); return ssize_t(2);
} }
if (active > 5 || active < 1)
{
logError("ERROR: Invalid active dpi modes.", __FILE__, __LINE__, __func__);
return ssize_t(2);
}
// Calculate the DPI value according to the formula // Calculate the DPI value according to the formula
int dpi_value = (dpi - 50) / 50; uint16_t dpi_value = (dpi - 50) / 50;
// Split the value into two bytes (least significant byte first) // Split the value into two bytes (least significant byte first)
uint8_t lsb = dpi_value & 0xFF; // Extract the least significant byte uint8_t lsb = dpi_value & 0xFF; // Extract the least significant byte
uint8_t msb = (dpi_value >> 8) & 0xFF; // Extract the most significant byte uint8_t msb = (dpi_value >> 8) & 0xFF; // Extract the most significant byte
_conf12->c1.dpi_modes =
(uint8_t)(((uint8_t)mode & 0x0F) | ((0x1 & 0x0F) << 4));
_conf12->c1.hdpi[(uint8_t)mode - 1 * 2] = lsb; _conf12->c1.dpi_modes = // number of active modes
_conf12->c1.hdpi[(uint8_t)mode - 1 * 2 + 1] = msb; (1 & 0x0f) << 4 | ((active & 0x0F));
_conf12->c1.col_dpi[0] = color[(uint8_t)mode - 1 * 3];
_conf12->c1.col_dpi[1] = color[(uint8_t)mode - 1 * 3 + 1]; _conf12->c1.hdpi[((uint8_t)mode - 1) * 2] = lsb;
_conf12->c1.col_dpi[2] = color[(uint8_t)mode - 1 * 3 + 2]; _conf12->c1.hdpi[((uint8_t)mode - 1) * 2 + 1] = msb;
_conf12->c1.col_dpi[((uint8_t)mode - 1) * 3] = color[0];
_conf12->c1.col_dpi[((uint8_t)mode - 1) * 3 + 1] = color[1];
_conf12->c1.col_dpi[((uint8_t)mode - 1) * 3 + 2] = color[2];
return ssize_t(0); return ssize_t(0);
} }
@ -156,7 +162,19 @@ int A811::getDPI(DPI_MODE mode)
logError("ERROR: Invalid DPI_MODE.", __FILE__, __LINE__, __func__); logError("ERROR: Invalid DPI_MODE.", __FILE__, __LINE__, __func__);
return ssize_t(1); return ssize_t(1);
} }
return 0; // Assume lsb and msb are given or extracted from your configuration structure
uint8_t lsb = _conf12->c1.hdpi[((uint8_t)mode - 1) * 2];
uint8_t msb = _conf12->c1.hdpi[((uint8_t)mode - 1) * 2 + 1];
// Reconstruct the dpi_value
uint16_t dpi_value = msb << 8 | lsb & 0xFF;
std::cout << std::hex << dpi_value << " : " << (int)lsb << " : " << (int)msb << std::endl;
// Reverse the formula to get the original dpi
uint16_t dpi = (dpi_value * 50) + 50;
return dpi;
} }
BATTERY_STAT A811::getBatteryStatus() BATTERY_STAT A811::getBatteryStatus()
@ -350,7 +368,7 @@ ssize_t A811::readConfigFromDevice(CONF_TYPE t_conf)
case CONF_TYPE::LIGHT: case CONF_TYPE::LIGHT:
_data[1] = 0x21; _data[1] = 0x21;
CHK(_connection->setReport(0x0305, _data, 8)); CHK(_connection->setReport(0x0305, _data, 8));
CHK(_connection->getReport(0x0308, (unsigned char*)&_conf12->c1, 520)); CHK(_connection->getReport(0x0308, (unsigned char *)&_conf12->c1, 520));
break; break;
case CONF_TYPE::KEY: case CONF_TYPE::KEY:
_data[1] = 0x22; _data[1] = 0x22;

View file

@ -163,9 +163,30 @@ public:
/// itse not a this class probelm i think just set the values, /// itse not a this class probelm i think just set the values,
// itse more a dpi loop problem just need to set the values from frontend like // itse more a dpi loop problem just need to set the values from frontend like
// explained before // explained before
ssize_t setDPI(DPI_MODE, unsigned char[3], int); //-- maybe active should be optional
/**
* @brief Set the DPI for a specific DPI MODE.
*
* This function allows you to set a specific DPI and an associated color
* for the mouse wheel for a Specific DPI mode.
*
* @param mode The mode for which to set the DPI and color values.
* @param color RGB
* @param dpi DPI value 50-26000
* @param active 1-5 how many DPI_MODE should be active.
*
* @return ssize_t Returns the status of the operation, where 0 indicates
* success and a negative value indicates failure.
*/
ssize_t setDPI(DPI_MODE, unsigned char[3], int, int);
// returns all active dpi configurations /**
* @brief Get the current DPI value for a DPI_MODE.
*
* This function retrieves the current light mode of the device.
*
* @return int The current DPI for DPI_MODE.
*/
int getDPI(DPI_MODE); int getDPI(DPI_MODE);
BATTERY_STAT getBatteryStatus(); BATTERY_STAT getBatteryStatus();

View file

@ -135,6 +135,7 @@ void Conf::testFunc()
sleep(2); sleep(2);
asd->setMultimediaButton(2, "media_volume_up"); asd->setMultimediaButton(2, "media_volume_up");
asd->setMultimediaButton(6, "dpi-cycle");
asd->writeConfigToDevice(CONF_TYPE::KEY); asd->writeConfigToDevice(CONF_TYPE::KEY);
std::cout << asd->getButton(3).name << std::endl; std::cout << asd->getButton(3).name << std::endl;
@ -149,10 +150,23 @@ void Conf::testFunc()
0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00}; 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00};
asd->setLightModeColors(LIGHT_MODE::BREATHING, cols2); asd->setLightModeColors(LIGHT_MODE::BREATHING, cols2);
unsigned char cols3[3] = {0xff, 0xff, 0x00}; unsigned char cols3[3] = {0xff, 0x00, 0x00};
//asd->setDPI(DPI_MODE::DPI_1, cols3, 13000); --> setting this kills everything asd->setDPI(DPI_MODE::DPI_1, cols3, 26000, 5);
cols3[0] = 0x0;
cols3[1] = 0xff;
asd->setDPI(DPI_MODE::DPI_2, cols3, 800, 5);
cols3[1] = 0x0;
cols3[2] = 0xff;
asd->setDPI(DPI_MODE::DPI_3, cols3, 1600, 5);
cols3[0] = 0xff;
cols3[2] = 0xff;
asd->setDPI(DPI_MODE::DPI_4, cols3, 3200, 5);
cols3[0] = 0xff;
cols3[1] = 0xff;
cols3[2] = 0xff;
asd->setDPI(DPI_MODE::DPI_5, cols3, 26000, 5);
//asd->writeConfigToDevice(CONF_TYPE::KEY); //asd->writeConfigToDevice(CONF_TYPE::KEY);
std::cout << "DPI at this: "<< asd->getDPI(DPI_MODE::DPI_1) << std::endl;
std::cout << "Battery capacity:" << std::dec << asd->getBatteryCapacity() << std::endl; std::cout << "Battery capacity:" << std::dec << asd->getBatteryCapacity() << std::endl;
asd->writeConfigToDevice(CONF_TYPE::LIGHT); asd->writeConfigToDevice(CONF_TYPE::LIGHT);