|
92 | 92 | return s;
|
93 | 93 | }
|
94 | 94 |
|
95 |
| - //============================================================================== |
96 |
| - /** */ |
97 |
| - struct iCUESDKConnector final |
98 |
| - { |
99 |
| - /** */ |
100 |
| - iCUESDKConnector() |
101 |
| - { |
102 |
| - isValid (CorsairConnect (sessionStateChangeHandler, this)); |
103 |
| - } |
104 |
| - |
105 |
| - /** */ |
106 |
| - ~iCUESDKConnector() |
107 |
| - { |
108 |
| - isValid (CorsairDisconnect()); |
109 |
| - } |
110 |
| - |
111 |
| - static void sessionStateChangeHandler (void*, const CorsairSessionStateChanged*) |
112 |
| - { |
113 |
| - } |
114 |
| - }; |
115 |
| - |
116 |
| - static juce::SharedResourcePointer<iCUESDKConnector> connector; |
117 |
| - |
118 |
| - //============================================================================== |
119 |
| - /** */ |
120 |
| - inline void logInfo() |
121 |
| - { |
122 |
| - CorsairSessionDetails details; |
123 |
| - juce::zerostruct (details); |
124 |
| - if (const auto result = toResult (CorsairGetSessionDetails (&details)); result.failed()) |
125 |
| - { |
126 |
| - juce::Logger::writeToLog ("Could not log iCUE SDK information: " + result.getErrorMessage()); |
127 |
| - return; |
128 |
| - } |
129 |
| - |
130 |
| - juce::String info; |
131 |
| - info |
132 |
| - << juce::newLine |
133 |
| - << "--------------------------------------------------" << juce::newLine << juce::newLine |
134 |
| - << "=== Corsair iCUE SDK Information ===" << juce::newLine << juce::newLine |
135 |
| - << "clientVersion: " << toString (details.clientVersion) << juce::newLine |
136 |
| - << "serverVersion: " << toString (details.serverVersion) << juce::newLine |
137 |
| - << "serverHostVersion: " << toString (details.serverHostVersion) << juce::newLine |
138 |
| - << juce::newLine |
139 |
| - << "--------------------------------------------------" << juce::newLine; |
140 |
| - |
141 |
| - juce::Logger::writeToLog (info); |
142 |
| - } |
143 |
| - |
144 | 95 | //==============================================================================
|
145 | 96 | /** */
|
146 | 97 | inline bool operator== (const CorsairDeviceInfo& lhs, const CorsairDeviceInfo& rhs)
|
|
159 | 110 | return ! operator== (lhs, rhs);
|
160 | 111 | }
|
161 | 112 |
|
| 113 | + //============================================================================== |
162 | 114 | /** */
|
163 | 115 | inline juce::Colour toColour (const CorsairLedColor& clc)
|
164 | 116 | {
|
|
177 | 129 | return c;
|
178 | 130 | }
|
179 | 131 |
|
| 132 | + //============================================================================== |
| 133 | + /** */ |
| 134 | + class iCUESDKSession final |
| 135 | + { |
| 136 | + public: |
| 137 | + /** */ |
| 138 | + iCUESDKSession() |
| 139 | + { |
| 140 | + juce::zerostruct (details); |
| 141 | + isValid (CorsairConnect (sessionStateChangeHandler, this)); |
| 142 | + } |
| 143 | + |
| 144 | + /** */ |
| 145 | + ~iCUESDKSession() |
| 146 | + { |
| 147 | + isValid (CorsairDisconnect()); |
| 148 | + } |
| 149 | + |
| 150 | + /** */ |
| 151 | + bool isConnected() const { return connected.load (std::memory_order_relaxed); } |
| 152 | + |
| 153 | + /** */ |
| 154 | + const CorsairSessionDetails& getDetails() const { return details; } |
| 155 | + |
| 156 | + //============================================================================== |
| 157 | + /** */ |
| 158 | + void logInfo() |
| 159 | + { |
| 160 | + juce::String info; |
| 161 | + info |
| 162 | + << juce::newLine |
| 163 | + << "--------------------------------------------------" << juce::newLine << juce::newLine |
| 164 | + << "=== Corsair iCUE SDK Information ===" << juce::newLine << juce::newLine |
| 165 | + << "clientVersion: " << toString (details.clientVersion) << juce::newLine |
| 166 | + << "serverVersion: " << toString (details.serverVersion) << juce::newLine |
| 167 | + << "serverHostVersion: " << toString (details.serverHostVersion) << juce::newLine |
| 168 | + << juce::newLine |
| 169 | + << "--------------------------------------------------" << juce::newLine; |
| 170 | + |
| 171 | + juce::Logger::writeToLog (info); |
| 172 | + } |
| 173 | + |
| 174 | + //============================================================================== |
| 175 | + /** */ |
| 176 | + static void sessionStateChangeHandler (void* sourcePtr, const CorsairSessionStateChanged* newSession) |
| 177 | + { |
| 178 | + if (auto* session = (iCUESDKSession*) sourcePtr) |
| 179 | + { |
| 180 | + session->connected = newSession != nullptr |
| 181 | + ? newSession->state == CSS_Connected |
| 182 | + : false; |
| 183 | + |
| 184 | + session->details = session->details; |
| 185 | + } |
| 186 | + } |
| 187 | + |
| 188 | + private: |
| 189 | + std::atomic<bool> connected { false }; |
| 190 | + CorsairSessionDetails details; |
| 191 | + |
| 192 | + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (iCUESDKSession) |
| 193 | + }; |
| 194 | + |
| 195 | + /** */ |
| 196 | + static juce::SharedResourcePointer<iCUESDKSession> globalSession; |
| 197 | + |
180 | 198 | //==============================================================================
|
181 | 199 | /**
|
182 | 200 | */
|
|
211 | 229 | return {};
|
212 | 230 | }
|
213 | 231 |
|
214 |
| - int numLEDs = device.ledCount; |
| 232 | + auto numLEDs = device.ledCount; |
215 | 233 | std::vector<CorsairLedPosition> ledIDs ((size_t) numLEDs);
|
216 | 234 | if (isValid (CorsairGetLedPositions (device.id, numLEDs, ledIDs.data(), &numLEDs)))
|
217 | 235 | return { ledIDs.data(), numLEDs };
|
|
0 commit comments