Skip to content

Commit

Permalink
Sensor Status added, Refactoring of CONSTANTS.ino to CONSTANTS.h
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerandhill committed Dec 1, 2021
1 parent f96647c commit cb122ba
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .vscode/arduino.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"sketch": "BackhoeAngleSensor_SENSOR.ino",
"board": "esp8266:esp8266:nodemcuv2",
"configuration": "CpuFrequency=80,VTable=flash,FlashSize=4M3M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,FlashErase=none,UploadSpeed=115200",
"port": "COM8",
"port": "COM9",
"output": "build"
}
47 changes: 47 additions & 0 deletions BNO055sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,53 @@ void updateSensor(void) {
temperature = bno.getTemp();
}

int getSensorSystemStatus()
{
// 0 = Idle
// 1 = System Error
// 2 = Initializing Peripherals
// 3 = System Iniitalization
// 4 = Executing Self-Test
// 5 = Sensor fusio algorithm running
// 6 = System running without fusion algorithms
uint8_t *system_status;

// 1 = test passed, 0 = test failed
// Bit 0 = Accelerometer self test
// Bit 1 = Magnetometer self test
// Bit 2 = Gyroscope self test
// Bit 3 = MCU self test
// 0x0F = all good!
uint8_t *self_test_result;

// 0 = No error
// 1 = Peripheral initialization error
// 2 = System initialization error
// 3 = Self test result failed
// 4 = Register map value out of range
// 5 = Register map address out of range
// 6 = Register map write error
// 7 = BNO low power mode not available for selected operat ion mode
// 8 = Accelerometer power mode not available

// 9 = Fusion algorithm configuration error
// 10 = Sensor configuration error
uint8_t *system_error;

bno.getSystemStatus(system_status, self_test_result, system_error);

bool warning = (int) system_status == 6 || ((int) system_status >= 2 && (int) system_status <= 4);
bool error = (int) system_status == 1 || (int) system_error != 0;

if(error) {
return SENSOR_STATUS_ERROR;
} else if(warning) {
return SENSOR_STATUS_WARNING;
}

return SENSOR_STATUS_OK;
}

void setOffsetToNow() {
updateSensor();

Expand Down
7 changes: 7 additions & 0 deletions BackhoeAngleSensor_SENSOR.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#include "CONSTANTS.h"
#include <Wire.h>

// Prototypes
void initSensor(void);
void initEEPROM(void);
void initEspNow(void);
void loopEspNow(void);

// Uncomment following line, the first time flashing to the controller!
// #define FLASHING_FIRST_TIME

Expand Down
8 changes: 6 additions & 2 deletions CONSTANTS.ino → CONSTANTS.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@


//#############SECTION ESP NOW #############
#define WIFI_UPDATE_PERIOD 500 // In Milliseconds
#define ESPNOW_SEND_RATE 500 // In Milliseconds

uint8_t broadcastAddressEsp32Display[] = {0xF0, 0x08, 0xD1, 0xFF, 0xC8, 0x38};

#define SENSOR_STATUS_ERROR 0 // Sensor OFFLINE or something really bad happened (Peripheral error, or something else)
#define SENSOR_STATUS_WARNING 1 // Sensor ALIVE but NOT OK (Something is weird, but not crucial)
#define SENSOR_STATUS_OK 2 // Sensor ALIVE and OK

//#############SECTION DISPLAY COMMANDS #############
#define DISPLAY_COMMAND_SET_OFFSET 0
#define DISPLAY_COMMAND_CALIBRATE_SENSOR 0
#define DISPLAY_COMMAND_FLIP_XY 1
14 changes: 9 additions & 5 deletions ESPnow.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ typedef struct struct_sensor_data {
float verticalAngle;
bool flipXYAxis;
int temperature;
int sensorSystemStatus;
} struct_sensor_data;
// Create a container for Sensor Data for the Display
struct_sensor_data sensorData;
Expand Down Expand Up @@ -110,27 +111,30 @@ void updateSensorDataStructure() {
sensorData.verticalAngle = getVerticalAngleWithOffset();
sensorData.flipXYAxis = getFlipXY();
sensorData.temperature = getTemperature();
sensorData.sensorSystemStatus = getSensorSystemStatus();
}

void processCommand() {

switch(incomingCommandType) {
case DISPLAY_COMMAND_SET_OFFSET:
Serial.print("DISPLAY_COMMAND_SET_OFFSET. Value: ");
Serial.println(incomingCommandValue);
case DISPLAY_COMMAND_CALIBRATE_SENSOR:
Serial.print("DISPLAY_COMMAND_CALIBRATE_SENSOR. Value: ");
setOffsetToNow();
break;

case DISPLAY_COMMAND_FLIP_XY:
Serial.print("DISPLAY_COMMAND_FLIP_XY. Value: ");
Serial.println(incomingCommandValue ? "True" : "False");
setFlipXYToEEPROM(incomingCommandValue);
break;
}

Serial.println(incomingCommandValue ? "True" : "False");

}

void loopEspNow() {

if(millis() - lastMillis > WIFI_UPDATE_PERIOD) {
if(millis() - lastMillis > ESPNOW_SEND_RATE) {
lastMillis = millis();
sendSensorValues();
}
Expand Down

0 comments on commit cb122ba

Please sign in to comment.