Replace Sleep() by std:🧵:sleep_for()

This commit is contained in:
Térence Clastres 2020-06-20 15:50:07 +02:00 committed by Adam Honse
parent 60baf6d05f
commit b79ff124e6
24 changed files with 80 additions and 232 deletions

View file

@ -14,16 +14,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
/*-------------------------------------------------------------*\ /*-------------------------------------------------------------*\
| This list contains the available I2C addresses for Aura GPUs | | This list contains the available I2C addresses for Aura GPUs |
@ -88,7 +79,7 @@ void DetectAuraGPUControllers(std::vector<i2c_smbus_interface*> &busses, std::ve
rgb_controllers.push_back(new_controller); rgb_controllers.push_back(new_controller);
} }
Sleep(1); std::this_thread::sleep_for(1ms);
} }
} }
} /* DetectAuraGPUControllers() */ } /* DetectAuraGPUControllers() */

View file

@ -6,16 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
/*----------------------------------------------------------------------*\ /*----------------------------------------------------------------------*\
| This list contains the available SMBus addresses for mapping Aura RAM | | This list contains the available SMBus addresses for mapping Aura RAM |
@ -178,7 +169,7 @@ void DetectAuraSMBusControllers(std::vector<i2c_smbus_interface*> &busses, std::
rgb_controllers.push_back(new_controller); rgb_controllers.push_back(new_controller);
} }
Sleep(1); std::this_thread::sleep_for(1ms);
} }
// Add Aura-enabled motherboard controllers // Add Aura-enabled motherboard controllers
@ -191,7 +182,7 @@ void DetectAuraSMBusControllers(std::vector<i2c_smbus_interface*> &busses, std::
rgb_controllers.push_back(new_controller); rgb_controllers.push_back(new_controller);
} }
Sleep(1); std::this_thread::sleep_for(1ms);
} }
} }

View file

@ -28,16 +28,7 @@
#define THREADRETURN return(NULL); #define THREADRETURN return(NULL);
#endif #endif
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
THREAD keepalive_thread(void *param) THREAD keepalive_thread(void *param)
{ {
@ -75,7 +66,7 @@ void CorsairLightingNodeController::KeepaliveThread()
while(1) while(1)
{ {
SendCommit(); SendCommit();
Sleep(5000); std::this_thread::sleep_for(5s);
} }
} }

View file

@ -11,16 +11,7 @@
#include <cstring> #include <cstring>
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
static unsigned int keys[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0x11, 0x12, static unsigned int keys[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0C, 0x0D, 0x0E, 0x0F, 0x11, 0x12,
0x14, 0x15, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x24, 0x25, 0x26, 0x14, 0x15, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x24, 0x25, 0x26,
@ -44,7 +35,7 @@ static void send_usb_msg(hid_device* dev, char * data_pkt)
int bytes = hid_send_feature_report(dev, (unsigned char *)usb_pkt, 65); int bytes = hid_send_feature_report(dev, (unsigned char *)usb_pkt, 65);
bytes++; bytes++;
Sleep(2); std::this_thread::sleep_for(1ms);
} }
CorsairPeripheralController::CorsairPeripheralController(hid_device* dev_handle) CorsairPeripheralController::CorsairPeripheralController(hid_device* dev_handle)

View file

@ -10,16 +10,7 @@
#include "CorsairVengeanceProController.h" #include "CorsairVengeanceProController.h"
#include <cstring> #include <cstring>
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
CorsairVengeanceProController::CorsairVengeanceProController(i2c_smbus_interface* bus, corsair_dev_id dev) CorsairVengeanceProController::CorsairVengeanceProController(i2c_smbus_interface* bus, corsair_dev_id dev)
{ {
@ -89,9 +80,9 @@ void CorsairVengeanceProController::SetLEDColor(unsigned int led, unsigned char
void CorsairVengeanceProController::ApplyColors() void CorsairVengeanceProController::ApplyColors()
{ {
bus->i2c_smbus_write_byte_data(dev, 0x26, 0x02); bus->i2c_smbus_write_byte_data(dev, 0x26, 0x02);
Sleep(1); std::this_thread::sleep_for(1ms);
bus->i2c_smbus_write_byte_data(dev, 0x21, 0x00); bus->i2c_smbus_write_byte_data(dev, 0x21, 0x00);
Sleep(1); std::this_thread::sleep_for(1ms);
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
{ {
@ -119,9 +110,9 @@ void CorsairVengeanceProController::SetEffect(unsigned char mode,
effect_mode = mode; effect_mode = mode;
bus->i2c_smbus_write_byte_data(dev, 0x26, 0x01); bus->i2c_smbus_write_byte_data(dev, 0x26, 0x01);
Sleep(1); std::this_thread::sleep_for(1ms);
bus->i2c_smbus_write_byte_data(dev, 0x21, 0x00); bus->i2c_smbus_write_byte_data(dev, 0x21, 0x00);
Sleep(1); std::this_thread::sleep_for(1ms);
unsigned char random_byte; unsigned char random_byte;
@ -165,7 +156,7 @@ bool CorsairVengeanceProController::WaitReady()
while (bus->i2c_smbus_read_byte_data(dev, 0x41) != 0x00) while (bus->i2c_smbus_read_byte_data(dev, 0x41) != 0x00)
{ {
i++; i++;
Sleep(1); std::this_thread::sleep_for(1ms);
} }
return false; return false;

View file

@ -6,16 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
/******************************************************************************************\ /******************************************************************************************\
* * * *
@ -50,7 +41,7 @@ bool TestForCorsairVengeanceProController(i2c_smbus_interface* bus, unsigned cha
} }
} }
Sleep(10); std::this_thread::sleep_for(10ms);
return(pass); return(pass);

View file

@ -10,16 +10,7 @@
#include "GloriousModelOController.h" #include "GloriousModelOController.h"
#include <cstring> #include <cstring>
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
GloriousModelOController::GloriousModelOController(hid_device* dev_handle) GloriousModelOController::GloriousModelOController(hid_device* dev_handle)
{ {
@ -139,7 +130,7 @@ void GloriousModelOController::SetLEDColor(RGBColor* color_buf)
*/ */
hid_send_feature_report(dev, usb_buf, sizeof(usb_buf)); hid_send_feature_report(dev, usb_buf, sizeof(usb_buf));
Sleep(1); std::this_thread::sleep_for(1ms);
} }
void GloriousModelOController::SetMode(unsigned char mode, void GloriousModelOController::SetMode(unsigned char mode,
@ -283,5 +274,5 @@ void GloriousModelOController::SetMode(unsigned char mode,
} }
hid_send_feature_report(dev, usb_buf, sizeof(usb_buf)); hid_send_feature_report(dev, usb_buf, sizeof(usb_buf));
Sleep(1); std::this_thread::sleep_for(1ms);
} }

View file

@ -11,16 +11,7 @@
#include <string> #include <string>
#include <cstring> #include <cstring>
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
HuePlusController::HuePlusController() HuePlusController::HuePlusController()
{ {
@ -64,7 +55,7 @@ unsigned int HuePlusController::GetLEDsOnChannel(unsigned int channel)
serialport->serial_write((char *)serial_buf, 2); serialport->serial_write((char *)serial_buf, 2);
serialport->serial_flush_tx(); serialport->serial_flush_tx();
Sleep(50); std::this_thread::sleep_for(50ms);
int bytes_read = serialport->serial_read((char *)serial_buf, 5); int bytes_read = serialport->serial_read((char *)serial_buf, 5);
@ -244,5 +235,5 @@ void HuePlusController::SendPacket
/*-----------------------------------------------------*\ /*-----------------------------------------------------*\
| Delay to allow Hue+ device to ready for next packet | | Delay to allow Hue+ device to ready for next packet |
\*-----------------------------------------------------*/ \*-----------------------------------------------------*/
Sleep(20); std::this_thread::sleep_for(20ms);
} }

View file

@ -6,16 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
/******************************************************************************************\ /******************************************************************************************\
* * * *
@ -76,7 +67,7 @@ void DetectHyperXDRAMControllers(std::vector<i2c_smbus_interface*> &busses, std:
{ {
busses[bus]->i2c_smbus_write_byte_data(0x37, 0x00, 0xFF); busses[bus]->i2c_smbus_write_byte_data(0x37, 0x00, 0xFF);
Sleep(1); std::this_thread::sleep_for(1ms);
for(int slot_addr = 0x50; slot_addr <= 0x57; slot_addr++) for(int slot_addr = 0x50; slot_addr <= 0x57; slot_addr++)
{ {
@ -89,7 +80,7 @@ void DetectHyperXDRAMControllers(std::vector<i2c_smbus_interface*> &busses, std:
slots_valid |= (1 << (slot_addr - 0x50)); slots_valid |= (1 << (slot_addr - 0x50));
} }
Sleep(1); std::this_thread::sleep_for(1ms);
} }
if(slots_valid != 0) if(slots_valid != 0)

View file

@ -11,17 +11,7 @@
#include <cstring> #include <cstring>
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
static unsigned int keys[] = {0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, static unsigned int keys[] = {0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
0x15, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1D, 0x1E, 0x20, 0x21, 0x22, 0x23, 0x24, 0x15, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1D, 0x1E, 0x20, 0x21, 0x22, 0x23, 0x24,
@ -107,7 +97,7 @@ void HyperXKeyboardController::SetMode
mode_colors[8] mode_colors[8]
); );
Sleep(100); std::this_thread::sleep_for(100ms);
} }
void HyperXKeyboardController::SetLEDsDirect(std::vector<RGBColor> colors) void HyperXKeyboardController::SetLEDsDirect(std::vector<RGBColor> colors)
@ -137,7 +127,7 @@ void HyperXKeyboardController::SetLEDsDirect(std::vector<RGBColor> colors)
red_color_data red_color_data
); );
Sleep(5); std::this_thread::sleep_for(5ms);
SendDirect SendDirect
( (
@ -145,7 +135,7 @@ void HyperXKeyboardController::SetLEDsDirect(std::vector<RGBColor> colors)
grn_color_data grn_color_data
); );
Sleep(5); std::this_thread::sleep_for(5ms);
SendDirect SendDirect
( (
@ -153,7 +143,7 @@ void HyperXKeyboardController::SetLEDsDirect(std::vector<RGBColor> colors)
blu_color_data blu_color_data
); );
Sleep(5); std::this_thread::sleep_for(5ms);
SendDirectExtended SendDirectExtended
( (
@ -189,7 +179,7 @@ void HyperXKeyboardController::SetLEDs(std::vector<RGBColor> colors)
red_color_data red_color_data
); );
Sleep(5); std::this_thread::sleep_for(5ms);
SendColor SendColor
( (
@ -198,7 +188,7 @@ void HyperXKeyboardController::SetLEDs(std::vector<RGBColor> colors)
grn_color_data grn_color_data
); );
Sleep(5); std::this_thread::sleep_for(5ms);
SendColor SendColor
( (
@ -207,7 +197,7 @@ void HyperXKeyboardController::SetLEDs(std::vector<RGBColor> colors)
blu_color_data blu_color_data
); );
Sleep(5); std::this_thread::sleep_for(5ms);
SendExtendedColor SendExtendedColor
( (

View file

@ -6,16 +6,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
/******************************************************************************************\ /******************************************************************************************\
* * * *
@ -44,13 +35,13 @@ void DetectPatriotViperControllers(std::vector<i2c_smbus_interface*> &busses, st
// Tests SPD addresses in order: 0x00, 0x40, 0x41, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68 // Tests SPD addresses in order: 0x00, 0x40, 0x41, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68
busses[bus]->i2c_smbus_write_byte_data(0x36, 0x00, 0xFF); busses[bus]->i2c_smbus_write_byte_data(0x36, 0x00, 0xFF);
Sleep(1); std::this_thread::sleep_for(1ms);
if(busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x00) == 0x23) if(busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x00) == 0x23)
{ {
busses[bus]->i2c_smbus_write_byte_data(0x37, 0x00, 0xFF); busses[bus]->i2c_smbus_write_byte_data(0x37, 0x00, 0xFF);
Sleep(1); std::this_thread::sleep_for(1ms);
if((busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x40) == 0x85) if((busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x40) == 0x85)
&&(busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x41) == 0x02) &&(busses[bus]->i2c_smbus_read_byte_data(slot_addr, 0x41) == 0x02)
@ -67,7 +58,7 @@ void DetectPatriotViperControllers(std::vector<i2c_smbus_interface*> &busses, st
} }
} }
Sleep(1); std::this_thread::sleep_for(1ms);
} }
if(slots_valid != 0) if(slots_valid != 0)

View file

@ -11,16 +11,7 @@
#include <cstring> #include <cstring>
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
static unsigned int keys[] = {0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x15, static unsigned int keys[] = {0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x15,
0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23,
@ -57,7 +48,7 @@ void PoseidonZRGBController::SetMode(unsigned char mode, unsigned char direction
active_speed active_speed
); );
Sleep(200); std::this_thread::sleep_for(200ms);
} }
void PoseidonZRGBController::SetLEDsDirect(std::vector<RGBColor> colors) void PoseidonZRGBController::SetLEDsDirect(std::vector<RGBColor> colors)
@ -107,7 +98,7 @@ void PoseidonZRGBController::SetLEDsDirect(std::vector<RGBColor> colors)
\*-----------------------------------------------------*/ \*-----------------------------------------------------*/
hid_send_feature_report(dev, red_grn_buf, 264); hid_send_feature_report(dev, red_grn_buf, 264);
Sleep(5); std::this_thread::sleep_for(5ms);
hid_send_feature_report(dev, blu_buf, 264); hid_send_feature_report(dev, blu_buf, 264);
} }
@ -132,7 +123,7 @@ void PoseidonZRGBController::SetLEDs(std::vector<RGBColor> colors)
red_color_data red_color_data
); );
Sleep(10); std::this_thread::sleep_for(10ms);
SendColor SendColor
( (
@ -141,7 +132,7 @@ void PoseidonZRGBController::SetLEDs(std::vector<RGBColor> colors)
grn_color_data grn_color_data
); );
Sleep(10); std::this_thread::sleep_for(10ms);
SendColor SendColor
( (
@ -150,7 +141,7 @@ void PoseidonZRGBController::SetLEDs(std::vector<RGBColor> colors)
blu_color_data blu_color_data
); );
Sleep(10); std::this_thread::sleep_for(10ms);
SendControl SendControl
( (

View file

@ -18,22 +18,14 @@
#ifdef __APPLE__ #ifdef __APPLE__
#include <unistd.h> #include <unistd.h>
#define MSG_NOSIGNAL 0 #define MSG_NOSIGNAL 0
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif #endif
#ifdef __linux__ #ifdef __linux__
#include <unistd.h> #include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif #endif
using namespace std::chrono_literals;
NetworkClient::NetworkClient(std::vector<RGBController *>& control) : controllers(control) NetworkClient::NetworkClient(std::vector<RGBController *>& control) : controllers(control)
{ {
strcpy(port_ip, "127.0.0.1"); strcpy(port_ip, "127.0.0.1");
@ -183,7 +175,7 @@ void NetworkClient::ConnectionThreadFunction()
server_controller_count = 0; server_controller_count = 0;
//Wait for server to connect //Wait for server to connect
Sleep(100); std::this_thread::sleep_for(100ms);
//Once server is connected, send client string //Once server is connected, send client string
SendData_ClientString(); SendData_ClientString();
@ -194,7 +186,7 @@ void NetworkClient::ConnectionThreadFunction()
//Wait for server controller count //Wait for server controller count
while(server_controller_count == 0) while(server_controller_count == 0)
{ {
Sleep(100); std::this_thread::sleep_for(100ms);
} }
printf("Client: Received controller count from server: %d\r\n", server_controller_count); printf("Client: Received controller count from server: %d\r\n", server_controller_count);
@ -209,7 +201,7 @@ void NetworkClient::ConnectionThreadFunction()
//Wait until controller is received //Wait until controller is received
while(server_controllers.size() == requested_controllers) while(server_controllers.size() == requested_controllers)
{ {
Sleep(100); std::this_thread::sleep_for(100ms);
} }
requested_controllers++; requested_controllers++;
@ -230,7 +222,7 @@ void NetworkClient::ConnectionThreadFunction()
ClientInfoChanged(); ClientInfoChanged();
} }
Sleep(1000); std::this_thread::sleep_for(1s);
} }
} }

View file

@ -28,11 +28,6 @@ const char yes = 1;
#include <Windows.h> #include <Windows.h>
#else #else
#include <unistd.h> #include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif #endif
NetworkServer::NetworkServer(std::vector<RGBController *>& control) : controllers(control) NetworkServer::NetworkServer(std::vector<RGBController *>& control) : controllers(control)

View file

@ -12,6 +12,7 @@
#include <mutex> #include <mutex>
#include <thread> #include <thread>
#include <chrono>
#pragma once #pragma once

View file

@ -1,16 +1,7 @@
#include "RGBController.h" #include "RGBController.h"
#include <cstring> #include <cstring>
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
RGBController::RGBController() RGBController::RGBController()
{ {
@ -1335,7 +1326,7 @@ void RGBController::DeviceCallThreadFunction()
} }
else else
{ {
Sleep(1); std::this_thread::sleep_for(1ms);
} }
} }
} }

View file

@ -13,6 +13,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <thread> #include <thread>
#include <chrono>
typedef unsigned int RGBColor; typedef unsigned int RGBColor;

View file

@ -26,16 +26,7 @@
#define THREADRETURN return(NULL); #define THREADRETURN return(NULL);
#endif #endif
#ifdef WIN32 using namespace std::chrono_literals;
#include <Windows.h>
#else
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
THREAD keepalive_thread(void *param) THREAD keepalive_thread(void *param)
{ {
@ -375,6 +366,6 @@ void RGBController_HyperXKeyboard::KeepaliveThread()
UpdateLEDs(); UpdateLEDs();
} }
} }
Sleep(10); std::this_thread::sleep_for(10ms);;
} }
} }

View file

@ -12,13 +12,11 @@
#include <fstream> #include <fstream>
#include <unistd.h> #include <unistd.h>
static void Sleep(unsigned int milliseconds) using namespace std::chrono_literals;
{
usleep(1000 * milliseconds);
}
void RGBController_OpenRazer::DeviceUpdateLEDs() void RGBController_OpenRazer::DeviceUpdateLEDs()
{ {
switch(matrix_type) switch(matrix_type)
{ {
case RAZER_TYPE_MATRIX_FRAME: case RAZER_TYPE_MATRIX_FRAME:
@ -79,7 +77,7 @@ void RGBController_OpenRazer::DeviceUpdateLEDs()
delete[] output_array; delete[] output_array;
Sleep(1); std::this_thread::sleep_for(1ms);
} }
if(matrix_type == RAZER_TYPE_MATRIX_FRAME) if(matrix_type == RAZER_TYPE_MATRIX_FRAME)
@ -550,7 +548,7 @@ void RGBController_OpenRazer::UpdateMode()
break; break;
} }
Sleep(20); std::this_thread::sleep_for(20ms);
} }
break; break;

View file

@ -16,6 +16,8 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/hid.h> #include <linux/hid.h>
using namespace std::chrono_literals;
void RGBController_OpenRazer::DeviceUpdateLEDs() void RGBController_OpenRazer::DeviceUpdateLEDs()
{ {
switch(matrix_type) switch(matrix_type)
@ -75,7 +77,7 @@ void RGBController_OpenRazer::DeviceUpdateLEDs()
delete[] output_array; delete[] output_array;
Sleep(1); std::this_thread::sleep_for(1ms);
} }
if(matrix_type == RAZER_TYPE_MATRIX_FRAME) if(matrix_type == RAZER_TYPE_MATRIX_FRAME)
@ -485,7 +487,7 @@ void RGBController_OpenRazer::UpdateMode()
break; break;
} }
Sleep(20); std::this_thread::sleep_for(20ms);
} }
break; break;

28
cli.cpp
View file

@ -9,29 +9,15 @@
#include "i2c_smbus.h" #include "i2c_smbus.h"
#include "NetworkServer.h" #include "NetworkServer.h"
/*-------------------------------------------------------------*\
| Quirk for MSVC; which doesn't support this case-insensitive |
| function |
\*-------------------------------------------------------------*/
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #define strcasecmp strcmpi
/* swy: quirk for MSVC; which doesn't support this case-insensitive function */
#define strcasecmp strcmpi
#endif #endif
#ifdef __APPLE__ using namespace std::chrono_literals;
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
#ifdef __linux__
#include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif
static std::vector<RGBController*> rgb_controllers; static std::vector<RGBController*> rgb_controllers;
static ProfileManager* profile_manager; static ProfileManager* profile_manager;
@ -943,7 +929,7 @@ void WaitWhileServerOnline(NetworkServer* srv)
{ {
while (network_server->GetOnline()) while (network_server->GetOnline())
{ {
Sleep(1000); std::this_thread::sleep_for(1s);
}; };
} }

View file

@ -13,11 +13,6 @@
#include <Windows.h> #include <Windows.h>
#else #else
#include <unistd.h> #include <unistd.h>
static void Sleep(unsigned int milliseconds)
{
usleep(1000 * milliseconds);
}
#endif #endif
i2c_smbus_interface::i2c_smbus_interface() i2c_smbus_interface::i2c_smbus_interface()

View file

@ -12,6 +12,8 @@
#include <Windows.h> #include <Windows.h>
#include "inpout32.h" #include "inpout32.h"
using namespace std::chrono_literals;
/* Return negative errno on error. */ /* Return negative errno on error. */
s32 i2c_smbus_i801::i801_access(u16 addr, char read_write, u8 command, int size, i2c_smbus_data *data) s32 i2c_smbus_i801::i801_access(u16 addr, char read_write, u8 command, int size, i2c_smbus_data *data)
{ {
@ -299,7 +301,7 @@ int i2c_smbus_i801::i801_check_post(int status)
/* try to stop the current command */ /* try to stop the current command */
Out32(SMBHSTCNT, Inp32(SMBHSTCNT) | SMBHSTCNT_KILL); Out32(SMBHSTCNT, Inp32(SMBHSTCNT) | SMBHSTCNT_KILL);
//usleep_range(1000, 2000); //usleep_range(1000, 2000);
Sleep(1); std::this_thread::sleep_for(1ms);
Out32(SMBHSTCNT, Inp32(SMBHSTCNT) & (~SMBHSTCNT_KILL)); Out32(SMBHSTCNT, Inp32(SMBHSTCNT) & (~SMBHSTCNT_KILL));
Out32(SMBHSTSTS, STATUS_FLAGS); Out32(SMBHSTSTS, STATUS_FLAGS);
@ -437,13 +439,14 @@ int i2c_smbus_i801::i801_transaction(int xact)
/* Wait for either BYTE_DONE or an error flag being set */ /* Wait for either BYTE_DONE or an error flag being set */
int i2c_smbus_i801::i801_wait_byte_done() int i2c_smbus_i801::i801_wait_byte_done()
{ {
int timeout = 0; int timeout = 0;
int status; int status;
/* We will always wait for a fraction of a second! */ /* We will always wait for a fraction of a second! */
do do
{ {
Sleep(1); std::this_thread::sleep_for(1ms);
//usleep_range(250, 500); //usleep_range(250, 500);
status = Inp32(SMBHSTSTS); status = Inp32(SMBHSTSTS);
} while (!(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE)) && (timeout++ < MAX_RETRIES)); } while (!(status & (STATUS_ERROR_FLAGS | SMBHSTSTS_BYTE_DONE)) && (timeout++ < MAX_RETRIES));

View file

@ -10,6 +10,8 @@
#include <Windows.h> #include <Windows.h>
#include "inpout32.h" #include "inpout32.h"
using namespace std::chrono_literals;
s32 i2c_smbus_nct6775::nct6775_access(u16 addr, char read_write, u8 command, int size, i2c_smbus_data *data) s32 i2c_smbus_nct6775::nct6775_access(u16 addr, char read_write, u8 command, int size, i2c_smbus_data *data)
{ {
int i, len, status, cnt; int i, len, status, cnt;
@ -115,7 +117,7 @@ s32 i2c_smbus_nct6775::nct6775_access(u16 addr, char read_write, u8 command, int
{ {
return -ETIMEDOUT; return -ETIMEDOUT;
} }
Sleep(1); std::this_thread::sleep_for(1ms);;
timeout++; timeout++;
} }
@ -154,7 +156,7 @@ s32 i2c_smbus_nct6775::nct6775_access(u16 addr, char read_write, u8 command, int
{ {
return -ETIMEDOUT; return -ETIMEDOUT;
} }
Sleep(1); std::this_thread::sleep_for(1ms);;
timeout++; timeout++;
} }