Skip to content

Commit

Permalink
v0.9.7 - Ajout virage treuil
Browse files Browse the repository at this point in the history
  • Loading branch information
fra589 committed Mar 25, 2023
1 parent dd6637a commit 7707c73
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 127 deletions.
63 changes: 33 additions & 30 deletions WeTimer/WeTimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,43 +43,45 @@

#define ORG_NAME "fra589"
#define APP_NAME "WeTimer\0"
#define APP_VERSION_STRING "v0.9.6"
#define APP_VERSION_DATE "20230128"
#define APP_VERSION_STRING "v0.9.7"
#define APP_VERSION_DATE "20230325"


//----------------------------------------------------------------------------------------------------
// Adresses EEProm pour sauvegarde des paramètres
//----------------------------------------------------------------------------------------------------
#define EEPROM_LENGTH 512
//----------------------------------------------------------------------------------------------------
#define ADDR_TEMPS_ARMEMENT 0
#define ADDR_TEMPS_VOL 2
#define ADDR_SERVO_STAB_VOL 4
#define ADDR_SERVO_STAB_TREUIL 6
#define ADDR_SERVO_STAB_DT 8
#define ADDR_SERVO_DERIVE_VOL 10
#define ADDR_SERVO_DERIVE_TREUIL 12
#define ADDR_SERVO_DERIVE_ZOOM 14
#define ADDR_CLI_SSID 16
#define ADDR_CLI_PWD 48 // 16 + 32
#define ADDR_AP_SSID 111 // 48 + 63
#define ADDR_AP_PWD 143 // 111 + 32
#define ADDR_TEMPS_ARMEMENT 0
#define ADDR_TEMPS_VOL 2
#define ADDR_SERVO_STAB_VOL 4
#define ADDR_SERVO_STAB_TREUIL 6
#define ADDR_SERVO_STAB_DT 8
#define ADDR_SERVO_DERIVE_VOL 10
#define ADDR_SERVO_DERIVE_TREUIL_TENDU 12
#define ADDR_SERVO_DERIVE_TREUIL_VIRAGE 14
#define ADDR_SERVO_DERIVE_ZOOM 16
#define ADDR_CLI_SSID 18
#define ADDR_CLI_PWD 50 // 18 + 32
#define ADDR_AP_SSID 113 // 50 + 63
#define ADDR_AP_PWD 145 // 113 + 32

//----------------------------------------------------------------------------------------------------
// Valeurs des paramètres par défauts
//----------------------------------------------------------------------------------------------------
#define DEFAULT_TEMPS_ARMEMENT 2 // Délai d'armement de la minuterie = 2 seconde
#define DEFAULT_TEMPS_VOL 183 // Temps de vol par défaut 3 minutes
#define DEFAULT_SERVO_STAB_VOL 1000 // Position servo au départ du vol (1000 micro secondes = 0°)
#define DEFAULT_SERVO_STAB_TREUIL 1200 // Position servo quand le switch crochet est actionné (câble tendu)
#define DEFAULT_SERVO_STAB_DT 2000 // Position servo au DT (2000 micro secondes = angle max du servo)
#define DEFAULT_SERVO_DERIVE_VOL 1100 // Position servo de dérive en vol spirale
#define DEFAULT_SERVO_DERIVE_TREUIL 1500 // Position servo de dérive câble tendu (montée droite)
#define DEFAULT_SERVO_DERIVE_ZOOM 1300 // Position servo de dérive câble tendu au zoom
#define DEFAULT_CLI_SSID "\0" // SSID client (la minuterie se connecte si défini)
#define DEFAULT_CLI_PWD "\0" // WPA-PSK/WPA2-PSK client
#define DEFAULT_AP_SSID "WeTimer_\0" // SSID de l'AP minuterie
#define DEFAULT_AP_PWD "\0" // WPA-PSK/WPA2-PSK AP
#define DEFAULT_TEMPS_ARMEMENT 2 // Délai d'armement de la minuterie = 2 seconde
#define DEFAULT_TEMPS_VOL 183 // Temps de vol par défaut 3 minutes
#define DEFAULT_SERVO_STAB_VOL 1000 // Position servo au départ du vol (1000 micro secondes = 0°)
#define DEFAULT_SERVO_STAB_TREUIL 1200 // Position servo quand le switch crochet est actionné (câble tendu)
#define DEFAULT_SERVO_STAB_DT 2000 // Position servo au DT (2000 micro secondes = angle max du servo)
#define DEFAULT_SERVO_DERIVE_VOL 1200 // Position servo de dérive en vol spirale
#define DEFAULT_SERVO_DERIVE_TREUIL_TENDU 1500 // Position servo de dérive câble tendu (montée droite)
#define DEFAULT_SERVO_DERIVE_TREUIL_VIRAGE 1100 // Position servo de dérive câble détendu (virage treuil)
#define DEFAULT_SERVO_DERIVE_ZOOM 1300 // Position servo de dérive câble tendu au zoom
#define DEFAULT_CLI_SSID "\0" // SSID client (la minuterie se connecte si défini)
#define DEFAULT_CLI_PWD "\0" // WPA-PSK/WPA2-PSK client
#define DEFAULT_AP_SSID "WeTimer_\0" // SSID de l'AP minuterie
#define DEFAULT_AP_PWD "\0" // WPA-PSK/WPA2-PSK AP

#define MIN_SERVO_MICROSECONDS 1000
#define MAX_SERVO_MICROSECONDS 2000
Expand All @@ -95,13 +97,13 @@
//----------------------------------------------------------------------------------------------------
// Valeurs d'état du switch crochet
//----------------------------------------------------------------------------------------------------
#define CROCHET_TENDU 0
#define CROCHET_TENDU 0
#define CROCHET_RELACHE 1

//----------------------------------------------------------------------------------------------------
// Valeurs d'état du switch zoom
//----------------------------------------------------------------------------------------------------
#define ZOOM_ON 0
#define ZOOM_ON 0
#define ZOOM_OFF 1

//----------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -130,10 +132,11 @@
extern unsigned int servoStabTreuil;
extern unsigned int servoStabDT;
extern unsigned int servoDeriveVol;
extern unsigned int servoDeriveTreuil;
extern unsigned int servoDeriveTreuilTendu;
extern unsigned int servoDeriveTreuilVirage;
extern unsigned int servoDeriveZoom;

// hostname for mDNS. Should work at least on windows. Try http://minuterie.local
// hostname for mDNS. Should work at least on windows. Try http://WeTimer.local
extern const char *myHostname;

// DNS server
Expand Down
128 changes: 77 additions & 51 deletions WeTimer/WeTimer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ char cli_pwd[63] = DEFAULT_CLI_PWD;
char ap_ssid[32] = DEFAULT_AP_SSID;
char ap_pwd[63] = DEFAULT_AP_PWD;

unsigned int delaiArmement = DEFAULT_TEMPS_ARMEMENT; // Secondes
unsigned int tempsVol = DEFAULT_TEMPS_VOL; // Secondes
unsigned int servoStabVol = DEFAULT_SERVO_STAB_VOL; // Microsecondes
unsigned int servoStabTreuil = DEFAULT_SERVO_STAB_TREUIL; // Microsecondes
unsigned int servoStabDT = DEFAULT_SERVO_STAB_DT; // Microsecondes
unsigned int servoDeriveVol = DEFAULT_SERVO_DERIVE_VOL; // Microsecondes
unsigned int servoDeriveTreuil = DEFAULT_SERVO_DERIVE_TREUIL; // Microsecondes
unsigned int servoDeriveZoom = DEFAULT_SERVO_DERIVE_ZOOM; // Microsecondes
unsigned int delaiArmement = DEFAULT_TEMPS_ARMEMENT; // Secondes
unsigned int tempsVol = DEFAULT_TEMPS_VOL; // Secondes
unsigned int servoStabVol = DEFAULT_SERVO_STAB_VOL; // Microsecondes
unsigned int servoStabTreuil = DEFAULT_SERVO_STAB_TREUIL; // Microsecondes
unsigned int servoStabDT = DEFAULT_SERVO_STAB_DT; // Microsecondes
unsigned int servoDeriveVol = DEFAULT_SERVO_DERIVE_VOL; // Microsecondes
unsigned int servoDeriveTreuilTendu = DEFAULT_SERVO_DERIVE_TREUIL_TENDU; // Microsecondes
unsigned int servoDeriveTreuilVirage = DEFAULT_SERVO_DERIVE_TREUIL_VIRAGE; // Microsecondes
unsigned int servoDeriveZoom = DEFAULT_SERVO_DERIVE_ZOOM; // Microsecondes

/* hostname for mDNS. Should work at least on windows. Try http://minuterie.local */
const char *myHostname = APP_NAME;
Expand All @@ -60,7 +61,8 @@ int zoom = 0;
Servo servoStab; // Variable globale servo stabilisateur
Servo servoDerive; // Servo pour la dérive

int timerStatus = STATUS_DT;
int timerStatus = STATUS_DT;
bool flagZoom = false;

unsigned long blinkInterval = 1000; // 1 secondes
unsigned long previousBlink = 0;
Expand All @@ -83,14 +85,15 @@ void setup() {
EEPROM.begin(EEPROM_LENGTH);

// Récupération des paramètres dans la Flash ou de leur valeur par défaut
delaiArmement = EEPROM_readInt(ADDR_TEMPS_ARMEMENT); if (delaiArmement == 0xFFFF) delaiArmement = DEFAULT_TEMPS_ARMEMENT;
tempsVol = EEPROM_readInt(ADDR_TEMPS_VOL); if (tempsVol == 0xFFFF) tempsVol = DEFAULT_TEMPS_VOL;
servoStabVol = EEPROM_readInt(ADDR_SERVO_STAB_VOL); if (servoStabVol == 0xFFFF) servoStabVol = DEFAULT_SERVO_STAB_VOL;
servoStabTreuil = EEPROM_readInt(ADDR_SERVO_STAB_TREUIL); if (servoStabTreuil == 0xFFFF) servoStabTreuil = DEFAULT_SERVO_STAB_TREUIL;
servoStabDT = EEPROM_readInt(ADDR_SERVO_STAB_DT); if (servoStabDT == 0xFFFF) servoStabDT = DEFAULT_SERVO_STAB_DT;
servoDeriveVol = EEPROM_readInt(ADDR_SERVO_DERIVE_VOL); if (servoDeriveVol == 0xFFFF) servoDeriveVol = DEFAULT_SERVO_DERIVE_VOL;
servoDeriveTreuil = EEPROM_readInt(ADDR_SERVO_DERIVE_TREUIL); if (servoDeriveTreuil == 0xFFFF) servoDeriveTreuil = DEFAULT_SERVO_DERIVE_TREUIL;
servoDeriveZoom = EEPROM_readInt(ADDR_SERVO_DERIVE_ZOOM); if (servoDeriveZoom == 0xFFFF) servoDeriveZoom = DEFAULT_SERVO_DERIVE_ZOOM;
delaiArmement = EEPROM_readInt(ADDR_TEMPS_ARMEMENT); if (delaiArmement == 0xFFFF) delaiArmement = DEFAULT_TEMPS_ARMEMENT;
tempsVol = EEPROM_readInt(ADDR_TEMPS_VOL); if (tempsVol == 0xFFFF) tempsVol = DEFAULT_TEMPS_VOL;
servoStabVol = EEPROM_readInt(ADDR_SERVO_STAB_VOL); if (servoStabVol == 0xFFFF) servoStabVol = DEFAULT_SERVO_STAB_VOL;
servoStabTreuil = EEPROM_readInt(ADDR_SERVO_STAB_TREUIL); if (servoStabTreuil == 0xFFFF) servoStabTreuil = DEFAULT_SERVO_STAB_TREUIL;
servoStabDT = EEPROM_readInt(ADDR_SERVO_STAB_DT); if (servoStabDT == 0xFFFF) servoStabDT = DEFAULT_SERVO_STAB_DT;
servoDeriveVol = EEPROM_readInt(ADDR_SERVO_DERIVE_VOL); if (servoDeriveVol == 0xFFFF) servoDeriveVol = DEFAULT_SERVO_DERIVE_VOL;
servoDeriveTreuilTendu = EEPROM_readInt(ADDR_SERVO_DERIVE_TREUIL_TENDU); if (servoDeriveTreuilTendu == 0xFFFF) servoDeriveTreuilTendu = DEFAULT_SERVO_DERIVE_TREUIL_TENDU;
servoDeriveTreuilVirage = EEPROM_readInt(ADDR_SERVO_DERIVE_TREUIL_VIRAGE); if (servoDeriveTreuilVirage == 0xFFFF) servoDeriveTreuilVirage = DEFAULT_SERVO_DERIVE_TREUIL_VIRAGE;
servoDeriveZoom = EEPROM_readInt(ADDR_SERVO_DERIVE_ZOOM); if (servoDeriveZoom == 0xFFFF) servoDeriveZoom = DEFAULT_SERVO_DERIVE_ZOOM;

char charTmp = char(EEPROM.read(ADDR_CLI_SSID));
if (charTmp != 0xFF) {
Expand Down Expand Up @@ -125,36 +128,38 @@ void setup() {
}

#ifdef debug
Serial.print("delaiArmement = "); Serial.println(delaiArmement);
Serial.print("tempsVol = "); Serial.println(tempsVol);
Serial.print("servoStabVol = "); Serial.println(servoStabVol);
Serial.print("servoStabTreuil = "); Serial.println(servoStabTreuil);
Serial.print("servoStabDT = "); Serial.println(servoStabDT);
Serial.print("servoDeriveVol = "); Serial.println(servoDeriveVol);
Serial.print("servoDeriveTreuil = "); Serial.println(servoDeriveTreuil);
Serial.print("cli_ssid = "); Serial.println(cli_ssid);
Serial.print("cli_pwd = "); Serial.println(cli_pwd);
Serial.print("ap_ssid = "); Serial.println(ap_ssid);
Serial.print("ap_pwd = "); Serial.println(ap_pwd);
Serial.print("delaiArmement.......... = "); Serial.println(delaiArmement);
Serial.print("tempsVol............... = "); Serial.println(tempsVol);
Serial.print("servoStabVol........... = "); Serial.println(servoStabVol);
Serial.print("servoStabTreuil........ = "); Serial.println(servoStabTreuil);
Serial.print("servoStabDT............ = "); Serial.println(servoStabDT);
Serial.print("servoDeriveVol......... = "); Serial.println(servoDeriveVol);
Serial.print("servoDeriveTreuilTendu. = "); Serial.println(servoDeriveTreuilTendu);
Serial.print("servoDeriveTreuilVirage = "); Serial.println(servoDeriveTreuilVirage);
Serial.print("servoDeriveZoom........ = "); Serial.println(servoDeriveZoom);
Serial.print("cli_ssid............... = "); Serial.println(cli_ssid);
Serial.print("cli_pwd................ = "); Serial.println(cli_pwd);
Serial.print("ap_ssid................ = "); Serial.println(ap_ssid);
Serial.print("ap_pwd................. = "); Serial.println(ap_pwd);
#endif

servoStab.attach(PIN_SERVO_STAB);
servoStab.writeMicroseconds(servoStabDT);
servoDerive.attach(PIN_SERVO_DERIVE);
servoDerive.writeMicroseconds(servoDeriveVol);
#ifdef debug
Serial.print("setup() : Servo stab en position DT ("); Serial.print(servoStabDT); Serial.println(")");
Serial.print("setup() : Servo derive en position vol ("); Serial.print(servoDeriveVol); Serial.println(")");
Serial.print("setup() : Position initiale Servo stab en position DT ("); Serial.print(servoStabDT); Serial.println(")");
Serial.print("setup() : Position initiale Servo derive en position vol ("); Serial.print(servoDeriveVol); Serial.println(")");
#endif

pinMode(PIN_SWITCH, INPUT_PULLUP);
pinMode(GND_SWITCH, OUTPUT);
digitalWrite(GND_SWITCH, LOW);

pinMode(PIN_ZOOM, INPUT_PULLUP);
pinMode(GND_ZOOM, OUTPUT);
digitalWrite(GND_ZOOM, LOW);

pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, ledState);

Expand Down Expand Up @@ -190,7 +195,7 @@ void setup() {
Serial.flush();
#endif
}

/* AP ouverte si pas de mot de passe. */
WiFi.softAPConfig(apIP, apIP, netMsk);
if (ap_pwd[0] == '\0') {
Expand Down Expand Up @@ -252,16 +257,17 @@ void loop() {
// On vient d'enfoncer la pédale du crochet
// On positionne les 2 servos en mode treuillage
servoStab.writeMicroseconds(servoStabTreuil);
servoDerive.writeMicroseconds(servoDeriveTreuil);
servoDerive.writeMicroseconds(servoDeriveTreuilTendu);
#ifdef debug
Serial.print("Tension du crochet : Stab en position treuil, servoStabTreuil = "); Serial.println(servoStabTreuil);
Serial.print("Tension du crochet : Dérive en position treuil, servoDeriveTreuil = "); Serial.println(servoDeriveTreuil);
Serial.print("Tension du crochet : Stab en position treuil, servoStabTreuil = "); Serial.println(servoStabTreuil);
Serial.print("Tension du crochet : Dérive en position treuil, servoDeriveTreuilTendu = "); Serial.println(servoDeriveTreuilTendu);
#endif
if (timerStatus == STATUS_DT) {
// On était en DT, on arme la minuterie
timerStatus = STATUS_ARMEE;
debut = millis();
blinkInterval = 1000; // 1 secondes
flagZoom = false; // Réinitialise le flag du Zoom
#ifdef debug
////Serial.println("Servo en position départ.");
Serial.println("timerStatus = STATUS_ARMEE");
Expand All @@ -285,17 +291,28 @@ void loop() {
}
} else { // new_crochet == CROCHET_RELACHE
// Le cable vient de se relacher,
// On positionne les 2 servos en mode plané si on est pas déthermalisé
if (timerStatus != STATUS_DT) {
// On positionne le servos stab en mode plané si on est pas déthermalisé
servoStab.writeMicroseconds(servoStabVol);
servoDerive.writeMicroseconds(servoDeriveVol);
#ifdef debug
Serial.print("Relâchement du crochet : Stab en position vol, servoStabVol = "); Serial.println(servoStabVol);
Serial.print("Relâchement du crochet : Dérive en position vol, servoDeriveVol = "); Serial.println(servoDeriveVol);
Serial.print("Relâchement du crochet : Stab en position vol, servoStabVol = "); Serial.println(servoStabVol);
#endif
if (flagZoom) {
// Le zoom à été activé, donc c'est sensé être largué. => Dérive en position virage vol.
servoDerive.writeMicroseconds(servoDeriveVol);
#ifdef debug
Serial.print("Relâchement du crochet : Dérive en position vol, servoDeriveVol = "); Serial.println(servoDeriveVol);
#endif
} else {
// Le zoom n'a pas encore été activé, on est sensé être encore vérouillé. => Dérive en position virage treuil.
servoDerive.writeMicroseconds(servoDeriveTreuilVirage);
#ifdef debug
Serial.print("Relâchement du crochet : Dérive en position virage treuil, servoDeriveTreuilVirage = "); Serial.println(servoDeriveTreuilVirage);
#endif
}
}
if (timerStatus == STATUS_TREUIL) {
// Début du vol
// Début du vol (ou virage treuil)
timerStatus = STATUS_VOL;
debut = millis();
blinkInterval = 500; // 1/2 secondes
Expand All @@ -319,21 +336,30 @@ void loop() {
if ((new_zoom == ZOOM_ON) && (crochet == CROCHET_TENDU)) {
// Servo dérive en position zoom
servoDerive.writeMicroseconds(servoDeriveZoom);
flagZoom = true; // Utilisé pour passer du virage treuil au virage plané.
#ifdef debug
Serial.print("Activation zoom : Dérive en position zoom, servoDeriveZoom = "); Serial.println(servoDeriveZoom);
#endif
} else if ((new_zoom == ZOOM_OFF) && (crochet == CROCHET_TENDU)) {
// Servo dérive en position treuil
servoDerive.writeMicroseconds(servoDeriveTreuil);
// Servo dérive en position treuil tendu
servoDerive.writeMicroseconds(servoDeriveTreuilTendu);
#ifdef debug
Serial.print("Désactivation zoom : Dérive en position treuil, servoDeriveTreuil = "); Serial.println(servoDeriveTreuil);
Serial.print("Désactivation zoom : Dérive en position treuil, servoDeriveTreuilTendu = "); Serial.println(servoDeriveTreuilTendu);
#endif
} else {
// Crochet détendu, servo dérive en position vol quelque soit l'état du switch zoom.
servoDerive.writeMicroseconds(servoDeriveVol);
#ifdef debug
Serial.print("Crochet détendu, zoom inactif : Dérive en position vol, servoDeriveVol = "); Serial.println(servoDeriveVol);
#endif
if (flagZoom) {
// Le zoom à été activé, donc c'est sensé être largué. => Dérive en position virage vol.
servoDerive.writeMicroseconds(servoDeriveVol);
#ifdef debug
Serial.print("Crochet détendu, zoom inactif : Dérive en position vol, servoDeriveVol = "); Serial.println(servoDeriveVol);
#endif
} else {
// Le zoom n'a pas encore été activé, on est sensé être encore vérouillé. => Dérive en position virage treuil.
servoDerive.writeMicroseconds(servoDeriveTreuilVirage);
#ifdef debug
Serial.print("Crochet détendu, zoom inactif : Dérive en position virage treuil, servoDeriveTreuilVirage = "); Serial.println(servoDeriveTreuilVirage);
#endif
}
}
zoom = new_zoom;
} // if (new_zoom != zoom)
Expand Down
Loading

0 comments on commit 7707c73

Please sign in to comment.