|
| 1 | +/*---------------------------------------------------------*\ |
| 2 | +| RGBController_RazerHanbo.cpp | |
| 3 | +| | |
| 4 | +| RGBController for Razer Hanbo devices | |
| 5 | +| | |
| 6 | +| Joseph East (dripsnek) 12 Apr 2025 | |
| 7 | +| | |
| 8 | +| This file is part of the OpenRGB project | |
| 9 | +| SPDX-License-Identifier: GPL-2.0-only | |
| 10 | +\*---------------------------------------------------------*/ |
| 11 | + |
| 12 | +#include "RGBController_RazerHanbo.h" |
| 13 | +#include "RazerDevices.h" |
| 14 | + |
| 15 | +/**------------------------------------------------------------------*\ |
| 16 | + @name Razer Hanbo Chroma |
| 17 | + @category Cooler |
| 18 | + @type USB |
| 19 | + @save :robot: |
| 20 | + @direct :white_check_mark: |
| 21 | + @effects :white_check_mark: |
| 22 | + @detectors DetectRazerHanboControllers |
| 23 | + @comment |
| 24 | +\*-------------------------------------------------------------------*/ |
| 25 | + |
| 26 | +RGBController_RazerHanbo::RGBController_RazerHanbo(RazerHanboController* controller_ptr) |
| 27 | +{ |
| 28 | + controller = controller_ptr; |
| 29 | + name = controller->GetName(); |
| 30 | + vendor = "Razer"; |
| 31 | + type = controller->GetDeviceType(); |
| 32 | + description = "Razer Hanbo Device"; |
| 33 | + location = controller->GetDeviceLocation(); |
| 34 | + version = controller->GetFirmwareString(); |
| 35 | + serial = controller->GetSerialString(); |
| 36 | + |
| 37 | + mode Direct; |
| 38 | + Direct.name = "Direct"; |
| 39 | + Direct.value = RAZER_HANBO_MODE_DIRECT; |
| 40 | + Direct.flags = MODE_FLAG_HAS_PER_LED_COLOR; |
| 41 | + Direct.color_mode = MODE_COLORS_PER_LED; |
| 42 | + Direct.brightness_min = MIN_BRIGHTNESS; |
| 43 | + Direct.brightness_max = MAX_BRIGHTNESS; |
| 44 | + Direct.brightness = MAX_BRIGHTNESS/2; |
| 45 | + modes.push_back(Direct); |
| 46 | + |
| 47 | + mode Off; |
| 48 | + Off.name = "Off"; |
| 49 | + Off.value = RAZER_HANBO_MODE_OFF; |
| 50 | + Off.flags = 0; |
| 51 | + Off.color_mode = MODE_COLORS_NONE; |
| 52 | + modes.push_back(Off); |
| 53 | + |
| 54 | + mode SpectrumCycle; |
| 55 | + SpectrumCycle.name = "Spectrum Cycle"; |
| 56 | + SpectrumCycle.value = RAZER_HANBO_MODE_SPECTRUM_CYCLE; |
| 57 | + SpectrumCycle.flags = 0; |
| 58 | + SpectrumCycle.color_mode = MODE_COLORS_NONE; |
| 59 | + modes.push_back(SpectrumCycle); |
| 60 | + |
| 61 | + local_mode = RAZER_HANBO_MODE_DIRECT; |
| 62 | + |
| 63 | + SetupZones(); |
| 64 | +} |
| 65 | + |
| 66 | +RGBController_RazerHanbo::~RGBController_RazerHanbo() |
| 67 | +{ |
| 68 | + delete controller; |
| 69 | +} |
| 70 | + |
| 71 | +void RGBController_RazerHanbo::SetupZones() |
| 72 | +{ |
| 73 | + unsigned int device_index = controller->GetDeviceIndex(); |
| 74 | + |
| 75 | + /*---------------------------------------------------------*\ |
| 76 | + | Fill in zone information based on device table | |
| 77 | + \*---------------------------------------------------------*/ |
| 78 | + for(unsigned int zone_id = 0; zone_id < RAZER_MAX_ZONES; zone_id++) |
| 79 | + { |
| 80 | + if(device_list[device_index]->zones[zone_id] != NULL) |
| 81 | + { |
| 82 | + zone new_zone; |
| 83 | + |
| 84 | + new_zone.name = device_list[device_index]->zones[zone_id]->name; |
| 85 | + new_zone.type = device_list[device_index]->zones[zone_id]->type; |
| 86 | + new_zone.leds_count = device_list[device_index]->zones[zone_id]->rows * device_list[device_index]->zones[zone_id]->cols; |
| 87 | + new_zone.leds_min = new_zone.leds_count; |
| 88 | + new_zone.leds_max = new_zone.leds_count; |
| 89 | + |
| 90 | + if(new_zone.type == ZONE_TYPE_MATRIX) |
| 91 | + { |
| 92 | + matrix_map_type * new_map = new matrix_map_type; |
| 93 | + |
| 94 | + new_zone.matrix_map = new_map; |
| 95 | + new_map->height = device_list[device_index]->zones[zone_id]->rows; |
| 96 | + new_map->width = device_list[device_index]->zones[zone_id]->cols; |
| 97 | + new_map->map = new unsigned int[new_map->height * new_map->width]; |
| 98 | + |
| 99 | + for(unsigned int y = 0; y < new_map->height; y++) |
| 100 | + { |
| 101 | + for(unsigned int x = 0; x < new_map->width; x++) |
| 102 | + { |
| 103 | + new_map->map[(y * new_map->width) + x] = (y * new_map->width) + x; |
| 104 | + } |
| 105 | + } |
| 106 | + } |
| 107 | + else |
| 108 | + { |
| 109 | + new_zone.matrix_map = NULL; |
| 110 | + } |
| 111 | + |
| 112 | + zones.push_back(new_zone); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + for(unsigned int zone_id = 0; zone_id < zones.size(); zone_id++) |
| 117 | + { |
| 118 | + for(unsigned int row_id = 0; row_id < device_list[device_index]->zones[zone_id]->rows; row_id++) |
| 119 | + { |
| 120 | + for(unsigned int col_id = 0; col_id < device_list[device_index]->zones[zone_id]->cols; col_id++) |
| 121 | + { |
| 122 | + led* new_led = new led(); |
| 123 | + |
| 124 | + new_led->name = device_list[device_index]->zones[zone_id]->name; |
| 125 | + |
| 126 | + if(zones[zone_id].leds_count > 1) |
| 127 | + { |
| 128 | + new_led->name.append(" LED "); |
| 129 | + new_led->name.append(std::to_string(col_id + 1)); |
| 130 | + } |
| 131 | + |
| 132 | + leds.push_back(*new_led); |
| 133 | + } |
| 134 | + } |
| 135 | + } |
| 136 | + |
| 137 | + SetupColors(); |
| 138 | +} |
| 139 | + |
| 140 | +void RGBController_RazerHanbo::ResizeZone(int /*zone*/, int /*new_size*/) |
| 141 | +{ |
| 142 | + /*---------------------------------------------------------*\ |
| 143 | + | This device does not support resizing zones | |
| 144 | + \*---------------------------------------------------------*/ |
| 145 | +} |
| 146 | + |
| 147 | +void RGBController_RazerHanbo::DeviceUpdateLEDs() |
| 148 | +{ |
| 149 | + UpdateZoneLEDs(PUMP); |
| 150 | + UpdateZoneLEDs(FAN1); |
| 151 | + UpdateZoneLEDs(FAN2); |
| 152 | + UpdateZoneLEDs(FAN3); |
| 153 | +} |
| 154 | + |
| 155 | +/*---------------------------------------------------------*\ |
| 156 | +| The Hanbo command set is arranged in terms of zones. | |
| 157 | +| Transactions are straight forward when grouped this way. | |
| 158 | +\*---------------------------------------------------------*/ |
| 159 | + |
| 160 | +void RGBController_RazerHanbo::UpdateZoneLEDs(int zoneid) |
| 161 | +{ |
| 162 | + controller->SetZoneLeds(zoneid, this->zones[zoneid]); |
| 163 | +} |
| 164 | + |
| 165 | +void RGBController_RazerHanbo::UpdateSingleLED(int /*led*/) |
| 166 | +{ |
| 167 | + DeviceUpdateLEDs(); |
| 168 | +} |
| 169 | + |
| 170 | +void RGBController_RazerHanbo::DeviceUpdateMode() |
| 171 | +{ |
| 172 | + switch(modes[active_mode].value) |
| 173 | + { |
| 174 | + case RAZER_HANBO_MODE_DIRECT: |
| 175 | + if(local_mode != RAZER_HANBO_MODE_DIRECT) |
| 176 | + controller->SetDirectMode(); |
| 177 | + break; |
| 178 | + |
| 179 | + case RAZER_HANBO_MODE_OFF: |
| 180 | + controller->SetModeOff(); |
| 181 | + break; |
| 182 | + |
| 183 | + case RAZER_HANBO_MODE_SPECTRUM_CYCLE: |
| 184 | + controller->SetModeSpectrumCycle(); |
| 185 | + break; |
| 186 | + } |
| 187 | + |
| 188 | + local_mode = modes[active_mode].value; |
| 189 | +} |
0 commit comments