From bf630245d0a2703a33f0e0d7ae376afed3a507e5 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Fri, 6 Sep 2024 23:41:07 -0500 Subject: [PATCH] Initial commit for Dream Cheeky Webmail Notifier --- .../DreamCheekyController.cpp | 83 ++++++++++++++++ .../DreamCheekyController.h | 31 ++++++ .../DreamCheekyControllerDetect.cpp | 40 ++++++++ .../RGBController_DreamCheeky.cpp | 94 +++++++++++++++++++ .../RGBController_DreamCheeky.h | 36 +++++++ README.md | 1 + 6 files changed, 285 insertions(+) create mode 100644 Controllers/DreamCheekyController/DreamCheekyController.cpp create mode 100644 Controllers/DreamCheekyController/DreamCheekyController.h create mode 100644 Controllers/DreamCheekyController/DreamCheekyControllerDetect.cpp create mode 100644 Controllers/DreamCheekyController/RGBController_DreamCheeky.cpp create mode 100644 Controllers/DreamCheekyController/RGBController_DreamCheeky.h diff --git a/Controllers/DreamCheekyController/DreamCheekyController.cpp b/Controllers/DreamCheekyController/DreamCheekyController.cpp new file mode 100644 index 00000000..203c4ed0 --- /dev/null +++ b/Controllers/DreamCheekyController/DreamCheekyController.cpp @@ -0,0 +1,83 @@ +/*---------------------------------------------------------*\ +| DreamCheekyController.cpp | +| | +| Driver for Dream Cheeky devices | +| | +| Adam Honse (calcprogrammer1@gmail.com) 06 Sep 2024 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#include +#include "DreamCheekyController.h" +#include "StringUtils.h" + +DreamCheekyController::DreamCheekyController(hid_device* dev_handle, const char* path) +{ + dev = dev_handle; + location = path; + + /*-----------------------------------------------------*\ + | The Dream Cheeky Webmail Notifier requires four | + | initialization packets before sending colors. | + \*-----------------------------------------------------*/ + const unsigned char init_0[9] = { 0x00, 0x1F, 0x02, 0x00, 0x5F, 0x00, 0x00, 0x1F, 0x03 }; + const unsigned char init_1[9] = { 0x00, 0x00, 0x02, 0x00, 0x5F, 0x00, 0x00, 0x1F, 0x04 }; + const unsigned char init_2[9] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1F, 0x05 }; + const unsigned char init_3[9] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; + + hid_write(dev, init_0, sizeof(init_0)); + hid_write(dev, init_1, sizeof(init_1)); + hid_write(dev, init_2, sizeof(init_2)); + hid_write(dev, init_3, sizeof(init_3)); +} + +DreamCheekyController::~DreamCheekyController() +{ + hid_close(dev); +} + +std::string DreamCheekyController::GetDeviceLocation() +{ + return("HID: " + location); +} + +std::string DreamCheekyController::GetSerialString() +{ + wchar_t serial_string[128]; + int ret = hid_get_serial_number_string(dev, serial_string, 128); + + if(ret != 0) + { + return(""); + } + + return(StringUtils::wstring_to_string(serial_string)); +} + +void DreamCheekyController::SetColor(unsigned char red, unsigned char grn, unsigned char blu) +{ + unsigned char usb_buf[9]; + + memset(usb_buf, 0, sizeof(usb_buf)); + + /*-----------------------------------------------------*\ + | The Dream Cheeky Webmail Notifier color values range | + | from 0-64, so we scale the 0-255 input range down by | + | right shifting by 2 to get the range 0-63. Add 1 if | + | the value is exactly 255 because otherwise the maximum| + | value of 64 would never be reached. | + \*-----------------------------------------------------*/ + usb_buf[0] = 0x00; + usb_buf[1] = (red >> 2) + (red == 255); + usb_buf[2] = (grn >> 2) + (grn == 255); + usb_buf[3] = (blu >> 2) + (blu == 255); + usb_buf[4] = 0x00; + usb_buf[5] = 0x00; + usb_buf[6] = 0x00; + usb_buf[7] = 0x1F; + usb_buf[8] = 0x05; + + hid_write(dev, usb_buf, sizeof(usb_buf)); +} diff --git a/Controllers/DreamCheekyController/DreamCheekyController.h b/Controllers/DreamCheekyController/DreamCheekyController.h new file mode 100644 index 00000000..b3ac4852 --- /dev/null +++ b/Controllers/DreamCheekyController/DreamCheekyController.h @@ -0,0 +1,31 @@ +/*---------------------------------------------------------*\ +| DreamCheekyController.h | +| | +| Driver for Dream Cheeky devices | +| | +| Adam Honse (calcprogrammer1@gmail.com) 06 Sep 2024 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#pragma once + +#include +#include + +class DreamCheekyController +{ +public: + DreamCheekyController(hid_device* dev_handle, const char* path); + ~DreamCheekyController(); + + std::string GetDeviceLocation(); + std::string GetSerialString(); + + void SetColor(unsigned char red, unsigned char grn, unsigned char blu); + +private: + hid_device* dev; + std::string location; +}; diff --git a/Controllers/DreamCheekyController/DreamCheekyControllerDetect.cpp b/Controllers/DreamCheekyController/DreamCheekyControllerDetect.cpp new file mode 100644 index 00000000..122e9de2 --- /dev/null +++ b/Controllers/DreamCheekyController/DreamCheekyControllerDetect.cpp @@ -0,0 +1,40 @@ +/*---------------------------------------------------------*\ +| DreamCheekyControllerDetect.cpp | +| | +| Detector for Dream Cheeky devices | +| | +| Adam Honse (calcprogrammer1@gmail.com) 06 Sep 2024 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#include "Detector.h" +#include "DreamCheekyController.h" +#include "RGBController_DreamCheeky.h" + +/*---------------------------------------------------------*\ +| Dream Cheeky USB Vendor ID | +\*---------------------------------------------------------*/ +#define DREAM_CHEEKY_VID 0x1D34 + +/*---------------------------------------------------------*\ +| Dream Cheeky USB Product ID | +\*---------------------------------------------------------*/ +#define DREAM_CHEEKY_WEBMAIL_NOTIFIER_PID 0x0004 + +void DetectDreamCheekyControllers(hid_device_info* info, const std::string& name) +{ + hid_device* dev = hid_open_path(info->path); + + if(dev) + { + DreamCheekyController* controller = new DreamCheekyController(dev, info->path); + RGBController_DreamCheeky* rgb_controller = new RGBController_DreamCheeky(controller); + rgb_controller->name = name; + + ResourceManager::get()->RegisterRGBController(rgb_controller); + } +} + +REGISTER_HID_DETECTOR( "Dream Cheeky Webmail Notifier", DetectDreamCheekyControllers, DREAM_CHEEKY_VID, DREAM_CHEEKY_WEBMAIL_NOTIFIER_PID ); diff --git a/Controllers/DreamCheekyController/RGBController_DreamCheeky.cpp b/Controllers/DreamCheekyController/RGBController_DreamCheeky.cpp new file mode 100644 index 00000000..b4e72897 --- /dev/null +++ b/Controllers/DreamCheekyController/RGBController_DreamCheeky.cpp @@ -0,0 +1,94 @@ +/*---------------------------------------------------------*\ +| RGBController_DreamCheeky.cpp | +| | +| RGBController for Dream Cheeky devices | +| | +| Adam Honse (calcprogrammer1@gmail.com) 06 Sep 2024 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#include "RGBController_DreamCheeky.h" + +RGBController_DreamCheeky::RGBController_DreamCheeky(DreamCheekyController* controller_ptr) +{ + controller = controller_ptr; + + name = "Dream Cheeky Device"; + type = DEVICE_TYPE_ACCESSORY; + vendor = "Dream Cheeky"; + description = "Dream Cheeky Device"; + location = controller->GetDeviceLocation(); + serial = controller->GetSerialString(); + + mode Direct; + Direct.name = "Direct"; + Direct.value = 0; + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; + Direct.color_mode = MODE_COLORS_PER_LED; + modes.push_back(Direct); + + SetupZones(); +} + +RGBController_DreamCheeky::~RGBController_DreamCheeky() +{ + +} + +void RGBController_DreamCheeky::SetupZones() +{ + zone mail_zone; + mail_zone.name = "LED"; + mail_zone.type = ZONE_TYPE_SINGLE; + mail_zone.leds_min = 1; + mail_zone.leds_max = 1; + mail_zone.leds_count = 1; + mail_zone.matrix_map = NULL; + zones.push_back(mail_zone); + + led mail_led; + mail_led.name = "LED"; + leds.push_back(mail_led); + + SetupColors(); +} + +void RGBController_DreamCheeky::ResizeZone(int /*zone*/, int /*new_size*/) +{ + /*-----------------------------------------------------*\ + | This device does not support resizing zones | + \*-----------------------------------------------------*/ +} + +void RGBController_DreamCheeky::DeviceUpdateLEDs() +{ + unsigned char red = RGBGetRValue(colors[0]); + unsigned char grn = RGBGetGValue(colors[0]); + unsigned char blu = RGBGetBValue(colors[0]); + + controller->SetColor(red, grn, blu); +} + +void RGBController_DreamCheeky::UpdateZoneLEDs(int /*zone*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_DreamCheeky::UpdateSingleLED(int /*led*/) +{ + DeviceUpdateLEDs(); +} + +void RGBController_DreamCheeky::DeviceUpdateMode() +{ + DeviceUpdateLEDs(); +} + +void RGBController_DreamCheeky::DeviceSaveMode() +{ + /*-----------------------------------------------------*\ + | This device does not support saving | + \*-----------------------------------------------------*/ +} diff --git a/Controllers/DreamCheekyController/RGBController_DreamCheeky.h b/Controllers/DreamCheekyController/RGBController_DreamCheeky.h new file mode 100644 index 00000000..657ce2ce --- /dev/null +++ b/Controllers/DreamCheekyController/RGBController_DreamCheeky.h @@ -0,0 +1,36 @@ +/*---------------------------------------------------------*\ +| RGBController_DreamCheeky.h | +| | +| RGBController for Dream Cheeky devices | +| | +| Adam Honse (calcprogrammer1@gmail.com) 06 Sep 2024 | +| | +| This file is part of the OpenRGB project | +| SPDX-License-Identifier: GPL-2.0-only | +\*---------------------------------------------------------*/ + +#pragma once + +#include "DreamCheekyController.h" +#include "RGBController.h" + +class RGBController_DreamCheeky : public RGBController +{ +public: + RGBController_DreamCheeky(DreamCheekyController* controller_ptr); + ~RGBController_DreamCheeky(); + + void SetupZones(); + + void ResizeZone(int zone, int new_size); + + void DeviceUpdateLEDs(); + void UpdateZoneLEDs(int zone); + void UpdateSingleLED(int led); + + void DeviceUpdateMode(); + void DeviceSaveMode(); + +private: + DreamCheekyController* controller; +}; diff --git a/README.md b/README.md index dbe514ad..a6a84595 100644 --- a/README.md +++ b/README.md @@ -164,4 +164,5 @@ While no code from these projects directly made its way into OpenRGB, these proj * Signal RGB Plugins: https://gitlab.com/signalrgb/signal-plugins/-/tree/master/Plugins * k550-macos https://github.com/vookimedlo/ck550-macos/tree/master * luxafor-python https://github.com/vmitchell85/luxafor-python + * dreamcheekyusb https://github.com/gbrayut/dreamcheekyusb