diff --git a/liaisonSerie/serial.c b/liaisonSerie/serial.c new file mode 100644 index 0000000..4f3c3b6 --- /dev/null +++ b/liaisonSerie/serial.c @@ -0,0 +1,55 @@ +/* + * Serial library + */ + +//// +// Include files +//// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "serial.h" + +//// +// Functions +//// + +// +// Open serial port device +// +int serialOpen(char *device,int mode){ +int flags=(mode==SERIAL_READ?O_RDONLY:(mode==SERIAL_WRITE?O_WRONLY:O_RDWR)); +int fd=open(device,flags|O_NOCTTY); +if(fd<0){ perror(device); exit(-1); } +return fd; +} + +// +// Serial port configuration +// +void serialConfig(int fd,int speed){ +struct termios new; +bzero(&new,sizeof(new)); +new.c_cflag=CLOCAL|CREAD|speed|CS8; +new.c_iflag=0; +new.c_oflag=0; +new.c_lflag=0; /* set input mode (non-canonical, no echo,...) */ +new.c_cc[VTIME]=0; /* inter-character timer unused */ +new.c_cc[VMIN]=1; /* blocking read until 1 char received */ +if(tcsetattr(fd,TCSANOW,&new)<0){ perror("serialInit.tcsetattr"); exit(-1); } +} + +// +// Serial port termination +// +void serialClose(int fd){ +close(fd); +} diff --git a/liaisonSerie/serial.h b/liaisonSerie/serial.h new file mode 100644 index 0000000..e7eac5b --- /dev/null +++ b/liaisonSerie/serial.h @@ -0,0 +1,18 @@ +/* + * Public definitions for serial library + */ + +//// +// Constants +//// + +#define SERIAL_READ 0 +#define SERIAL_WRITE 1 +#define SERIAL_BOTH 2 + +//// +// Public prototypes +//// +int serialOpen(char *device,int mode); +void serialConfig(int fd,int speed); +void serialClose(int fd); diff --git a/liaisonSerie/test.c b/liaisonSerie/test.c new file mode 100644 index 0000000..50bf655 --- /dev/null +++ b/liaisonSerie/test.c @@ -0,0 +1,40 @@ +/* + * Test on serial device + */ + +//// +// Include files +//// +#include +#include +#include +#include + +#include "serial.h" + +//// +// Constants +//// +#define SERIAL_DEVICE "/dev/ttyACM0" + +//// +// Global variables +//// + +//// +// Main function +//// + +int main(void){ +int c=0; +int sd=serialOpen(SERIAL_DEVICE,SERIAL_BOTH); +serialConfig(sd,B9600); +if(write(sd,&c,sizeof(char))!=1){ perror("main.write"); exit(-1); } +int i; +for(i=0;i<8;i++){ + if(read(sd,&c,sizeof(char))!=1){ perror("main.read"); exit(-1); } + printf("%02x\n",c); + } +serialClose(sd); +exit(0); +} diff --git a/liaisonSerie/test.c~ b/liaisonSerie/test.c~ new file mode 100644 index 0000000..50bf655 --- /dev/null +++ b/liaisonSerie/test.c~ @@ -0,0 +1,40 @@ +/* + * Test on serial device + */ + +//// +// Include files +//// +#include +#include +#include +#include + +#include "serial.h" + +//// +// Constants +//// +#define SERIAL_DEVICE "/dev/ttyACM0" + +//// +// Global variables +//// + +//// +// Main function +//// + +int main(void){ +int c=0; +int sd=serialOpen(SERIAL_DEVICE,SERIAL_BOTH); +serialConfig(sd,B9600); +if(write(sd,&c,sizeof(char))!=1){ perror("main.write"); exit(-1); } +int i; +for(i=0;i<8;i++){ + if(read(sd,&c,sizeof(char))!=1){ perror("main.read"); exit(-1); } + printf("%02x\n",c); + } +serialClose(sd); +exit(0); +} diff --git a/pageHTML/Menu.css b/pageHTML/Menu.css index 85520d7..e3669d1 100644 --- a/pageHTML/Menu.css +++ b/pageHTML/Menu.css @@ -1,5 +1,4 @@ .introduction { - color: red; font-size: 40px; font-family: Verdana; font-style: italic; @@ -9,7 +8,7 @@ body { - color: black; /* Le texte de la page sera blanc */ + color: black; } .onoffswitch { diff --git a/pageHTML/Menu.html b/pageHTML/Menu.html index 07627d2..0aa6368 100644 --- a/pageHTML/Menu.html +++ b/pageHTML/Menu.html @@ -1,25 +1,44 @@ - - + + + + + Menu Veilleuse connectée - - -

Bienvenue sur le menu de votre veilleuse connectée

- - -

Etat de la veilleuse

-
- - +
+ diff --git a/pageHTML/intensite.html b/pageHTML/intensite.html deleted file mode 100644 index 4735525..0000000 --- a/pageHTML/intensite.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - Changement d'intensité - - - -

Changement d'intensite de votre veilleuse connectée

-
- - - 50 -
- -

Retour

- - diff --git a/pageHTML/mode.css b/pageHTML/mode.css deleted file mode 100644 index 1ca81e2..0000000 --- a/pageHTML/mode.css +++ /dev/null @@ -1,45 +0,0 @@ -.onoffswitch { - position: relative; width: 138px; - -webkit-user-select:none; -moz-user-select:none; -ms-user-select: none; -} -.onoffswitch-checkbox { - display: none; -} -.onoffswitch-label { - display: block; overflow: hidden; cursor: pointer; - border: 2px solid #999999; border-radius: 19px; -} -.onoffswitch-inner { - display: block; width: 200%; margin-left: -100%; - transition: margin 0.3s ease-in 0s; -} -.onoffswitch-inner:before, .onoffswitch-inner:after { - display: block; float: left; width: 50%; height: 34px; padding: 0; line-height: 34px; - font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold; - box-sizing: border-box; -} -.onoffswitch-inner:before { - content: "Automatique"; - padding-left: 10px; - background-color: #30A9C7; color: #FFFFFF; -} -.onoffswitch-inner:after { - content: "Manuel"; - padding-right: 10px; - background-color: #EEEEEE; color: #999999; - text-align: right; -} -.onoffswitch-switch { - display: block; width: 23px; margin: 5.5px; - background: #FFFFFF; - position: absolute; top: 0; bottom: 0; - right: 100px; - border: 2px solid #999999; border-radius: 19px; - transition: all 0.3s ease-in 0s; -} -.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner { - margin-left: 0; -} -.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch { - right: 0px; -} \ No newline at end of file diff --git a/pageHTML/mode.html b/pageHTML/mode.html deleted file mode 100644 index dd0a351..0000000 --- a/pageHTML/mode.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - Changement de mode - - -

Changement de mode de votre veilleuse connectée

-
- - -
- -

Retour

- - diff --git a/serveur/serveur b/serveur/serveur new file mode 100755 index 0000000..65e9014 Binary files /dev/null and b/serveur/serveur differ diff --git a/serveur/serveur.c b/serveur/serveur.c index d19ab03..e23b39c 100644 --- a/serveur/serveur.c +++ b/serveur/serveur.c @@ -7,80 +7,81 @@ #define WAIT_DELAY 50 static int callback_http( - struct libwebsocket_context *this, -struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, -void *user,void *in,size_t len) + struct libwebsocket_context *this, + struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, + void *user,void *in,size_t len) { -return 0; + return 0; } static int callback_my( - struct libwebsocket_context * this, -struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, -void *user,void *in,size_t len) + struct libwebsocket_context * this, + struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, + void *user,void *in,size_t len) { -static char *message=NULL; -static int msize=0; -switch(reason){ -case LWS_CALLBACK_ESTABLISHED: - printf("connection established\n"); -message=NULL; -// Declenchement d'un prochain envoi au navigateur -libwebsocket_callback_on_writable(this,wsi); -break; -case LWS_CALLBACK_RECEIVE: -// Ici sont traites les messages envoyes par le navigateur - printf("received data: %s\n",(char *)in); -message=malloc(len+LWS_SEND_BUFFER_PRE_PADDING+LWS_SEND_BUFFER_POST_PADDING); -if(message==NULL){ perror("callback_my.malloc"); exit(EXIT_FAILURE); } -memcpy(message+LWS_SEND_BUFFER_PRE_PADDING,in,len); -// Declenchement d'un prochain envoi au navigateur -msize=len; -libwebsocket_callback_on_writable(this,wsi); -break; -case LWS_CALLBACK_SERVER_WRITEABLE: -// Ici sont envoyes les messages au navigateur -if(message!=NULL){ -char *out=message+LWS_SEND_BUFFER_PRE_PADDING; -libwebsocket_write(wsi,(unsigned char *)out,msize,LWS_WRITE_TEXT); -free(message); -message=NULL; -} -break; -default: -break; -} -return 0; + static char *message=NULL; + static int msize=0; + switch(reason){ + case LWS_CALLBACK_ESTABLISHED: + printf("connection established\n"); + message=NULL; + // Declenchement d'un prochain envoi au navigateur + libwebsocket_callback_on_writable(this,wsi); + break; + case LWS_CALLBACK_RECEIVE: + // Ici sont traites les messages envoyes par le navigateur + printf("received data: %s\n",(char *)in); + message=malloc(len+LWS_SEND_BUFFER_PRE_PADDING+LWS_SEND_BUFFER_POST_PADDING); + if(message==NULL){ perror("callback_my.malloc"); exit(EXIT_FAILURE); } + memcpy(message+LWS_SEND_BUFFER_PRE_PADDING,in,len); + // Declenchement d'un prochain envoi au navigateur + msize=len; + libwebsocket_callback_on_writable(this,wsi); + break; + case LWS_CALLBACK_SERVER_WRITEABLE: + // Ici sont envoyes les messages au navigateur + if(message!=NULL){ + char *out=message+LWS_SEND_BUFFER_PRE_PADDING; + libwebsocket_write(wsi,(unsigned char *)out,msize,LWS_WRITE_TEXT); + free(message); + message=NULL; + } + break; + default: + break; + } + return 0; } static struct libwebsocket_protocols protocols[] = { - { - "http-only", // name - callback_http, // callback - 0, // data size - 0 // maximum frame size - }, - {"myprotocol",callback_my,0,MAX_FRAME_SIZE}, - {NULL,NULL,0,0} + { + "http-only", // name + callback_http, // callback + 0, // data size + 0 // maximum frame size + }, + {"myprotocol",callback_my,0,MAX_FRAME_SIZE}, + {NULL,NULL,0,0} }; int main(void) { - int port=9000; - struct lws_context_creation_info info; - memset(&info,0,sizeof info); - info.port=port; - info.protocols=protocols; - info.gid=-1; - info.uid=-1; - struct libwebsocket_context *context=libwebsocket_create_context(&info); - if(context==NULL){ - fprintf(stderr, "libwebsocket init failed\n"); - return -1; - } - printf("starting server...\n"); - while(1){ - libwebsocket_service(context,WAIT_DELAY); - } - libwebsocket_context_destroy(context); - return 0; -} \ No newline at end of file + //port du serveur + int port=9000; + struct lws_context_creation_info info; + memset(&info,0,sizeof info); + info.port=port; + info.protocols=protocols; + info.gid=-1; + info.uid=-1; + struct libwebsocket_context *context=libwebsocket_create_context(&info); + if(context==NULL){ + fprintf(stderr, "libwebsocket init failed\n"); + return -1; + } + printf("starting server...\n"); + while(1){ + libwebsocket_service(context,WAIT_DELAY); + } + libwebsocket_context_destroy(context); + return 0; +} -- libgit2 0.21.2