39 this->settings.
mode = mode;
40 maxPrint = maxSetted = minPrint = minSetted = 0;
47 miosix::FastInterruptDisableLock dLock;
48 ctrlPin1::mode(miosix::Mode::OUTPUT);
49 ctrlPin2::mode(miosix::Mode::OUTPUT);
68 if (response.find(
'!') != std::string::npos)
71 if (response.find(
'#') != std::string::npos)
94 float val = stof(response.substr(3, 6)) / 10.0;
101 TRACE(
"TARE RESETTED\n");
105 TRACE(
"COMMUTED TO GROSS WEIGHT\n");
109 TRACE(
"COMMUTED TO NET WEIGHT\n");
118 TRACE(
"max and min values erased!\n");
119 maxWeight.
valid =
false;
120 minWeight.
valid =
false;
127#ifdef PRINT_ALL_SAMPLES
134 TRACE(
"No valida data has been collected\n");
139 TRACE(
"NEW MAX %.2f (ts: %.3f [s])\n", maxWeight.
load,
146 TRACE(
"NEW MIN %.2f (ts: %.3f [s])\n", minWeight.
load,
161 switch (settings.
mode)
234 if (response.find(
'!') != std::string::npos)
236 TRACE(
"Gross weight reception error\n");
240 else if (response.find(
'#') != std::string::npos)
242 TRACE(
"Gross weight execution error\n");
256 strcpy(req.
req, loadCellValues[toRequest].c_str());
262 std::string strVal = std::to_string(abs(value));
263 strVal.insert(strVal.begin(), 6 - strVal.length(),
'0');
268 strcpy(req.
value, strVal.c_str());
269 TRACE(
"value sent: %s\n", strVal.c_str());
281 miosix::Thread::sleep(10);
294 return std::string(buf);
miosix::Gpio< GPIOC_BASE, 1 > ctrlPin1
Control R/W pin 1.
miosix::Gpio< GPIOC_BASE, 2 > ctrlPin2
Control R/W pin 2.
void receive(T *buf)
Wrapper to the serial receive method. This also sets the control pins to enable the receiver mode.
MBLoadCellData getMaxWeight()
Returns a copy of the max weight detected.
MBLoadCellData sampleContModTd(void)
Sampling in the "continuous Mod Td" mode.
MBLoadCellData sampleContModT(void)
Sampling in the "continuous Mod T" mode.
void resetMaxMinWeights()
Permits to reset the peak weight value.
MBLoadCellData sampleAsciiModTd(void)
Sampling in the "ASCII Mod Td" mode.
std::string receiveASCII()
Wrapper to the serial recvString method. This also sets the control pins to enable the receiver mode.
MBLoadCellData getMinWeight()
Returns a copy of the min weight detected.
void printData()
Prints the last sample received.
void transmitASCII(const std::string &buf)
Wrapper to the serial sendString method. This also sets the control pins to enable the transmission m...
ReturnsStates asciiRequest(LoadCellValuesEnum r, int value=0)
Generates and sends a request in ASCII mode, waits for the response and updates the lastSample struct...
bool init() override
Initializes the serial communication with the load cell.
void generateRequest(DataAsciiRequest &req, const LoadCellValuesEnum toRequest, int value=0)
Forges a request for the ascii mode.
MBLoadCellData sampleImpl() override
Requests the weight sampled from the load cell or waits for a sample depending on the mode selected (...
bool selfTest() override
Check if the sensor is working.
MBLoadCell(USARTInterface &serial, LoadCellModes mode)
constructor that initializes the serial communication with the load cell
Abstract class that implements the interface for the USART/UART serial communication.
virtual bool readBlocking(void *buffer, size_t nBytes, std::chrono::nanoseconds timeout=std::chrono::nanoseconds::zero())
Blocking read operation to read nBytes until the data transfer is complete or the timeout is reached.
virtual void writeString(const char *buffer)=0
Write a string to the serial, comprising the '\0' character.
This file includes all the types the logdecoder script will decode.
ReturnsStates
Structure of the errors in the ASCII requests.
LoadCellModes
Enumeration of all the modes supported by the driver.
LoadCellValuesEnum
Enumeration of all the requests in ASCII mode.
Structure that contains all the parameters for the request to be sent.
void setChecksum()
In base of the address and the request parameter calculates the checksum.
Structure of the output of the load cell in [continuous mode -> ModT].
Structure of the output of the load cell in [continuous mode -> ModTd].
Structure that stores a data value, with his timestamp and his validity.
void print(std::ostream &os) const
void updateValue(LoadCellValuesEnum val, float data)
Updates the correct value with the data passed. Also, memorizes the maximum and minimum value of the ...