diff --git a/Development/Software/Communications/Bluetooth.cpp b/Development/Software/Communications/Bluetooth.cpp index f80a4533b5e42d5cdad5b0a00477de4ae1c82720..da793a45aef6deccdcb320686dc70f70723dbdc6 100644 --- a/Development/Software/Communications/Bluetooth.cpp +++ b/Development/Software/Communications/Bluetooth.cpp @@ -1,72 +1,72 @@ -/* - * Bluetooth.cpp - * - * Created on: Nov 15, 2015 - * Author: Branden Sammons - */ - -class Bluetooth { - -public: - - /** - * connect() : - * Takes 1 argument, A Bluetooth address, and tries to connect to that address - * only if this device has successfully paired with the address given before. - * If the other address is recognized then we attempt to connect and returns - * true if successful. - * - * Arguments : - * Bluetooth address of another device - * - * Returns : - * Boolean determining whether connection was made. - */ - virtual bool connect(/* Bluetooth address */) {} - - - - /** - * pair() : - * Attempts to pair with the Bluetooth Address given, returns true if successful. - * - * Arguments : - * Bluetooth address of another device - * - * Returns : - * Boolean determining whether pairing was successful. - */ - virtual bool pair(/* Bluetooth address */) {} - - - - /** - * send() : - * Sends the given data to the last device a connection was established with. - * - * Arguments : - * String to be sent - * - * Returns : - * Boolean determining whether sending was successful. - */ - virtual bool send(std::string *string) {} - - - - /** - * receive() : - * Receives the data coming to the device by storing it in the pointer specified. - * - * Arguments : - * Pointer to store data that is incoming. - * - * Returns : - * Boolean determining whether receive was successful. - */ - virtual bool receive(std::string *string) {} -}; - - - - +///* +// * Bluetooth.cpp +// * +// * Created on: Nov 15, 2015 +// * Author: Branden Sammons +// */ +// +//class Bluetooth { +// +//public: +// +// /** +// * connect() : +// * Takes 1 argument, A Bluetooth address, and tries to connect to that address +// * only if this device has successfully paired with the address given before. +// * If the other address is recognized then we attempt to connect and returns +// * true if successful. +// * +// * Arguments : +// * Bluetooth address of another device +// * +// * Returns : +// * Boolean determining whether connection was made. +// */ +// virtual bool connect(/* Bluetooth address */) {} +// +// +// +// /** +// * pair() : +// * Attempts to pair with the Bluetooth Address given, returns true if successful. +// * +// * Arguments : +// * Bluetooth address of another device +// * +// * Returns : +// * Boolean determining whether pairing was successful. +// */ +// virtual bool pair(/* Bluetooth address */) {} +// +// +// +// /** +// * send() : +// * Sends the given data to the last device a connection was established with. +// * +// * Arguments : +// * String to be sent +// * +// * Returns : +// * Boolean determining whether sending was successful. +// */ +// virtual bool send(std::string *string) {} +// +// +// +// /** +// * receive() : +// * Receives the data coming to the device by storing it in the pointer specified. +// * +// * Arguments : +// * Pointer to store data that is incoming. +// * +// * Returns : +// * Boolean determining whether receive was successful. +// */ +// virtual bool receive(std::string *string) {} +//}; +// +// +// +// diff --git a/Development/Software/Controller API/GyroService.cpp b/Development/Software/Controller API/GyroService.cpp index 8e6478f94eee9214026315f01f02100ff6cf5bab..2c5ea903c0f5e113f553e386adf644bce50a2837 100644 --- a/Development/Software/Controller API/GyroService.cpp +++ b/Development/Software/Controller API/GyroService.cpp @@ -16,7 +16,7 @@ void GyroService::run() _mailbox->send(msg); // Sleep 5 seconds - sleep(5); + usleep(500000); } } diff --git a/Development/Software/Controller API/MPU9250.cpp b/Development/Software/Controller API/MPU9250.cpp index c4f495358d1a9fe2a1b0dc32707b268cf7efc038..b4f29ab58c1ecabf47c20837abd9d73f5f195879 100644 --- a/Development/Software/Controller API/MPU9250.cpp +++ b/Development/Software/Controller API/MPU9250.cpp @@ -4,6 +4,12 @@ #include "MPU9250.h" +#pragma region Definitions +#define USER_CTRL 0x6A + + +#pragma endregion + MPU9250* MPU9250::myInstance = 0; #pragma region Creation/Deletion @@ -33,7 +39,7 @@ MPU9250::MPU9250() { spi = new Spi(0); // set the frequency ( 10Mhz ) - spi->frequency(10000000); + spi->frequency(1000000); // set the mode spi->mode(MRAA_SPI_MODE1); @@ -41,8 +47,10 @@ MPU9250::MPU9250() { // ensure MSB is sent first spi->lsbmode(false); - // set up registers - // place holder + usleep(10); + + // This disables I2C from the start + spi->write_word(0x10 | USER_CTRL); } /** @@ -62,12 +70,9 @@ MPU9250::~MPU9250() { * Input : Address to read from * Returns : Results from chip */ -uint16_t MPU9250::read(uint8_t address) { - - //Set up address line for correct communication - uint16_t datatoSend = address << 8; +uint8_t MPU9250::read(uint8_t address) { - return spi->write_word(datatoSend); + return spi->write_word(address); } /** @@ -79,13 +84,7 @@ uint16_t MPU9250::read(uint8_t address) { */ void MPU9250::write(uint8_t address, uint8_t data) { - //Set up address line for correct communication - uint16_t datatoSend = address << 8; - - // Add in the data we want to write - datatoSend = datatoSend | data; - - spi->write_word(datatoSend); + spi->write_word((data << 8) | address); } #pragma endregion diff --git a/Development/Software/Controller API/MPU9250.h b/Development/Software/Controller API/MPU9250.h index c8f4e934b2eeed0cf652e8f5eecd736f42a706fe..14413a5c28decde284f0cfe7903e4d4e9fea033e 100644 --- a/Development/Software/Controller API/MPU9250.h +++ b/Development/Software/Controller API/MPU9250.h @@ -15,7 +15,7 @@ class MPU9250 public: static MPU9250* instance(); - uint16_t read(uint8_t address); + uint8_t read(uint8_t address); void write(uint8_t address, uint8_t data); protected: diff --git a/Development/Software/Controller API/Service.h b/Development/Software/Controller API/Service.h index 1312e3608f868f2d8c3c09bd5653496de677f49c..fcfeec57934a0c9f400a99e2e209879cfd7c79b5 100644 --- a/Development/Software/Controller API/Service.h +++ b/Development/Software/Controller API/Service.h @@ -1,5 +1,6 @@ #pragma once +#include <unistd.h> #include <iostream> #include <stdio.h> #include <list> @@ -12,7 +13,6 @@ struct ServiceInfo int id; string name; double frequency; - }; class Service @@ -21,7 +21,8 @@ public: Service(int id, string name, double freq); - virtual void run() = 0; + virtual void thread() = 0; + ServiceInfo info(); private: diff --git a/Development/Software/Controller API/Source.cpp b/Development/Software/Controller API/Source.cpp index be6dfd3fa94fe238e6206ee19439d001344b7eca..97b2239a8eeb23b4334c379aae5ceddceb38e0d5 100644 --- a/Development/Software/Controller API/Source.cpp +++ b/Development/Software/Controller API/Source.cpp @@ -1,13 +1,15 @@ #include <stdio.h> #include <iostream> #include <string> - -#include "LSM9DS0.h" +#include <stdint.h> using namespace std; int main(int argc, char **argv) { - + uint16_t test = 0xFFFF; + + cout << test << endl; + return 0; } \ No newline at end of file diff --git a/Development/Software/Default Controller/Default Controller.vcxproj b/Development/Software/Default Controller/Default Controller.vcxproj index 622091a709dd5d3b7004f0429f1ed71560506ab2..edb48573a9b90e1ef7e44aa4bfce75d1c87d1a60 100644 --- a/Development/Software/Default Controller/Default Controller.vcxproj +++ b/Development/Software/Default Controller/Default Controller.vcxproj @@ -15,7 +15,7 @@ <Text Include="README.txt" /> </ItemGroup> <ItemGroup> - <ClCompile Include="Source.c" /> + <ClCompile Include="Source.cpp" /> </ItemGroup> <PropertyGroup Label="Globals"> <ProjectGuid>{AC5B185E-4C05-4379-9A89-FF1D1CDA7775}</ProjectGuid> diff --git a/Development/Software/Default Controller/Default Controller.vcxproj.filters b/Development/Software/Default Controller/Default Controller.vcxproj.filters index d5ae14ddb29964c1245a979fb3cd8b24cd263883..a17ea4ba9e09edf5ca8159d882a75796441efd23 100644 --- a/Development/Software/Default Controller/Default Controller.vcxproj.filters +++ b/Development/Software/Default Controller/Default Controller.vcxproj.filters @@ -23,7 +23,7 @@ </Text> </ItemGroup> <ItemGroup> - <ClCompile Include="Source.c"> + <ClCompile Include="Source.cpp"> <Filter>Source Files</Filter> </ClCompile> </ItemGroup> diff --git a/Development/Software/Default Controller/Source.c b/Development/Software/Default Controller/Source.c deleted file mode 100644 index d9ad0537a93bb54c40ffa0cc32ed1649521b0410..0000000000000000000000000000000000000000 --- a/Development/Software/Default Controller/Source.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <stdio.h> - -int main() -{ - return 0; -} \ No newline at end of file diff --git a/Development/Software/Default Controller/Source.cpp b/Development/Software/Default Controller/Source.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec616dfdafc0f2321c0466dec8d8930a1ccd4cf1 --- /dev/null +++ b/Development/Software/Default Controller/Source.cpp @@ -0,0 +1,65 @@ +#include <stdio.h> +#include <iostream> +#include <string> +#include <stdint.h> +#include <unistd.h> +#include "mraa.hpp" + +using namespace mraa; + +using namespace std; + +#pragma region Definitions + +#define USER_CTRL 0x6A +#define WHO_AM_I 0x75 +#define AM_I_TRUE true + +#pragma endregion + +int main(int argc, char **argv) +{ + // set up the mraa library + mraa_init(); + + // set the SPI channels + Spi* spi = new Spi(0); + + // set the frequency ( 10Mhz ) + spi->frequency(1000000); + + // set the mode + spi->mode(MRAA_SPI_MODE1); + + // ensure MSB is sent first + spi->lsbmode(false); + + usleep(1000000); + + // This disables I2C from the start + spi->write_word(0x10 | USER_CTRL); + + usleep(1000000); + + while (AM_I_TRUE) + { + uint8_t result = spi->write_word(WHO_AM_I); + + cout << "I should be 0x71, I am " << hex << result << endl; + + usleep(1000000); + } + + while (!AM_I_TRUE) + { + uint16_t gyroX = spi->write_word(0x43) | spi->write_word(0x44); + uint16_t gyroY = spi->write_word(0x45) | spi->write_word(0x46); + uint16_t gyroZ = spi->write_word(0x47) | spi->write_word(0x48); + + cout << "X: " << hex << gyroX << " Y: " << hex << gyroY << " Z: " << hex << gyroZ << endl; + + usleep(1000000); + } + + delete spi; +} \ No newline at end of file diff --git a/Development/Software/Default Controller/Source1.cpp b/Development/Software/Default Controller/Source1.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391