In this project research has been done on different types of special input for practical uses in applications and games. A gyroscope sensor is used to determine certain values. The NodeMCU ESP8266 microprocessor is used to receive these values and assign them to variables. It uses its built in Wi-Fi connectivity to send these values to a server.
Wayne used the Arduino IDE programming environment to receive, read and send values. Programming the NodeMCU has been done in the language ‘C’. He used the Simple and Fast Multimedia Library (SFML) to build an application that could receive the values from the server in a ‘JSON’-string and turn it into an object from which the values could be extracted. The application uses those values to move the player. It is written in the language ‘C++’.
Wayne contributed about 97% of all the work to this project. Under well received guidance was he able to accomplish everything in this project. An example of the process of serializing a ‘JSON’-document can be found below. As well as an example of receiving a ‘JSON’-string by ‘HTTP-request’ and deserializing the ‘JSON’-string to be used as values.
//Convert Raw Data to Scaled Data
scaleddata convertRawToScaled(byte addr, rawdata data_in)
{
scaleddata values;
float scale_value = 0.0;
byte Gyro, Accl;
getMPU6050scales(MPU_addr, Gyro, Accl);
switch (Gyro) {
case 0: scale_value = MPU_GYRO_250_SCALE; break;
case 1: scale_value = MPU_GYRO_500_SCALE; break;
case 2: scale_value = MPU_GYRO_1000_SCALE; break;
case 3: scale_value = MPU_GYRO_2000_SCALE; break;
default: break;
}
values.GyX = (float) data_in.GyX / scale_value;
values.GyY = (float) data_in.GyY / scale_value;
values.GyZ = (float) data_in.GyZ / scale_value;
scale_value = 0.0;
switch (Accl) {
case 0: scale_value = MPU_ACCL_2_SCALE; break;
case 1: scale_value = MPU_ACCL_4_SCALE; break;
case 2: scale_value = MPU_ACCL_8_SCALE; break;
case 3: scale_value = MPU_ACCL_16_SCALE; break;
default: break;
}
values.AcX = (float) data_in.AcX / scale_value;
values.AcY = (float) data_in.AcY / scale_value;
values.AcZ = (float) data_in.AcZ / scale_value;
values.Tmp = (float) data_in.Tmp / 340.0 + 36.53;
return values;
}
JsonObject addValuesToJsonDoc(scaleddata* val)
{
//Fill JsonObject
jsonObj[“AcX”] = val->AcX;
jsonObj[“AcY”] = val->AcY;
jsonObj[“AcZ”] = val->AcZ;
jsonObj[“GyX”] = val->GyX;
jsonObj[“GyY”] = val->GyY;
jsonObj[“GyZ”] = val->GyZ;
return jsonObj;
}
Controller::Controller(std::string* anUrl, std::string* aPath,
sf::RenderWindow* aWindow)
{
request = sf::Http::Request(*aPath,
sf::Http::Request::Get);
http.setHost(*anUrl);
response = http.sendRequest(request);
//Check if Http-request is Correct<br>
if (response.getStatus() == sf::Http::Response::Ok)
{
// Check Contents of Response
std::cout << “Request succeeded.” << std::endl;
//Convert Response to Json-object
values = GetResponseInObject(&response, &values);
}
else {
std::cout << “Request failed.” << std::endl;
EXIT_FAILURE;
aWindow->close();
}
valueNames = AddToValueNames(&valueNames, “AcX”);
valueNames = AddToValueNames(&valueNames, “AcY”);
valueNames = AddToValueNames(&valueNames, “AcZ”);
valueNames = AddToValueNames(&valueNames, “GyX”);
valueNames = AddToValueNames(&valueNames, “GyY”);
valueNames = AddToValueNames(&valueNames, “GyZ”);
}