-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#pragma once | ||
|
||
// This is the configuration file for the robot | ||
// Fill all the required the parameters and | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "i2c.h" | ||
|
||
void i2c_scan() | ||
{ | ||
Serial.println("I2C scanner. Scanning ..."); | ||
byte count = 0; | ||
|
||
Wire.begin(); | ||
Serial.println("..."); | ||
for (byte i = 8; i < 120; i++) | ||
{ | ||
// Serial.println (i); | ||
Wire.beginTransmission(i); | ||
if (Wire.endTransmission() == 0) | ||
{ | ||
Serial.print("Found address: "); | ||
Serial.print(i, DEC); | ||
Serial.print(" (0x"); | ||
Serial.print(i, HEX); | ||
Serial.println(")"); | ||
count++; | ||
delay(1); // maybe unneeded? | ||
} // end of good response | ||
} // end of for loop | ||
|
||
Serial.printf("Done.......\nFound %d device(s)\n\n", count); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#pragma once | ||
|
||
#include <Arduino.h> | ||
#include <Wire.h> | ||
|
||
void i2c_scan(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include "memory.h" | ||
|
||
SW_Memory memory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
#include "./src/robot_memory.h" | ||
|
||
extern SW_Memory memory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* @brief Swarm Robot Memory Manager Library | ||
* @author Nuwan Jaliyagoda, Pasan Tennakoon, Dilshani Karunarathna | ||
* @version 1.0.0 | ||
* @url N/A | ||
* | ||
* ------------------------------------------------------------------------------ | ||
*/ | ||
|
||
#include <Arduino.h> | ||
#include "EEPROM.h" | ||
#include "robot_memory.h" | ||
|
||
#include "config/pins.h" | ||
#include "config/definitions.h" | ||
|
||
#define MIN_ROBOT_ID 0 | ||
#define MAX_ROBOT_ID 31 | ||
|
||
#define EEPROM_SIZE 10 | ||
|
||
SW_Memory::SW_Memory() | ||
{ // Memory constructor | ||
} | ||
|
||
void SW_Memory::begin() | ||
{ | ||
this->displayMemoryDetails(); | ||
EEPROM.begin(EEPROM_SIZE); | ||
Serial.println(F(">> Memory\t:enabled")); | ||
} | ||
|
||
void SW_Memory::displayMemoryDetails() | ||
{ | ||
Serial.printf("\n\nThe program uses %d kB and has free space of %d kB\n\n", ESP.getSketchSize() / 1000, ESP.getFreeSketchSpace() / 1000); | ||
} | ||
|
||
int SW_Memory::getRobotId() | ||
{ // TODO: implement a variable as cache for reduce the number of memory read occurances | ||
return (int)this->read(EEPROM_ROBOT_ID); | ||
} | ||
|
||
boolean SW_Memory::getMemoryStatus() | ||
{ | ||
return (this->read(EEPROM_PROGRAMMED) == 1); | ||
} | ||
|
||
uint8_t SW_Memory::read(int adr) | ||
{ | ||
return EEPROM.read(adr); | ||
} | ||
void SW_Memory::write(uint16_t address, uint8_t data) | ||
{ // address: [0-511], data: [0-255] | ||
EEPROM.write(address, data); | ||
delay(200); | ||
EEPROM.commit(); | ||
} | ||
void SW_Memory::test() | ||
{ // A dummy Function for now | ||
} | ||
|
||
void SW_Memory::setupRobotWithId(uint8_t id) | ||
{ | ||
this->setRobotId(id); | ||
} | ||
|
||
void SW_Memory::setRobotId(uint8_t id) | ||
{ | ||
if (id >= MIN_ROBOT_ID && id <= MAX_ROBOT_ID) | ||
{ | ||
EEPROM.write(EEPROM_ROBOT_ID, id); | ||
delay(200); | ||
EEPROM.write(EEPROM_PROGRAMMED, 1); | ||
delay(200); | ||
EEPROM.commit(); | ||
Serial.printf("Mem_Done\t: %d is written as Robot Id\n", id); | ||
} | ||
else | ||
{ | ||
Serial.printf("Mem_Error\t: %d is an invalid Robot Id\n", id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* @brief Swarm Robot Memory Manager Library | ||
* @author Nuwan Jaliyagoda, Pasan Tennakoon, Dilshani Karunarathna | ||
* @version 1.0.0 | ||
* @url N/A | ||
* | ||
* ------------------------------------------------------------------------------ | ||
*/ | ||
|
||
#ifndef SW_Memory_h | ||
#define SW_Memory_h | ||
|
||
#include <Arduino.h> | ||
|
||
class SW_Memory | ||
{ | ||
public: | ||
SW_Memory(); | ||
|
||
int getRobotId(); | ||
int8_t getErrorCorrection(uint8_t id); | ||
|
||
void begin(); | ||
void test(); | ||
|
||
void setupRobotWithId(uint8_t id); | ||
|
||
void setRobotId(uint8_t id); | ||
|
||
boolean getMemoryStatus(); | ||
|
||
// REM: Better to keep following 2 private | ||
uint8_t read(int adr); | ||
void write(uint16_t address, uint8_t data); | ||
|
||
enum addr | ||
{ | ||
EEPROM_PROGRAMMED, | ||
EEPROM_ROBOT_ID | ||
}; | ||
|
||
private: | ||
void displayMemoryDetails(); | ||
}; | ||
|
||
#endif |