Skip to content

Commit

Permalink
Added examples for the SMC and Socket classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementDreptin committed Nov 6, 2022
1 parent 773a410 commit d60641c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/SMC.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# System Managment Controller (SMC)

Change the power LED behavior (the LED in the middle of the power button):
```C++
void Init()
{
// Play to boot animation where all 4 LEDs turn on and off then make the power LED blink
XexUtils::SMC::SetPowerLED(PowerLED_Blink, true);
}
```

Set the color of the 4 LEDs around the power button (the ones that turn on when controllers are connected):
```C++
void Init()
{
XexUtils::SMC::SetLEDColors(LEDColor_Off, LEDColor_Red, LEDColor_Green, LEDColor_Orange);
}
```
48 changes: 48 additions & 0 deletions examples/Socket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Socket

Connect to a server through insecure sockets and exchange data:
```C++
void Init()
{
HRESULT hr = S_OK;

// Create the socket
uint16_t port = 12345;
XexUtils::Socket socket("<ip_address>", port);

// Connect to the server
hr = socket.Connect();
if (FAILED(hr))
{
XexUtils::Log::Error("Couldn't connect to server");
return;
}

// Send a packet
const char packet[] = "hello world";
int bytesSent = socket.Send(packet, sizeof(packet));
if (bytesSent != sizeof(packet))
{
XexUtils::Log::Error("Not all packets were sent");
socket.Disconnect();
return;
}

// Wait for the server to process the request and send a response
Sleep(500);

// Receive the response
char buffer[4096] = { 0 };
int bytesReceived = socket.Receive(buffer, sizeof(buffer));
if (bytesReceive == -1)
{
XexUtils::Log::Error("Couldn't receive the server response");
socket.Disconnect();
return;
}

// Do something with what is inside buffer

socket.Disconnect();
}
```

0 comments on commit d60641c

Please sign in to comment.