Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: torque_calibration_ywsim
Diff: HX711.h
- Revision:
- 2:1af13a8a8275
- Parent:
- 1:06652a775538
- Child:
- 3:d246aa415f3a
--- a/HX711.h Mon Sep 11 10:43:54 2017 +0000 +++ b/HX711.h Tue Sep 12 14:38:13 2017 +0000 @@ -44,7 +44,7 @@ /** - * @brief READY/#BUSY BIT + * @brief READY/BUSY DATA */ typedef enum { HX711_DATA_BUSY = 0, /*!< HX711 data is NOT ready to be read. */ @@ -53,25 +53,39 @@ -/* + /** + * @brief SCALE + */ + typedef enum { + HX711_SCALE_kg = 0, /*!< HX711 Scale in kg. */ + HX711_SCALE_g = 1, /*!< HX711 Scale in g. */ + HX711_SCALE_mg = 2, /*!< HX711 Scale in mg. */ + HX711_SCALE_ug = 3 /*!< HX711 Scale in ug. */ + } HX711_scale_t; + + + + #ifndef VECTOR_STRUCT_H #define VECTOR_STRUCT_H typedef struct { - uint16_t EEPROM_Data; - uint16_t DAC_Data; - } Vector_data_t; - + float myRawValue_WithCalibratedMass; + float myRawValue_WithoutCalibratedMass; + float myRawValue_TareWeight; + uint32_t myRawValue; + } Vector_count_t; + typedef struct { - uint32_t DAC_New_Value; - } Vector_new_dac_value_t; + float myMass; + } Vector_mass_t; #endif -*/ + /** * @brief INTERNAL CONSTANTS */ -#define HX711_PIN_HIGH 0x00 /*!< Pin 'HIGH' */ +#define HX711_PIN_HIGH 0x01 /*!< Pin 'HIGH' */ #define HX711_PIN_LOW 0x00 /*!< Pin 'LOW' */ typedef enum { @@ -86,9 +100,8 @@ * * @param pd_sck HX711 Power down control (high active) and serial clock input * @param dout HX711 Serial data output - * @param myChannelGain HX711 Channel and Gain */ - HX711 ( PinName PD_SCK, PinName DOUT, HX711_channel_gain_t myChannel_Gain ); + HX711 ( PinName PD_SCK, PinName DOUT ); /** Delete HX711 object. */ @@ -101,16 +114,44 @@ /** It puts the device into power-down mode. */ HX711_status_t HX711_PowerDown ( void ); - - + + /** It sets both the channel and the gain for the next measurement. + */ + HX711_status_t HX711_SetChannelAndGain ( HX711_channel_gain_t myChannel_Gain ); + + /** It gets both the channel and the gain for the current measurement. + */ + HX711_channel_gain_t HX711_GetChannelAndGain ( void ); + + /** It reads raw data from the device. + */ + HX711_status_t HX711_ReadRawData ( HX711_channel_gain_t myChannel_Gain, Vector_count_t* myNewRawData, uint32_t myAverage ); + + /** It reads raw data with an user-specified calibrated mass. + */ + HX711_status_t HX711_ReadData_WithCalibratedMass ( HX711_channel_gain_t myChannel_Gain, Vector_count_t* myNewRawData, uint32_t myAverage ); + + /** It reads raw data without any mass. + */ + HX711_status_t HX711_ReadData_WithoutMass ( HX711_channel_gain_t myChannel_Gain, Vector_count_t* myNewRawData, uint32_t myAverage ); + + /** It reads raw data without any mass after the system is calibrated. + */ + HX711_status_t HX711_SetAutoTare ( HX711_channel_gain_t myChannel_Gain, Vector_count_t* myNewRawData, float myTime ); + + /** It calculates scaled data. + */ + Vector_mass_t HX711_CalculateMass ( Vector_count_t* myNewRawData, float myCalibratedMass, HX711_scale_t myScaleCalibratedMass ); -private: - DigitalOut _PD_SCK; - DigitalIn _DOUT; - uint32_t _HX711_CHANNEL_GAIN; +private: + DigitalOut _PD_SCK; + DigitalIn _DOUT; + HX711_channel_gain_t _HX711_CHANNEL_GAIN; + HX711_scale_t _HX711_SCALE; + float _HX711_USER_CALIBATED_MASS; }; #endif