Skip to content

Commit

Permalink
Automatically configure the Bluetooth module the first time it is tur…
Browse files Browse the repository at this point in the history
…ned on
  • Loading branch information
Lauszus committed Feb 19, 2018
1 parent 47158be commit bf9c301
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion EEPROM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
cfg_t cfg; // Struct for all the configuration values

//static const char *firmwareVersion = "1.0.0";
static const uint8_t eepromVersion = 2; // EEPROM version - used to restore the EEPROM values if the configuration struct have changed
static const uint8_t eepromVersion = 3; // EEPROM version - used to restore the EEPROM values if the configuration struct have changed

/* EEPROM Address Definitions */
static const uint8_t versionAddr = 0; // Set the first byte to the EEPROM version
Expand Down Expand Up @@ -72,5 +72,7 @@ void restoreEEPROMValues() {
cfg.accYzero = cfg.accZzero = 0;
cfg.leftMotorScaler = cfg.rightMotorScaler = 1;

cfg.configureBtModule = true;

updateEEPROMValues();
}
2 changes: 2 additions & 0 deletions EEPROM.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ typedef struct {
// TODO: Implement this:
double accYzero, accZzero; // Accelerometer zero values
double leftMotorScaler, rightMotorScaler; // Used if there is difference between the motors

bool configureBtModule; // Used to configure the Bluetooth module the first time it is turned on
} cfg_t;

extern cfg_t cfg;
Expand Down
12 changes: 12 additions & 0 deletions Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ void sendData(uint8_t *data, uint8_t length);
uint8_t getCheckSum(uint8_t *data, size_t length);

void initSerial() {
// Automatically configure the Bluetooth module the first time it is turned on
if (cfg.configureBtModule) {
cfg.configureBtModule = false;
updateEEPROMValues();

Serial.begin(9600);
Serial.println("AT+NAMESegway"); // Set the name to 'Segway'
delay(1000); // The module waits 1 s before it considers a message complete
Serial.println("AT+PIN0000"); // Set the pin to '0000'
delay(1000); // The module waits 1 s before it considers a message complete
Serial.println("AT+BAUD7"); // Finally change the baud rate to '57600'
}
Serial.begin(57600);
Serial.setTimeout(10); // Only wait 10ms for serial data
}
Expand Down

0 comments on commit bf9c301

Please sign in to comment.