-
Notifications
You must be signed in to change notification settings - Fork 0
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
17 changed files
with
1,682 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Name, Type, SubType, Offset, Size, Flags | ||
nvs, data, nvs, 0x9000, 0x5000, | ||
otadata, data, ota, 0xe000, 0x2000, | ||
app0, app, ota_0, 0x10000, 0x1B0000, | ||
spiffs, data, spiffs, 0x1C0000,0x40000, |
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 @@ | ||
# Name, Type, SubType, Offset, Size, Flags | ||
nvs, data, nvs, 0x9000, 0x5000, | ||
otadata, data, ota, 0xe000, 0x2000, | ||
app0, app, ota_0, 0x10000, 0x180000, | ||
app1, app, ota_1, 0x190000,0x180000, | ||
spiffs, data, spiffs, 0x310000,0x0F0000, |
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,39 @@ | ||
|
||
This directory is intended for project header files. | ||
|
||
A header file is a file containing C declarations and macro definitions | ||
to be shared between several project source files. You request the use of a | ||
header file in your project source file (C, C++, etc) located in `src` folder | ||
by including it, with the C preprocessing directive `#include'. | ||
|
||
```src/main.c | ||
|
||
#include "header.h" | ||
|
||
int main (void) | ||
{ | ||
... | ||
} | ||
``` | ||
|
||
Including a header file produces the same results as copying the header file | ||
into each source file that needs it. Such copying would be time-consuming | ||
and error-prone. With a header file, the related declarations appear | ||
in only one place. If they need to be changed, they can be changed in one | ||
place, and programs that include the header file will automatically use the | ||
new version when next recompiled. The header file eliminates the labor of | ||
finding and changing all the copies as well as the risk that a failure to | ||
find one copy will result in inconsistencies within a program. | ||
|
||
In C, the usual convention is to give header files names that end with `.h'. | ||
It is most portable to use only letters, digits, dashes, and underscores in | ||
header file names, and at most one dot. | ||
|
||
Read more about using header files in official GCC documentation: | ||
|
||
* Include Syntax | ||
* Include Operation | ||
* Once-Only Headers | ||
* Computed Includes | ||
|
||
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html |
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 @@ | ||
|
||
This directory is intended for project specific (private) libraries. | ||
PlatformIO will compile them to static libraries and link into executable file. | ||
|
||
The source code of each library should be placed in a an own separate directory | ||
("lib/your_library_name/[here are source files]"). | ||
|
||
For example, see a structure of the following two libraries `Foo` and `Bar`: | ||
|
||
|--lib | ||
| | | ||
| |--Bar | ||
| | |--docs | ||
| | |--examples | ||
| | |--src | ||
| | |- Bar.c | ||
| | |- Bar.h | ||
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html | ||
| | | ||
| |--Foo | ||
| | |- Foo.c | ||
| | |- Foo.h | ||
| | | ||
| |- README --> THIS FILE | ||
| | ||
|- platformio.ini | ||
|--src | ||
|- main.c | ||
|
||
and a contents of `src/main.c`: | ||
``` | ||
#include <Foo.h> | ||
#include <Bar.h> | ||
|
||
int main (void) | ||
{ | ||
... | ||
} | ||
|
||
``` | ||
|
||
PlatformIO Library Dependency Finder will find automatically dependent | ||
libraries scanning project source files. | ||
|
||
More information about PlatformIO Library Dependency Finder | ||
- https://docs.platformio.org/page/librarymanager/ldf.html |
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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Stefan Kremser | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
143 changes: 143 additions & 0 deletions
143
C3MikroBUS/PlatformIO/C3mBUS_NVS/lib/SimpleList/README.md
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,143 @@ | ||
# SimpleList | ||
|
||
**Use [std::list](https://de.cppreference.com/w/cpp/container/list) whenever possible, or at least [LinkedList](https://github.com/ivanseidel/LinkedList), as it's more tested and still maintained!!!** | ||
|
||
Nothing big, just my own implementation of a linked list in c++ for all kind of Arduino projects. | ||
This Arduino Library was inspired by the [LinkedList](https://github.com/ivanseidel/LinkedList) | ||
and is mostly compatible too it. | ||
I made it to get a deeper understanding of lists. | ||
|
||
## Installation | ||
|
||
1) [Download](https://github.com/spacehuhn/SimpleList/archive/master.zip) the source code from GitHub. | ||
2) Unzip and rename the Folder name to "SimpleList". | ||
3) Paste it in your Library folder (Usually located somewhere at documents/Arduino/libraries). | ||
4) Restart the Arduino IDE. | ||
|
||
You can also just download the [SimpleList.h](https://github.com/spacehuhn/SimpleList/blob/master/SimpleList.h) | ||
file and paste it in your Arduino sketch folder. | ||
|
||
## Usage | ||
|
||
### Include the library | ||
```c++ | ||
#include <SimpleList.h> | ||
``` | ||
|
||
### Creating a SimpleList | ||
```c++ | ||
// A list of integer | ||
SimpleList<int> *myLinkedList = new SimpleList<int>(); | ||
|
||
// A list of 'MyClass' | ||
SimpleList<MyClass> *mySimpleList = new SimpleList<MyClass>(); | ||
``` | ||
|
||
### Getting the list size | ||
```c++ | ||
int theSize = myList->size(); | ||
``` | ||
|
||
### Adding compare function | ||
```c++ | ||
// Add a compare function to sort or search the list | ||
list->setCompare([](int &a, int &b) -> int { | ||
if(a < b) return -1; | ||
if(a == b) return 0; | ||
if(a > b) return 1; | ||
}); | ||
``` | ||
### Adding elements | ||
```c++ | ||
// add(obj) will add the object at the end of the list | ||
myList->add(myObject); | ||
// add(index, obj) method will insert the object at the specified index | ||
myList->add(0, myObject); // Add at the beginning | ||
myList->add(3, myObject); // Add at index 3 | ||
// insert will try to put the object at the correct spot to keep the list isSorted (compare function is required!) | ||
myList->insert(myObject); | ||
``` | ||
|
||
### Getting elements | ||
```c++ | ||
// Get the first element | ||
myObject = myList->get(0); | ||
|
||
// Get the third element | ||
myObject = myList->get(2); | ||
|
||
// Get the last element | ||
myObject = myList->get(myList->size() - 1); | ||
``` | ||
### Sorting the list | ||
```c++ | ||
// PLEASE NOTE: compare function must be set! | ||
// Sort the list | ||
list->sort(); | ||
// Check if list is currently sorted | ||
bool isSorted = list->isSorted(); | ||
``` | ||
|
||
### Replacing elements | ||
```c++ | ||
// Replace the first element | ||
myList->replace(0, myObject); | ||
|
||
// Replace the third element | ||
myList->replace(2, myObject); | ||
|
||
// Replace the last element | ||
myList->replace(myList->size() - 1, myObject); | ||
``` | ||
### Removing elements | ||
```c++ | ||
// Remove the first object | ||
myList->remove(0); | ||
// pop() will remove and return the last element | ||
myDeletedObject = myList->pop(); | ||
// shift() will remove and return the first element | ||
myDeletedObject = myList->shift(); | ||
// clear() will erase the entire list, leaving it with 0 elements | ||
myList->clear(); | ||
// Please note that clear() wont free memory from pointers, you have to manually delete/free those! | ||
// Example: | ||
while(list->size() > 0){ | ||
delete myList->get(0).somePointer; | ||
list->remove(0); | ||
} | ||
``` | ||
|
||
### Searching for elements | ||
```c++ | ||
// PLEASE NOTE: compare function must be set! | ||
|
||
// seach() returns the index of the element, not the element itself! | ||
int indexOfSeven = list->search(7); | ||
|
||
// When the list is sorted, you can also do a more efficient binary search | ||
// here find the element | ||
int indexOfIntOne = list->binSearch(1); | ||
``` | ||
### Counting elements | ||
```c++ | ||
// PLEASE NOTE: compare function must be set! | ||
int numberOfZeros = myList->count(0); | ||
``` | ||
|
||
### Swapping elements | ||
```c++ | ||
// swap(index-X, index-Y) | ||
list->swap(0, list->size()-1); | ||
``` |
128 changes: 128 additions & 0 deletions
128
C3MikroBUS/PlatformIO/C3mBUS_NVS/lib/SimpleList/examples/IntegerList/IntegerList.ino
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,128 @@ | ||
/* | ||
=========================================== | ||
Copyright (c) 2018 Stefan Kremser | ||
github.com/spacehuhn | ||
=========================================== | ||
*/ | ||
|
||
#include <SimpleList.h> | ||
|
||
SimpleList<int>* list; | ||
|
||
void printList() { | ||
Serial.print("=>"); | ||
|
||
for (int i = 0; i < list->size(); i++) { | ||
Serial.print(list->get(i)); | ||
Serial.print("->"); | ||
} | ||
Serial.println("//"); | ||
} | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
delay(200); | ||
|
||
// create new list | ||
list = new SimpleList<int>(); | ||
|
||
Serial.println("Create list:"); | ||
|
||
// add a bunch of numbers | ||
list->add(1); | ||
list->add(0); | ||
list->add(7); | ||
list->add(1); | ||
list->add(6); | ||
list->add(16); | ||
|
||
// print out the list | ||
printList(); | ||
// => 1 -> 0 -> 7 -> 1 -> 6 -> 16 -> // | ||
|
||
// remove first and last | ||
Serial.println("Remove first and last:"); | ||
list->remove(5); // remove node at index 5, alternative: removeNode(listSize-1); | ||
list->remove(0); // remove node at index 0 | ||
printList(); | ||
// => 0 -> 7 -> 1 -> 6 -> // | ||
|
||
// add number 4 at the end | ||
Serial.println("Add number 4 at the end:"); | ||
list->add(4); | ||
printList(); | ||
// => 0 -> 7 -> 1 -> 6 -> 4 -> // | ||
|
||
// replace number 0 with 3 | ||
Serial.println("Replace number 0 with 3:"); | ||
list->replace(0, 3); | ||
printList(); | ||
// => 3 -> 7 -> 1 -> 6 -> 4 -> // | ||
|
||
// add a compare function to sort or search the list | ||
list->setCompare([](int& a, int& b) -> int { | ||
if (a < b) return -1; | ||
else if (a > b) return 1; | ||
else return 0; | ||
}); | ||
|
||
// find the number 7 and replace it with a 2 | ||
Serial.println("Replace number 7 with 2:"); | ||
list->replace(list->search(7), 2); | ||
printList(); | ||
// => 3 -> 2 -> 1 -> 6 -> 4 -> // | ||
|
||
// sort the list | ||
Serial.println("Sort list:"); | ||
list->sort(); | ||
printList(); | ||
// => 1 -> 2 -> 3 -> 4 -> 6 -> // | ||
|
||
// perform a fast binary search (only works when the list is sorted!) | ||
Serial.println("1 at index (bin-search): " + (String)list->binSearch(1)); | ||
Serial.println("6 at index (bin-search): " + (String)list->binSearch(6)); | ||
Serial.println("3 at index (bin-search): " + (String)list->binSearch(3)); | ||
|
||
// or do the slower sequential search (won't make a time difference in small lists like this) | ||
|
||
Serial.println("1 at index (seq-search): " + (String)list->search(1)); | ||
Serial.println("6 at index (seq-search): " + (String)list->search(6)); | ||
Serial.println("3 at index (seq-search): " + (String)list->search(3)); | ||
|
||
// insert number 5 (which ist the list size) in the sorted list | ||
// note here that insert() will try to put the object in correct spot to keep the list sorted | ||
Serial.println("Insert number 5:"); | ||
list->insert(list->size()); | ||
printList(); | ||
// => 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> // | ||
|
||
// empty the list | ||
Serial.println("Empty the list:"); | ||
list->clear(); | ||
// => Empty list :( | ||
printList(); | ||
|
||
// add random numbers | ||
Serial.println("Add random numbers:"); | ||
|
||
for (int i = 0; i < 10; i++) list->add(random(0, 9)); | ||
printList(); | ||
|
||
// with shift() you get and remove the first object from the list | ||
Serial.println("removed first object " + (String)list->shift()); | ||
printList(); | ||
|
||
// with pop() you get and remove the last object from the list | ||
Serial.println("removed last object " + (String)list->pop()); | ||
printList(); | ||
|
||
Serial.println("List sorted: " + String(list->isSorted() ? "true" : "false")); | ||
printList(); | ||
list->sort(); | ||
Serial.println("List sorted: " + String(list->isSorted() ? "true" : "false")); | ||
printList(); | ||
|
||
Serial.println("Done"); | ||
} | ||
|
||
void loop() {} |
Oops, something went wrong.