MCPcopy Create free account
hub / github.com/Duet3D/RepRapFirmware / AccelerometerTaskCode

Function AccelerometerTaskCode

src/Accelerometers/Accelerometers.cpp:102–230  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102[[noreturn]] void AccelerometerTaskCode(void*) noexcept
103{
104 for (;;)
105 {
106 TaskBase::TakeIndexed(NotifyIndices::AccelerometerDataCollector);
107 FileStore *_ecv_null f = accelerometerFile; // capture volatile variable
108 if (f != nullptr)
109 {
110 // Collect and write the samples
111 unsigned int samplesWritten = 0;
112 unsigned int samplesWanted = numSamplesRequested;
113 unsigned int numOverflows = 0;
114 const uint16_t mask = (1u << resolution) - 1;
115 const int decimalPlaces = GetDecimalPlaces(resolution);
116 bool recordFailedStart = false;
117
118 if (not_null(accelerometer)->StartCollecting(TranslateAxes(axesRequested)))
119 {
120 successfulStart = true;
121 uint16_t dataRate = 0;
122 do
123 {
124 const uint16_t *_ecv_array data;
125 bool overflowedOrSpuriousInterrupts;
126 unsigned int samplesRead = not_null(accelerometer)->CollectData(&data, dataRate, overflowedOrSpuriousInterrupts);
127 if (samplesRead == 0)
128 {
129 // samplesRead == 0 indicates an error, e.g. no interrupt
130 samplesWanted = 0;
131 not_null(f)->Write((overflowedOrSpuriousInterrupts) ? "Too many spurious interrupts from accelerometer\n" : "Failed to collect data from accelerometer\n");
132 not_null(f)->Truncate(); // truncate the file in case we didn't write all the preallocated space
133 not_null(f)->Close();
134 f = nullptr;
135 AddLocalAccelerometerRun(0);
136 }
137 else
138 {
139 if (overflowedOrSpuriousInterrupts)
140 {
141 ++numOverflows;
142 }
143 if (samplesWritten == 0)
144 {
145 // The first sample taken after waking up is inaccurate, so discard it
146 --samplesRead;
147 data += 3;
148 }
149 if (samplesRead >= samplesWanted)
150 {
151 samplesRead = samplesWanted;
152 }
153
154 while (samplesRead != 0)
155 {
156 // Write a row of data
157 String<StringLength50> temp;
158 temp.printf("%u", samplesWritten);
159

Callers

nothing calls this directly

Calls 12

GetDecimalPlacesFunction · 0.85
TranslateAxesFunction · 0.85
AddLocalAccelerometerRunFunction · 0.85
GetBitsAfterPointFunction · 0.85
CollectDataMethod · 0.80
TruncateMethod · 0.80
catfMethod · 0.80
catMethod · 0.80
StopCollectingMethod · 0.80
WriteMethod · 0.60
CloseMethod · 0.45
printfMethod · 0.45

Tested by

no test coverage detected