Skip to content

Commit

Permalink
bulk:
Browse files Browse the repository at this point in the history
- device labels
- commander pro fan detection
- cosmetic UI changes
  • Loading branch information
jurkovic-nikola committed Aug 13, 2024
1 parent 4c5b100 commit ad6d7cd
Show file tree
Hide file tree
Showing 24 changed files with 595 additions and 40 deletions.
2 changes: 1 addition & 1 deletion OpenLinkHub.service
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Unit]
Description=Open source interface for iCUE LINK System Hub
Description=Open source interface for iCUE LINK System Hub, Corsair AIOs and Hubs

[Service]
User=nikola
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ sudo udevadm control --reload-rules && sudo udevadm trigger
mkdir OpenLinkHub && cd OpenLinkHub

# Download latest build from https://github.com/jurkovic-nikola/OpenLinkHub/releases
wget https://github.com/jurkovic-nikola/OpenLinkHub/releases/download/0.1.0-beta/0.1.2-beta.zip
wget https://github.com/jurkovic-nikola/OpenLinkHub/releases/download/0.1.3-beta/0.1.3-beta.zip

# Extract package
unzip -x 0.1.2-beta.zip
unzip -x 0.1.3-beta.zip

# Continue from 3. Installation section for next steps
```
Expand Down
18 changes: 18 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ $ curl -X POST http:/127.0.0.1:27003/api/temperatures -d '{ "profile":"Example",
"message": "Profile is successfully saved"
}
```
### Temperature Profile - Create Liquid Temperature Profile
```bash
$ curl -X POST http:/127.0.0.1:27003/api/temperatures -d '{ "profile":"Example", "static":false, "sensor":2 }' --silent | jq
{
"code": 200,
"status": 1,
"message": "Profile is successfully saved"
}
```
### Temperature Profile - Create static CPU Profile
```bash
$ curl -X POST http:/127.0.0.1:27003/api/temperatures -d '{ "profile":"Example", "static":true, "sensor":0 }' --silent | jq
Expand Down Expand Up @@ -307,4 +316,13 @@ $ curl -X POST http:/127.0.0.1:27003/api/color -d '{"deviceId":"5C126A3EB51A3956
"status": 1,
"message": "Device RGB profile is successfully changed"
}
```
### Labels - Change device label
```bash
$ curl -X POST http:/127.0.0.1:27003/api/label -d '{"deviceId":"5C126A3EB51A39569ABADC4C3A1FCF54", channelId:13, "label":"Front Intake 1"}' --silent | jq
{
"code": 200,
"status": 1,
"message": "Device label is successfully applied"
}
```
36 changes: 35 additions & 1 deletion src/devices/cc/cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type DeviceProfile struct {
Serial string
RGBProfiles map[int]string
SpeedProfiles map[int]string
Labels map[int]string
}

// Devices contain information about devices connected to a Commander Core
Expand All @@ -138,6 +139,7 @@ type Devices struct {
PumpModes map[byte]string `json:"-"`
Profile string `json:"profile"`
RGB string `json:"rgb"`
Label string `json:"label"`
HasSpeed bool
HasTemps bool
IsTemperatureProbe bool
Expand Down Expand Up @@ -627,7 +629,7 @@ func (d *Device) setDeviceColor() {

// Send it
d.writeColor(buff)
time.Sleep(40 * time.Millisecond)
time.Sleep(20 * time.Millisecond)
}
}
}(lightChannels)
Expand All @@ -646,6 +648,7 @@ func (d *Device) getDevices() int {
if status == 0x07 {
// Get a persistent speed profile. Fallback to Normal is anything fails
speedProfile := "Normal"
label := "Not Set"
if d.DeviceProfile != nil {
// Profile is set
if sp, ok := d.DeviceProfile.SpeedProfiles[i]; ok {
Expand All @@ -659,6 +662,10 @@ func (d *Device) getDevices() int {
} else {
logger.Log(logger.Fields{"serial": d.Serial, "profile": sp}).Warn("Tried to apply non-existing channel")
}
// Device label
if lb, ok := d.DeviceProfile.Labels[i]; ok {
label = lb
}
} else {
logger.Log(logger.Fields{"serial": d.Serial}).Warn("DeviceProfile is not set, probably first startup")
}
Expand Down Expand Up @@ -699,6 +706,7 @@ func (d *Device) getDevices() int {
LedChannels: LedChannels,
HubId: d.Serial,
Profile: speedProfile,
Label: label,
HasSpeed: true,
HasTemps: false,
}
Expand Down Expand Up @@ -1108,6 +1116,20 @@ func (d *Device) UpdateDeviceSpeed(channelId int, value uint16) uint8 {
return 0
}

// UpdateDeviceLabel will set / update device label
func (d *Device) UpdateDeviceLabel(channelId int, label string) uint8 {
mutex.Lock()
defer mutex.Unlock()

if _, ok := d.Devices[channelId]; !ok {
return 0
}

d.Devices[channelId].Label = label
d.saveDeviceProfile()
return 1
}

// UpdateSpeedProfile will update device channel speed.
// If channelId is 0, all device channels will be updated
func (d *Device) UpdateSpeedProfile(channelId int, profile string) uint8 {
Expand Down Expand Up @@ -1219,18 +1241,26 @@ func (d *Device) resetLEDPorts() {
func (d *Device) saveDeviceProfile() {
speedProfiles := make(map[int]string, len(d.Devices))
rgbProfiles := make(map[int]string, len(d.Devices))
labels := make(map[int]string, len(d.Devices))

for _, device := range d.Devices {
if device.IsTemperatureProbe {
continue
}
speedProfiles[device.ChannelId] = device.Profile
rgbProfiles[device.ChannelId] = device.RGB
}

for _, device := range d.Devices {
labels[device.ChannelId] = device.Label
}

deviceProfile := &DeviceProfile{
Product: d.Product,
Serial: d.Serial,
SpeedProfiles: speedProfiles,
RGBProfiles: rgbProfiles,
Labels: labels,
}

// First save, assign saved profile to a device
Expand All @@ -1241,6 +1271,10 @@ func (d *Device) saveDeviceProfile() {
}
rgbProfiles[device.ChannelId] = "static"
}

for _, device := range d.Devices {
labels[device.ChannelId] = "Not Set"
}
d.DeviceProfile = deviceProfile
}

Expand Down
30 changes: 29 additions & 1 deletion src/devices/ccxt/ccxt.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ type DeviceProfile struct {
Serial string
RGBProfiles map[int]string
SpeedProfiles map[int]string
Labels map[int]string
ExternalHubDeviceType int
ExternalHubDeviceAmount int
}
Expand All @@ -161,6 +162,7 @@ type Devices struct {
PumpModes map[byte]string `json:"-"`
Profile string `json:"profile"`
RGB string `json:"rgb"`
Label string `json:"label"`
HasSpeed bool
HasTemps bool
IsTemperatureProbe bool
Expand Down Expand Up @@ -279,7 +281,7 @@ func (d *Device) getProduct() {
if err != nil {
logger.Log(logger.Fields{"error": err}).Fatal("Unable to get product")
}
product = strings.Replace(product, "CORSAIR", "", -1)
product = strings.Replace(product, "CORSAIR ", "", -1)
d.Product = product
}

Expand Down Expand Up @@ -1036,6 +1038,7 @@ func (d *Device) getDevices() int {
if status == 0x07 {
// Get a persistent speed profile. Fallback to Normal is anything fails
speedProfile := "Normal"
label := "Not Set"
if d.DeviceProfile != nil {
// Profile is set
if sp, ok := d.DeviceProfile.SpeedProfiles[i]; ok {
Expand All @@ -1049,6 +1052,11 @@ func (d *Device) getDevices() int {
} else {
logger.Log(logger.Fields{"serial": d.Serial, "profile": sp}).Warn("Tried to apply non-existing channel")
}

// Device label
if lb, ok := d.DeviceProfile.Labels[i]; ok {
label = lb
}
} else {
logger.Log(logger.Fields{"serial": d.Serial}).Warn("DeviceProfile is not set, probably first startup")
}
Expand Down Expand Up @@ -1092,6 +1100,7 @@ func (d *Device) getDevices() int {
HasSpeed: true,
HasTemps: false,
RGB: rgbProfile,
Label: label,
CellSize: 4,
}
devices[m] = device
Expand Down Expand Up @@ -1181,6 +1190,8 @@ func (d *Device) getDevices() int {
func (d *Device) saveDeviceProfile() {
speedProfiles := make(map[int]string, len(d.Devices))
rgbProfiles := make(map[int]string, len(d.Devices))
labels := make(map[int]string, len(d.Devices))

for _, device := range d.Devices {
if device.IsTemperatureProbe {
continue
Expand All @@ -1195,13 +1206,15 @@ func (d *Device) saveDeviceProfile() {
if device.LedChannels > 0 {
rgbProfiles[device.ChannelId] = device.RGB
}
labels[device.ChannelId] = device.Label
}

deviceProfile := &DeviceProfile{
Product: d.Product,
Serial: d.Serial,
SpeedProfiles: speedProfiles,
RGBProfiles: rgbProfiles,
Labels: labels,
}

// First save, assign saved profile to a device
Expand All @@ -1210,6 +1223,7 @@ func (d *Device) saveDeviceProfile() {
if device.LedChannels > 0 {
rgbProfiles[device.ChannelId] = "static"
}
labels[device.ChannelId] = "Not Set"
}
deviceProfile.ExternalHubDeviceAmount = 0
deviceProfile.ExternalHubDeviceType = 0
Expand Down Expand Up @@ -1400,6 +1414,20 @@ func (d *Device) UpdateDeviceSpeed(channelId int, value uint16) uint8 {
return 0
}

// UpdateDeviceLabel will set / update device label
func (d *Device) UpdateDeviceLabel(channelId int, label string) uint8 {
mutex.Lock()
defer mutex.Unlock()

if _, ok := d.Devices[channelId]; !ok {
return 0
}

d.Devices[channelId].Label = label
d.saveDeviceProfile()
return 1
}

// initLedPorts will prep LED physical ports for reading
func (d *Device) initLedPorts() {
for i := 1; i <= 6; i++ {
Expand Down
Loading

0 comments on commit ad6d7cd

Please sign in to comment.