diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..1bce3a6 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,7 @@ +Copyright 2024 Gumaca NHS Robotics Club + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..14ac1dc --- /dev/null +++ b/keywords.txt @@ -0,0 +1,29 @@ +####################################### +# Syntax Coloring Map APIR +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Peripheral KEYWORD1 +TemperatureSensor KEYWORD1 +TemperatureMeasurement KEYWORD1 +TemperatureSensorModel KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +getPin KEYWORD2 +getModel KEYWORD2 +configure KEYWORD2 +receive KEYWORD2 +pow KEYWORD2 +square KEYWORD2 +cubed KEYWORD2 +calculateTemperature KEYWORD2 + +####################################### +# Constants (LITERAL1) +####################################### \ No newline at end of file diff --git a/library.properties b/library.properties new file mode 100644 index 0000000..231c6b1 --- /dev/null +++ b/library.properties @@ -0,0 +1,6 @@ +name = APIR +version = 0.1 +author = Gumaca NHS Robotics Club +sentence = An Arduino library for robotic enthusiasts +category = Other +url = https://github.com/GNHS-Robotics-Club/APIR \ No newline at end of file diff --git a/src/APIR.h b/src/APIR.h new file mode 100644 index 0000000..9997b80 --- /dev/null +++ b/src/APIR.h @@ -0,0 +1,16 @@ +#ifndef APIR_H +#define APIR_H + +/** + * This is the main file for APIR. + * + * @since 1.0 + * @author Gumaca NHS Robotics Club +*/ + +#include "peripherals/Peripheral.h" +#include "peripherals/TemperatureSensor.h" +#include "math/Math.h" + + +#endif \ No newline at end of file diff --git a/src/math/Math.cpp b/src/math/Math.cpp new file mode 100644 index 0000000..acefdfa --- /dev/null +++ b/src/math/Math.cpp @@ -0,0 +1,24 @@ +#include "Math.h" + +double math::pow(double base, double exponent) { + + if(exponent == 0.0) return 1; + + double output = base; + + int count = 1; + + while(count < exponent) { + output *= base; + count++; + } + return output; +} + +double math::square(double base) { + return base * base; +} + +double math::cubed(double base) { + return base * base * base; +} \ No newline at end of file diff --git a/src/math/Math.h b/src/math/Math.h new file mode 100644 index 0000000..bcd3c6f --- /dev/null +++ b/src/math/Math.h @@ -0,0 +1,39 @@ +#ifndef MATH_H +#define MATH_H + +/** + * A math library for calculations. + * + * @since 1.0 + * @author Gumaca NHS Robotics Club +*/ + +namespace math { + /** + * A function that returns the base raised + * to the exponent. + * + * @since 1.0 + * @return Gets the base raised to the exponent . +*/ +double pow(double base, double exponent); + +/** + * A function that returns the base raised to 2. + * + * @since 1.0 + * @return Gets the base raised to 2. +*/ +double square(double base); + +/** + * A function that returns the base raised to 3. + * + * @since 1.0 + * @return Gets the base raised to 3. +*/ +double cubed(double base); + +} + +#endif \ No newline at end of file diff --git a/src/peripherals/Peripheral.cpp b/src/peripherals/Peripheral.cpp new file mode 100644 index 0000000..56ec34a --- /dev/null +++ b/src/peripherals/Peripheral.cpp @@ -0,0 +1,11 @@ +#include "Peripheral.h" + +Peripheral::Peripheral(uint8_t pin, uint8_t model): pin(pin), model(model) {} + +uint8_t Peripheral::getPin() { + return this->pin; +} + +uint8_t Peripheral::getModel() { + return this->model; +} \ No newline at end of file diff --git a/src/peripherals/Peripheral.h b/src/peripherals/Peripheral.h new file mode 100644 index 0000000..acebead --- /dev/null +++ b/src/peripherals/Peripheral.h @@ -0,0 +1,66 @@ +#ifndef PERIPHERAL_H +#define PERIPHERAL_H + +#include "Arduino.h" + +/** + * Represents an Arduino Uno peripheral. + * + * @since 1.0 + * @author Gumaca NHS Robotics Club +*/ +class Peripheral { + + /** + * The pin of the peripheral. + */ + uint8_t pin; + + /** + * The model of the peripheral. + */ + uint8_t model; + + + public: + + Peripheral(uint8_t pin, uint8_t model); + + virtual ~Peripheral() = default; + + /** + * Returns the peripheral's pin. + * + * @since 1.0 + * @return Returns the peripheral's pin. + */ + uint8_t getPin(); + + /** + * Returns the peripheral's model. + * + * @since 1.0 + * @return Returns the peripheral's model. + */ + uint8_t getModel(); + + /** + * Configures the peripheral before the + * peripheral performs any actions. + * + * @since 1.0 + */ + virtual void configure() = 0; + + /** + * Receive the data from the + * peripheral's pin. + * + * @since 1.0 + * @return Returns the data from the peripheral's pin. + */ + virtual int receive() = 0; + +}; + +#endif \ No newline at end of file diff --git a/src/peripherals/TemperatureSensor.cpp b/src/peripherals/TemperatureSensor.cpp new file mode 100644 index 0000000..fb8325b --- /dev/null +++ b/src/peripherals/TemperatureSensor.cpp @@ -0,0 +1,19 @@ +#include "TemperatureSensor.h" + +TemperatureSensor::TemperatureSensor(uint8_t pin, uint8_t model): Peripheral(pin, model) {} + +void TemperatureSensor::configure() { + + pinMode(getPin(), INPUT); + +} + +int TemperatureSensor::receive() { + return (getModel() == TemperatureSensorModel::TMP_36) ? analogRead(getPin()) : 0; +} + +int TemperatureSensor::calculateTemperature(TemperatureMeasurement measurementType) { + const int celcius = ((receive() / 1023.0 * 5.0 * 1000) - 500) / 10; + + return (measurementType == TemperatureMeasurement::CELSIUS) ? celcius : celcius * 1.8 + 32; +} \ No newline at end of file diff --git a/src/peripherals/TemperatureSensor.h b/src/peripherals/TemperatureSensor.h new file mode 100644 index 0000000..261fb2c --- /dev/null +++ b/src/peripherals/TemperatureSensor.h @@ -0,0 +1,46 @@ +#ifndef TEMP_SENSOR_H +#define TEMP_SENSOR_H + +#include "Arduino.h" +#include "Peripheral.h" + +/** + * All of the supported temperature sensor models. + * + * @since 1.0 + * @author Gumaca NHS Robotics Club +*/ +enum TemperatureSensorModel : uint8_t { + TMP_36, +}; + +/** + * All of the supported temperature measurement types. + * + * @since 1.0 + * @author Gumaca NHS Robotics Club +*/ +enum TemperatureMeasurement { + CELSIUS, + FAHRENHEIT, +}; + +/** + * An Arduino Uno peripheral that measures the temperature. + * + * @since 1.0 + * @author Gumaca NHS Robotics Club +*/ +class TemperatureSensor : public Peripheral { + + public: + TemperatureSensor(uint8_t pin, uint8_t model); + + void configure(); + + int receive(); + + int calculateTemperature(TemperatureMeasurement measurementType); +}; + +#endif \ No newline at end of file