Skip to content

Commit

Permalink
update build-ci and readme.md (#10)
Browse files Browse the repository at this point in the history
* update build-ci + readme.
  • Loading branch information
RobTillaart authored Oct 17, 2021
1 parent ecf17e4 commit a9fc94b
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 61 deletions.
10 changes: 7 additions & 3 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
- uno
- leonardo
- due
- zero
# - due
# - zero
# - leonardo
- m4
- esp32
# - esp8266
# - mega2560
10 changes: 7 additions & 3 deletions .github/workflows/arduino_test_runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ name: Arduino CI
on: [push, pull_request]

jobs:
arduino_ci:
runTest:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: Arduino-CI/action@master
# Arduino-CI/[email protected]
- uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- run: |
gem install arduino_ci
arduino_ci.rb
64 changes: 56 additions & 8 deletions ADT7470.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
//
// FILE: ADT7470.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.1.3
// PURPOSE: Arduino library for I2C ADT7470 Fan Monitoring
// URL: https://github.com/RobTillaart/ADT7470
// http://forum.arduino.cc/index.php?topic=363218.0
//
// HISTORY:
// 0.0.00 2015-12-02 initial version
// 0.0.01 2015-12-03 first beta
// 0.1.0 2020-07-15 major refactor - first public version
// 0.1.1 2020-08 fixes after testing
// 0.1.2 2020-12-09 arduino-ci
// HISTORY:
// 0.0.00 2015-12-02 initial version
// 0.0.01 2015-12-03 first beta
// 0.1.0 2020-07-15 major refactor - first public version
// 0.1.1 2020-08 fixes after testing
// 0.1.2 2020-12-09 arduino-ci
// 0.1.3 2021-10-17 update Arduino-CI
//


#include "ADT7470.h"

Expand Down Expand Up @@ -71,18 +74,21 @@ ADT7470::ADT7470(uint8_t address)
_address = address;
}


#if defined (ESP8266) || defined(ESP32)
void ADT7470::begin(uint8_t sda, uint8_t scl)
{
Wire.begin(sda, scl);
}
#endif


void ADT7470::begin()
{
Wire.begin();
}


//
// GENERIC
//
Expand All @@ -91,41 +97,49 @@ boolean ADT7470::isConnected()
return ((getDeviceID() == 0x70) && (getCompanyID() == 0x41));
}


uint8_t ADT7470::getRevision()
{
return getReg8(ADT7470_REVISION_REGISTER);
}


uint8_t ADT7470::getDeviceID()
{
return getReg8(ADT7470_DEVICEID_REGISTER);
}


uint8_t ADT7470::getCompanyID()
{
return getReg8(ADT7470_COMPANYID_REGISTER);
}


void ADT7470::startMonitoring()
{
setRegMask(ADT7470_CONFIG_REGISTER_1, ADT7470_START);
}


void ADT7470::stopMonitoring()
{
clrRegMask(ADT7470_CONFIG_REGISTER_1, ADT7470_START);
}


void ADT7470::powerDown()
{
setRegMask(ADT7470_CONFIG_REGISTER_2, ADT7470_POWERDOWN);
}


void ADT7470::powerUp()
{
clrRegMask(ADT7470_CONFIG_REGISTER_2, ADT7470_POWERDOWN);
}


//
// MEASURE TEMPERATURE
//
Expand All @@ -148,11 +162,13 @@ int8_t ADT7470::getTemperature(uint8_t idx)
return (int8_t) getReg8(ADT7470_TEMP_BASE + idx);
}


int8_t ADT7470::getMaxTemperature()
{
return (int8_t)getReg8(ADT7470_TEMP_MAX);
}


bool ADT7470::setTemperatureLimit(uint8_t idx, int8_t low, int8_t high)
{
if ((idx >= 10) || (low >= high)) return false;
Expand All @@ -161,20 +177,21 @@ bool ADT7470::setTemperatureLimit(uint8_t idx, int8_t low, int8_t high)
return true;
}


int8_t ADT7470::getTemperatureLowLimit(uint8_t idx)
{
int8_t rv = getReg8(ADT7470_TEMP_LIMIT_BASE + 2 * idx);
return rv;
}


int8_t ADT7470::getTemperatureHighLimit(uint8_t idx)
{
int8_t rv = getReg8(ADT7470_TEMP_LIMIT_BASE + 2 * idx + 1);
return rv;
}



//
// SET FAN SPEED
//
Expand All @@ -185,12 +202,14 @@ bool ADT7470::setPWM(uint8_t idx, uint8_t val)
return true;
}


uint8_t ADT7470::getPWM(uint8_t idx)
{
if (idx >= 4) return 0;
return getReg8(ADT7470_FAN_PWM_BASE + idx);
}


bool ADT7470::setFanLowFreq(uint8_t val)
{
if (val > 7) return false;
Expand All @@ -206,6 +225,7 @@ bool ADT7470::setFanLowFreq(uint8_t val)
return true;
}


bool ADT7470::setFanHighFreq(uint8_t val)
{
if (val > 7) return false;
Expand All @@ -216,6 +236,7 @@ bool ADT7470::setFanHighFreq(uint8_t val)
return true;
}


void ADT7470::setInvertPWM(uint8_t idx)
{
if (idx == 0) setReg8(ADT7470_FAN_PWM_CONFIG_1, 0x10); // bit 5
Expand All @@ -224,6 +245,7 @@ void ADT7470::setInvertPWM(uint8_t idx)
if (idx == 3) setReg8(ADT7470_FAN_PWM_CONFIG_2, 0x80);
}


uint8_t ADT7470::getInvertPWM(uint8_t idx)
{
if (idx == 0) return getReg8(ADT7470_FAN_PWM_CONFIG_1) & 0x10;
Expand Down Expand Up @@ -251,29 +273,34 @@ bool ADT7470::setPulsesPerRevolution(uint8_t idx, uint8_t val)
return true;
}


uint8_t ADT7470::getPulsesPerRevolution(uint8_t idx)
{
if (idx >= 4) return 0;
uint8_t reg = getReg8(ADT7470_FAN_PPR_REGISTER);
return ((reg >> (idx * 2)) & 0x03) + 1;
}


void ADT7470::setFastTach()
{
setRegMask(ADT7470_CONFIG_REGISTER_1, ADT7470_FAST_TACH);
}


void ADT7470::setSlowTach()
{
clrRegMask(ADT7470_CONFIG_REGISTER_1, ADT7470_FAST_TACH);
}


uint16_t ADT7470::getTach(uint8_t idx)
{
if (idx >= 4) return 0;
return getReg16(ADT7470_TACH_BASE + idx * 2);
}


uint32_t ADT7470::getRPM(uint8_t idx)
{
if (idx >= 4) return 0;
Expand All @@ -298,18 +325,21 @@ bool ADT7470::setTachLimits(uint8_t idx, uint16_t low, uint16_t high)
return true;
}


uint16_t ADT7470::getTachLowLimits(uint8_t idx)
{
uint16_t rv = getReg16(ADT7470_TACH_LOW_LIMIT_BASE + idx * 2);
return rv;
}


uint16_t ADT7470::getTachHighLimits(uint8_t idx)
{
uint16_t rv = getReg16(ADT7470_TACH_HIGH_LIMIT_BASE + idx * 2);
return rv;
}


//
// INTERRUPTS
//
Expand All @@ -324,12 +354,14 @@ uint16_t ADT7470::getTemperatureIRQstatus()
return val;
}


uint8_t ADT7470::getFanIRQstatus()
{
uint8_t val = (getReg8(ADT7470_IRQ_STATUS_2) & 0xF0) >> 4;
return val;
}


// TODO MERGE? setTemperatureIRQMask(idx, val); ?
void ADT7470::setTemperatureIRQMask(uint8_t idx)
{
Expand All @@ -344,6 +376,7 @@ void ADT7470::setTemperatureIRQMask(uint8_t idx)
setReg8(reg, val);
}


void ADT7470::clrTemperatureIRQMask(uint8_t idx)
{
uint8_t reg = ADT7470_IRQ_MASK_REG_1;
Expand All @@ -357,6 +390,7 @@ void ADT7470::clrTemperatureIRQMask(uint8_t idx)
setReg8(reg, val);
}


uint8_t ADT7470::getTemperatureIRQMask(uint8_t idx)
{
uint8_t reg = ADT7470_IRQ_MASK_REG_1;
Expand All @@ -368,25 +402,29 @@ uint8_t ADT7470::getTemperatureIRQMask(uint8_t idx)
return getReg8(reg) & (1 << idx);
}


void ADT7470::setFanIRQMask(uint8_t idx)
{
uint8_t val = getReg8(ADT7470_IRQ_MASK_REG_2);
val |= (1 << (idx + 4));
setReg8(ADT7470_IRQ_MASK_REG_2, val);
}


void ADT7470::clrFanIRQMask(uint8_t idx)
{
uint8_t val = getReg8(ADT7470_IRQ_MASK_REG_2);
val &= ~(1 << (idx + 4));
setReg8(ADT7470_IRQ_MASK_REG_2, val);
}


uint8_t ADT7470::getFanIRQMask(uint8_t idx)
{
return getReg8(ADT7470_IRQ_MASK_REG_2) & (1 << (idx + 4));
}


//////////////////////////////////////////////////////////////////////////////
//
// REGISTER OPERATORS
Expand All @@ -399,6 +437,7 @@ void ADT7470::setRegMask(uint8_t reg, uint8_t mask)
_write(reg, t);
}


void ADT7470::clrRegMask(uint8_t reg, uint8_t mask)
{
uint8_t t;
Expand All @@ -407,18 +446,21 @@ void ADT7470::clrRegMask(uint8_t reg, uint8_t mask)
_write(reg, t);
}


uint8_t ADT7470::getReg8(uint8_t reg)
{
uint8_t val;
_read(reg, &val);
return val;
}


void ADT7470::setReg8(uint8_t reg, uint8_t val)
{
_write(reg, val);
}


uint16_t ADT7470::getReg16(uint8_t reg)
{
uint8_t h, l;
Expand All @@ -427,6 +469,7 @@ uint16_t ADT7470::getReg16(uint8_t reg)
return (((uint16_t)h) << 8) | l;
}


void ADT7470::setReg16(uint8_t reg, uint16_t val)
{
_write(reg + 1, val & 0xFF);
Expand All @@ -443,6 +486,7 @@ int ADT7470::_write(const uint8_t reg, uint8_t value)
return _write(reg, &value, 1);
}


int ADT7470::_write(const uint8_t reg, uint8_t *buffer, uint8_t length)
{
Wire.beginTransmission(_address);
Expand All @@ -452,11 +496,13 @@ int ADT7470::_write(const uint8_t reg, uint8_t *buffer, uint8_t length)
return rv;
}


int ADT7470::_read(const uint8_t reg, uint8_t *value)
{
return _read(reg, value, 1);
}


int ADT7470::_read(const uint8_t reg, uint8_t *buffer, uint8_t length)
{
Wire.beginTransmission(_address);
Expand All @@ -474,4 +520,6 @@ int ADT7470::_read(const uint8_t reg, uint8_t *buffer, uint8_t length)
return cnt;
}


// -- END OF FILE --

Loading

0 comments on commit a9fc94b

Please sign in to comment.