Smart coffee machine with facial recognition and remote control

Dependencies:   Camera_LS_Y201 EthernetInterface EthernetNetIf HTTPClient SRF05 TextLCD mbed-rtos mbed-src

Files at this revision

API Documentation at this revision

Comitter:
projetmacintel
Date:
Wed Jan 15 11:09:52 2014 +0000
Commit message:
dep?t final PAO Macintel

Changed in this revision

Camera_LS_Y201_RTOS.lib Show annotated file Show diff for this revision Revisions of this file
Camera_LS_Y201_RTOS/Camera_LS_Y201.cpp Show annotated file Show diff for this revision Revisions of this file
Camera_LS_Y201_RTOS/Camera_LS_Y201.h Show annotated file Show diff for this revision Revisions of this file
Camera_LS_Y201_RTOS/SerialBuffered.cpp Show annotated file Show diff for this revision Revisions of this file
Camera_LS_Y201_RTOS/SerialBuffered.h Show annotated file Show diff for this revision Revisions of this file
EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
EthernetNetIf.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
SRF05.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
cafe.cpp Show annotated file Show diff for this revision Revisions of this file
cafe.h Show annotated file Show diff for this revision Revisions of this file
camera.cpp Show annotated file Show diff for this revision Revisions of this file
camera.h Show annotated file Show diff for this revision Revisions of this file
capteur_tasse.cpp Show annotated file Show diff for this revision Revisions of this file
capteur_tasse.h Show annotated file Show diff for this revision Revisions of this file
eau.cpp Show annotated file Show diff for this revision Revisions of this file
eau.h Show annotated file Show diff for this revision Revisions of this file
ecran_lcd.cpp Show annotated file Show diff for this revision Revisions of this file
ecran_lcd.h Show annotated file Show diff for this revision Revisions of this file
ethernet.cpp Show annotated file Show diff for this revision Revisions of this file
ethernet.h Show annotated file Show diff for this revision Revisions of this file
intelligence.cpp Show annotated file Show diff for this revision Revisions of this file
intelligence.h Show annotated file Show diff for this revision Revisions of this file
led.cpp Show annotated file Show diff for this revision Revisions of this file
led.h Show annotated file Show diff for this revision Revisions of this file
machine.cpp Show annotated file Show diff for this revision Revisions of this file
machine.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed-src.lib Show annotated file Show diff for this revision Revisions of this file
preferences.cpp Show annotated file Show diff for this revision Revisions of this file
preferences.h Show annotated file Show diff for this revision Revisions of this file
purge.cpp Show annotated file Show diff for this revision Revisions of this file
purge.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 43669f623d43 Camera_LS_Y201_RTOS.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Camera_LS_Y201_RTOS.lib	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/lndv3/code/Camera_LS_Y201/#043f4f40d1d0
diff -r 000000000000 -r 43669f623d43 Camera_LS_Y201_RTOS/Camera_LS_Y201.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Camera_LS_Y201_RTOS/Camera_LS_Y201.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,476 @@
+/**
+ * =============================================================================
+ * LS-Y201 device driver class (Version 0.0.1)
+ * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
+ *                      January 2010
+ * =============================================================================
+ * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * =============================================================================
+ */
+
+#include "Camera_LS_Y201.h"
+
+/**
+ * Create.
+ *
+ * @param tx Transmitter.
+ * @param rx Receiver.
+ */
+Camera_LS_Y201::Camera_LS_Y201(PinName tx, PinName rx) : serial(tx, rx) {
+    serial.baud(38400);
+    setImageSize(Camera_LS_Y201::ImageSize320x280);
+}
+
+/**
+ * Dispose.
+ */
+Camera_LS_Y201::~Camera_LS_Y201() {
+}
+
+/**
+ * Reset module.
+ *
+ * @return Error code.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::reset() {
+    uint8_t send[4] = {
+        0x56,
+        0x00,
+        0x26,
+        0x00
+    };
+    uint8_t recv[4];
+
+    waitIdle();
+    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
+        return SendError;
+    }
+    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
+        return RecvError;
+    }
+    if ((recv[0] == 0x76)
+            && (recv[1] == 0x00)
+            && (recv[2] == 0x26)
+            && (recv[3] == 0x00)) {
+        ErrorCode r = waitInitEnd();
+        if (r != NoError) {
+            return r;
+        }
+        wait(4);
+        return NoError;
+    } else {
+        return UnexpectedReply;
+    }
+}
+
+/**
+ * Set image size.
+ *
+ * @param is Image size.
+ * @return Error code.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::setImageSize(ImageSize is) {
+    uint8_t send[9] = {
+        0x56,
+        0x00,
+        0x31,
+        0x05,
+        0x04,
+        0x01,
+        0x00,
+        0x19,
+        0x00    // 0x11:320x240, 0x00:640x480, 0x22:160x120
+    };
+    uint8_t recv[5];
+    switch (is) {
+        case ImageSize160x120:
+            send[8] = 0x22;
+            break;
+        case ImageSize320x280:
+            send[8] = 0x11;
+            break;
+        case ImageSize640x480:
+            send[8] = 0x00;
+            break;
+        default:
+            return InvalidArguments;
+    }
+    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
+        return SendError;
+    }
+    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
+        return RecvError;
+    }
+    if ((recv[0] == 0x76)
+            && (recv[1] == 0x00)
+            && (recv[2] == 0x31)
+            && (recv[3] == 0x00)
+            && (recv[4] == 0x00)) {
+        wait(1);
+        return reset();
+    } else {
+        return UnexpectedReply;
+    }
+}
+
+/**
+ * Take picture.
+ *
+ * @return Error code.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::takePicture() {
+    uint8_t send[5] = {
+        0x56,
+        0x00,
+        0x36,
+        0x01,
+        0x00
+    };
+    uint8_t recv[5];
+
+    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
+        return SendError;
+    }
+    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
+        return RecvError;
+    }
+
+    if ((recv[0] == 0x76)
+            && (recv[1] == 0x00)
+            && (recv[2] == 0x36)
+            && (recv[3] == 0x00)
+            && (recv[4] == 0x00)) {
+        /*
+         * I think the camera need a time for operating.
+         * But there is no any comments on the documents.
+         */
+        wait_ms(100);
+        return NoError;
+    } else {
+        return UnexpectedReply;
+    }
+}
+
+/**
+ * Read jpeg file size.
+ *
+ * @param fileSize File size.
+ * @return Error code.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::readJpegFileSize(int *fileSize) {
+    uint8_t send[5] = {
+        0x56,
+        0x00,
+        0x34,
+        0x01,
+        0x00
+    };
+    uint8_t recv[9];
+
+    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
+        return SendError;
+    }
+    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
+        return RecvError;
+    }
+
+    if ((recv[0] == 0x76)
+            && (recv[1] == 0x00)
+            && (recv[2] == 0x34)
+            && (recv[3] == 0x00)
+            && (recv[4] == 0x04)
+            && (recv[5] == 0x00)
+            && (recv[6] == 0x00)) {
+        *fileSize = ((recv[7] & 0x00ff) << 8)
+                    | ((recv[8] & 0x00ff) << 0);
+        return NoError;
+    } else {
+        return UnexpectedReply;
+    }
+}
+
+/**
+ * Read jpeg file content.
+ *
+ * @param func A pointer to a call back function.
+ * @return Error code.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::readJpegFileContent(
+    void (*func)(int done, int total, uint8_t *buf, size_t siz, char *rep),
+    void (*sendSocket)(char *chaine, int taille_chaine, char *reponse, int longueur_reponse_max),
+    char *response
+) {
+    uint8_t send[16] = {
+        0x56,
+        0x00,
+        0x32,
+        0x0C,
+        0x00,
+        0x0A,
+        0x00,
+        0x00,
+        0x00, // MH
+        0x00, // ML
+        0x00,
+        0x00,
+        0x00, // KH
+        0x00, // KL
+        0x00, // XX
+        0x00  // XX
+    };
+    
+    // Doit etre inférieur au MSS du réseau. MTU = MSS + TCP/IP header
+    // généralement, MSS = 1460
+    int TAILLE_BUF = 1024;
+    
+    uint8_t body[TAILLE_BUF]; // Valeur par défaut 32
+    uint16_t m = 0; // Staring address.
+    uint16_t k = sizeof(body); // Packet size.
+    uint16_t x = 10;    // Interval time. XX XX * 0.01m[sec]
+    bool end = false;
+
+    /*
+     * Get the data size.
+     */
+    int siz_done = 0;
+    int siz_total = 0;
+    ErrorCode r = readJpegFileSize(&siz_total);
+    printf("\tBreizh size totale %d \r\n", siz_total);
+    
+    // Envoi de la taille au serveur
+    char requete[10];
+    sprintf(requete,"%d",siz_total);
+    printf("\tRequete %s \r\n\r", requete);
+    sendSocket(requete, sizeof(requete), response, 30); // Envoi de la taille de l'image. Réception de "TAILLE OK"
+    printf("\tReponse %s : %s\r\n\r", requete, response);     
+    
+    if (r != NoError) {
+        return r;
+    }
+
+    do {
+        send[8] = (m >> 8) & 0xff;
+        send[9] = (m >> 0) & 0xff;
+        send[12] = (k >> 8) & 0xff;
+        send[13] = (k >> 0) & 0xff;
+        send[14] = (x >> 8) & 0xff;
+        send[15] = (x >> 0) & 0xff;
+        /*
+         * Send a command.
+         */
+        if (!sendBytes(send, sizeof(send), 200 * 1000)) {
+            return SendError;
+        }
+        /*
+         * Read the header of the response.
+         */
+        uint8_t header[5];
+        if (!recvBytes(header, sizeof(header), 2 * 1000 * 1000)) {
+            return RecvError;
+        }
+        /*
+         * Check the response and fetch an image data.
+         */
+        if ((header[0] == 0x76)
+                && (header[1] == 0x00)
+                && (header[2] == 0x32)
+                && (header[3] == 0x00)
+                && (header[4] == 0x00)) {
+            if (!recvBytes(body, sizeof(body), 2 * 1000 * 1000)) {
+                return RecvError;
+            }
+            siz_done += sizeof(body);
+            if (func != NULL) {
+                if (siz_done > siz_total) {
+                    siz_done = siz_total;
+                }
+                func(siz_done, siz_total, body, sizeof(body), response);
+            }
+            for (int i = 1; i < sizeof(body); i++) {
+                if ((body[i - 1] == 0xFF) && (body[i - 0] == 0xD9)) {
+                    end = true;
+                }
+            }
+        } else {
+            return UnexpectedReply;
+        }
+        /*
+         * Read the footer of the response.
+         */
+        uint8_t footer[5];
+        if (!recvBytes(footer, sizeof(footer), 2 * 1000 * 1000)) {
+            return RecvError;
+        }
+
+        m += sizeof(body);
+    } while (!end);
+    
+    if(siz_total % TAILLE_BUF > 0) {
+        printf("\tBreizh siz_total non divisible par taille_buffer\r\n");
+    }
+    else {
+        printf("\tBreizh siz_total divisible par taille_buffer\r\n");
+    }
+    
+    return NoError;
+}
+
+/**
+ * Stop taking pictures.
+ *
+ * @return Error code.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::stopTakingPictures() {
+    uint8_t send[5] = {
+        0x56,
+        0x00,
+        0x36,
+        0x01,
+        0x03
+    };
+    uint8_t recv[5];
+
+    if (!sendBytes(send, sizeof(send), 200 * 1000)) {
+        return SendError;
+    }
+    if (!recvBytes(recv, sizeof(recv), 200 * 1000)) {
+        return RecvError;
+    }
+
+    if ((recv[0] == 0x76)
+            && (recv[1] == 0x00)
+            && (recv[2] == 0x36)
+            && (recv[3] == 0x00)
+            && (recv[4] == 0x00)) {
+        /*
+         * I think the camera need a time for operating.
+         * But there is no any comments on the documents.
+         */
+        wait_ms(100);
+        return NoError;
+    } else {
+        return UnexpectedReply;
+    }
+}
+
+/**
+ * Wait init end codes.
+ *
+ * @return True if the data sended.
+ */
+Camera_LS_Y201::ErrorCode Camera_LS_Y201::waitInitEnd() {
+    static const char *PWR_ON_MSG = "Init end\x0d\x0a";
+    for (int i = 0; i < strlen(PWR_ON_MSG); i++) {
+        static const int MAXCNT = 128;
+        int cnt = 0;
+        uint8_t c = 0x00;
+        do {
+            if (!recvBytes(&c, sizeof(c), 500 * 1000)) {
+                return Timeout;
+            }
+
+            /*
+             * What is the version of the camera.
+             * You can check the version with this code.
+             *
+             * VC0703 1.00
+             * 3o ctrl in
+             * Init end
+             */
+#if 0
+            printf("%c", c);
+#endif
+
+            cnt++;
+            if (MAXCNT < cnt) {
+                return UnexpectedReply;
+            }
+        } while (c != PWR_ON_MSG[i]);
+    }
+    return NoError;
+}
+
+/**
+ * Send bytes to camera module.
+ *
+ * @param buf Pointer to the data buffer.
+ * @param len Length of the data buffer.
+ *
+ * @return True if the data sended.
+ */
+bool Camera_LS_Y201::sendBytes(uint8_t *buf, size_t len, int timeout_us) {
+    for (uint32_t i = 0; i < (uint32_t)len; i++) {
+        int cnt = 0;
+        while (!serial.writeable()) {
+            wait_us(1);
+            cnt++;
+            if (timeout_us < cnt) {
+                return false;
+            }
+        }
+        serial.putc(buf[i]);
+    }
+    return true;
+}
+
+/**
+ * Receive bytes from camera module.
+ *
+ * @param buf Pointer to the data buffer.
+ * @param len Length of the data buffer.
+ *
+ * @return True if the data received.
+ */
+bool Camera_LS_Y201::recvBytes(uint8_t *buf, size_t len, int timeout_us) {
+    for (uint32_t i = 0; i < (uint32_t)len; i++) {
+        int cnt = 0;
+        while (!serial.readable()) {
+            wait_us(1);
+            cnt++;
+            if (timeout_us < cnt) {
+                return false;
+            }
+        }
+        buf[i] = serial.getc();
+    }
+    return true;
+}
+
+/**
+ * Wait received.
+ *
+ * @return True if the data received.
+ */
+bool Camera_LS_Y201::waitRecv() {
+    while (!serial.readable()) {
+    }
+    return true;
+}
+
+/**
+ * Wait idle state.
+ */
+bool Camera_LS_Y201::waitIdle() {
+    while (serial.readable()) {
+        serial.getc();
+    }
+    return true;
+}
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 Camera_LS_Y201_RTOS/Camera_LS_Y201.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Camera_LS_Y201_RTOS/Camera_LS_Y201.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,170 @@
+/**
+ * =============================================================================
+ * LS-Y201 device driver class (Version 0.0.1)
+ * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
+ *                      January 2010
+ * =============================================================================
+ * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * =============================================================================
+ */
+
+#ifndef LS_Y201_H
+#define LS_Y201_H
+
+#include "mbed.h"
+#include "SerialBuffered.h"
+
+/**
+ * Camera
+ */
+class Camera_LS_Y201 {
+public:
+
+    /**
+     * Create.
+     *
+     * @param tx Transmitter.
+     * @param rx Receiver.
+     */
+    Camera_LS_Y201(PinName tx, PinName rx);
+    
+    /**
+     * Dispose.
+     */
+    ~Camera_LS_Y201();
+    
+    /**
+     * Error code.
+     */
+    enum ErrorCode {
+        NoError = 0,
+        UnexpectedReply,
+        Timeout,
+        SendError,
+        RecvError,
+        InvalidArguments
+    };
+    
+    /**
+     * Image size.
+     */
+    enum ImageSize {
+        ImageSize160x120,   /**< 160x120. */
+        ImageSize320x280,   /**< 320x280. */
+        ImageSize640x480    /**< 640x480. */
+    };
+
+    /**
+     * Reset module.
+     *
+     * @return Error code.
+     */
+    ErrorCode reset();
+
+    /**
+     * Set image size.
+     *
+     * @param is Image size.
+     * @return Error code.
+     */
+    ErrorCode setImageSize(ImageSize is);
+
+    /**
+     * Take picture.
+     *
+     * @return Error code.
+     */
+    ErrorCode takePicture();
+
+    /**
+     * Read jpeg file size.
+     *
+     * @param fileSize File size.
+     * @return Error code.
+     */
+    ErrorCode readJpegFileSize(int *fileSize);
+
+    /**
+     * Read jpeg file content.
+     *
+     * @param func A pointer to a call back function.
+     * @return Error code.
+     */
+    ErrorCode readJpegFileContent(
+        void (*func)(int done, int total, uint8_t *buf, size_t siz, char *rep),
+        void (*sendSocket)(char *chaine, int taille_chaine, char *reponse, int longueur_reponse_max),
+        char *response
+    );
+
+    /**
+     * Stop taking pictures.
+     *
+     * @return Error code.
+     */
+    ErrorCode stopTakingPictures();
+
+private:
+    SerialBuffered serial;
+
+    /**
+     * Wait init end codes.
+     *
+     * @return Error code.
+     */
+    ErrorCode waitInitEnd();
+
+    /**
+     * Send bytes to camera module.
+     *
+     * @param buf Pointer to the data buffer.
+     * @param len Length of the data buffer.
+     *
+     * @return True if the data sended.
+     */
+    bool sendBytes(uint8_t *buf, size_t len, int timeout_us);
+
+    /**
+     * Receive bytes from camera module.
+     *
+     * @param buf Pointer to the data buffer.
+     * @param len Length of the data buffer.
+     *
+     * @return True if the data received.
+     */
+    bool recvBytes(uint8_t *buf, size_t len, int timeout_us);
+
+    /**
+     * Wait received.
+     *
+     * @return True if the data received.
+     */
+    bool waitRecv();
+
+    /**
+     * Wait idle state.
+     *
+     * @return True if it succeed.
+     */
+    bool waitIdle();
+
+};
+
+#endif
diff -r 000000000000 -r 43669f623d43 Camera_LS_Y201_RTOS/SerialBuffered.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Camera_LS_Y201_RTOS/SerialBuffered.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,128 @@
+/**
+ * =============================================================================
+ * LS-Y201 device driver class (Version 0.0.1)
+ * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
+ *                      January 2010
+ * =============================================================================
+ * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * =============================================================================
+ */
+
+#include <RawSerial.h>
+#include "mbed.h"
+#include "SerialBuffered.h"
+
+/**
+ * Create a buffered serial class.
+ *
+ * @param tx A pin for transmit.
+ * @param rx A pin for receive.
+ */
+SerialBuffered::SerialBuffered(PinName tx, PinName rx) : RawSerial(tx, rx) {
+    indexContentStart = 0;
+    indexContentEnd = 0;
+    timeout = 1;
+    attach(this, &SerialBuffered::handleInterrupt);
+}
+
+/**
+ * Destroy.
+ */
+SerialBuffered::~SerialBuffered() {
+}
+
+/**
+ * Set timeout for getc().
+ *
+ * @param ms milliseconds. (-1:Disable timeout)
+ */
+void SerialBuffered::setTimeout(int ms) {
+    timeout = ms;
+}
+
+/**
+ * Read requested bytes.
+ *
+ * @param bytes A pointer to a buffer.
+ * @param requested Length.
+ *
+ * @return Readed byte length.
+ */
+size_t SerialBuffered::readBytes(uint8_t *bytes, size_t requested) {
+    int i = 0;
+    while (i < requested) {
+        int c = getc();
+        if (c < 0) {
+            break;
+        }
+        bytes[i] = c;
+        i++;
+    }
+    return i;
+}
+
+/**
+ * Get a character.
+ *
+ * @return A character. (-1:timeout)
+ */
+int SerialBuffered::getc() {
+    timer.reset();
+    timer.start();
+    while (indexContentStart == indexContentEnd) {
+        wait_ms(1);
+        if ((timeout > 0) && (timer.read_ms() > timeout)) {
+            /*
+             * Timeout occured.
+             */
+            // printf("Timeout occured.\n");
+            return EOF;
+        }
+    }
+    timer.stop();
+
+    uint8_t result = buffer[indexContentStart++];
+    indexContentStart =  indexContentStart % BUFFERSIZE;
+
+    return result;
+}
+
+/**
+ * Returns 1 if there is a character available to read, 0 otherwise.
+ */
+int SerialBuffered::readable() {
+    return indexContentStart != indexContentEnd;
+}
+
+void SerialBuffered::handleInterrupt() {
+    while (RawSerial::readable()) {
+        if (indexContentStart == ((indexContentEnd + 1) % BUFFERSIZE)) {
+            /*
+             * Buffer overrun occured.
+             */
+            // printf("Buffer overrun occured.\n");
+            RawSerial::getc();
+        } else {
+            buffer[indexContentEnd++] = RawSerial::getc();
+            indexContentEnd = indexContentEnd % BUFFERSIZE;
+        }
+    }
+}
diff -r 000000000000 -r 43669f623d43 Camera_LS_Y201_RTOS/SerialBuffered.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Camera_LS_Y201_RTOS/SerialBuffered.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,89 @@
+/**
+ * =============================================================================
+ * LS-Y201 device driver class (Version 0.0.1)
+ * Reference documents: LinkSprite JPEG Color Camera Serial UART Interface
+ *                      January 2010
+ * =============================================================================
+ * Copyright (c) 2010 Shinichiro Nakamura (CuBeatSystems)
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ * =============================================================================
+ */
+
+#ifndef _SERIAL_BUFFERED_H_
+#define _SERIAL_BUFFERED_H_
+
+/**
+ * Buffered serial class.
+ */
+class SerialBuffered : public RawSerial {
+public:
+    /**
+     * Create a buffered serial class.
+     *
+     * @param tx A pin for transmit.
+     * @param rx A pin for receive.
+     */
+    SerialBuffered(PinName tx, PinName rx);
+
+    /**
+     * Destroy.
+     */
+    virtual ~SerialBuffered();
+
+    /**
+     * Get a character.
+     *
+     * @return A character. (-1:timeout)
+     */
+    int getc();
+
+    /**
+     * Returns 1 if there is a character available to read, 0 otherwise.
+     */
+    int readable();
+
+    /**
+     * Set timeout for getc().
+     *
+     * @param ms milliseconds. (-1:Disable timeout)
+     */
+    void setTimeout(int ms);
+
+    /**
+     * Read requested bytes.
+     *
+     * @param bytes A pointer to a buffer.
+     * @param requested Length.
+     *
+     * @return Readed byte length.
+     */
+    size_t readBytes(uint8_t *bytes, size_t requested);
+
+private:
+    void handleInterrupt();
+    static const int BUFFERSIZE = 4096;
+    uint8_t buffer[BUFFERSIZE];            // points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end
+    uint16_t indexContentStart;   // index of first bytes of content
+    uint16_t indexContentEnd;     // index of bytes after last byte of content
+    int timeout;
+    Timer timer;
+};
+
+#endif
diff -r 000000000000 -r 43669f623d43 EthernetInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#6a67d2bddc7c
diff -r 000000000000 -r 43669f623d43 EthernetNetIf.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetNetIf.lib	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mamezu/code/EthernetNetIf/#0f6c82fcde82
diff -r 000000000000 -r 43669f623d43 HTTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#1f743885e7de
diff -r 000000000000 -r 43669f623d43 SRF05.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SRF05.lib	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/SRF05/#e758665e072c
diff -r 000000000000 -r 43669f623d43 TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
diff -r 000000000000 -r 43669f623d43 cafe.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cafe.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,55 @@
+#include "cafe.h"
+
+DigitalOut relaisCafe(p6); // 22
+
+void faireUnCafe()
+{
+    bool message_affiche = false;
+    
+    while(!tasseEnPlace())
+    {
+        if(!message_affiche)
+        {
+            afficherAuCentreDeLEcran("Veuillez placer", "votre tasse");
+            message_affiche = true;
+        }
+    }
+    
+    afficherAuCentreDeLEcran("Boisson en cours", "de preparation");
+    
+    wait(0.1);
+    relaisCafe = 1;
+    wait(0.5);
+    relaisCafe = 0;
+    wait(0.5);
+    wait(17);
+    attendreFinDePreparation();
+    afficherAuCentreDeLEcran("Votre cafe", "est pret");
+}
+
+void checkCafe()
+{
+    char reponse[20];
+    
+    // On cherche à savoir si une demande de café (via Internet) a été effectuée
+    if(envoyerRequete("gestion_cafe.php", reponse, 20))
+    {
+        if(reponse[1] == '1')
+        {
+            printf("Check café : demande\n\r");
+            envoyerRequete("gestion_cafe.php?boisson_en_preparation");
+            
+            if(machineEteinte())
+                allumerMachine();
+            
+            while(machineOccupee()); // On attend les éventuelles préparations en cours
+            
+            setPreferenceLongueur(reponse[3] - '0' + 1);
+            setPreferenceIntensite(reponse[5] - '0' + 1);
+            faireUnCafe();
+            
+            envoyerRequete("gestion_cafe.php?boisson_prete");
+        }
+    }
+}
+
diff -r 000000000000 -r 43669f623d43 cafe.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cafe.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,16 @@
+#ifndef CAFE_H
+#define CAFE_H
+
+#include "mbed.h"
+#include "rtos.h"
+#include "machine.h"
+#include "ethernet.h"
+#include "ecran_lcd.h"
+#include "preferences.h"
+#include "capteur_tasse.h"
+#include "purge.h"
+
+void faireUnCafe();
+void checkCafe();
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 camera.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/camera.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,154 @@
+#include "camera.h"
+
+LocalFileSystem local("local");
+Camera_LS_Y201 camera(p13, p14);
+
+typedef struct work
+{
+    FILE *fp;
+} work_t;
+ 
+work_t work;
+
+void acallback_func(int done, int total, uint8_t *buf, size_t siz, char *reponse)
+{
+    // Fonction de callback pour écriture de l'image
+    // buf : pointeur sur un buffer
+    // siz : taille tu buffer
+    //printf("callback : buffer de taille %d\r\n", siz);
+    //fwrite(buf, siz, 1, work.fp);
+    
+    
+    envoyerChaineSocket((char*)buf, siz, reponse, 30);
+    //printf("callback response : %s\r\n", reponse);
+    
+    
+    //static int n = 0;
+    //int tmp = done * 100 / total;
+    
+    //if(n != tmp)
+    //{
+    //    n = tmp;
+    //    printf("Writing...: %3d%%\r\n", n); 
+    //}
+}
+
+int acapture(Camera_LS_Y201 *cam, char *reponse)
+{
+    // Prise de l'image
+    if(cam->takePicture() != 0)
+        return -1;
+    
+    printf("\tPhoto prise\r\n");
+    //afficherAuCentreDeLEcran("Photo prise", "wesh");
+ 
+    // Ouverture du fichier
+    //work.fp = fopen(nom_fichier, "wb");
+    //if(work.fp == NULL)
+    //    return -2;
+ 
+    // Lecture du contenu
+    //printf("%s\r\n", nom_fichier);
+    
+    if(cam->readJpegFileContent(acallback_func, envoyerChaineSocket, reponse) != 0)
+    {
+        //fclose(work.fp);
+        return -3;
+    }
+    
+    //fclose(work.fp);
+    wait(1);
+ 
+    // Fin de la prise d'image
+    cam->stopTakingPictures();
+ 
+    return 0; // Retourne donc 0 en cas de succès
+}
+
+bool initialiserCamera()
+{
+    int initCam;
+    
+    do
+    {
+        printf("Reset CAMERA\r\n");
+        initCam = camera.reset();
+    } while(initCam != 0);
+    
+    if(initCam != 0)
+    {
+        printf("Echec de l'initialisation caméra %d\r\n", initCam);
+        afficherAuCentreDeLEcran("Echec init", "camera");
+        return false;
+    }
+    
+    else
+    {
+        printf("Initialisation caméra OK.\r\n");
+        afficherAuCentreDeLEcran("Initialisation", "camera : ok");
+        return true;
+    }
+}
+
+bool detecterUtilisateur(bool *utilisateur_reconnu, char* nom_utilisateur, int* preference_intensite, int *preference_longueur)
+{
+    printf("\tDébut détection utilisateur\r\n");
+    char reponse[30], requete[10];
+    int taille_reponse = 0;
+    
+    if(connexionSocket())
+    {
+        sprintf(requete,"PHOTO");
+        
+        // Envoi de "RECO". Réception de "RECO OK"
+        envoyerChaineSocket(requete, sizeof(requete), reponse, 30); 
+        //printf("Reponse %s : %s\r\n\r", requete, reponse);
+        
+        int r = acapture(&camera, reponse);
+
+        if(r != 0)
+            printf("IMG_TEST:NG. (code=%d)\r\n", r);
+        
+        /*else
+            printf("IMG_TEST:OK.\r\n");*/
+        
+        // Parsing des parametres depuis la réponse
+        
+        /* CHAINES A RECEVOIR :
+            USER=Leo 2 3            // cas Léo reconnu
+            USER=Simon 3 4          // cas Simon reconnu
+            USER-                  // cas aucun visage
+            USER?userTest          // cas visage non reconnu
+        */
+        
+        //sprintf(reponse, "USER?userTest");
+        //sprintf(reponse, "USER=Simon 3 4");
+        printf("Chaine d'identification : [%s]\n\r", reponse);
+        
+        if(reponse[4] == '-')
+        {
+            deconnexionSocket();
+            return false;
+        }
+        
+        *utilisateur_reconnu = (reponse[4] != '?');
+        taille_reponse = strlen(reponse);
+        
+        int j;
+        for(j = 5 ; j < taille_reponse && reponse[j] != ' ' ; j++)
+            nom_utilisateur[j - 5] = reponse[j];
+        nom_utilisateur[j - 5] = '\0';
+        
+        *preference_intensite = reponse[taille_reponse - 3] - '0';
+        *preference_longueur = reponse[taille_reponse - 1] - '0';
+        
+        deconnexionSocket();
+        return true;
+    }
+    
+    else
+    {
+        printf("\tErreur d'ouverture du socket\r\n\r");
+        return false;
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 camera.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/camera.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,19 @@
+#ifndef CAMERA_H
+#define CAMERA_H
+
+#include "mbed.h"
+#include "rtos.h"
+#include "ecran_lcd.h"
+#include "led.h"
+#include "ethernet.h"
+#include "Camera_LS_Y201.h"
+#include <string.h>
+#include <stdlib.h>
+
+void acallback_func(int done, int total, uint8_t *buf, size_t siz, char *reponse);
+int acapture(Camera_LS_Y201 *cam, char *reponse);
+//void detecterUtilisateur(char* utilisateur, int* preference_longueur, int* preference_intensite);
+bool detecterUtilisateur(bool *utilisateur_reconnu, char* nom_utilisateur, int* preference_intensite, int *preference_longueur);
+bool initialiserCamera();
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 capteur_tasse.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/capteur_tasse.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,18 @@
+#include "capteur_tasse.h"
+
+SRF05 capteurTasse(p10, p9);
+
+bool tasseEnPlace()
+{
+    return getDistanceDetectee() < 7;
+}
+
+int getDistanceDetectee()
+{
+    return (int)capteurTasse.read();
+}
+
+void attlendreUnMouvement()
+{
+    wait(3);
+}
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 capteur_tasse.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/capteur_tasse.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,12 @@
+#ifndef CAPTEUR_H
+#define CAPTEUR_H
+
+#include "mbed.h"
+#include "rtos.h"
+#include "SRF05.h"
+
+bool tasseEnPlace();
+void attendreUnMouvement();
+int getDistanceDetectee();
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 eau.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eau.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,37 @@
+#include "eau.h"
+
+DigitalOut relaisEau(p23);
+DigitalIn capteurEau(p11);
+
+void informerServeurEtatBacEau(int capteur_eau);
+
+void checkContenanceReserveEau(bool initialisation)
+{
+    capteurEau.mode(PullUp);
+    
+    if(initialisation)
+        informerServeurEtatBacEau(capteurEau);
+    
+    if(relaisEau != capteurEau.read() || initialisation)
+    {
+        // On informe le serveur de l'absence (ou non) d'eau
+        if(!initialisation)
+            informerServeurEtatBacEau(capteurEau);
+    
+        // On renvoie l'information à la machine
+        if((int)capteurEau.read() == 1)
+            relaisEau = 0;
+        
+        else
+            relaisEau = 1;
+    }
+}
+
+void informerServeurEtatBacEau(int capteur_eau)
+{
+    if(capteur_eau == 0)
+        envoyerRequete("gestion_eau.php?bac_vide");
+                        
+    else
+        envoyerRequete("gestion_eau.php?bac_plein");
+}
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 eau.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eau.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,10 @@
+#ifndef EAU_H
+#define EAU_H
+
+#include "mbed.h"
+#include "rtos.h"
+#include "ethernet.h"
+
+void checkContenanceReserveEau(bool initialisation);
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 ecran_lcd.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ecran_lcd.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,150 @@
+#include "ecran_lcd.h"
+
+TextLCD ecranLCD(p30, p26, p25, p27, p28, p29); // rs, e, d4-d7
+char message_ecran_1_haut[50], message_ecran_1_bas[50], message_ecran_2_haut[50], message_ecran_2_bas[50];
+bool afficher_double_message, mettre_a_jour_ecran;
+
+void thread_ecran(void const *args)
+{
+    Timer t;
+    mettre_a_jour_ecran = false;
+    wait(1);
+    
+    while(1)
+    {
+        if(mettre_a_jour_ecran)
+        {
+            ecranLCD.cls();
+            mettre_a_jour_ecran = false;
+            
+            if(!afficher_double_message)
+            {
+                afficherSurUneLigne(message_ecran_1_haut, 1);
+                afficherSurUneLigne(message_ecran_1_bas, 2);
+            }
+            
+            else
+            {
+                t.reset();
+                t.start();
+                bool mise_a_jour_1 = false, mise_a_jour_2 = false;
+                
+                while(!mettre_a_jour_ecran)
+                {
+                    if(t.read() < 1.5)
+                    {
+                        if(!mise_a_jour_1)
+                        {
+                            ecranLCD.cls();
+                            afficherSurUneLigne(message_ecran_1_haut, 1);
+                            afficherSurUneLigne(message_ecran_1_bas, 2);
+                            mise_a_jour_1 = true;
+                        }
+                    }
+                    
+                    else if(t.read() > 1.5*2)
+                    {
+                        t.reset();
+                        mise_a_jour_1 = false;
+                        mise_a_jour_2 = false;
+                    }
+                    
+                    else
+                    {
+                        if(!mise_a_jour_2)
+                        {
+                            ecranLCD.cls();
+                            afficherSurUneLigne(message_ecran_2_haut, 1);
+                            afficherSurUneLigne(message_ecran_2_bas, 2);
+                            mise_a_jour_2 = true;
+                        }
+                    }
+                }
+                
+                t.stop();
+            }
+            
+        }
+    }
+}
+
+void afficherSurUneLigne(const char* texte_brut, int ligne)
+{
+    int i;
+    char texte[17];
+    for(i = 0 ; i < 16 ; i ++)
+        texte[i] = texte_brut[i];
+    
+    texte[i] = '\0';
+    
+    int nb_espaces_a_ajouter = (ecranLCD.columns() - strlen(texte)) / 2;
+
+    if(nb_espaces_a_ajouter < 0)
+        nb_espaces_a_ajouter = 0;
+
+    ecranLCD.locate(nb_espaces_a_ajouter, ligne - 1);
+    ecranLCD.printf(texte);
+
+    if(ligne == 1)
+        printf("Affichage ecran : ");
+
+    printf("%s ", texte);
+
+    if(ligne == 2)
+        printf("\n\r");
+}
+
+/* Surement deprecated */
+void faireDefilerSurEcran(const char* texte, int vitesse)
+{
+    int k = 0;
+    
+    for(int i = 0 ; i < 999 ; i ++)
+    {
+        ecranLCD.cls();
+    
+        for(int j = 0 ; j < strlen(texte) - k ; j ++)
+            ecranLCD.printf("%c", texte[k + j]);
+        
+        for(int j = strlen(texte) - k ; j < 15 - k ; j ++)
+            ecranLCD.printf(" ");
+        
+        for(int j = 15 - k ; j < 15 ; j ++)
+            ecranLCD.printf("%c", texte[j - (15 - k)]);
+        
+        wait(0.3);
+        
+        k ++;
+        
+        if(k == 15)
+            k = 0;
+    }
+}
+
+void afficherAuCentreDeLEcran(const char* texte_haut, const char* texte_bas)
+{
+    sprintf(message_ecran_1_haut, "%s", texte_haut);
+    sprintf(message_ecran_1_bas, "%s", texte_bas);
+    sprintf(message_ecran_2_haut, "");
+    sprintf(message_ecran_2_bas, "");
+    afficher_double_message = false;
+    mettre_a_jour_ecran = true;
+}
+
+void afficherAuCentreDeLEcran(const char* texte_1_haut, const char* texte_1_bas, const char* texte_2_haut, const char* texte_2_bas)
+{
+    sprintf(message_ecran_1_haut, "%s", texte_1_haut);
+    sprintf(message_ecran_1_bas, "%s", texte_1_bas);
+    sprintf(message_ecran_2_haut, "%s", texte_2_haut);
+    sprintf(message_ecran_2_bas, "%s", texte_2_bas);
+    afficher_double_message = true;
+    mettre_a_jour_ecran = true;
+}
+
+void afficherAuCentreDeLEcran(int nombre1, int nombre2)
+{
+    char s1[20], s2[20];
+    sprintf(s1, "%i", nombre1);
+    sprintf(s2, "%i", nombre2);
+    afficherAuCentreDeLEcran(s1, s2);
+}
diff -r 000000000000 -r 43669f623d43 ecran_lcd.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ecran_lcd.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,15 @@
+#ifndef ECRAN_H
+#define ECRAN_H
+
+#include "mbed.h"
+#include "rtos.h"
+#include "TextLCD.h"
+
+void thread_ecran(void const *args);
+void afficherSurUneLigne(const char* texte, int ligne);
+void faireDefilerSurEcran(const char* texte, int vitesse); /* surement deprecated */
+void afficherAuCentreDeLEcran(const char* texte1, const char* texte2);
+void afficherAuCentreDeLEcran(const char* texte_1_haut, const char* texte_1_bas, const char* texte_2_haut, const char* texte_2_bas);
+void afficherAuCentreDeLEcran(int nombre1, int nombre2);
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 ethernet.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ethernet.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,113 @@
+#include "ethernet.h"
+
+//const char* ECHO_SERVER_ADDRESS = "194.254.15.213/reco/";
+const char* ECHO_SERVER_ADDRESS = "192.168.1.40";
+const int ECHO_SERVER_PORT = 4242;
+
+EthernetInterface eth;
+TCPSocketConnection socket;
+HTTPClient http;
+int timeOut = HTTP_CLIENT_DEFAULT_TIMEOUT;
+
+bool preparationEthernet()
+{
+    afficherAuCentreDeLEcran("Preparation :", "Ethernet (1/2)");
+    wait(0.5);
+    
+    if(eth.init() == 0)
+    //if( eth.init("192.168.1.67", "255.255.255.0", ECHO_SERVER_ADDRESS) == 0) // Test en local (Sans DHCP)
+    {
+        afficherAuCentreDeLEcran("Preparation :", "Ethernet (2/2)");
+        
+        if(eth.connect() == 0)
+        {
+            afficherAuCentreDeLEcran("Machine", "connectee");
+            allumerLed(1);
+            return true;
+        }
+        
+        else
+            afficherAuCentreDeLEcran("Erreur :", "Ethernet (2/2)");
+    }
+        
+    else
+        afficherAuCentreDeLEcran("Erreur :", "Ethernet (1/2)");
+    
+    wait(2);
+    afficherAuCentreDeLEcran("Err ethernet", eth.getMACAddress());
+        
+    allumerLed(2);
+    return false;
+}
+
+void deconnexionEthernet()
+{
+    eth.disconnect();
+    afficherAuCentreDeLEcran("Machine", "deconnectee");
+}
+
+bool connexionSocket()
+{
+    /*int i = 0;
+    while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0)
+    {
+        printf("Unable to connect to (%s) on port (%d)\r\n\r", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
+        wait(1);
+        i++;
+        if(i>5)
+        {
+            return 0; // Échec
+        }
+    }
+    return 1;*/
+    for(int i = 0 ; i < 4 ; i ++)
+    {
+        if(socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0)
+        {
+            afficherAuCentreDeLEcran("Serveur", "injoignable", "sur", ECHO_SERVER_ADDRESS);
+            wait(3);
+        }
+        
+        else
+            return true;
+    }
+    
+    return false;
+}
+
+void deconnexionSocket()
+{
+    socket.close();
+}
+
+bool envoyerRequete(char complement_url[200], char *reponse, int longueur_reponse)
+{
+    char url[500];
+    sprintf(url, "http://asi-12-cafetiere.insa-rouen.fr/mbed/%s", complement_url);
+    //sprintf(url, "http://192.168.1.10/mbed/%s", complement_url);
+    HTTPResult retour = http.get(url, reponse, longueur_reponse);
+
+    if(retour != HTTP_OK)
+    {
+        afficherAuCentreDeLEcran("ECHEC", "Envoi requete");
+        wait(1);
+    }
+
+    return retour == HTTP_OK; // Succès
+}
+
+bool envoyerRequete(char complement_url[200])
+{
+    char reponse_vide[1];
+    return envoyerRequete(complement_url, reponse_vide, 1);
+}
+
+void envoyerChaineSocket(char *chaine, int taille_chaine, char *reponse, int longueur_reponse_max)
+{
+    int m;
+    socket.send_all(chaine, taille_chaine);
+    m = socket.receive(reponse,longueur_reponse_max);
+    reponse[m] = '\0';
+}
+
+
diff -r 000000000000 -r 43669f623d43 ethernet.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ethernet.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,19 @@
+#ifndef ETHERNET_H
+#define ETHERNET_H
+
+#include "mbed.h"
+#include "rtos.h"
+#include "led.h"
+#include "ecran_lcd.h"
+#include "EthernetInterface.h"
+#include "HTTPClient.h"
+
+bool preparationEthernet();
+bool connexionSocket();
+void deconnexionEthernet();
+void deconnexionSocket();
+bool envoyerRequete(char complement_url[200]);
+bool envoyerRequete(char complement_url[200], char *reponse, int longueur_reponse);
+void envoyerChaineSocket(char *chaine, int taille_chaine, char *reponse, int longueur_max_reponse);
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 intelligence.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/intelligence.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,114 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "cafe.h"
+#include "camera.h"
+#include "capteur_tasse.h"
+#include "eau.h"
+#include "ethernet.h"
+#include "led.h"
+#include "machine.h"
+#include "preferences.h"
+#include "purge.h"
+#include "ecran_lcd.h"
+#include "intelligence.h"
+
+// Variable globale partagée entre threads
+bool p_detection_visage;
+bool p_prendre_et_envoyer_photos_en_continu;
+
+bool communiquerAuServeurPreferencesUtilisateur(int preference_intensite, int preference_longueur)
+{
+    printf("\tCommunication des prefs au serveur : %d | %d\n\r", preference_intensite, preference_longueur);
+    char requete[9], reponse[10];
+    sprintf(requete, "SAVE %d %d", preference_intensite, preference_longueur);
+    printf("\tTentative connexion socket\n\r");
+    if(connexionSocket())
+    {
+        envoyerChaineSocket(requete, 9, reponse, 10);
+        printf("\tEnvoi de [%s]\n\r", requete);
+        printf("\tTentative deconnexion socket\n\r");
+        deconnexionSocket();
+        return strcmp("SAVE OK", reponse);
+    }
+    return false;
+}
+
+/*bool detecterUtilisateur()
+{
+    return true;
+}*/
+
+
+
+
+void async_desactiverDetectionVisage()
+{
+    p_detection_visage = false;
+}
+
+void async_activerDetectionVisage()
+{
+    p_detection_visage = true;
+}
+
+bool async_visageDetecte()
+{
+    return p_detection_visage;
+}
+
+void thread_detection_visage(void const *args)
+{
+    do
+    {
+        //p_detection_visage = detecterUtilisateur();
+    } while(p_detection_visage);
+}
+
+void communiquerAuServeurEmissionsPhotos()
+{
+
+}
+
+void communiquerAuServeurFinEmissionPhotos()
+{
+
+}
+
+void thread_prendreEtEnvoyerPhotosEnContinu(void const *args)
+{
+    // Le serveur se prépare à recevoir plusieurs photos
+    communiquerAuServeurEmissionsPhotos();
+    
+    while(p_prendre_et_envoyer_photos_en_continu)
+    {
+        // La machine prend une photo et l'envoi en traitement au serveur
+        
+    }
+    
+    // On informe le serveur de la fin de prise de photos
+    communiquerAuServeurFinEmissionPhotos();
+}
+
+void async_lancerPriseEtEnvoiPhotosEnContinu()
+{
+    p_prendre_et_envoyer_photos_en_continu = true;
+    Thread thread_PEEPEC(thread_prendreEtEnvoyerPhotosEnContinu);
+}
+
+void async_stopperPriseEtEnvoiPhotosEnContinu()
+{
+    p_prendre_et_envoyer_photos_en_continu = false;
+}
+
+void thread_check(void const *args)
+{
+    checkContenanceReserveEau(true); // initialisation
+    
+    while(1)
+    {
+        checkPurge();
+        checkCafe();
+        checkContenanceReserveEau(false);
+        wait(0.5);
+    }
+}
diff -r 000000000000 -r 43669f623d43 intelligence.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/intelligence.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,23 @@
+#ifndef INTELLIGENCE_H
+#define INTELLIGENCE_H
+
+#include "mbed.h"
+#include "rtos.h"
+#include "eau.h"
+
+// Threads :
+void thread_detection_visage(void const *args);
+void thread_check(void const *args);
+void thread_prendreEtEnvoyerPhotosEnContinu(void const *args);
+
+//bool detecterUtilisateur();
+void async_desactiverDetectionVisage();
+void async_activerDetectionVisage();
+bool async_visageDetecte();
+void communiquerAuServeurEmissionsPhotos();
+void communiquerAuServeurFinEmissionPhotos();
+bool communiquerAuServeurPreferencesUtilisateur(int preference_intensite, int preference_longueur);
+void async_lancerPriseEtEnvoiPhotosEnContinu();
+void async_stopperPriseEtEnvoiPhotosEnContinu();
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 led.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/led.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,60 @@
+#include "led.h"
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalOut led4(LED4);
+
+void actionSurLed(int num, int val)
+{
+    switch(num)
+    {
+        case 1:
+            led1 = val;
+            break;
+        
+        case 2:
+            led2 = val;
+            break;
+        
+        case 3:
+            led3 = val;
+            break;
+        
+        case 4:
+            led4 = val;
+            break;
+    }
+}
+
+void allumerLed(int num)
+{
+    actionSurLed(num, 1);
+}
+
+void eteindreLed(int num)
+{
+    actionSurLed(num, 0);
+}
+
+void inverserLed(int num)
+{
+    switch(num)
+    {
+        case 1:
+            led1 = !led1;
+            break;
+        
+        case 2:
+            led2 = !led2;
+            break;
+        
+        case 3:
+            led3 = !led3;
+            break;
+        
+        case 4:
+            led4 = !led4;
+            break;
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 led.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/led.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,12 @@
+#ifndef LED_H
+#define LED_H
+
+#include "mbed.h"
+#include "rtos.h"
+
+void actionSurLed(int num, int val);
+void allumerLed(int num);
+void eteindreLed(int num);
+void inverserLed(int num);
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 machine.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/machine.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,87 @@
+#include "machine.h"
+
+DigitalOut relaisMachine(p5);
+AnalogIn capteurLumiereChauffe(p16);
+DigitalOut relaisLectureCapteursMachine(p8);
+
+void attendreFinDePreparation()
+{
+    while(!capteurChauffeClignotant());
+    while(capteurChauffeClignotant());
+}
+
+bool machineEteinte()
+{
+    // La machine est considérée comme éteinte si le capteur de chauffe ne clignote
+    // pas et si les voyant d'intensité sont éteints
+    return !capteurChauffeClignotant() && getPreferenceIntensite() == -1;
+}
+
+void allumerMachine()
+{
+    relaisMachine = 1;
+    relaisLectureCapteursMachine = 1;
+    
+    // On attend la fin de la chauffe
+    while(capteurChauffeClignotant());
+    
+    relaisLectureCapteursMachine = 0;
+    
+    // La machine est prete
+    relaisMachine = 0;
+    wait(0.2);
+}
+
+bool capteurChauffeClignotant()
+{
+    return capteurChauffeClignotant(0.5, 0.5);
+}
+
+bool capteurChauffeClignotant(float seuil_min, float seuil_max)
+{
+    Timer t;
+    t.start();
+    
+    int nb = 0;
+    
+    float valeur_actuelle, valeur_min = 1.0, valeur_max = 0.0;
+    
+    wait(0.2); // on attend un état stable
+    while(t.read() < 1.0)
+    {
+        nb ++;
+        valeur_actuelle = capteurLumiereChauffe.read();
+        wait(0.02);
+        
+        if(valeur_min > valeur_actuelle)
+            valeur_min = valeur_actuelle;
+        
+        if(valeur_max < valeur_actuelle)
+            valeur_max = valeur_actuelle;
+    }
+        
+    printf("Min : %.3f\t\tMax : %.3f\t\t%d\r\n", valeur_min, valeur_max, nb);
+        
+    t.stop();
+    
+    return valeur_min < seuil_min && valeur_max > seuil_max;
+}
+
+void eteindreMachine()
+{
+    relaisMachine = 1;
+    wait(1);
+    relaisLectureCapteursMachine = 1;
+    
+    // On attend la fin de la chauffe
+    while(capteurChauffeClignotant());
+    
+    relaisLectureCapteursMachine = 0;
+    relaisMachine = 0;
+    wait(0.2);
+}
+
+bool machineOccupee()
+{
+    return getPreferenceIntensite() == -1;
+}
diff -r 000000000000 -r 43669f623d43 machine.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/machine.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,17 @@
+#ifndef MACHINE_H
+#define MACHINE_H
+
+#include "mbed.h"
+#include "rtos.h"
+#include "ecran_lcd.h"
+#include "preferences.h"
+
+void attendreFinDePreparation();
+bool machineOccupee();
+void eteindreMachine();
+void allumerMachine();
+bool capteurChauffeClignotant();
+bool machineEteinte();
+bool capteurChauffeClignotant(float seuil_min, float seuil_max);
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,156 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "cafe.h"
+#include "camera.h"
+#include "capteur_tasse.h"
+#include "eau.h"
+#include "ethernet.h"
+#include "led.h"
+#include "machine.h"
+#include "preferences.h"
+#include "purge.h"
+#include "ecran_lcd.h"
+#include "intelligence.h"
+
+#define TIMEOUT_DETECTION   20.0
+
+int main()
+{
+    //thread_checkCapteurs();
+    /*if(getPreferenceIntensite() == -1)
+        allumerMachine();*/
+    //printf("%d\n\r", getPreferenceIntensite());
+    
+    Thread threadEcran(thread_ecran);
+    wait(1);
+    afficherAuCentreDeLEcran("Demarrage", "du systeme");
+    
+    Timer t;
+    char nom_utilisateur[25];
+    DigitalIn boutonPoussoir(p12);
+    int preference_longueur = 0, preference_intensite = 0;
+    bool detection_visage = false, utilisateur_reconnu = false;
+    wait(1);
+    
+    if(preparationEthernet())
+    {
+        checkContenanceReserveEau(true);
+        wait(1); // Pour laisser l'affichage du message
+        
+        if(initialiserCamera())
+        {
+            wait(1); // Pour laisser l'affichage du message
+            while(boutonPoussoir.read() != 1) // Arret du système avec pression sur BP
+            {
+                t.reset();
+                
+                do
+                {
+                    checkPurge();
+                    checkCafe();
+                    checkContenanceReserveEau(false);
+                    afficherAuCentreDeLEcran("Pret a", "vous servir");
+                    
+                    if(boutonPoussoir.read() == 1)
+                        break;
+                    
+                    // Recherche d'un visage en permanence
+                    detection_visage = detecterUtilisateur(&utilisateur_reconnu, 
+                                                            nom_utilisateur, 
+                                                            &preference_intensite, 
+                                                            &preference_longueur);
+                } while(!detection_visage);
+                
+                if(boutonPoussoir.read() == 1)
+                    break;
+                    
+                //async_desactiverDetectionVisage();
+                // Lancement d'une détection en boucle
+                //Thread threadDetectionVisage(thread_detection_visage);
+                //wait(3);
+                
+                if(utilisateur_reconnu)
+                {
+                    afficherAuCentreDeLEcran("Bonjour", nom_utilisateur);
+                    setPreferenceLongueur(preference_longueur);
+                    setPreferenceIntensite(preference_intensite);
+                    wait(3);
+                    
+                    t.start();
+                    afficherAuCentreDeLEcran("Veuillez changer", "vos preferences", "puis placer", "votre tasse");
+                    while(/*async_visageDetecte() && */!tasseEnPlace() && t.read() < TIMEOUT_DETECTION);
+                    t.stop();
+                    
+                    if(t.read() >= TIMEOUT_DETECTION)
+                        continue;
+                        
+                    /*if(!async_visageDetecte())
+                        continue;*/
+                        
+                    // Sinon, c'est que l'utilisateur a placé sa tasse
+                    
+                    // On lance la prise de photos en continu pour enrichir la base
+                    //async_lancerPriseEtEnvoiPhotosEnContinu();
+                    
+                    // On lance la production de café
+                    faireUnCafe();
+                    
+                    afficherAuCentreDeLEcran("Sauvegarde de", "vos preferences");
+                    communiquerAuServeurPreferencesUtilisateur(getPreferenceIntensite(), getPreferenceLongueur());
+                    wait(2);
+                    afficherAuCentreDeLEcran("Retirez", "votre tasse");
+                    
+                    // On arrete la prise de photos et on en informe le serveur
+                    //async_stopperPriseEtEnvoiPhotosEnContinu();
+                    
+                    // On attend que l'utilisateur retire sa tasse
+                    while(tasseEnPlace());
+                }
+                
+                else
+                {
+                    t.start();
+                    afficherAuCentreDeLEcran("Nouvel", "utilisateur", "Veuillez placer", "votre tasse");
+                    while(/*async_visageDetecte() && */!tasseEnPlace() && t.read() < TIMEOUT_DETECTION);
+                    t.stop();
+                    
+                    if(t.read() >= TIMEOUT_DETECTION)
+                        continue;
+                        
+                    /*if(!async_visageDetecte())
+                        continue;*/
+                        
+                    // Sinon, c'est que l'utilisateur a placé sa tasse
+                    
+                    // On lance la prise de photos en continu pour enrichir la base
+                    //async_lancerPriseEtEnvoiPhotosEnContinu();
+                    
+                    afficherAuCentreDeLEcran("Faites votre", "selection", "puis", "validez");
+                    while(!capteurChauffeClignotant());
+                    
+                    afficherAuCentreDeLEcran("Merci de", "patienter");
+                    while(capteurChauffeClignotant()); // on attend la fin de café
+                    
+                    // On recherche les préférences de l'utilisateur et on les communique au serveur
+                    afficherAuCentreDeLEcran("Lecture de", "vos preferences");
+                    if(communiquerAuServeurPreferencesUtilisateur(getPreferenceIntensite(), getPreferenceLongueur()))
+                    {
+                        afficherAuCentreDeLEcran("Echec de ", "sauvegarde");
+                        wait(1);
+                    }
+                    
+                    // On arrete la prise de photos et on en informe le serveur
+                    //async_stopperPriseEtEnvoiPhotosEnContinu();
+                    
+                    // On attend que l'utilisateur retire sa tasse
+                    afficherAuCentreDeLEcran("Retirez", "votre tasse");
+                    while(tasseEnPlace());
+                }
+            }
+        }
+        
+        deconnexionEthernet();
+    }
+    
+    return 0;
+}
diff -r 000000000000 -r 43669f623d43 mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#29007aef10a4
diff -r 000000000000 -r 43669f623d43 mbed-src.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-src.lib	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-src/#847f030b50ee
diff -r 000000000000 -r 43669f623d43 preferences.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/preferences.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,211 @@
+#include "preferences.h"
+
+DigitalOut relaisSelectionRotation1(p21);
+DigitalOut relaisSelectionRotation2(p22);
+DigitalOut relaisSelectionPression(p24);
+DigitalOut relaisLectureCapteurs(p8);
+
+AnalogIn capteurLumiereHaut(p15);
+AnalogIn capteurLumiereBas(p20);
+
+float largeur_impulsion_relais = 0.08;
+float seuil_capteurs_lumiere = 0.5;
+
+void thread_checkCapteurs()
+{
+    AnalogIn capteurLumiere1(p15); // - longueur 3
+    AnalogIn capteurLumiere2(p16); // - signal chauffe
+    AnalogIn capteurLumiere3(p17); // défaut grain
+    AnalogIn capteurLumiere4(p18); // symbole bas gauche
+    AnalogIn capteurLumiere5(p19); // longueur 3 ---> BUG (valeur divisée par deux ?)
+    AnalogIn capteurLumiere6(p20); // - intensité 3
+    DigitalOut relaisUtilisationCapteurs(p8);
+    DigitalIn capteurEau(p11);
+    capteurEau.mode(PullUp);
+
+    relaisUtilisationCapteurs = 1;
+    
+    while(1)
+    {
+        printf("1:%.3f\t 2:%.3f 3:%.3f\t 4:%.3f\t 5:%.3f\t 6:%.3f\t EAU:%d\n\r", capteurLumiere1.read(), capteurLumiere2.read(), capteurLumiere3.read(), capteurLumiere4.read(), capteurLumiere5.read(), capteurLumiere6.read(), capteurEau.read());
+    }
+}
+
+int getPreferenceLongueur()
+{
+    float val;
+    int nombre_incrementations = 0;
+    
+    do // on se positionne sur le capteur de lumière
+    {
+        val = getValeurCapteurLumiere(capteurLumiereHaut);
+        if(val > seuil_capteurs_lumiere)
+        {
+            simulerSelectionLongueur();
+            nombre_incrementations ++;
+            
+            if(nombre_incrementations == 5)
+                return -1; // aucun voyant n'est allumé
+        }
+    } while(val > seuil_capteurs_lumiere);
+    
+    switch(nombre_incrementations) // on retourne sur la position initiale
+    {
+        case 0:
+            // cas où l'on se trouve déjà sur le capteur de lumière
+            break;
+        
+        case 1:
+            simulerSelectionPrecedenteLongueur();
+            break;
+        
+        case 2:
+            simulerSelectionPrecedenteLongueur();
+            simulerSelectionPrecedenteLongueur();
+            break;
+        
+        case 3:
+            simulerSelectionLongueur();
+            simulerSelectionLongueur();
+            break;
+        
+        case 4:
+            simulerSelectionLongueur();
+            break;
+    }
+    
+    int selection = (3 + 5 - nombre_incrementations) % 5;
+    if(selection == 0)
+        return 5;
+    
+    else
+        return selection;
+}
+
+int getPreferenceIntensite()
+{
+    float val;
+    int rang = -1, selection;
+    
+    for(int i = 0 ; i < 6 ; i ++)
+    {
+        val = getValeurCapteurLumiere(capteurLumiereBas);
+        if(val < seuil_capteurs_lumiere)
+        {
+            rang = i;
+        
+            if(i == 0)
+                break;
+        }
+        
+        simulerSelectionIntensite();
+    }
+    
+    if(rang == -1)
+        return -1;
+    
+    selection = (6 - rang + 3) % 6;
+    if(selection == 0)
+        return 6;
+    
+    else
+        return selection;
+}
+
+int setPreferenceLongueur(int preference)
+{
+    float val;
+    
+    do // on se positionne sur le capteur de lumière
+    {
+        val = getValeurCapteurLumiere(capteurLumiereHaut);
+        if(val > seuil_capteurs_lumiere)
+            simulerSelectionLongueur();
+    } while(val > seuil_capteurs_lumiere);
+    
+    switch(preference) // puis on atteind la sélection souhaitée, au plus tot
+    {
+        case 1:
+            simulerSelectionPrecedenteLongueur();
+            simulerSelectionPrecedenteLongueur();
+            break;
+            
+        case 2:
+            simulerSelectionPrecedenteLongueur();
+            break;
+            
+        case 3:
+            // On y est déjà
+            break;
+        
+        case 4:
+            simulerSelectionLongueur();
+            break;
+        
+        case 5:
+            simulerSelectionLongueur();
+            simulerSelectionLongueur();
+            break;
+     }
+    
+    return 0;
+}
+
+int setPreferenceIntensite(int preference)
+{
+    float val;
+    
+    do
+    {
+        val = getValeurCapteurLumiere(capteurLumiereBas);
+        if(val > seuil_capteurs_lumiere)
+            simulerSelectionIntensite();
+    } while(val > seuil_capteurs_lumiere);
+    
+    for(int i = 0 ; i < (3 + preference) % 6 ; i ++)
+        simulerSelectionIntensite();
+    
+    return 0;
+}
+
+float getValeurCapteurLumiere(AnalogIn capteurLumiere)
+{
+    relaisLectureCapteurs = 1;
+    wait(0.01);
+    float valeur_capteur = capteurLumiere.read();
+    relaisLectureCapteurs = 0;
+    wait(0.01);
+    return valeur_capteur;
+}
+
+void simulerSelectionLongueur()
+{
+    relaisSelectionRotation1 = 1;
+    wait(largeur_impulsion_relais / 2);
+    relaisSelectionRotation2 = 1;
+    wait(largeur_impulsion_relais / 2);
+    relaisSelectionRotation1 = 0;
+    wait(largeur_impulsion_relais / 2);
+    relaisSelectionRotation2 = 0;
+    wait(1.5*largeur_impulsion_relais);
+}
+
+void simulerSelectionPrecedenteLongueur()
+{
+    relaisSelectionRotation2 = 1;
+    wait(largeur_impulsion_relais / 2);
+    relaisSelectionRotation1 = 1;
+    wait(largeur_impulsion_relais / 2);
+    relaisSelectionRotation2 = 0;
+    wait(largeur_impulsion_relais / 2);
+    relaisSelectionRotation1 = 0;
+    wait(1.5*largeur_impulsion_relais);
+}
+
+void simulerSelectionIntensite()
+{
+    relaisSelectionPression = 1;
+    wait(largeur_impulsion_relais);
+    relaisSelectionPression = 0;
+    wait(largeur_impulsion_relais);
+}
diff -r 000000000000 -r 43669f623d43 preferences.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/preferences.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,23 @@
+#ifndef PREFERENCES_H
+#define PREFERENCES_H
+
+#include "mbed.h"
+#include "rtos.h"
+#include "led.h"
+#include "ecran_lcd.h"
+#include "machine.h"
+
+int getPreferenceLongueur();
+int getPreferenceIntensite();
+
+int setPreferenceLongueur(int preference);
+int setPreferenceIntensite(int preference);
+
+void simulerSelectionLongueur();
+void simulerSelectionPrecedenteLongueur();
+void simulerSelectionIntensite();
+
+void thread_checkCapteurs();
+float getValeurCapteurLumiere(AnalogIn capteurLumiere);
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 purge.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/purge.cpp	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,53 @@
+#include "purge.h"
+
+DigitalOut relaisPurge(p7);
+
+void purgerLaMachine()
+{
+    /*bool message_affiche = false;
+    
+    while(!tasseEnPlace())
+    {
+        if(!message_affiche)
+        {
+            afficherAuCentreDeLEcran("Veuillez placer", "un recipient");
+            message_affiche = true;
+        }
+    }*/
+    
+    afficherAuCentreDeLEcran("Purge de", "la machine...");
+    
+    wait(0.1);
+    relaisPurge = 1;
+    wait(0.5);
+    relaisPurge = 0;
+    wait(1);
+    
+    while(capteurChauffeClignotant(0.5, 0.05)); // On attend la fin de la purge
+    afficherAuCentreDeLEcran("Machine purgee !", "");
+    
+    wait(3);
+}
+
+void checkPurge()
+{
+    char reponse[20];
+    
+    // On cherche à savoir si une demande de purge (via Internet) a été effectuée
+    if(envoyerRequete("gestion_purge.php", reponse, 20))
+    {
+        if(reponse[1] == '1')
+        {
+            printf("Check purge : demande\n\r");
+            envoyerRequete("gestion_purge.php?purge_en_cours");
+            
+            if(machineEteinte())
+                allumerMachine();
+            
+            while(capteurChauffeClignotant()); // On attend les éventuelles préparations en cours
+            
+            purgerLaMachine();
+            envoyerRequete("gestion_purge.php?fin_purge");
+        }
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 43669f623d43 purge.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/purge.h	Wed Jan 15 11:09:52 2014 +0000
@@ -0,0 +1,14 @@
+#ifndef PURGE_H
+#define PURGE_H
+
+#include "mbed.h"
+#include "rtos.h"
+#include "ethernet.h"
+#include "ecran_lcd.h"
+#include "machine.h"
+#include "capteur_tasse.h"
+
+void purgerLaMachine();
+void checkPurge();
+
+#endif
\ No newline at end of file