|
| 1 | +/*---------------------------------------------------------*\ |
| 2 | +| RGBController_RazerKrakenV3.cpp | |
| 3 | +| | |
| 4 | +| RGBController for Razer devices with 9-byte report | |
| 5 | +| | |
| 6 | +| Greg Sandstrom (superstrom) 1 Nov 2025 | |
| 7 | +| | |
| 8 | +| This file is part of the OpenRGB project | |
| 9 | +| SPDX-License-Identifier: GPL-2.0-or-later | |
| 10 | +\*---------------------------------------------------------*/ |
| 11 | + |
| 12 | +#include <vector> |
| 13 | +#include "RazerDevices.h" |
| 14 | +#include "RGBController_RazerKrakenV3.h" |
| 15 | + |
| 16 | +RGBController_RazerKrakenV3::RGBController_RazerKrakenV3(RazerKrakenV3Controller* controller_ptr) |
| 17 | +{ |
| 18 | + controller = controller_ptr; |
| 19 | + |
| 20 | + name = controller->GetName(); |
| 21 | + vendor = "Razer"; |
| 22 | + type = controller->GetDeviceType(); |
| 23 | + description = "Razer Device"; |
| 24 | + location = controller->GetDeviceLocation(); |
| 25 | + version = controller->GetFirmwareString(); |
| 26 | + serial = controller->GetSerialString(); |
| 27 | + uint8_t max_brightness = controller->GetMaxBrightness(); |
| 28 | + |
| 29 | + // By default, the device starts as Wave/Spectrum Cycle. |
| 30 | + // Set Wave as first mode, so switching to Direct calls DeviceUpdateMode() |
| 31 | + |
| 32 | + mode Wave; |
| 33 | + Wave.name = "Wave"; |
| 34 | + Wave.value = RAZER_KRAKEN_V3_MODE_WAVE; |
| 35 | + Wave.flags = MODE_FLAG_HAS_BRIGHTNESS; |
| 36 | + Wave.direction = MODE_DIRECTION_RIGHT; |
| 37 | + Wave.color_mode = MODE_COLORS_NONE; |
| 38 | + Wave.brightness_min = 0; |
| 39 | + Wave.brightness_max = max_brightness; |
| 40 | + Wave.brightness = max_brightness; |
| 41 | + modes.push_back(Wave); |
| 42 | + |
| 43 | + |
| 44 | + mode Direct; |
| 45 | + Direct.name = "Direct"; |
| 46 | + Direct.value = RAZER_KRAKEN_V3_MODE_DIRECT; |
| 47 | + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR | MODE_FLAG_HAS_BRIGHTNESS; |
| 48 | + Direct.color_mode = MODE_COLORS_PER_LED; |
| 49 | + Direct.brightness_min = 0; |
| 50 | + Direct.brightness_max = max_brightness; |
| 51 | + Direct.brightness = max_brightness; |
| 52 | + modes.push_back(Direct); |
| 53 | + |
| 54 | + SetupZones(); |
| 55 | +} |
| 56 | + |
| 57 | +RGBController_RazerKrakenV3::~RGBController_RazerKrakenV3() |
| 58 | +{ |
| 59 | + delete controller; |
| 60 | +} |
| 61 | + |
| 62 | +void RGBController_RazerKrakenV3::SetupZones() |
| 63 | +{ |
| 64 | + unsigned int device_index = controller->GetDeviceIndex(); |
| 65 | + |
| 66 | + /*---------------------------------------------------------*\ |
| 67 | + | Fill in zone information based on device table | |
| 68 | + \*---------------------------------------------------------*/ |
| 69 | + for(unsigned int zone_id = 0; zone_id < RAZER_MAX_ZONES; zone_id++) |
| 70 | + { |
| 71 | + if(device_list[device_index]->zones[zone_id] != NULL) |
| 72 | + { |
| 73 | + zone new_zone; |
| 74 | + |
| 75 | + new_zone.name = device_list[device_index]->zones[zone_id]->name; |
| 76 | + new_zone.type = device_list[device_index]->zones[zone_id]->type; |
| 77 | + |
| 78 | + new_zone.leds_count = device_list[device_index]->zones[zone_id]->rows * device_list[device_index]->zones[zone_id]->cols; |
| 79 | + new_zone.leds_min = new_zone.leds_count; |
| 80 | + new_zone.leds_max = new_zone.leds_count; |
| 81 | + |
| 82 | + if(new_zone.type == ZONE_TYPE_MATRIX) |
| 83 | + { |
| 84 | + matrix_map_type * new_map = new matrix_map_type; |
| 85 | + new_zone.matrix_map = new_map; |
| 86 | + |
| 87 | + new_map->height = device_list[device_index]->zones[zone_id]->rows; |
| 88 | + new_map->width = device_list[device_index]->zones[zone_id]->cols; |
| 89 | + |
| 90 | + new_map->map = new unsigned int[new_map->height * new_map->width]; |
| 91 | + |
| 92 | + for(unsigned int y = 0; y < new_map->height; y++) |
| 93 | + { |
| 94 | + for(unsigned int x = 0; x < new_map->width; x++) |
| 95 | + { |
| 96 | + new_map->map[(y * new_map->width) + x] = (y * new_map->width) + x; |
| 97 | + } |
| 98 | + } |
| 99 | + } |
| 100 | + else |
| 101 | + { |
| 102 | + new_zone.matrix_map = NULL; |
| 103 | + } |
| 104 | + |
| 105 | + zones.push_back(new_zone); |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + for(unsigned int zone_id = 0; zone_id < zones.size(); zone_id++) |
| 110 | + { |
| 111 | + for (unsigned int row_id = 0; row_id < device_list[device_index]->zones[zone_id]->rows; row_id++) |
| 112 | + { |
| 113 | + for (unsigned int col_id = 0; col_id < device_list[device_index]->zones[zone_id]->cols; col_id++) |
| 114 | + { |
| 115 | + led* new_led = new led(); |
| 116 | + |
| 117 | + new_led->name = device_list[device_index]->zones[zone_id]->name; |
| 118 | + |
| 119 | + if(zones[zone_id].leds_count > 1) |
| 120 | + { |
| 121 | + new_led->name.append(" LED "); |
| 122 | + new_led->name.append(std::to_string(col_id + 1)); |
| 123 | + } |
| 124 | + |
| 125 | + leds.push_back(*new_led); |
| 126 | + } |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + SetupColors(); |
| 131 | +} |
| 132 | + |
| 133 | +void RGBController_RazerKrakenV3::ResizeZone(int /*zone*/, int /*new_size*/) |
| 134 | +{ |
| 135 | + |
| 136 | +} |
| 137 | + |
| 138 | +void RGBController_RazerKrakenV3::DeviceUpdateLEDs() |
| 139 | +{ |
| 140 | + if(modes[active_mode].value == RAZER_KRAKEN_V3_MODE_DIRECT) |
| 141 | + { |
| 142 | + controller->SetDirect(&colors[0]); |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +void RGBController_RazerKrakenV3::UpdateZoneLEDs(int /*zone*/) |
| 147 | +{ |
| 148 | + DeviceUpdateLEDs(); |
| 149 | +} |
| 150 | + |
| 151 | +void RGBController_RazerKrakenV3::UpdateSingleLED(int /*led*/) |
| 152 | +{ |
| 153 | + DeviceUpdateLEDs(); |
| 154 | +} |
| 155 | + |
| 156 | +void RGBController_RazerKrakenV3::DeviceUpdateMode() |
| 157 | +{ |
| 158 | + switch(modes[active_mode].value) |
| 159 | + { |
| 160 | + case RAZER_KRAKEN_V3_MODE_DIRECT: |
| 161 | + controller->SetModeDirect(); |
| 162 | + controller->SetBrightness(modes[active_mode].brightness); |
| 163 | + break; |
| 164 | + |
| 165 | + case RAZER_KRAKEN_V3_MODE_WAVE: |
| 166 | + controller->SetModeWave(); |
| 167 | + controller->SetBrightness(modes[active_mode].brightness); |
| 168 | + break; |
| 169 | + } |
| 170 | +} |
0 commit comments