Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two changes #3

Merged
merged 2 commits into from
May 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/lorasoundkit/lorasoundkit.ino
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ void setup(void) {
printf("End setup\n");
}

// add 12 bits value to payloadbuffer
int add12bitsToBuf( unsigned char* buf, int nibbleCount, short val) {
if ( nibbleCount % 2 == 0) {
buf[ nibbleCount / 2] = val >> 4;
buf[ nibbleCount / 2 + 1] = (val << 4) & 0xF0;
}
else {
buf[ nibbleCount / 2] |= ((val >> 8) & 0x0F);
buf[ nibbleCount / 2 + 1] = val;
}
return nibbleCount + 3;
}

// compose message, and send it to TTN
// convert shorts to 12 bit integers, to save 25% space in th TTN message
static void sendToTTN( Measurement& la, Measurement& lc, Measurement& lz) {
Expand Down Expand Up @@ -110,19 +123,6 @@ static void sendToTTN( Measurement& la, Measurement& lc, Measurement& lz) {
digitalWrite( LED_BUILTIN, LOW);
}

// add 12 bits value to payloadbuffer
int add12bitsToBuf( unsigned char* buf, int nibbleCount, short val) {
if ( nibbleCount % 2 == 0) {
buf[ nibbleCount / 2] = val >> 4;
buf[ nibbleCount / 2 + 1] = (val << 4) & 0xF0;
}
else {
buf[ nibbleCount / 2] |= ((val >> 8) & 0x0F);
buf[ nibbleCount / 2 + 1] = val;
}
return nibbleCount + 3;
}

// Arduino Main Loop
void loop(void) {

Expand Down
2 changes: 1 addition & 1 deletion src/lorasoundkit/measurement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Measurement::Measurement( float* weighting) {
}

void Measurement::reset() {
avg = min = max = 0.0;
avg = 0.0;
_n = 0;
min = FLT_MAX;
max = FLT_MIN;
Expand Down