-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9900936
commit 1cc28fd
Showing
10 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
####################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |