Skip to content

Commit

Permalink
Add and update Doxygen documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Erriez committed Sep 12, 2020
1 parent d267e30 commit 461346c
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 10 deletions.
Binary file modified ErriezOregonTHN128.pdf
Binary file not shown.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ void loop()
OregonTHN128_Transmit(&data);
// Wait ~30 seconds before sending next temperature
Serial.flush();
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ void loop()
{
char line[10];
char tempStr[5];

OregonTHN128Data_t data;

// Check temperature received
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#define RF_TX_PIN 3
#define ONE_WIRE_BUS 2

// Create OneWire and DS1820 objects
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature ds1820(&oneWire);

Expand Down
17 changes: 16 additions & 1 deletion src/ErriezOregonTHN128.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,42 @@
#include <stdio.h>
#include "ErriezOregonTHN128.h"

/* Bit data macro's */
/*!
* \defgroup Bit data macro's
* @{
*/
/*! Set rolling address */
#define SET_ROL_ADDR(x) (((x) & 0x07) << 0)
/*! Get rolling address */
#define GET_ROL_ADDR(x) (((x) & 0x07) << 0)

/*! Set channel */
#define SET_CHANNEL(x) ((((x) - 1) & 0x03) << 6)
/*! Get channel */
#define GET_CHANNEL(x) ((((x) >> 6) & 0x03) + 1)

/*! Set temperature */
#define SET_TEMP(x) ((((((uint32_t)(x) / 100) % 10)) << 16) | \
((((uint32_t)(x) / 10) % 10) << 12) | \
(((x) % 10) << 8))
/*! Get temperature */
#define GET_TEMP(x) (((((x) >> 16) & 0x0f) * 100) + \
((((x) >> 12) & 0x0f) * 10) + \
(((x) >> 8) & 0x0f))

/*! Sign bit */
#define SIGN_BIT (1UL << 21)

/*! Low battery bit */
#define LOW_BAT_BIT (1UL << 23)

/*! Set CRC */
#define SET_CRC(x) ((uint32_t)(x) << 24)
/*! Get CRC */
#define GET_CRC(x) ((x) >> 24)

/*! @} */


/*!
* \brief Calculate CRC
Expand Down
82 changes: 77 additions & 5 deletions src/ErriezOregonTHN128Receive.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@

#include "ErriezOregonTHN128Receive.h"

/*!
* \brief Receive state
*/
typedef enum {
StateSearchSync = 0,
StateMid0 = 1,
StateMid1 = 2,
StateEnd = 3,
StateRxComplete = 4
StateSearchSync = 0, /*!< Search for sync */
StateMid0 = 1, /*!< Sample at the middle of a pulse part 1 */
StateMid1 = 2, /*!< Sample at the middle of a pulse part 2 */
StateEnd = 3, /*!< Sample at the end of a pulse to store bit */
StateRxComplete = 4 /*!< Receive complete */
} RxState_t;

/* Static variables */
Expand All @@ -58,6 +61,9 @@ static volatile RxState_t _rxState = StateSearchSync;
void rfPinChange(void);


/*!
* \brief Receive enable
*/
static void rxEnable()
{
/* Enable INTx change interrupt */
Expand All @@ -67,12 +73,28 @@ static void rxEnable()
_rxState = StateSearchSync;
}

/*!
* \brief Receive disable
*/
static void rxDisable()
{
/* Disable INTx change interrupt */
detachInterrupt(_rxInt);
}

/*!
* \brief Check is pulse duration is within range
* \param tPulse
* Measured pulse length in us
* \param tMin
* Minimum pulse length in us
* \param tMax
* Maximum pulse length in us
* \retval true
* Pulse is in range
* \retval false
* Pulse not in range
*/
static bool isPulseInRange(uint16_t tPulse, uint16_t tMin, uint16_t tMax)
{
/* Check is pulse length between min and max time */
Expand All @@ -83,6 +105,13 @@ static bool isPulseInRange(uint16_t tPulse, uint16_t tMin, uint16_t tMax)
}
}

/*!
* \brief Find synchronisation
* \retval true
* Sync found
* \retval false
* Sync not found
*/
static bool findSync()
{
/* Read sync pulse */
Expand All @@ -103,6 +132,12 @@ static bool findSync()
return false;
}

/*!
* \brief Store a logical bit 1 or 0
* \param one
* true: Bit 1\n
* false: Bit 0
*/
static void storeBit(bool one)
{
/* Store received bit */
Expand All @@ -123,6 +158,9 @@ static void storeBit(bool one)
}
}

/*!
* \brief Handle pulse RF receive pin
*/
static void handlePulse()
{
if (isPulseInRange(_tPinHigh, T_BIT_SHORT_MIN, T_BIT_SHORT_MAX)) {
Expand All @@ -146,6 +184,9 @@ static void handlePulse()
}
}

/*!
* \brief Handle space RF receive pin
*/
static void handleSpace()
{
/* State machine */
Expand All @@ -170,6 +211,9 @@ static void handleSpace()
}
}

/*!
* \brief RF pin level change
*/
void rfPinChange(void)
{
uint32_t tNow;
Expand Down Expand Up @@ -223,6 +267,12 @@ void rfPinChange(void)
/*------------------------------------------------------------------------------------------------*/
/* Public functions */
/*------------------------------------------------------------------------------------------------*/
/*!
* \brief Initialize receiver pin
* \details
* Connect RX pin to an external interrupt pin such as INT0 (D2) or INT1 (D3)
* \param extIntPin
*/
void OregonTHN128_RxBegin(uint8_t extIntPin)
{
/* Save interrupt number of the RF pin */
Expand All @@ -235,24 +285,46 @@ void OregonTHN128_RxBegin(uint8_t extIntPin)
rxEnable();
}

/*!
* \brief Receive enable
*/
void OregonTHN128_RxEnable()
{
/* Enable receive */
rxEnable();
}

/*!
* \brief Receive disable
*/
void OregonTHN128_RxDisable()
{
/* Disable receive */
rxDisable();
}

/*!
* \brief Check if data received
* \retval true
* Data received
* \retval false
* No data available
*/
bool OregonTHN128_Available()
{
/* Return receive complete */
return (_rxState == StateRxComplete) ? true : false;
}

/*!
* \brief Read data
* \param data
* Structure OregonTHN128Data_t output
* \retval true
* Data received
* \retval false
* No data available
*/
bool OregonTHN128_Read(OregonTHN128Data_t *data)
{
if (OregonTHN128_Available()) {
Expand Down
1 change: 0 additions & 1 deletion src/ErriezOregonTHN128Receive.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ void OregonTHN128_RxBegin(uint8_t extIntPin);
void OregonTHN128_RxEnable();
void OregonTHN128_RxDisable();
bool OregonTHN128_Available(void);
uint32_t OregonTHN128_GetRawData();
bool OregonTHN128_Read(OregonTHN128Data_t *data);

#ifdef __cplusplus
Expand Down
33 changes: 32 additions & 1 deletion src/ErriezOregonTHN128Transmit.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,49 @@ extern void delay100ms(void);
static int8_t _rfTxPort = -1;
static int8_t _rfTxBit = -1;

/* Optimized RF transmit pin macro's */
/*!
* \defgroup Transmit pin control
* \details
* Optimized for AVR microcontrollers
* @{
*/

/*!
* \def RF_TX_PIN_INIT(rfTxPin)
* \brief Initialize RF transmit pin
* \param rfTxPin
* TX pin to external interrupt pin (INT0 or INT1)
*/
#define RF_TX_PIN_INIT(rfTxPin) { \
_rfTxPort = digitalPinToPort(rfTxPin); \
_rfTxBit = digitalPinToBitMask(rfTxPin); \
*portModeRegister(_rfTxPort) |= _rfTxBit; \
}

/*!
* \def RF_TX_PIN_DISABLE()
* \brief TX pin disable
*/
#define RF_TX_PIN_DISABLE() { \
if ((_rfTxPort >= 0) && (_rfTxBit >= 0)) { \
*portModeRegister(_rfTxPort) &= ~_rfTxBit; \
} \
}

/*!
* \def RF_TX_PIN_HIGH()
* \brief TX pin high
*/
#define RF_TX_PIN_HIGH() { *portOutputRegister(_rfTxPort) |= _rfTxBit; }

/*!
* \def RF_TX_PIN_LOW()
* \brief TX pin low
*/
#define RF_TX_PIN_LOW() { *portOutputRegister(_rfTxPort) &= ~_rfTxBit; }

/*! @} */


/*!
* \brief Transmit sync pulse
Expand Down Expand Up @@ -132,6 +161,8 @@ static void txData(uint32_t data)
/*------------------------------------------------------------------------------------------------*/
/*!
* \brief Transmit begin
* \details
* Connect rfTxPin to any DIGITAL pin
* \param rfTxPin
* Arduino transmit pin
*/
Expand Down

0 comments on commit 461346c

Please sign in to comment.