diff --git a/MotionToPhotonMeter.ino b/MotionToPhotonMeter.ino index 10044f722bf92959d547fee87d1f67226167fa8f..2a9f326592aa5553f49699868524635557f3a7c9 100644 --- a/MotionToPhotonMeter.ino +++ b/MotionToPhotonMeter.ino @@ -6,6 +6,8 @@ void startMeasureing(unsigned int numberOfSamples); unsigned int getPhotoDiodeReading(); void setThresholdValue(unsigned int newThreshold); +unsigned int getDeflectionValue(); +void setDeflectionValue(unsigned int newDeflection); unsigned int getThresholdValue(); String getStatus(); unsigned int getCurrentNumberOfResults(); @@ -26,6 +28,7 @@ Servo rotation_servo; /* Global Values */ int zeroValueForServo = 0; +unsigned int deflection = 10; long startTime = -1; int triggerValue = 2500; unsigned int requested_measurements = -1; @@ -38,7 +41,7 @@ unsigned long result_buffer[result_buffer_length]; unsigned int result_number = 0; /* Server */ -MotionToPhotonServer server(result_buffer, result_buffer_length, getPhotoDiodeReading, getThresholdValue, setThresholdValue, getStatus, startMeasureing, getCurrentNumberOfResults, abortMeasurement); +MotionToPhotonServer server(result_buffer, result_buffer_length, getPhotoDiodeReading, getThresholdValue, setThresholdValue, getDeflectionValue, setDeflectionValue, getStatus, startMeasureing, getCurrentNumberOfResults, abortMeasurement); /* Multicore */ TaskHandle_t TaskCore0; @@ -55,7 +58,7 @@ void core1( void * pvParameters ){ && result_number < requested_measurements){ zeroServo(); //Rearm delay(5000); - rotation_servo.write(0); //big movement + rotation_servo.write(zeroValueForServo - deflection); //deflection movement } if(current_internal_status == InternalStatus::Zeroed){ @@ -101,12 +104,10 @@ void setup() { server.setup(); esp_task_wdt_init(6000,false); - disableCore0WDT(); - disableCore1WDT(); xTaskCreatePinnedToCore( core0, // Task function. - "Server", // name of task. - 100000, // Stack size of task + "Server", // name of task. + 10000, // Stack size of task NULL, // parameter of the task 2, // priority of the task &TaskCore0, // Task handle to keep track of created task @@ -114,18 +115,21 @@ void setup() { delay(500); xTaskCreatePinnedToCore( core1, // Task function. - "Meter", // name of task. - 100000, // Stack size of task + "Meter", // name of task. + 10000, // Stack size of task NULL, // parameter of the task 2, // priority of the task &TaskCore1, // Task handle to keep track of created task 1); // pin task to core 1 delay(500); + disableCore0WDT(); + disableCore1WDT(); } void loop(){} //Still needed for arduino core to work void startMeasureing(unsigned int numberOfSamples){ + if(numberOfSamples > result_buffer_length) return; memset(result_buffer, 0l, result_buffer_length * sizeof(long)); //clear buffer result_number = 0; requested_measurements = numberOfSamples; @@ -151,6 +155,14 @@ unsigned int getThresholdValue(){ return triggerValue; } +unsigned int getDeflectionValue(){ + return deflection; +} + +void setDeflectionValue(unsigned int newDeflection){ + deflection = newDeflection; +} + String getStatus(){ return Status_Text[current_status]; } diff --git a/MotionToPhotonServer.cpp b/MotionToPhotonServer.cpp index 218325b452a5c774ca60dd3ed8e3f496f8854809..bb3f6192944d1735cd6fb8dc20576212cd8259d1 100644 --- a/MotionToPhotonServer.cpp +++ b/MotionToPhotonServer.cpp @@ -2,10 +2,12 @@ /* Server Setup */ - MotionToPhotonServer::MotionToPhotonServer(unsigned long* result_buffer_, unsigned int result_buffer_length_, unsigned int (* getPhotodiodeReadingFunction)(), unsigned int (* getThresholdFunction)(), void (* setThresholdFunction)(unsigned int), String (* getStatusFunction)(), void (* startMeasureFunction)(unsigned int), unsigned int (* getCurrentNumberOfResultsFunction)(), void (* abortMeasurementFunction)()) { + MotionToPhotonServer::MotionToPhotonServer(unsigned long* result_buffer_, unsigned int result_buffer_length_, unsigned int (* getPhotodiodeReadingFunction)(), unsigned int (* getThresholdFunction)(), void (* setThresholdFunction)(unsigned int), unsigned int (* getDeflectionFunction)(), void (* setDeflectionFunction)(unsigned int), String (* getStatusFunction)(), void (* startMeasureFunction)(unsigned int), unsigned int (* getCurrentNumberOfResultsFunction)(), void (* abortMeasurementFunction)()) { getPhotodiodeReading = getPhotodiodeReadingFunction; getThreshold = getThresholdFunction; setThreshold = setThresholdFunction; + getDeflection = getDeflectionFunction; + setDeflection = setDeflectionFunction; getStatus = getStatusFunction; startMeasure = startMeasureFunction; abortMeasurement = abortMeasurementFunction; @@ -32,6 +34,8 @@ server.on("/sensor", [this](){this->pageSensor();}); server.on("/setThreshold", [this](){this->pageSetThreshold();}); server.on("/getThreshold", [this](){this->pageGetThreshold();}); + server.on("/setDeflection", [this](){this->pageSetDeflection();}); + server.on("/getDeflection", [this](){this->pageGetDeflection();}); server.on("/abort", [this](){this->pageAbort();}); server.onNotFound([this](){this->pageNotFound();}); @@ -68,6 +72,21 @@ server.send(200, "text/plain", String(getThreshold())); } + void MotionToPhotonServer::pageSetDeflection(){ + if(server.args() <= 0){ + server.send(400, "text/plain", "No parameters given. Give d=<deflection>"); + return; + } + unsigned int deflection = String(server.arg(0)).toInt(); + + setDeflection(deflection); + server.send(200, "text/plain", "Ok."); + } + + void MotionToPhotonServer::pageGetDeflection(){ + server.send(200, "text/plain", String(getDeflection())); + } + void MotionToPhotonServer::pageSensor(){ server.send(200, "text/plain", String(getPhotodiodeReading())); } diff --git a/MotionToPhotonServer.h b/MotionToPhotonServer.h index 81cdede99420d4177c040316167c0fba7e4325f3..a73cc9c31bca2064a11ebf0bb981c21bebc1f954 100644 --- a/MotionToPhotonServer.h +++ b/MotionToPhotonServer.h @@ -10,9 +10,11 @@ class MotionToPhotonServer private: unsigned int (* getPhotodiodeReading)(); unsigned int (* getThreshold)(); + unsigned int (* getDeflection)(); unsigned int (* getCurrentNumberOfResults)(); String (* getStatus)(); void (* setThreshold)(unsigned int); + void (* setDeflection)(unsigned int); void (* startMeasure)(unsigned int); void (* abortMeasurement)(); @@ -39,6 +41,8 @@ class MotionToPhotonServer void pageStatus(); void pageSetThreshold(); void pageGetThreshold(); + void pageSetDeflection(); + void pageGetDeflection(); void pageMeasure(); void pageResults(); void pageIndex(); @@ -50,7 +54,7 @@ class MotionToPhotonServer public: /* Server functions */ - MotionToPhotonServer(unsigned long* result_buffer_, unsigned int result_buffer_length_, unsigned int (* getPhotodiodeReadingFunction)(), unsigned int (* getThresholdFunction)(), void (* setThresholdFunction)(unsigned int), String (* getStatusFunction)(), void (* startMeasureFunction)(unsigned int), unsigned int (* getCurrentNumberOfResultsFunction)(), void (* abortMeasurementFunction)()); + MotionToPhotonServer(unsigned long* result_buffer_, unsigned int result_buffer_length_, unsigned int (* getPhotodiodeReadingFunction)(), unsigned int (* getThresholdFunction)(), void (* setThresholdFunction)(unsigned int), unsigned int (* getDeflectionFunction)(), void (* setDeflectionFunction)(unsigned int), String (* getStatusFunction)(), void (* startMeasureFunction)(unsigned int), unsigned int (* getCurrentNumberOfResultsFunction)(), void (* abortMeasurementFunction)()); void setup(); void serve(); diff --git a/data/index.html b/data/index.html index 685ef8f538ff315bc43ba130c2fe9275ba71ddf3..9c0266a33eeb87d4fb928b0542aaa4f601d1418a 100644 --- a/data/index.html +++ b/data/index.html @@ -66,13 +66,23 @@ } function setThreshold(){ - if(document.getElementById("sensorThreshhold").checkValidity()){ - makeRequest('setThreshold?t=' + document.getElementById("sensorThreshhold").value); + if(document.getElementById("sensorThreshold").checkValidity()){ + makeRequest('setThreshold?t=' + document.getElementById("sensorThreshold").value); } } function getThreshold(){ - document.getElementById("sensorThreshhold").value = makeRequest('getThreshold'); + document.getElementById("sensorThreshold").value = makeRequest('getThreshold'); + } + + function setDeflection(){ + if(document.getElementById("servoDeflection").checkValidity()){ + makeRequest('setDeflection?d=' + document.getElementById("servoDeflection").value); + } + } + + function getDeflection(){ + document.getElementById("servoDeflection").value = makeRequest('getDeflection'); } /* Statistics */ @@ -120,11 +130,12 @@ } } - document.onload = function(){ + document.addEventListener('DOMContentLoaded', (event) => { getThreshold(); + getDeflection(); getStatus(); getSensor(); - } + }); </script> </head> <body style="display: flex; flex-direction: row; align-items: center; flex-wrap: wrap; justify-content: center;"> @@ -134,7 +145,7 @@ </div> <div style="display: flex; flex-direction: column; align-items: stretch; flex-wrap: wrap; justify-content: center;"> <div id="statistics" class="box niceBorder" style="width: 500px; height: 80px;"></div> - <textarea id="results" class="textbox" style="width: 500px; height: 500px;"></textarea> + <textarea id="results" class="textbox" style="width: 500px; height: 650px;"></textarea> </div> <div style="display: flex; flex-direction: column; align-items: stretch; flex-wrap: wrap; justify-content: center;"> <div class="box niceBorder"> @@ -149,9 +160,14 @@ </div> <div class="box niceBorder"> <div style="padding: 5px;">Sensor Threshold:</div> - <input type="number" id="sensorThreshhold" min="1" max="5000" value="2500"> + <input type="number" id="sensorThreshold" min="1" max="5000"> <div class="button" onclick="setThreshold()">Set!</div> </div> + <div class="box niceBorder"> + <div style="padding: 5px;">Servo Deflection:</div> + <input type="number" id="servoDeflection" min="1" max="360"> + <div class="button" onclick="setDeflection()">Set!</div> + </div> <div class="box niceBorder"> <div style="padding: 5px;">Times to Meassure:</div> <input type="number" id="numberOfCycles" min="1" max="500" value="1">