Initial commit
This commit is contained in:
parent
7d6a8fecbe
commit
f88c046ca7
23
lw12.c
23
lw12.c
|
@ -10,10 +10,6 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
//#include <netdb.h>
|
||||
|
||||
#include "lw12.h"
|
||||
|
||||
|
@ -45,22 +41,3 @@ int lw12_sendcmd(int sockfd, struct sockaddr_in *addr, char *cmd) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int sockfd = 0;
|
||||
struct sockaddr_in server_addr;
|
||||
|
||||
char serverip[] = "192.168.178.24";
|
||||
uint16_t serverport = 5000;
|
||||
|
||||
lw12_connect(&sockfd, &server_addr, serverport, serverip);
|
||||
lw12_sendcmd(sockfd, &server_addr, (char *)LIGHTS_ON);
|
||||
|
||||
usleep(2000000);
|
||||
|
||||
lw12_sendcmd(sockfd, &server_addr, (char *)LIGHTS_OFF);
|
||||
|
||||
close(sockfd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
13
lw12.h
13
lw12.h
|
@ -8,12 +8,21 @@
|
|||
#ifndef LW12_H
|
||||
#define LW12_H
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#define LW12_CMD_LENGTH 9
|
||||
|
||||
#define LIGHTS_ON "\x7e\x04\x04\x01\xff\xff\xff\x00\xef"
|
||||
#define LIGHTS_OFF "\x7e\x04\x04\x00\x00\x0f\xff\x00\xef"
|
||||
#define LIGHTS_INIT "\x7e\x07\x05\x03\xff\xbf\x40\x00\xef"
|
||||
#define LIGHTS_OFF "\x7e\x04\x04\x00\x00\x0f\x00\x00\xef"
|
||||
|
||||
// set lights "7e070503{red:02x}{green:02x}{blue:02x}00ef"
|
||||
#define LIGHT_COLOR "\x7\xe\x07\x05\x03\x00\x00\x00\x00\xef"
|
||||
#define LIGHT_COLOR "\x7e\x07\x05\x03\x00\x00\x00\x00\xef"
|
||||
|
||||
int lw12_connect(int *sockfd, struct sockaddr_in *addr, uint16_t port,
|
||||
char *hostname);
|
||||
int lw12_sendcmd(int sockfd, struct sockaddr_in *addr, char *cmd);
|
||||
|
||||
#endif /* !LW12_H */
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* lw12ctl.c
|
||||
* Copyright (C) 2017 jpk <jpk@thor>
|
||||
*
|
||||
* Distributed under terms of the MIT license.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "lw12.h"
|
||||
|
||||
int main() {
|
||||
int sockfd = 0;
|
||||
struct sockaddr_in server_addr;
|
||||
|
||||
char serverip[] = "192.168.178.24";
|
||||
uint16_t serverport = 5000;
|
||||
|
||||
lw12_connect(&sockfd, &server_addr, serverport, serverip);
|
||||
lw12_sendcmd(sockfd, &server_addr, (char *)LIGHTS_ON);
|
||||
lw12_sendcmd(sockfd, &server_addr, (char *)LIGHTS_INIT);
|
||||
|
||||
usleep(2000000);
|
||||
|
||||
lw12_sendcmd(sockfd, &server_addr, (char *)LIGHTS_OFF);
|
||||
|
||||
close(sockfd);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue