You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: devices/Hx711/Hx711.cs
+77-30Lines changed: 77 additions & 30 deletions
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,13 @@ public class Scale
16
16
// pulse train required to read a sample and setup gain factor for next reading
17
17
privatereadonlybyte[]_readSamplePulseTrain;
18
18
19
+
// sample buffer to hold data read from DOUT
20
+
privatereadonlybyte[]_readSampleBuffer;
21
+
22
+
//setup Dout wait buffers
23
+
privatereadonlybyte[]_clkWaitDoutBuffer;
24
+
privatereadonlybyte[]_doutWaitBuffer;
25
+
19
26
privatereadonlySpiDevice_spiDevice;
20
27
21
28
/// <summary>
@@ -26,13 +33,13 @@ public class Scale
26
33
/// <summary>
27
34
/// Gets or sets the value that's subtracted from the actual reading.
28
35
/// </summary>
29
-
publicintOffset{get;set;}
36
+
publicdoubleOffset{get;set;}=0;
30
37
31
38
/// <summary>
32
39
/// Gets or sets the gain factor that the Hx711 uses when sampling.
33
40
/// </summary>
34
41
/// <remarks>
35
-
/// The default value is <see cref="GainLevel.Gain128"/>.
42
+
/// The default value is <see cref="GainLevel.GainA128"/>.
36
43
/// </remarks>
37
44
publicGainLevelGain{get;set;}
38
45
@@ -53,12 +60,18 @@ public class Scale
53
60
/// Initializes a new instance of the <see cref="Scale"/> class.
54
61
/// </summary>
55
62
/// <param name="spiDevice">The <see cref="SpiDevice"/> that is used as channel to communicate with the Hx711.</param>
56
-
/// <param name="gain"><see cref="GainLevel"/> that will be used for the scale. If not provided, the default is <see cref="GainLevel.Gain128"/>.</param>
63
+
/// <param name="gain"><see cref="GainLevel"/> that will be used for the scale. If not provided, the default is <see cref="GainLevel.GainA128"/>.</param>
/// Wakes up and resets the device. Optional set gain level and channel.
114
135
/// </summary>
115
-
publicvoidPowerUp()
136
+
/// <param name="gain"><see cref="GainLevel"/> that will be used for the scale. If not provided, the default is <see cref="GainLevel.GainA128"/>.</param>
137
+
publicvoidPowerUp(GainLevelgain=GainLevel.None)
116
138
{
117
-
// only required if the device is in power down mode
118
-
varcurrentDout=_spiDevice.ReadByte();
119
-
120
-
if(currentDout!=0)
139
+
// PowerDown then PowerUP to activate on-chip power on rest circuitry
140
+
PowerDown();
141
+
//set PD_CLK low to awake and reset to default mode GainA128
142
+
//Wait for DOUT low means HX711 ready to accept new commands
143
+
WaitForConversion();
144
+
//switch to another channel mode if it is specified
145
+
if(gain!=GainLevel.None)
121
146
{
122
-
// transition of CLK signal high > low to wake-up device
0 commit comments