Added code for the linked list handling and completed the class diagram

This commit is contained in:
anschrammh 2019-02-25 23:35:01 +01:00
parent cc15cf3366
commit d790b72dcd
5 changed files with 166 additions and 38 deletions

View File

@ -708,13 +708,30 @@
"height": 13, "height": 13,
"text": "-isListEmpty(ViewLinkedList viewLinkedList): boolean", "text": "-isListEmpty(ViewLinkedList viewLinkedList): boolean",
"horizontalAlignment": 0 "horizontalAlignment": 0
},
{
"_type": "UMLOperationView",
"_id": "AAAAAAFpJr23NJTFEu0=",
"_parent": {
"$ref": "AAAAAAFpHq11g76xBiU="
},
"model": {
"$ref": "AAAAAAFpJr23GpTCSEg="
},
"font": "Arial;13;0",
"left": 221,
"top": 977,
"width": 523.16748046875,
"height": 13,
"text": "-removeLinkByUID(ViewLinkedList *viewLinkedList, UID: const unsigned char): boolean",
"horizontalAlignment": 0
} }
], ],
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 216, "left": 216,
"top": 822, "top": 822,
"width": 533.16748046875, "width": 533.16748046875,
"height": 158 "height": 173
}, },
{ {
"_type": "UMLReceptionCompartmentView", "_type": "UMLReceptionCompartmentView",
@ -754,7 +771,7 @@
"left": 216, "left": 216,
"top": 744, "top": 744,
"width": 533.16748046875, "width": 533.16748046875,
"height": 236, "height": 251,
"nameCompartment": { "nameCompartment": {
"$ref": "AAAAAAFpHq11gr6ruDw=" "$ref": "AAAAAAFpHq11gr6ruDw="
}, },
@ -793,7 +810,7 @@
"visible": false, "visible": false,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 813, "left": 813,
"top": 876, "top": 881,
"height": 13, "height": 13,
"alpha": 1.5707963267948966, "alpha": 1.5707963267948966,
"distance": 15, "distance": 15,
@ -814,7 +831,7 @@
"visible": null, "visible": null,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 813, "left": 813,
"top": 891, "top": 896,
"height": 13, "height": 13,
"alpha": 1.5707963267948966, "alpha": 1.5707963267948966,
"distance": 30, "distance": 30,
@ -835,7 +852,7 @@
"visible": false, "visible": false,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 814, "left": 814,
"top": 847, "top": 851,
"height": 13, "height": 13,
"alpha": -1.5707963267948966, "alpha": -1.5707963267948966,
"distance": 15, "distance": 15,
@ -856,7 +873,7 @@
"visible": false, "visible": false,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 852, "left": 852,
"top": 878, "top": 881,
"height": 13, "height": 13,
"alpha": 0.5235987755982988, "alpha": 0.5235987755982988,
"distance": 30, "distance": 30,
@ -877,7 +894,7 @@
"visible": false, "visible": false,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 850, "left": 850,
"top": 891, "top": 895,
"height": 13, "height": 13,
"alpha": 0.7853981633974483, "alpha": 0.7853981633974483,
"distance": 40, "distance": 40,
@ -898,7 +915,7 @@
"visible": false, "visible": false,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 857, "left": 857,
"top": 851, "top": 854,
"height": 13, "height": 13,
"alpha": -0.5235987755982988, "alpha": -0.5235987755982988,
"distance": 25, "distance": 25,
@ -918,7 +935,7 @@
}, },
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 758, "left": 758,
"top": 880, "top": 884,
"width": 94.65625, "width": 94.65625,
"height": 13, "height": 13,
"alpha": -0.3058788210270264, "alpha": -0.3058788210270264,
@ -939,8 +956,8 @@
}, },
"visible": false, "visible": false,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 776, "left": 777,
"top": 889, "top": 894,
"height": 13, "height": 13,
"alpha": -0.7853981633974483, "alpha": -0.7853981633974483,
"distance": 40, "distance": 40,
@ -960,7 +977,7 @@
"visible": false, "visible": false,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 770, "left": 770,
"top": 849, "top": 853,
"height": 13, "height": 13,
"alpha": 0.5235987755982988, "alpha": 0.5235987755982988,
"distance": 25, "distance": 25,
@ -1005,7 +1022,7 @@
"$ref": "AAAAAAFpHqCuVb5uVUA=" "$ref": "AAAAAAFpHqCuVb5uVUA="
}, },
"lineStyle": 1, "lineStyle": 1,
"points": "879:870;749:867", "points": "879:873;749:872",
"showVisibility": true, "showVisibility": true,
"nameLabel": { "nameLabel": {
"$ref": "AAAAAAFpHucSvL8/DjI=" "$ref": "AAAAAAFpHucSvL8/DjI="
@ -3667,8 +3684,8 @@
}, },
"visible": false, "visible": false,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 481, "left": 480,
"top": 1008, "top": 1016,
"height": 13, "height": 13,
"alpha": 1.5707963267948966, "alpha": 1.5707963267948966,
"distance": 15, "distance": 15,
@ -3688,8 +3705,8 @@
}, },
"visible": null, "visible": null,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 496, "left": 495,
"top": 1009, "top": 1017,
"height": 13, "height": 13,
"alpha": 1.5707963267948966, "alpha": 1.5707963267948966,
"distance": 30, "distance": 30,
@ -3709,8 +3726,8 @@
}, },
"visible": false, "visible": false,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 452, "left": 451,
"top": 1005, "top": 1013,
"height": 13, "height": 13,
"alpha": -1.5707963267948966, "alpha": -1.5707963267948966,
"distance": 15, "distance": 15,
@ -3730,8 +3747,8 @@
}, },
"visible": false, "visible": false,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 482, "left": 481,
"top": 1001, "top": 1016,
"height": 13, "height": 13,
"alpha": 0.5235987755982988, "alpha": 0.5235987755982988,
"distance": 30, "distance": 30,
@ -3751,8 +3768,8 @@
}, },
"visible": false, "visible": false,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 495, "left": 494,
"top": 1004, "top": 1019,
"height": 13, "height": 13,
"alpha": 0.7853981633974483, "alpha": 0.7853981633974483,
"distance": 40, "distance": 40,
@ -3772,8 +3789,8 @@
}, },
"visible": false, "visible": false,
"font": "Arial;13;0", "font": "Arial;13;0",
"left": 455, "left": 454,
"top": 994, "top": 1009,
"height": 13, "height": 13,
"alpha": -0.5235987755982988, "alpha": -0.5235987755982988,
"distance": 25, "distance": 25,
@ -3879,7 +3896,7 @@
"$ref": "AAAAAAFpHq11gr6quCs=" "$ref": "AAAAAAFpHq11gr6quCs="
}, },
"lineStyle": 1, "lineStyle": 1,
"points": "470:980;464:1047", "points": "469:995;464:1047",
"showVisibility": true, "showVisibility": true,
"nameLabel": { "nameLabel": {
"$ref": "AAAAAAFpIVDGIBS5fjw=" "$ref": "AAAAAAFpIVDGIBS5fjw="
@ -4563,7 +4580,8 @@
"_parent": { "_parent": {
"$ref": "AAAAAAFpIV35vBs6xGk=" "$ref": "AAAAAAFpIV35vBs6xGk="
}, },
"name": "ViewLinkedList *viewLinkedList" "name": "ViewLinkedList *viewLinkedList",
"type": ""
}, },
{ {
"_type": "UMLParameter", "_type": "UMLParameter",
@ -4571,7 +4589,8 @@
"_parent": { "_parent": {
"$ref": "AAAAAAFpIV35vBs6xGk=" "$ref": "AAAAAAFpIV35vBs6xGk="
}, },
"name": "ViewLink viewLink" "name": "ViewLink viewLink",
"type": ""
}, },
{ {
"_type": "UMLParameter", "_type": "UMLParameter",
@ -4612,6 +4631,43 @@
"type": "" "type": ""
} }
] ]
},
{
"_type": "UMLOperation",
"_id": "AAAAAAFpJr23GpTCSEg=",
"_parent": {
"$ref": "AAAAAAFpHq11gr6oq4M="
},
"name": "removeLinkByUID",
"visibility": "private",
"parameters": [
{
"_type": "UMLParameter",
"_id": "AAAAAAFpJr40KZUjrSE=",
"_parent": {
"$ref": "AAAAAAFpJr23GpTCSEg="
},
"type": "boolean",
"direction": "return"
},
{
"_type": "UMLParameter",
"_id": "AAAAAAFpJr5+j5XLL6Y=",
"_parent": {
"$ref": "AAAAAAFpJr23GpTCSEg="
},
"name": "ViewLinkedList *viewLinkedList"
},
{
"_type": "UMLParameter",
"_id": "AAAAAAFpJr5+j5XMdAM=",
"_parent": {
"$ref": "AAAAAAFpJr23GpTCSEg="
},
"name": "UID",
"type": "const unsigned char"
}
]
} }
] ]
}, },

View File

@ -28,11 +28,70 @@ boolean ScreenManager::addNewLinkAtTheEnd(ViewLinkedList *viewLinkedList, ViewLi
//Because of the const member //Because of the const member
memcpy(newViewLink, &viewLink, sizeof(*newViewLink)); memcpy(newViewLink, &viewLink, sizeof(*newViewLink));
/*TO DO*/ if(isListEmpty(*viewLinkedList))*viewLinkedList = newViewLink;
else
{
if((*viewLinkedList)->UID == newViewLink->UID)
{
ViewLink *link = *viewLinkedList;
*viewLinkedList = newViewLink;
newViewLink->next = link->next;
free(link);
return true;
}
ViewLinkedList cursor = *viewLinkedList;
while(cursor->next != NULL)
{
if(cursor->next->UID == newViewLink->UID)
{
ViewLink *link = cursor->next;
cursor->next = newViewLink;
newViewLink->next = link->next;
free(link);
return true;
}
cursor = cursor->next;
}
cursor->next = newViewLink;
}
return true; return true;
} }
boolean ScreenManager::removeView(const unsigned char UID)
{
return removeLinkByUID(&_viewLinkedList ,UID);
}
boolean ScreenManager::removeLinkByUID(ViewLinkedList *viewLinkedList, const unsigned char UID)
{
if(isListEmpty(*viewLinkedList))return false;
if((*viewLinkedList)->UID == UID)
{
ViewLink *tmp = *viewLinkedList;
*viewLinkedList = (*viewLinkedList)->next;
free(tmp);
return true;
}
ViewLinkedList cursor = *viewLinkedList;
while(!isListEmpty(cursor->next))
{
if(cursor->next->UID == UID)
{
ViewLink *tmp = cursor->next;
cursor->next = cursor->next->next;
free(tmp);
return true;
}
cursor = cursor->next;
}
return false;
}
boolean ScreenManager::isListEmpty(ViewLinkedList viewLinkedList) boolean ScreenManager::isListEmpty(ViewLinkedList viewLinkedList)
{ {
return viewLinkedList == NULL; return viewLinkedList == NULL;
@ -46,10 +105,11 @@ unsigned char ScreenManager::getError() const
void ScreenManager::iterateThroughList() void ScreenManager::iterateThroughList()
{ {
Serial.println("Lets go through"); Serial.println("Lets go through");
while(!isListEmpty(_viewLinkedList)) ViewLinkedList temp = _viewLinkedList;
while(!isListEmpty(temp))
{ {
Serial.print("UID : ");Serial.println(_viewLinkedList->UID); Serial.print("UID : ");Serial.println(temp->UID);
_viewLinkedList = _viewLinkedList->next; temp = temp->next;
} }
} }

View File

@ -8,6 +8,7 @@ class ScreenManager
friend class SAB; friend class SAB;
public: public:
boolean addView(boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*), void *pData, const unsigned char UID); boolean addView(boolean (*viewLogicFunction)(Adafruit_SSD1306&, void*), void *pData, const unsigned char UID);
boolean removeView(const unsigned char UID);
unsigned char getError() const; unsigned char getError() const;
@ -18,6 +19,7 @@ class ScreenManager
private: private:
void *createEmptyList(); void *createEmptyList();
boolean addNewLinkAtTheEnd(ViewLinkedList *viewLinkedList, ViewLink viewLink); boolean addNewLinkAtTheEnd(ViewLinkedList *viewLinkedList, ViewLink viewLink);
boolean removeLinkByUID(ViewLinkedList *viewLinkedList, const unsigned char UID);
boolean isListEmpty(ViewLinkedList viewLinkedList); boolean isListEmpty(ViewLinkedList viewLinkedList);
Adafruit_SSD1306 &_displayRef; Adafruit_SSD1306 &_displayRef;

View File

@ -2,7 +2,6 @@
#include "PinMapping.h" #include "PinMapping.h"
#include "SAB.h" #include "SAB.h"
#include "views.h" #include "views.h"
#define DEBUG #define DEBUG
SAB sab; SAB sab;
@ -19,6 +18,17 @@ void setup() {
} }
void loop() { void loop() {
// put your main code here, to run repeatedly: sab.getScreenManager().addView(&(view_1), NULL, 7);
Serial.println(ESP.getFreeHeap());
sab.getScreenManager().addView(&(view_1), NULL, 3);
Serial.println(ESP.getFreeHeap());
sab.getScreenManager().addView(&(view_1), NULL, 6);
Serial.println(ESP.getFreeHeap());
sab.getScreenManager().removeView(6);
Serial.println(ESP.getFreeHeap());
sab.getScreenManager().removeView(7);
Serial.println(ESP.getFreeHeap());
sab.getScreenManager().removeView(3);
Serial.println(ESP.getFreeHeap());
delay(3000);
} }

View File

@ -4,7 +4,7 @@
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
#include <Arduino.h> #include <Arduino.h>
enum Pin { GPIO_0 = 0, typedef enum { GPIO_0 = 0,
GPIO_1_TX = 1, GPIO_1_TX = 1,
GPIO_2 = 2, GPIO_2 = 2,
GPIO_3_RX = 3, GPIO_3_RX = 3,
@ -17,7 +17,7 @@ enum Pin { GPIO_0 = 0,
GPIO_15 = 15, GPIO_15 = 15,
GPIO_16 = 16, GPIO_16 = 16,
ADC = A0, ADC = A0,
DEFAULT_PIN = -1}; DEFAULT_PIN = -1} Pin;
#define RTC_BEGIN_ERR B00000001 #define RTC_BEGIN_ERR B00000001
#define DISP_BEGIN_ERR B00000010 #define DISP_BEGIN_ERR B00000010
@ -30,7 +30,7 @@ typedef struct viewLink{
void *pData; void *pData;
const unsigned char UID; const unsigned char UID;
viewLink *next; struct viewLink *next;
} ViewLink, *ViewLinkedList; } ViewLink, *ViewLinkedList;