add config.ini

This commit is contained in:
Mathis 2024-01-19 16:37:35 +01:00
parent 15bd7c7741
commit fe671182cd
3 changed files with 19 additions and 10 deletions

View File

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

View File

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