From fbd4b79eca72ab3b75b99ff71067486cb256c370 Mon Sep 17 00:00:00 2001 From: Rob Tillaart Date: Mon, 17 Jun 2024 14:16:16 +0200 Subject: [PATCH] refactor constructor after fix #50 (#51) - fix #50, bug in constructor (thanks Mathieu!) - refactor constructor --- CHANGELOG..md | 6 ++++++ HX711.cpp | 12 ++++++++++-- HX711.h | 21 +++++++++++---------- README.md | 2 +- library.json | 2 +- library.properties | 2 +- 6 files changed, 30 insertions(+), 15 deletions(-) diff --git a/CHANGELOG..md b/CHANGELOG..md index 7aea9ca..6c19057 100644 --- a/CHANGELOG..md +++ b/CHANGELOG..md @@ -5,6 +5,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.5.0] - 2024-06-17 +- fix #50, bug in constructor (thanks Mathieu!) + - refactor constructor + +---- + ## [0.4.0] - 2024-03-02 - add fastProcessor option in **begin()** (Thanks to palmerr23) - updated license diff --git a/HX711.cpp b/HX711.cpp index f6ee14c..4bb43ad 100644 --- a/HX711.cpp +++ b/HX711.cpp @@ -1,7 +1,7 @@ // // FILE: HX711.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.4.0 +// VERSION: 0.5.0 // PURPOSE: Library for load cells for UNO // URL: https://github.com/RobTillaart/HX711_MP // URL: https://github.com/RobTillaart/HX711 @@ -12,6 +12,13 @@ HX711::HX711() { + _gain = HX711_CHANNEL_A_GAIN_128; + _offset = 0; + _scale = 1; + _lastRead = 0; + _price = 0; + _mode = HX711_AVERAGE_MODE; + _fastProcessor = false; } @@ -38,10 +45,11 @@ void HX711::reset() { power_down(); power_up(); + _gain = HX711_CHANNEL_A_GAIN_128; _offset = 0; _scale = 1; - _gain = HX711_CHANNEL_A_GAIN_128; _lastRead = 0; + _price = 0; _mode = HX711_AVERAGE_MODE; } diff --git a/HX711.h b/HX711.h index 7d1b4da..d2b31a5 100644 --- a/HX711.h +++ b/HX711.h @@ -2,19 +2,20 @@ // // FILE: HX711.h // AUTHOR: Rob Tillaart -// VERSION: 0.4.0 +// VERSION: 0.5.0 // PURPOSE: Library for load cells for Arduino // URL: https://github.com/RobTillaart/HX711_MP // URL: https://github.com/RobTillaart/HX711 // // NOTES // Superset of interface of HX711 class of Bogde -// float instead of long as float has 23 bits mantissa. +// uses float instead of long as float has 23 bits mantissa +// which almost perfectly matches the 24 bit ADC. #include "Arduino.h" -#define HX711_LIB_VERSION (F("0.4.0")) +#define HX711_LIB_VERSION (F("0.5.0")) const uint8_t HX711_AVERAGE_MODE = 0x00; @@ -175,16 +176,16 @@ class HX711 uint8_t _dataPin; uint8_t _clockPin; - uint8_t _gain = 128; // default channel A - long _offset = 0; - float _scale = 1; - uint32_t _lastRead = 0; - float _price = 0; - uint8_t _mode = HX711_AVERAGE_MODE; + uint8_t _gain; + long _offset; + float _scale; + uint32_t _lastRead; + float _price; + uint8_t _mode; + bool _fastProcessor; void _insertSort(float * array, uint8_t size); uint8_t _shiftIn(); - bool _fastProcessor = false; }; diff --git a/README.md b/README.md index b08e6fe..c5d85c1 100644 --- a/README.md +++ b/README.md @@ -386,7 +386,7 @@ See https://github.com/RobTillaart/HX711/issues/40 - example the adding scale - void weight_clr(), void weight_add(), float weight_get() - adding scale - decide pricing keep/not => move to .cpp -- add **setRate()** and **getRate()** +- add **setRate()** and **getRate()** - sample rate 10/80 SPS - optional? diff --git a/library.json b/library.json index e1e9f21..f836e7f 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/HX711" }, - "version": "0.4.0", + "version": "0.5.0", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/library.properties b/library.properties index fba3e5e..dd71b7f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=HX711 -version=0.4.0 +version=0.5.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for HX711 load cell amplifier