SapFlow Probe
A low-cost HRM probe for measuring a tree's water consumption
weight.cpp
Go to the documentation of this file.
1 #include "weight.h"
2 
4 
5 // Gets the weight from the scale
6 char * read_weight( char * buffer, int len ){
7  // Clear the buffer in case someone was messing with the cable
8  int n = Serial1.available();
9  while( Serial1.available() > len ){
10  Serial1.readBytes(buffer, len);
11  }
12  if( Serial1.available() ){
13  Serial1.readBytes(buffer, Serial1.available());
14  }
15 
16  // Now request the weight
17  Serial1.print("P\r\n");
18  len = 1 + Serial1.readBytesUntil('\n', buffer, len-1);
19  buffer[len] = 0; // Null-terminate the string
20  int start_index, value_length, i;
21  // Filter out spaces and linefeed
22  for( i = 0; buffer[i]; ++i){
23  if( buffer[i] >= '0' )
24  break;
25  }
26  start_index = i;
27  for( ; buffer[i]; ++i){
28  if( buffer[i] < '.' )
29  break;
30  }
31  value_length = i - start_index;
32 
33  memmove(buffer, buffer+start_index, value_length);
34  buffer[value_length] = 0; // null terminate
35  return( buffer );
36 }
weight.h
read_weight
char * read_weight(char *buffer, int len)
Gets the weight from the scale.
Definition: weight.cpp:6