From 7204905bc4835683587a67d711f68f583ad59698 Mon Sep 17 00:00:00 2001 From: medina5 Date: Wed, 14 Jan 2026 21:03:56 +0100 Subject: [PATCH] tableaux --- .devcontainer/nodered/flows.json | 192 ++++++++++++-------- autom.cpp | 290 ++++++++++++++++++------------- main.cpp | 91 +++++++--- 3 files changed, 364 insertions(+), 209 deletions(-) diff --git a/.devcontainer/nodered/flows.json b/.devcontainer/nodered/flows.json index bad539c..f380cd3 100644 --- a/.devcontainer/nodered/flows.json +++ b/.devcontainer/nodered/flows.json @@ -221,17 +221,6 @@ "disabled": "false", "groupType": "default" }, - { - "id": "34e2708f001f89c4", - "type": "ui-spacer", - "group": "6b44d4b22cd7b3dc", - "name": "spacer", - "tooltip": "", - "order": 11, - "width": 1, - "height": 1, - "className": "" - }, { "id": "050148aff99031d4", "type": "ui-group", @@ -253,7 +242,7 @@ "group": "5fe915fcd26e78ae", "name": "", "label": "B0", - "order": 1, + "order": 8, "width": 0, "height": 0, "emulateClick": false, @@ -292,7 +281,7 @@ "group": "5fe915fcd26e78ae", "name": "", "label": "B1", - "order": 2, + "order": 7, "width": 0, "height": 0, "emulateClick": false, @@ -331,7 +320,7 @@ "group": "5fe915fcd26e78ae", "name": "", "label": "B2", - "order": 3, + "order": 6, "width": 0, "height": 0, "emulateClick": false, @@ -370,7 +359,7 @@ "group": "5fe915fcd26e78ae", "name": "", "label": "B3", - "order": 4, + "order": 5, "width": 0, "height": 0, "emulateClick": false, @@ -591,7 +580,7 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "c3dd11d0778f9e67", - "order": 1, + "order": 8, "width": 0, "height": 0, "name": "", @@ -615,7 +604,7 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "c3dd11d0778f9e67", - "order": 2, + "order": 7, "width": 0, "height": 0, "name": "", @@ -639,7 +628,7 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "c3dd11d0778f9e67", - "order": 3, + "order": 6, "width": 0, "height": 0, "name": "", @@ -723,7 +712,7 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "c3dd11d0778f9e67", - "order": 4, + "order": 5, "width": 0, "height": 0, "name": "", @@ -747,7 +736,7 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "c3dd11d0778f9e67", - "order": 5, + "order": 4, "width": 0, "height": 0, "name": "", @@ -771,7 +760,7 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "c3dd11d0778f9e67", - "order": 6, + "order": 3, "width": 0, "height": 0, "name": "", @@ -795,7 +784,7 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "c3dd11d0778f9e67", - "order": 7, + "order": 2, "width": 0, "height": 0, "name": "", @@ -819,7 +808,7 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "c3dd11d0778f9e67", - "order": 8, + "order": 1, "width": 0, "height": 0, "name": "", @@ -974,7 +963,7 @@ "group": "5fe915fcd26e78ae", "name": "", "label": "B4", - "order": 5, + "order": 4, "width": 0, "height": 0, "emulateClick": false, @@ -1013,7 +1002,7 @@ "group": "5fe915fcd26e78ae", "name": "", "label": "B5", - "order": 6, + "order": 3, "width": 0, "height": 0, "emulateClick": false, @@ -1052,7 +1041,7 @@ "group": "5fe915fcd26e78ae", "name": "", "label": "B6", - "order": 7, + "order": 2, "width": 0, "height": 0, "emulateClick": false, @@ -1091,7 +1080,7 @@ "group": "5fe915fcd26e78ae", "name": "", "label": "B7", - "order": 8, + "order": 1, "width": 0, "height": 0, "emulateClick": false, @@ -1210,7 +1199,7 @@ "name": "", "label": "I0", "group": "00ea85a0e0b38df3", - "order": 1, + "order": 8, "width": 0, "height": 0, "passthru": false, @@ -1364,7 +1353,7 @@ "name": "", "label": "I1", "group": "00ea85a0e0b38df3", - "order": 2, + "order": 7, "width": 0, "height": 0, "passthru": false, @@ -1418,7 +1407,7 @@ "name": "", "label": "I2", "group": "00ea85a0e0b38df3", - "order": 3, + "order": 6, "width": 0, "height": 0, "passthru": false, @@ -1472,7 +1461,7 @@ "name": "", "label": "I3", "group": "00ea85a0e0b38df3", - "order": 4, + "order": 5, "width": 0, "height": 0, "passthru": false, @@ -1526,7 +1515,7 @@ "name": "", "label": "I4", "group": "00ea85a0e0b38df3", - "order": 5, + "order": 4, "width": 0, "height": 0, "passthru": false, @@ -1580,7 +1569,7 @@ "name": "", "label": "I5", "group": "00ea85a0e0b38df3", - "order": 6, + "order": 3, "width": 0, "height": 0, "passthru": false, @@ -1634,7 +1623,7 @@ "name": "", "label": "I6", "group": "00ea85a0e0b38df3", - "order": 7, + "order": 2, "width": 0, "height": 0, "passthru": false, @@ -1688,7 +1677,7 @@ "name": "", "label": "I7", "group": "00ea85a0e0b38df3", - "order": 8, + "order": 1, "width": 0, "height": 0, "passthru": false, @@ -2035,7 +2024,7 @@ "id": "1cd3d290f7f7d539", "type": "function", "z": "86a34ee77bf6db10", - "name": "s8", + "name": "s8 🟢", "func": "msg.payload = Number(msg.payload.s8) == 1 ? \"🟢\" : \"⚪\";\n\nreturn msg;", "outputs": 1, "timeout": 0, @@ -2055,7 +2044,7 @@ "id": "88310a9e40d564fc", "type": "function", "z": "86a34ee77bf6db10", - "name": "s8", + "name": "s8 🟠", "func": "msg.payload = Number(msg.payload.s8) == 2 ? \"🟠\" : \"⚪\";\n\nreturn msg;", "outputs": 1, "timeout": 0, @@ -2075,7 +2064,7 @@ "id": "b543660f60319f21", "type": "function", "z": "86a34ee77bf6db10", - "name": "s8", + "name": "s8 🔴", "func": "msg.payload = Number(msg.payload.s8) == 3 ? \"🔴\" : \"⚪\";\n\nreturn msg;", "outputs": 1, "timeout": 0, @@ -2336,13 +2325,13 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "6b44d4b22cd7b3dc", - "order": 8, + "order": 7, "width": "1", "height": "1", "name": "", "label": "c1", "format": "{{msg.payload}}", - "layout": "row-left", + "layout": "row-right", "style": false, "font": "", "fontSize": 16, @@ -2366,7 +2355,7 @@ "name": "", "label": "c2", "format": "{{msg.payload}}", - "layout": "row-right", + "layout": "row-left", "style": false, "font": "", "fontSize": 16, @@ -2444,7 +2433,7 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "6b44d4b22cd7b3dc", - "order": 12, + "order": 10, "width": "1", "height": "1", "name": "", @@ -2468,7 +2457,7 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "6b44d4b22cd7b3dc", - "order": 13, + "order": 12, "width": "1", "height": "1", "name": "", @@ -2492,13 +2481,13 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "6b44d4b22cd7b3dc", - "order": 14, + "order": 13, "width": "1", "height": "1", "name": "", "label": "c5", "format": "{{msg.payload}}", - "layout": "row-left", + "layout": "row-right", "style": false, "font": "", "fontSize": 16, @@ -2516,7 +2505,7 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "6b44d4b22cd7b3dc", - "order": 15, + "order": 14, "width": "1", "height": "1", "name": "", @@ -2540,13 +2529,13 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "6b44d4b22cd7b3dc", - "order": 16, + "order": 15, "width": "1", "height": "1", "name": "", "label": "c7", "format": "{{msg.payload}}", - "layout": "row-right", + "layout": "row-left", "style": false, "font": "", "fontSize": 16, @@ -2670,17 +2659,17 @@ "name": "", "label": "Actionneur 0", "format": "{{msg.payload}}", - "layout": "row-spread", + "layout": "row-left", "style": false, "font": "", "fontSize": 16, "color": "#717171", "wrapText": false, "className": "", - "value": "payloads", + "value": "payload", "valueType": "msg", - "x": 1870, - "y": 880, + "x": 890, + "y": 1920, "wires": [] }, { @@ -2688,23 +2677,23 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "6b44d4b22cd7b3dc", - "order": 7, + "order": 8, "width": "2", "height": "1", "name": "", "label": "Actionneur 1", "format": "{{msg.payload}}", - "layout": "row-spread", + "layout": "row-left", "style": false, "font": "", "fontSize": 16, "color": "#717171", "wrapText": false, "className": "", - "value": "payloads", + "value": "payload", "valueType": "msg", - "x": 1870, - "y": 920, + "x": 890, + "y": 1960, "wires": [] }, { @@ -2712,23 +2701,23 @@ "type": "ui-text", "z": "86a34ee77bf6db10", "group": "6b44d4b22cd7b3dc", - "order": 10, + "order": 11, "width": "2", "height": "1", "name": "", "label": "Actionneur 2", "format": "{{msg.payload}}", - "layout": "row-spread", + "layout": "row-left", "style": false, "font": "", "fontSize": 16, "color": "#717171", "wrapText": false, "className": "", - "value": "payloads", + "value": "payload", "valueType": "msg", - "x": 1870, - "y": 960, + "x": 890, + "y": 2000, "wires": [] }, { @@ -2788,8 +2777,8 @@ "links": [ "e5da08ba69fe6fb8" ], - "x": 655, - "y": 1940, + "x": 665, + "y": 2100, "wires": [] }, { @@ -2797,7 +2786,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s9 🠙", - "func": "msg.ui_update = msg.payload.s9 == 1 ? { \"color\": \"#000\"} : { \"color\": \"#ddd\"};\nglobal.set(\"s9\", msg.payload.s9);\nreturn msg;", + "func": "msg.ui_update = msg.payload.s9 < 0 ? { \"color\": \"#000\"} : { \"color\": \"#ddd\"};\n\nif (msg.payload.s9 > 0)\n global.set(\"s9\", 1);\nelse if (msg.payload.s9 < 0)\n global.set(\"s9\", -1);\nelse \n global.set(\"s9\", 0);\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -2817,7 +2806,7 @@ "type": "function", "z": "86a34ee77bf6db10", "name": "s9 🠛", - "func": "msg.ui_update = msg.payload.s9 == 1 ? { \"color\": \"#000\"} : { \"color\": \"#ddd\"};\nreturn msg;", + "func": "msg.ui_update = msg.payload.s9 > 0 ? { \"color\": \"#000\"} : { \"color\": \"#ddd\"};\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, @@ -2971,7 +2960,10 @@ "397735dd2560f7cf", "963da6ffcbd90744", "1f5adfcb29a89bb1", - "100a58f1b621c53a" + "100a58f1b621c53a", + "29d203e016b983f6", + "e41bd818da135c8c", + "e7b6444f18166784" ] ] }, @@ -3030,7 +3022,7 @@ "id": "ffe1e88c3c60e495", "type": "function", "z": "86a34ee77bf6db10", - "name": "function 3", + "name": "x30", "func": "msg.payload = msg.payload * 30;\nreturn msg;", "outputs": 1, "timeout": 0, @@ -3038,7 +3030,7 @@ "initialize": "", "finalize": "", "libs": [], - "x": 1680, + "x": 1670, "y": 760, "wires": [ [ @@ -3106,6 +3098,66 @@ [] ] }, + { + "id": "29d203e016b983f6", + "type": "function", + "z": "86a34ee77bf6db10", + "name": "a0", + "func": "msg.payload = Number(msg.payload.a0) ? \"🟩\" : \"🟥\";\nreturn msg;", + "outputs": 1, + "timeout": 0, + "noerr": 0, + "initialize": "", + "finalize": "", + "libs": [], + "x": 690, + "y": 1920, + "wires": [ + [ + "c219b897538f7dfd" + ] + ] + }, + { + "id": "e41bd818da135c8c", + "type": "function", + "z": "86a34ee77bf6db10", + "name": "a1", + "func": "msg.payload = Number(msg.payload.a1) ? \"🟩\" : \"🟥\";\nreturn msg;", + "outputs": 1, + "timeout": 0, + "noerr": 0, + "initialize": "", + "finalize": "", + "libs": [], + "x": 690, + "y": 1960, + "wires": [ + [ + "74204db55792e5ad" + ] + ] + }, + { + "id": "e7b6444f18166784", + "type": "function", + "z": "86a34ee77bf6db10", + "name": "a2", + "func": "msg.payload = Number(msg.payload.a2) ? \"🟩\" : \"🟥\";\nreturn msg;", + "outputs": 1, + "timeout": 0, + "noerr": 0, + "initialize": "", + "finalize": "", + "libs": [], + "x": 690, + "y": 2000, + "wires": [ + [ + "8d5eb1827691bec4" + ] + ] + }, { "id": "cefd0feeeaf4227c", "type": "function", @@ -3937,7 +3989,6 @@ "id": "e5da08ba69fe6fb8", "type": "link in", "z": "b5e17af18ea9731a", - "d": true, "name": "link in 1", "links": [ "397735dd2560f7cf" @@ -4035,6 +4086,7 @@ "id": "978ded7ba3456f70", "type": "link in", "z": "93dc5b41180d0746", + "d": true, "name": "link in 2", "links": [ "c613454bd48662e1" diff --git a/autom.cpp b/autom.cpp index de4e3b4..29dff54 100644 --- a/autom.cpp +++ b/autom.cpp @@ -50,7 +50,8 @@ unsigned long millis() int marche = 0; int arret = 1; -int light = 0; +int reset = 0; + int b0, b1, b2, b3, b4, b5, b6, b7; int i0, i1, i2, i3, i4, i5, i6, i7; int s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11; @@ -61,6 +62,16 @@ int p0; int a0, a1, a2, a3, a4, a5, a6, a7; int c0, c1, c2, c3, c4, c5, c6, c7; +int bouton[8]; +int interrupteur[8]; +int capteur[8]; +int sortie[12]; + +int moteur[4]; +int niveau[4]; +int consigne[4]; +int actionneur[8]; + void process(); /* ******************************************************** @@ -84,66 +95,100 @@ void mqtt_send(mqtt::async_client *client); class callback : public virtual mqtt::callback { public: - void message_arrived(mqtt::const_message_ptr msg) override { - std::string payload = msg->to_string(); + void message_arrived(mqtt::const_message_ptr msg) override + { + std::string payload = msg->to_string(); - try { - json j = json::parse(payload); + try + { + json j = json::parse(payload); - marche = 0; arret = 1; - b0 = b1 = b2 = b3 = b4 = b5 = b6 = b7 = 0; + marche = 0; + arret = 1; + b0 = b1 = b2 = b3 = b4 = b5 = b6 = b7 = 0; - // Ne rien faire si l'objet JSON est vide - if (j.empty()) return; + // Ne rien faire si l'objet JSON est vide + if (j.empty()) + return; - if (j.contains("marche")) marche = j["marche"].get() != 0; - if (j.contains("arret")) arret = j["arret"].get() != 0; + if (j.contains("marche")) + marche = j["marche"].get() != 0; + + if (j.contains("arret")) + arret = j["arret"].get() != 0; + + if (j.contains("reset")) + reset = j["reset"].get() != 0; if (j.contains("b0") && j["b0"].is_number()) - b0 = j["b0"].get(); + { + bouton[0] = b0 = j["b0"].get(); + } if (j.contains("b1") && j["b1"].is_number()) - b1 = j["b1"].get(); + { + bouton[1] = b1 = j["b1"].get(); + } if (j.contains("b2") && j["b2"].is_number()) - b2 = j["b2"].get(); + { + bouton[2] = b2 = j["b2"].get(); + } if (j.contains("b3") && j["b3"].is_number()) - b3 = j["b3"].get(); + { + bouton[3] = b3 = j["b3"].get(); + } if (j.contains("b4") && j["b4"].is_number()) - b4 = j["b4"].get(); + { + bouton[4] = b4 = j["b4"].get(); + } if (j.contains("b5") && j["b5"].is_number()) - b5 = j["b5"].get(); + { + bouton[5] = b5 = j["b5"].get(); + } if (j.contains("b6") && j["b6"].is_number()) - b6 = j["b6"].get(); + { + bouton[6] = b6 = j["b6"].get(); + } if (j.contains("b7") && j["b7"].is_number()) - b7 = j["b7"].get(); + { + bouton[7] = b7 = j["b7"].get(); + } - if (j.contains("i0")) i0 = j["i0"].get(); - if (j.contains("i1")) i1 = j["i1"].get(); - if (j.contains("i2")) i2 = j["i2"].get(); - if (j.contains("i3")) i3 = j["i3"].get(); - if (j.contains("i4")) i4 = j["i4"].get(); - if (j.contains("i5")) i5 = j["i5"].get(); - if (j.contains("i6")) i6 = j["i6"].get(); - if (j.contains("i7")) i7 = j["i7"].get(); + if (j.contains("i0")) + interrupteur[0] = i0 = j["i0"].get(); + if (j.contains("i1")) + interrupteur[1] = i1 = j["i1"].get(); + if (j.contains("i2")) + interrupteur[2] = i2 = j["i2"].get(); + if (j.contains("i3")) + interrupteur[3] = i3 = j["i3"].get(); + if (j.contains("i4")) + interrupteur[4] = i4 = j["i4"].get(); + if (j.contains("i5")) + interrupteur[5] = i5 = j["i5"].get(); + if (j.contains("i6")) + interrupteur[6] = i6 = j["i6"].get(); + if (j.contains("i7")) + interrupteur[7] = i7 = j["i7"].get(); if (j.contains("c0") && j["c0"].is_number()) - c0 = j["c0"].get(); + capteur[0] = c0 = j["c0"].get(); if (j.contains("c1") && j["c1"].is_number()) - c1 = j["c1"].get(); + capteur[1] = c1 = j["c1"].get(); if (j.contains("c2") && j["c2"].is_number()) - c2 = j["c2"].get(); + capteur[2] = c2 = j["c2"].get(); if (j.contains("c3") && j["c3"].is_number()) - c3 = j["c3"].get(); + capteur[3] = c3 = j["c3"].get(); if (j.contains("c4") && j["c4"].is_number()) - c4 = j["c4"].get(); + capteur[4] = c4 = j["c4"].get(); if (j.contains("c5") && j["c5"].is_number()) - c5 = j["c5"].get(); + capteur[5] = c5 = j["c5"].get(); if (j.contains("c6") && j["c6"].is_number()) - c6 = j["c6"].get(); + capteur[6] = c6 = j["c6"].get(); if (j.contains("c7") && j["c7"].is_number()) - c7 = j["c7"].get(); + capteur[7] = c7 = j["c7"].get(); if (j.contains("v0") && j["v0"].is_number()) - v0 = j["v0"].get(); + v0 = j["v0"].get(); if (j.contains("p0") && j["p0"].is_number()) p0 = j["p0"].get(); @@ -151,29 +196,33 @@ public: process(); mqtt_send(&client); } - catch (const json::parse_error& e) { - std::cerr << "Erreur JSON : " << e.what() << "\n"; - } - } + catch (const json::parse_error &e) + { + std::cerr << "Erreur JSON : " << e.what() << "\n"; + } + } }; callback cb; -void mqtt_open(mqtt::async_client* client) { - - client->set_callback(cb); - mqtt::connect_options connOpts; - connOpts.set_clean_session(true); - connOpts.set_user_name("admin"); - connOpts.set_password("geii2025"); - try { - client->connect(connOpts)->wait(); - client->start_consuming(); - client->subscribe(TOPIC, QOS)->wait(); - } catch (const mqtt::exception &exc) { - std::cerr << "Erreur MQTT: " << exc.what() << "\n"; - } +void mqtt_open(mqtt::async_client *client) +{ + client->set_callback(cb); + mqtt::connect_options connOpts; + connOpts.set_clean_session(true); + connOpts.set_user_name("admin"); + connOpts.set_password("geii2025"); + try + { + client->connect(connOpts)->wait(); + client->start_consuming(); + client->subscribe(TOPIC, QOS)->wait(); + } + catch (const mqtt::exception &exc) + { + std::cerr << "Erreur MQTT: " << exc.what() << "\n"; + } } void mqtt_send(mqtt::async_client *client) @@ -211,18 +260,21 @@ void mqtt_send(mqtt::async_client *client) client->publish(msg); } -void mqtt_close() { - try { - client.unsubscribe(TOPIC)->wait(); - client.stop_consuming(); - client.disconnect()->wait(); - } catch(const mqtt::exception &exc){ - std::cerr << "Erreur déconnexion MQTT: " << exc.what() << std::endl; - } +void mqtt_close() +{ + try + { + client.unsubscribe(TOPIC)->wait(); + client.stop_consuming(); + client.disconnect()->wait(); + } + catch (const mqtt::exception &exc) + { + std::cerr << "Erreur déconnexion MQTT: " << exc.what() << std::endl; + } } // ************************************************************ - /* ******************************************************** * TEMPORISATION RETARD A LA MONTEE * * La sortie passe à 1 au bout de la tempo * @@ -230,20 +282,20 @@ void mqtt_close() { class TemporisationRetardMontee { - // methodes - public : - // Contructeur qui prend la duree souhaitee de la temporisation + // methodes +public: + // Contructeur qui prend la duree souhaitee de la temporisation TemporisationRetardMontee(unsigned long duree) { this->duree = duree; sortie = false; captureTemps = false; } - // Activation de la temporisation. Doit etre fait tout le temps de la duree de la tempo + // Activation de la temporisation. Doit etre fait tout le temps de la duree de la tempo void activation() { // Capture du temps de reference - if(!captureTemps) + if (!captureTemps) { debut = millis(); captureTemps = true; @@ -269,44 +321,44 @@ class TemporisationRetardMontee captureTemps = false; } // Interrogation du bit de fin de tempo - bool getSortie() + bool getSortie() { - return(sortie); + return (sortie); } // Recuperation du temps ecoule depuis le debut si necessaire unsigned long getTempsEcoule() { - return(tempsEcoule); + return (tempsEcoule); } - // Attributs - private: - unsigned long duree; - unsigned long debut; - unsigned long tempsEcoule; - bool captureTemps; - bool sortie; + // Attributs +private: + unsigned long duree; + unsigned long debut; + unsigned long tempsEcoule; + bool captureTemps; + bool sortie; }; /******************************************************** -* TEMPORISATION RETARD A LA DESCENTE * -* La sortie passe à 0 au bout de la tempo * -*********************************************************/ + * TEMPORISATION RETARD A LA DESCENTE * + * La sortie passe à 0 au bout de la tempo * + *********************************************************/ class TemporisationRetardDescente { - public : - // Contructeur qui prend la duree souhaitee de la temporisation +public: + // Contructeur qui prend la duree souhaitee de la temporisation TemporisationRetardDescente(unsigned long duree) { this->duree = duree; sortie = false; captureTemps = false; } - // Activation de la temporisation. Doit etre fait tout le temps de la duree de la tempo + // Activation de la temporisation. Doit etre fait tout le temps de la duree de la tempo void activation() { // Capture du temps de reference - if(!captureTemps) + if (!captureTemps) { debut = millis(); captureTemps = true; @@ -329,22 +381,22 @@ class TemporisationRetardDescente captureTemps = false; } // Interrogration du bit de fin de tempo - bool getSortie() + bool getSortie() { - return(sortie); + return (sortie); } // Recuperation du temps ecoule depuis le debut si necessaire - unsigned long getTempsEcoule() + unsigned long getTempsEcoule() { - return(tempsEcoule); + return (tempsEcoule); } - private: - unsigned long duree; - unsigned long debut; - unsigned long tempsEcoule; - bool captureTemps; - bool sortie; +private: + unsigned long duree; + unsigned long debut; + unsigned long tempsEcoule; + bool captureTemps; + bool sortie; }; /******************************************************** @@ -352,22 +404,22 @@ class TemporisationRetardDescente *********************************************************/ class Clignoteur { - // methodes - public : + // methodes +public: // Construteur qui prend en parametre le temps haut ou bas souhaitee Clignoteur(int baseDeTemps) { this->baseDeTemps = baseDeTemps; } // Fonction qui renvoie true si le clignoteur est ├á l'├®tat haut et false s'il est ├á l'├®tat bas - bool statut() + bool statut() { return ((millis() / baseDeTemps) % 2 == 1); } - // Attributs - private: - int baseDeTemps; + // Attributs +private: + int baseDeTemps; }; /******************************************************** @@ -376,8 +428,8 @@ class Clignoteur *********************************************************/ class Compteur { - // methodes - public : + // methodes +public: // Constructeur qui prend en parametre la valeur de preselection Compteur(int valeurPreselection) { @@ -402,18 +454,18 @@ class Compteur // recuperation de la valeur courante int getValeurCourante() { - return(valeur); + return (valeur); } // est-ce que la preselection est atteinte (sortie Q compteur Siemens ou Schnieder) bool getSortie() { - return(valeur == valeurPreselection); + return (valeur == valeurPreselection); } - // Attributs - private: - int valeur; - int valeurPreselection; + // Attributs +private: + int valeur; + int valeurPreselection; }; /******************************************************** @@ -421,9 +473,9 @@ class Compteur *********************************************************/ class MiseAEchelle { - public : +public: // Constructeur qui ne prend en parametre la plage d'entree et la plage de sortie - MiseAEchelle(float minEntree,float maxEntree,float minSortie,float maxSortie) + MiseAEchelle(float minEntree, float maxEntree, float minSortie, float maxSortie) { this->minEntree = minEntree; this->maxEntree = maxEntree; @@ -433,19 +485,19 @@ class MiseAEchelle // fonction de conversion qui prend la valeur a convertir et renvoie la valeur convertie float convertir(float valeurAConvertir) { - if(valeurAConvertir >= minEntree && valeurAConvertir <= maxEntree) + if (valeurAConvertir >= minEntree && valeurAConvertir <= maxEntree) { float norm = (1 / (maxEntree - minEntree)) * (valeurAConvertir - minEntree); float scale = (maxSortie - minSortie) * norm + minSortie; - return(scale); + return (scale); } - return(-1000); + return (-1000); } - // Attributs - private: - float minEntree; - float minSortie; - float maxEntree; + // Attributs +private: + float minEntree; + float minSortie; + float maxEntree; float maxSortie; }; diff --git a/main.cpp b/main.cpp index 064a8b3..624c022 100644 --- a/main.cpp +++ b/main.cpp @@ -9,6 +9,10 @@ int marche_frontmontant = 0; int arret_precedent = 1; int arret_frontdescedant = 0; +int bouton_precedent[8]; +int bouton_frontmontant[8]; +int bouton_frontdescendant[8]; + int b0_precedent = 0; int b0_frontmontant = 0; int b1_precedent = 0; @@ -33,11 +37,15 @@ int sens = 1; int ci = 0; int mode_auto = 0; +int mode_manu = 0; int etape = 0; +int etape_2 = 0; int c5_frontdescendant = 0; int c5_precedent = 0; + + int main() { mqtt_open(&client); @@ -56,33 +64,76 @@ int main() void process() { // Détection du front montant (état courant supérieur à l'état précédent) - b0_frontmontant = b0 > b0_precedent; - b1_frontmontant = b1 > b1_precedent; - b2_frontmontant = b2 > b2_precedent; - b3_frontmontant = b3 > b3_precedent; - b4_frontmontant = b4 > b4_precedent; - b5_frontmontant = b5 > b5_precedent; - b6_frontmontant = b6 > b6_precedent; - b7_frontmontant = b7 > b7_precedent; + for(int i = 0; i < 8 ; i++) { + bouton_frontmontant[i] = bouton[i] > bouton_precedent[i]; + bouton_frontdescendant[i] = bouton[i] < bouton_precedent[i]; + } marche_frontmontant = marche > marche_precedent; arret_frontdescedant = arret < arret_precedent; - c5_frontdescendant = c5 < c5_precedent; - m0 = i0; - m1 = i1; + /* + int etape_suivante = etape; + int etape_suivante2 = etape_2; + + if (etape == 0 && b6_frontmontant == 1) { + etape_suivante = 1; + } + + if (etape == 1 && b6_frontmontant == 1) { + etape_suivante = 0; + } + + if (etape_2 == 0 && b7_frontmontant == 1) + { + etape_suivante2 = 1; + } + + if (etape_2 == 1 && b7_frontmontant == 1) + { + etape_suivante2 = 0; + } + + etape = etape_suivante; + etape_2 = etape_suivante2; + + m0 = etape == 1; + m1 = etape_2 == 1; + */ + + + if (b6_frontmontant) { + m0 = !m0; + } + + if (b7_frontmontant) { + m1 = !m1; + } + + + if (abs(p0 - v0) < 3) { + m0 = m1 = 0; + + } else { + + if (p0 < v0) + { + m0 = 1; + m1 = 0; + } + + if (p0 > v0) + { + m0 = 0; + m1 = 1; + } + } // Prêt pour un nouveau tour // L'état courant devient l'état précédent - b0_precedent = b0; - b1_precedent = b1; - b2_precedent = b2; - b3_precedent = b3; - b4_precedent = b4; - b5_precedent = b5; - b6_precedent = b6; - b7_precedent = b7; + for (int i = 0; i < 8; i++) { + bouton_precedent[i] = bouton[i]; + } marche_precedent = marche; arret_precedent = arret; - c5_precedent = c5; }