diff --git a/libraries/HX711_MP/CHANGELOG..md b/libraries/HX711_MP/CHANGELOG..md index cbd313ad..25e02007 100644 --- a/libraries/HX711_MP/CHANGELOG..md +++ b/libraries/HX711_MP/CHANGELOG..md @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [0.3.0] - 2024-06-17 +- fix #5, reset bug +- refactor constructor +- move code to .cpp file (to match HX711) + +---- + ## [0.2.0] - 2024-03-02 - add fastProcessor option in **begin()** (Thanks to palmerr23) - updated license diff --git a/libraries/HX711_MP/HX711_MP.cpp b/libraries/HX711_MP/HX711_MP.cpp index 29d73b48..ee9f99fc 100644 --- a/libraries/HX711_MP/HX711_MP.cpp +++ b/libraries/HX711_MP/HX711_MP.cpp @@ -1,7 +1,7 @@ // // FILE: HX711_MP.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.2.0 +// VERSION: 0.3.0 // PURPOSE: Library for load cells for UNO // URL: https://github.com/RobTillaart/HX711_MP // URL: https://github.com/RobTillaart/HX711 @@ -21,7 +21,9 @@ HX711_MP::HX711_MP(uint8_t size) { _size = 2; // hard coded minimum!! } - reset(); + _gain = HX711_CHANNEL_A_GAIN_128; + _lastRead = 0; + _mode = HX711_AVERAGE_MODE; } @@ -263,6 +265,46 @@ float HX711_MP::get_units(uint8_t times) } +/////////////////////////////////////////////////////////////// +// +// MODE +// +void HX711_MP::set_raw_mode() +{ + _mode = HX711_RAW_MODE; +} + + +void HX711_MP::set_average_mode() +{ + _mode = HX711_AVERAGE_MODE; +} + + +void HX711_MP::set_median_mode() +{ + _mode = HX711_MEDIAN_MODE; +} + + +void HX711_MP::set_medavg_mode() +{ + _mode = HX711_MEDAVG_MODE; +} + + +void HX711_MP::set_runavg_mode() +{ + _mode = HX711_RUNAVG_MODE; +} + + +uint8_t HX711_MP::get_mode() +{ + return _mode; +} + + /////////////////////////////////////////////////////////////// // // GAIN @@ -352,6 +394,12 @@ void HX711_MP::power_up() } +uint32_t HX711_MP::last_read() +{ + return _lastRead; +} + + /////////////////////////////////////////////////////////////// // // PRIVATE diff --git a/libraries/HX711_MP/HX711_MP.h b/libraries/HX711_MP/HX711_MP.h index 4f867617..9823be5b 100644 --- a/libraries/HX711_MP/HX711_MP.h +++ b/libraries/HX711_MP/HX711_MP.h @@ -2,19 +2,20 @@ // // FILE: HX711_MP.h // AUTHOR: Rob Tillaart -// VERSION: 0.2.0 +// VERSION: 0.3.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_MP_LIB_VERSION (F("0.2.0")) +#define HX711_MP_LIB_VERSION (F("0.3.0")) const uint8_t HX711_AVERAGE_MODE = 0x00; @@ -100,13 +101,13 @@ public: // // get set mode for get_value() and indirect get_units(). // in median and medavg mode only 3..15 samples are allowed. - void set_raw_mode() { _mode = HX711_RAW_MODE; }; - void set_average_mode() { _mode = HX711_AVERAGE_MODE; }; - void set_median_mode() { _mode = HX711_MEDIAN_MODE; }; - void set_medavg_mode() { _mode = HX711_MEDAVG_MODE; }; + void set_raw_mode(); + void set_average_mode(); + void set_median_mode(); + void set_medavg_mode(); // set_run_avg will use a default alpha of 0.5. - void set_runavg_mode() { _mode = HX711_RUNAVG_MODE; }; - uint8_t get_mode() { return _mode; }; + void set_runavg_mode(); + uint8_t get_mode(); /////////////////////////////////////////////////////////////// @@ -159,10 +160,7 @@ public: // TIME OF LAST READ - uint32_t last_read() - { - return _lastRead; - } + uint32_t last_read(); /////////////////////////////////////////////////////////////// @@ -176,12 +174,12 @@ public: private: - uint8_t _dataPin = -1; - uint8_t _clockPin = -1; + uint8_t _dataPin; + uint8_t _clockPin; - uint8_t _gain = 128; // default channel A - uint32_t _lastRead = 0; - uint8_t _mode = HX711_AVERAGE_MODE; + uint8_t _gain; + uint32_t _lastRead; + uint8_t _mode; void _insertSort(float * array, uint8_t size); uint8_t _shiftIn(); diff --git a/libraries/HX711_MP/library.json b/libraries/HX711_MP/library.json index ed0bbc5b..3f59e511 100644 --- a/libraries/HX711_MP/library.json +++ b/libraries/HX711_MP/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/HX711_MP" }, - "version": "0.2.0", + "version": "0.3.0", "license": "MIT", "frameworks": "*", "platforms": "*", diff --git a/libraries/HX711_MP/library.properties b/libraries/HX711_MP/library.properties index 2815d00a..bf03ac95 100644 --- a/libraries/HX711_MP/library.properties +++ b/libraries/HX711_MP/library.properties @@ -1,5 +1,5 @@ name=HX711_MP -version=0.2.0 +version=0.3.0 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for HX711 load cell amplifier.