add config.ini

This commit is contained in:
Mathis 2024-01-19 16:37:35 +01:00
parent 81c9ececf6
commit 1e59d9dc46
3 changed files with 21 additions and 10 deletions

View File

@ -14,3 +14,10 @@ build_flags =
-D MONITOR_SPEED=${config.monitor_speed}
; DO NOT TOUCH --- END
-D WAITING_WIFI_DELAY=1000
;;;;;;;;;;;;;;;;;;;;;;
;;; Servo config ;;;
;;;;;;;;;;;;;;;;;;;;;;
-D RIGHT_POS=18
-D MIDDLE_POS=32
-D LEFT_POS=52

View File

@ -13,7 +13,7 @@ ServoMotorComponent::ServoMotorComponent(int PIN, unsigned long updatePeriod, f
this->PIN = PIN;
this->myservo.attach(PIN);
this->desiredposition = Position::MIDDLE;
this->currentPosition = 32;
this->currentPosition = MIDDLE_POS;
this->lastUpTime = millis();
this->updatePeriod = updatePeriod;
this->step = step;
@ -27,13 +27,13 @@ ServoMotorComponent::ServoMotorComponent(int PIN, unsigned long updatePeriod, f
void ServoMotorComponent::setDesiredPosition(Position desiredPosition) {
switch (desiredPosition) {
case Position::LEFT:
this->desiredposition = 52;
this->desiredposition = LEFT_POS;
break;
case Position::MIDDLE:
this->desiredposition = 32;
this->desiredposition = MIDDLE_POS;
break;
case Position::RIGHT:
this->desiredposition = 18;
this->desiredposition = RIGHT_POS;
break;
default:
break;
@ -49,10 +49,10 @@ void ServoMotorComponent::refresh() {
|| millis() - this->lastUpTime <= this->updatePeriod) return;
if (this->currentPosition > this->desiredposition) {
this->currentPosition--;
this->currentPosition -= this->step;
}
if (this->currentPosition < this->desiredposition) {
this->currentPosition++;
this->currentPosition += this->step;
}
this->lastUpTime = millis();
this->myservo.write(this->PIN, this->currentPosition);

View File

@ -1,6 +1,7 @@
#include "Program.h"
#include "Arduino.h"
#include "DolibarrClient.h"
#include "ServoMotorComponent.h"
int initialize_wifi(WifiConfig wifi) {
WiFiClass::mode(WIFI_STA); //Optional
@ -17,13 +18,16 @@ int initialize_wifi(WifiConfig wifi) {
Program::Program() {
Serial.begin(MONITOR_SPEED);
struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD};
struct DolibarrConfig dolibarr = {DOLIBARR_URL, DOLIBARR_API_TOKEN};
initialize_wifi(wifi_c);
this->client = new DolibarrClient(dolibarr);
this->servo = new ServoMotorComponent(2, 1, 0.1);
//struct WifiConfig wifi_c = {WIFI_SSID, WIFI_PASSWORD};
//struct DolibarrConfig dolibarr = {DOLIBARR_URL, DOLIBARR_API_TOKEN};
//initialize_wifi(wifi_c);
//this->client = new DolibarrClient(dolibarr);
}
void Program::loop() {
this->servo->refresh();
this->servo->setDesiredPosition(Position::LEFT);
}