Skip to content

Commit bc4a8f1

Browse files
committed
first draft of thermistor reader
1 parent 6358756 commit bc4a8f1

3 files changed

Lines changed: 58 additions & 0 deletions

File tree

ascendfsw/include/AnalogTemp.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef ANALOGTEMP_H
2+
#define ANALOGTEMP_H
3+
4+
#include "Sensor.h"
5+
6+
class AnalogTemp : public Sensor {
7+
8+
private:
9+
10+
public:
11+
AnalogTemp();
12+
AnalogTemp(unsigned long minimum_period);
13+
14+
bool verify() override;
15+
String readData() override;
16+
void readDataPacket(uint8_t*& packet) override;
17+
String decodeToCSV(uint8_t*& packet) override;
18+
19+
20+
};
21+
22+
#endif

ascendfsw/include/PayloadConfig.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
/** @brief Default I2C Address for TMP117 */
4848
#define TMP117_I2C_ADDR 0x48
4949

50+
/** @brief ADC Pin for Thermistor Readings */
51+
#define THERMISTOR_PIN 28
52+
5053
/** @brief StratoSense board I2C Bus */
5154
#define STRATOSENSE_I2C Wire1
5255

ascendfsw/src/AnalogTemp.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "AnalogTemp.h"
2+
#include "PayloadConfig.h"
3+
4+
AnalogTemp::AnalogTemp() : AnalogTemp(1000) {}
5+
6+
AnalogTemp::AnalogTemp(unsigned long minimum_period)
7+
: Sensor("AnalogTemp", "ADC_Read,", minimum_period) {
8+
9+
}
10+
11+
bool AnalogTemp::verify(){
12+
pinMode(THERMISTOR_PIN, INPUT);
13+
return true;
14+
}
15+
String AnalogTemp::readData(){
16+
return String(analogRead(THERMISTOR_PIN));
17+
}
18+
void AnalogTemp::readDataPacket(uint8_t*& packet){
19+
int adc_reading = analogRead(THERMISTOR_PIN);
20+
21+
memcpy(packet, &adc_reading, sizeof(int));
22+
23+
packet += sizeof(int);
24+
}
25+
String AnalogTemp::decodeToCSV(uint8_t*& packet){
26+
int adc_reading = 0;
27+
28+
memcpy(&adc_reading, packet, sizeof(int));
29+
30+
packet += sizeof(int);
31+
32+
return String(adc_reading);
33+
}

0 commit comments

Comments
 (0)