FOSSASAT-1B
Loading...
Searching...
No Matches
pin_interface.cpp
1#include "pin_interface.h"
2
3void Pin_Interface_Set_Temp_Resolution(uint8_t sensorAddr, uint8_t res) {
4 // set resolution
5 Wire.beginTransmission(sensorAddr);
7 Wire.write(res);
8 Wire.endTransmission();
9
10 // set mode back to temperature reading
11 Wire.beginTransmission(sensorAddr);
12 Wire.write((uint8_t)0x00);
13 Wire.endTransmission();
14}
15
16float Pin_Interface_Read_Temperature(uint8_t sensorAddr) {
17 // read data from I2C sensor
18 Wire.requestFrom(sensorAddr, (uint8_t)2);
19 uint8_t msb = Wire.read();
20 uint8_t lsb = Wire.read();
21
22 // convert raw data to temperature
24 float temp = tempRaw * 0.0625f;
25 return(temp);
26}
27
28int8_t Pin_Interface_Read_Temperature_Internal() {
29 // select temperature sensor and reference
30 ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX3);
31 // start AD conversion
32 ADCSRA |= _BV(ADEN) | _BV(ADSC);
33 // Detect end-of-conversion
34 while (bit_is_set(ADCSRA, ADSC));
35 // get raw data
36 uint16_t raw = ADCL | (ADCH << 8);
37
38 // convert to real temperature
40 return(temp);
41}
42
43float Pin_Interface_Read_Voltage(uint8_t pin) {
44 // map ADC value to voltage
45 return((analogRead(pin) * 3.3) / 1023.0);
46}
47
48void Pin_Interface_Watchdog_Heartbeat(bool manageBattery) {
49 // toggle watchdog pin
51
52 // check voltage
53 if(manageBattery) {
54 Power_Control_Check_Battery_Limit();
55 }
56}
57
58void Pin_Interface_Watchdog_Restart() {
59 FOSSASAT_DEBUG_PRINTLN(F("Rst"));
60
61 // do not pet watchdog for more than 30 seconds to restart
63 LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
64 }
65}
#define MCU_TEMP_COEFFICIENT
#define MCU_TEMP_OFFSET
#define DIGITAL_OUT_WATCHDOG_HEARTBEAT
#define WATCHDOG_RESET_NUM_SLEEP_CYCLES
#define TEMP_SENSOR_REG_CONFIG
T Persistent_Storage_Read(uint16_t addr)
This function reads a value of type T from EEPROM.
This module controls access to the components connect to via pins.