From f05f791841b20ece897c1ffdfd729e6ec46e4558 Mon Sep 17 00:00:00 2001 From: Kristian Sloth Lauszus Date: Thu, 25 Feb 2016 17:48:18 +0100 Subject: [PATCH] Show tilt using LEDs by default --- examples/HID/SRWS1/SRWS1.h | 2 +- examples/HID/SRWS1/SRWS1.ino | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/HID/SRWS1/SRWS1.h b/examples/HID/SRWS1/SRWS1.h index fb47fbb5..8222bdee 100644 --- a/examples/HID/SRWS1/SRWS1.h +++ b/examples/HID/SRWS1/SRWS1.h @@ -67,6 +67,7 @@ public: return HIDUniversal::isReady() && HIDUniversal::VID == STEELSERIES_VID && HIDUniversal::PID == STEELSERIES_SRWS1_PID; }; void setLeds(uint16_t leds); + SRWS1Data srws1Data; private: void ParseHIDData(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf); // Called by the HIDUniversal library @@ -76,7 +77,6 @@ private: setLeds(0); return 0; }; - SRWS1Data srws1Data; }; #endif diff --git a/examples/HID/SRWS1/SRWS1.ino b/examples/HID/SRWS1/SRWS1.ino index c1a3fe6a..646f3df2 100644 --- a/examples/HID/SRWS1/SRWS1.ino +++ b/examples/HID/SRWS1/SRWS1.ino @@ -26,12 +26,12 @@ void loop() { Usb.Task(); if (srw1.connected()) { -#if 1 // Set to 1 in order to show a crazy strobe light effect +#if 0 // Set to 1 in order to show a crazy strobe light effect static uint32_t timer; if (millis() - timer > 12) { timer = millis(); // Reset timer - static uint16_t leds = 0; + static uint16_t leds = 0; /*D_PrintHex (leds, 0x80); Serial.println();*/ srw1.setLeds(leds); // Update LEDs @@ -41,16 +41,18 @@ void loop() { leds <<= 1; if (leds == 0x8000) // All are actually turned off, as there is only 15 LEDs dirUp = false; // If we have reached the end i.e. all LEDs are off, then change direction - if (!(leds & 0x8000)) // If last bit is not set set the lowest bit + else if (!(leds & 0x8000)) // If last bit is not set set the lowest bit leds |= 1; // Set lowest bit } else { leds >>= 1; if (leds == 0) // Check if all LEDs are off dirUp = true; // If all LEDs are off, then repeat the sequence - if (!(leds & 0x1)) // If last bit is not set set the lowest bit + else if (!(leds & 0x1)) // If last bit is not set set the lowest bit leds |= 1 << 15; // Set top bit } } +#else + srw1.setLeds(1 << map(srw1.srws1Data.tilt, -1800, 1800, 0, 14)); // Turn on a LED according to tilt value #endif } }