cue-sdk
npm i cue-sdk

cue-sdk

A Node.js native wrapper around CUE SDK

by CorsairOfficial

3.0.0 (see all)License:MITTypeScript:DefinitelyTyped
npm i cue-sdk
Readme

cue-sdk-node

Intro

This wrapper can be used in node and electron apps. It uses prebuildify and is prebuilt for some runtime environments:

Node: 10.16.0, 11.8.0, 12.x, 13.x, 14.x

Electron: 6.0.0, 7.0.0, 8.0.0

Prerequisites

Windows:

macOS:

Installation

Note: you might need to install some tools to build from source on Windows before running npm install : https://github.com/nodejs/node-gyp#installation

npm install cue-sdk --save

Usage

1. Create sdk instance

const sdk = require('cue-sdk')

2. Perform handshake

const details = sdk.CorsairPerformProtocolHandshake()
const errCode = sdk.CorsairGetLastError()
if (errCode === 0) {
  // 'CE_Success'
}

3. Control your devices

const n = sdk.CorsairGetDeviceCount();

for (let i = 0; i < n; ++i) {
  const info = sdk.CorsairGetDeviceInfo(i);

  // example: read device properties
  if (info.capsMask & sdk.CorsairDeviceCaps.CDC_PropertyLookup) {
    console.log(info);
    Object.keys(sdk.CorsairDevicePropertyId).forEach(p => {
      const prop = sdk.CorsairGetDeviceProperty(i, sdk.CorsairDevicePropertyId[p]);
      if (!prop) {
        console.log(p, ':', sdk.CorsairErrorToString(sdk.CorsairGetLastError()));
      } else {
        console.log(p, prop.value);
      }
    });
  }

  if (info.capsMask & sdk.CorsairDeviceCaps.CDC_Lighting) {
    const positions = sdk.CorsairGetLedPositionsByDeviceIndex(i);
    const maxX = positions.reduce((acc, curr) => Math.max(curr.left, acc), 0);
    // create red gradient
    const colors = positions.map(p => ({ ledId: p.ledId, r: Math.floor(p.left / maxX * 255), g: 0, b: 0 }));
    sdk.CorsairSetLedsColorsBufferByDeviceIndex(i, colors);
    sdk.CorsairSetLedsColorsFlushBuffer();
  }
}

Links

Downloads/wk

84

GitHub Stars

25

LAST COMMIT

3mos ago

MAINTAINERS

1

CONTRIBUTORS

2

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
3.0.0
latest
3mos ago
No alternatives found
No tutorials found
Add a tutorial