Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: HTTPScriptIMU.cpp
- Revision:
- 0:3fb3c13f3cf5
diff -r 000000000000 -r 3fb3c13f3cf5 HTTPScriptIMU.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPScriptIMU.cpp Wed Apr 15 12:53:31 2020 +0000
@@ -0,0 +1,57 @@
+/*
+ * HTTPScriptIMU.cpp
+ * Copyright (c) 2020, ZHAW
+ * All rights reserved.
+ */
+
+#include "HTTPScriptIMU.h"
+
+using namespace std;
+
+inline string float2String(float f) {
+
+ char buffer[32];
+ sprintf(buffer, "%.3f", f);
+
+ return string(buffer);
+}
+
+/**
+ * Create and initialize this http script.
+ * @param imu a reference to the imu to read data from.
+ */
+HTTPScriptIMU::HTTPScriptIMU(IMU& imu) : imu(imu) {}
+
+HTTPScriptIMU::~HTTPScriptIMU() {}
+
+/**
+ * This method gets called by the http server, when an object of this class is
+ * registered with the server, and the corresponding script is called
+ * by an http client.
+ */
+string HTTPScriptIMU::call(vector<string> names, vector<string> values) {
+
+ string response;
+
+ response += " <imu>\r\n";
+ response += " <acceleration>\r\n";
+ response += " <x><float>"+float2String(imu.readAccelerationX())+"</float></x>\r\n";
+ response += " <y><float>"+float2String(imu.readAccelerationY())+"</float></y>\r\n";
+ response += " <z><float>"+float2String(imu.readAccelerationZ())+"</float></z>\r\n";
+ response += " </acceleration>\r\n";
+ response += " <gyro>\r\n";
+ response += " <x><float>"+float2String(imu.readGyroX())+"</float></x>\r\n";
+ response += " <y><float>"+float2String(imu.readGyroY())+"</float></y>\r\n";
+ response += " <z><float>"+float2String(imu.readGyroZ())+"</float></z>\r\n";
+ response += " </gyro>\r\n";
+ response += " <magnetometer>\r\n";
+ response += " <x><float>"+float2String(imu.readMagnetometerX())+"</float></x>\r\n";
+ response += " <y><float>"+float2String(imu.readMagnetometerY())+"</float></y>\r\n";
+ response += " <z><float>"+float2String(imu.readMagnetometerZ())+"</float></z>\r\n";
+ response += " </magnetometer>\r\n";
+
+ response += " </imu>\r\n";
+
+ return response;
+}
+