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,
"text": "-isListEmpty(ViewLinkedList viewLinkedList): boolean",
"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",
"left": 216,
"top": 822,
"width": 533.16748046875,
"height": 158
"height": 173
},
{
"_type": "UMLReceptionCompartmentView",
@ -754,7 +771,7 @@
"left": 216,
"top": 744,
"width": 533.16748046875,
"height": 236,
"height": 251,
"nameCompartment": {
"$ref": "AAAAAAFpHq11gr6ruDw="
},
@ -793,7 +810,7 @@
"visible": false,
"font": "Arial;13;0",
"left": 813,
"top": 876,
"top": 881,
"height": 13,
"alpha": 1.5707963267948966,
"distance": 15,
@ -814,7 +831,7 @@
"visible": null,
"font": "Arial;13;0",
"left": 813,
"top": 891,
"top": 896,
"height": 13,
"alpha": 1.5707963267948966,
"distance": 30,
@ -835,7 +852,7 @@
"visible": false,
"font": "Arial;13;0",
"left": 814,
"top": 847,
"top": 851,
"height": 13,
"alpha": -1.5707963267948966,
"distance": 15,
@ -856,7 +873,7 @@
"visible": false,
"font": "Arial;13;0",
"left": 852,
"top": 878,
"top": 881,
"height": 13,
"alpha": 0.5235987755982988,
"distance": 30,
@ -877,7 +894,7 @@
"visible": false,
"font": "Arial;13;0",
"left": 850,
"top": 891,
"top": 895,
"height": 13,
"alpha": 0.7853981633974483,
"distance": 40,
@ -898,7 +915,7 @@
"visible": false,
"font": "Arial;13;0",
"left": 857,
"top": 851,
"top": 854,
"height": 13,
"alpha": -0.5235987755982988,
"distance": 25,
@ -918,7 +935,7 @@
},
"font": "Arial;13;0",
"left": 758,
"top": 880,
"top": 884,
"width": 94.65625,
"height": 13,
"alpha": -0.3058788210270264,
@ -939,8 +956,8 @@
},
"visible": false,
"font": "Arial;13;0",
"left": 776,
"top": 889,
"left": 777,
"top": 894,
"height": 13,
"alpha": -0.7853981633974483,
"distance": 40,
@ -960,7 +977,7 @@
"visible": false,
"font": "Arial;13;0",
"left": 770,
"top": 849,
"top": 853,
"height": 13,
"alpha": 0.5235987755982988,
"distance": 25,
@ -1005,7 +1022,7 @@
"$ref": "AAAAAAFpHqCuVb5uVUA="
},
"lineStyle": 1,
"points": "879:870;749:867",
"points": "879:873;749:872",
"showVisibility": true,
"nameLabel": {
"$ref": "AAAAAAFpHucSvL8/DjI="
@ -3667,8 +3684,8 @@
},
"visible": false,
"font": "Arial;13;0",
"left": 481,
"top": 1008,
"left": 480,
"top": 1016,
"height": 13,
"alpha": 1.5707963267948966,
"distance": 15,
@ -3688,8 +3705,8 @@
},
"visible": null,
"font": "Arial;13;0",
"left": 496,
"top": 1009,
"left": 495,
"top": 1017,
"height": 13,
"alpha": 1.5707963267948966,
"distance": 30,
@ -3709,8 +3726,8 @@
},
"visible": false,
"font": "Arial;13;0",
"left": 452,
"top": 1005,
"left": 451,
"top": 1013,
"height": 13,
"alpha": -1.5707963267948966,
"distance": 15,
@ -3730,8 +3747,8 @@
},
"visible": false,
"font": "Arial;13;0",
"left": 482,
"top": 1001,
"left": 481,
"top": 1016,
"height": 13,
"alpha": 0.5235987755982988,
"distance": 30,
@ -3751,8 +3768,8 @@
},
"visible": false,
"font": "Arial;13;0",
"left": 495,
"top": 1004,
"left": 494,
"top": 1019,
"height": 13,
"alpha": 0.7853981633974483,
"distance": 40,
@ -3772,8 +3789,8 @@
},
"visible": false,
"font": "Arial;13;0",
"left": 455,
"top": 994,
"left": 454,
"top": 1009,
"height": 13,
"alpha": -0.5235987755982988,
"distance": 25,
@ -3879,7 +3896,7 @@
"$ref": "AAAAAAFpHq11gr6quCs="
},
"lineStyle": 1,
"points": "470:980;464:1047",
"points": "469:995;464:1047",
"showVisibility": true,
"nameLabel": {
"$ref": "AAAAAAFpIVDGIBS5fjw="
@ -4563,7 +4580,8 @@
"_parent": {
"$ref": "AAAAAAFpIV35vBs6xGk="
},
"name": "ViewLinkedList *viewLinkedList"
"name": "ViewLinkedList *viewLinkedList",
"type": ""
},
{
"_type": "UMLParameter",
@ -4571,7 +4589,8 @@
"_parent": {
"$ref": "AAAAAAFpIV35vBs6xGk="
},
"name": "ViewLink viewLink"
"name": "ViewLink viewLink",
"type": ""
},
{
"_type": "UMLParameter",
@ -4612,6 +4631,43 @@
"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
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;
}
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)
{
return viewLinkedList == NULL;
@ -46,10 +105,11 @@ unsigned char ScreenManager::getError() const
void ScreenManager::iterateThroughList()
{
Serial.println("Lets go through");
while(!isListEmpty(_viewLinkedList))
ViewLinkedList temp = _viewLinkedList;
while(!isListEmpty(temp))
{
Serial.print("UID : ");Serial.println(_viewLinkedList->UID);
_viewLinkedList = _viewLinkedList->next;
Serial.print("UID : ");Serial.println(temp->UID);
temp = temp->next;
}
}

View File

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

View File

@ -2,7 +2,6 @@
#include "PinMapping.h"
#include "SAB.h"
#include "views.h"
#define DEBUG
SAB sab;
@ -19,6 +18,17 @@ void setup() {
}
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 <Arduino.h>
enum Pin { GPIO_0 = 0,
typedef enum { GPIO_0 = 0,
GPIO_1_TX = 1,
GPIO_2 = 2,
GPIO_3_RX = 3,
@ -17,7 +17,7 @@ enum Pin { GPIO_0 = 0,
GPIO_15 = 15,
GPIO_16 = 16,
ADC = A0,
DEFAULT_PIN = -1};
DEFAULT_PIN = -1} Pin;
#define RTC_BEGIN_ERR B00000001
#define DISP_BEGIN_ERR B00000010
@ -30,7 +30,7 @@ typedef struct viewLink{
void *pData;
const unsigned char UID;
viewLink *next;
struct viewLink *next;
} ViewLink, *ViewLinkedList;