summaryrefslogtreecommitdiffstats
path: root/fiz/naloga/merjenje/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fiz/naloga/merjenje/src/main.cpp')
-rw-r--r--fiz/naloga/merjenje/src/main.cpp48
1 files changed, 36 insertions, 12 deletions
diff --git a/fiz/naloga/merjenje/src/main.cpp b/fiz/naloga/merjenje/src/main.cpp
index a5209da..afe19de 100644
--- a/fiz/naloga/merjenje/src/main.cpp
+++ b/fiz/naloga/merjenje/src/main.cpp
@@ -10,10 +10,11 @@
#include <WiFiUdp.h>
#include <ESP8266httpUpdate.h>
#include <ESPAsyncWebServer.h>
+#include <limits>
#undef __POLLEDTIMING_H__ // http://github.com/dplasa/FTPClientServer/pull/19
#include <FTPServer.h>
#define TEXT_ENC "text/plain"
-#include "MPU9250.h"
+#include "mpu9250.h"
const int str2pin_map[] = { D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10, 0, 0, 0, 0, 0, 0, 0, 0, 0, A0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
int str2pin (const char * s) {
if (s[0] >= '0' && s[0] <= '9')
@@ -40,7 +41,8 @@ void notFound (AsyncWebServerRequest * request) {
FTPServer ftpServer(LittleFS);
DNSServer dnsServer;
AsyncWebServer httpServer(80);
-MPU9250 mpu;
+bfs::Mpu9250 imu;
+File measureFile;
int do_reload = 0;
int measure = 0;
void reload (bool w) {
@@ -120,7 +122,11 @@ void reload (bool w) {
return;
}
measure = 1;
- r->send(201, TEXT_ENC, "OK\n");
+ char filename[32];
+ snprintf(filename, 32, "meritev%lld.tsv", time(NULL));
+ Serial.println(String("opening measureFile ")+filename);
+ measureFile = LittleFS.open(filename, "w");
+ r->send(201, TEXT_ENC, String(filename) + "\n");
});
ADD_AUTH(m);
auto k = httpServer.on("/k", [](AsyncWebServerRequest * r) {
@@ -129,28 +135,46 @@ void reload (bool w) {
return;
}
measure = 0;
+ measureFile.close();
+ digitalWrite(LED_BUILTIN, HIGH); // izklopi luč
r->send(201, TEXT_ENC, "OK\n");
});
ADD_AUTH(k);
auto c = httpServer.on("/c", [](AsyncWebServerRequest * r) {
- r->send(201, TEXT_ENC, "glej sporočila na UART za navodila\n");
- mpu.calibrateMag();
+ r->send(404, TEXT_ENC, "404\n");
});
ADD_AUTH(c);
httpServer.begin();
Wire.begin();
- int naslov = settings["mpu_address"].as<int>();
- if (!mpu.setup(naslov)) {
- Serial.println("mpu ni dosegljiv na naslovu " + naslov);
+ Wire.setClock(400000);
+ imu.Config(&Wire, bfs::Mpu9250::I2C_ADDR_PRIM);
+ if (!imu.Begin()) {
+ Serial.println("mpu ni dosegljiv na naslovu 0x68");
}
- mpu.verbose(true);
+ if (!imu.ConfigSrd(19))
+ Serial.println("imu.ConfigSrd(19)");
Serial.println("reload: done");
}
void handleMeasure () {
- if (!mpu.update()) {
- Serial.println("!mpu.update()");
+ if (!imu.Read())
+ Serial.println("!imu.Read()");
+ Serial.print(imu.new_imu_data());
+ Serial.print("\t");
+ Serial.print(imu.mag_x_ut());
+ Serial.print("\t");
+ Serial.print(imu.mag_y_ut());
+ Serial.print("\t");
+ Serial.print(imu.mag_z_ut());
+ Serial.print("\t");
+ Serial.print(imu.die_temp_c());
+ Serial.print("\n");
+ if (!measureFile.isFile())
+ Serial.println("!measureFile.isFile()");
+ else {
+ digitalWrite(LED_BUILTIN, LOW); // vklopi luč
+ measureFile.printf("%lu\t%d\t%f\t%f\t%f\t%f\n", millis(), imu.new_imu_data(), imu.mag_x_ut(), imu.mag_y_ut(), imu.mag_z_ut(), imu.die_temp_c());
+ // String(millis())+String("\t")+imu.new_imu_data()+String("\t")+imu.mag_x_ut()+String("\t")+imu.mag_y_ut()+String("\t")+imu.mag_z_ut()+String("\t")+imu.die_temp_c()+String("\n"));
}
- Serial.printf("getMag: X: %f\tY: %f\tZ: %f\n", mpu.getMagX(), mpu.getMagY(), mpu.getMagZ());
return;
}
void setup () {