Generic Step Motor WebInterface - control a step motor using a Pololu A4983 driver from a webinterface (EXPERIMENTAL PROTOTYPE - just to be used as a proof-of-concept for a IoT talk, will not be updating this code so often)
Dependencies: EthernetNetIf RPCInterface mbed HTTPServer
CmdListObjects/TList.cpp@0:8b3857d4ce02, 2012-04-16 (annotated)
- Committer:
- botdream
- Date:
- Mon Apr 16 09:41:53 2012 +0000
- Revision:
- 0:8b3857d4ce02
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
botdream | 0:8b3857d4ce02 | 1 | //--------------------------------------------------------------------------------------------- |
botdream | 0:8b3857d4ce02 | 2 | #include "TList.h" |
botdream | 0:8b3857d4ce02 | 3 | //--------------------------------------------------------------------------------------------- |
botdream | 0:8b3857d4ce02 | 4 | //#define internaldebug // send debug messages to USB Serial port (9600,1,N) |
botdream | 0:8b3857d4ce02 | 5 | //--------------------------------------------------------------------------------------------- |
botdream | 0:8b3857d4ce02 | 6 | uint8_t ListCount; // Global TList counter |
botdream | 0:8b3857d4ce02 | 7 | //--------------------------------------------------------------------------------------------- |
botdream | 0:8b3857d4ce02 | 8 | TList *pListFirst; |
botdream | 0:8b3857d4ce02 | 9 | TList *pListLast; |
botdream | 0:8b3857d4ce02 | 10 | //--------------------------------------------------------------------------------------------- |
botdream | 0:8b3857d4ce02 | 11 | // Main TList demo code |
botdream | 0:8b3857d4ce02 | 12 | //--------------------------------------------------------------------------------------------- |
botdream | 0:8b3857d4ce02 | 13 | /* |
botdream | 0:8b3857d4ce02 | 14 | // temporary TList object |
botdream | 0:8b3857d4ce02 | 15 | TList *pListPointer; |
botdream | 0:8b3857d4ce02 | 16 | |
botdream | 0:8b3857d4ce02 | 17 | pListPointer = SetListNextObject(); |
botdream | 0:8b3857d4ce02 | 18 | TObjectStep *pobjectstep = new TObjectStep(1000, 100, 0); |
botdream | 0:8b3857d4ce02 | 19 | pListPointer->cmdtype = 0x01; |
botdream | 0:8b3857d4ce02 | 20 | pListPointer->cmdobject = (TObjectStep*)pobjectstep; |
botdream | 0:8b3857d4ce02 | 21 | |
botdream | 0:8b3857d4ce02 | 22 | pListPointer = SetListNextObject(); |
botdream | 0:8b3857d4ce02 | 23 | TObjectWait *pobjectwait = new TObjectWait(750); |
botdream | 0:8b3857d4ce02 | 24 | pListPointer->cmdtype = 0x04; |
botdream | 0:8b3857d4ce02 | 25 | pListPointer->cmdobject = (TObjectWait*)pobjectwait; |
botdream | 0:8b3857d4ce02 | 26 | |
botdream | 0:8b3857d4ce02 | 27 | pListPointer = SetListNextObject(); |
botdream | 0:8b3857d4ce02 | 28 | TObjectStep *pobjectstep1 = new TObjectStep(2500, 150, 1); |
botdream | 0:8b3857d4ce02 | 29 | pListPointer->cmdtype = 0x01; |
botdream | 0:8b3857d4ce02 | 30 | pListPointer->cmdobject = (TObjectStep*)pobjectstep1; |
botdream | 0:8b3857d4ce02 | 31 | |
botdream | 0:8b3857d4ce02 | 32 | pListPointer = SetListNextObject(); |
botdream | 0:8b3857d4ce02 | 33 | TObjectWait *pobjectwait2 = new TObjectWait(225); |
botdream | 0:8b3857d4ce02 | 34 | pListPointer->cmdtype = 0x04; |
botdream | 0:8b3857d4ce02 | 35 | pListPointer->cmdobject = (TObjectWait*)pobjectwait2; |
botdream | 0:8b3857d4ce02 | 36 | |
botdream | 0:8b3857d4ce02 | 37 | #ifdef internaldebug |
botdream | 0:8b3857d4ce02 | 38 | // set pListPointer to the first object of the list |
botdream | 0:8b3857d4ce02 | 39 | pListPointer = GetListFirstObject(); |
botdream | 0:8b3857d4ce02 | 40 | TObjectStep *ptemp = static_cast<TObjectStep*>(pListPointer->cmdobject); |
botdream | 0:8b3857d4ce02 | 41 | printf("ObjectsStep(%d) %ld|%ld|%d\r\n",ptemp->typecode,ptemp->nsteps, ptemp->deltatime, ptemp->direction); |
botdream | 0:8b3857d4ce02 | 42 | |
botdream | 0:8b3857d4ce02 | 43 | pListPointer = pListPointer->nextobject; |
botdream | 0:8b3857d4ce02 | 44 | TObjectWait *ptemp2 = static_cast<TObjectWait*>(pListPointer->cmdobject); |
botdream | 0:8b3857d4ce02 | 45 | printf("ObjectsWait(%d) %ld\r\n",ptemp2->typecode,ptemp2->waittime); |
botdream | 0:8b3857d4ce02 | 46 | |
botdream | 0:8b3857d4ce02 | 47 | pListPointer = pListPointer->nextobject; |
botdream | 0:8b3857d4ce02 | 48 | ptemp = static_cast<TObjectStep*>(pListPointer->cmdobject); |
botdream | 0:8b3857d4ce02 | 49 | printf("ObjectsStep(%d) %ld|%ld|%d\r\n",ptemp->typecode,ptemp->nsteps, ptemp->deltatime, ptemp->direction); |
botdream | 0:8b3857d4ce02 | 50 | |
botdream | 0:8b3857d4ce02 | 51 | pListPointer = pListPointer->nextobject; |
botdream | 0:8b3857d4ce02 | 52 | TObjectWait *ptemp3 = static_cast<TObjectWait*>(pListPointer->cmdobject); |
botdream | 0:8b3857d4ce02 | 53 | printf("ObjectsWait(%d) %ld\r\n",ptemp3->typecode,ptemp3->waittime); |
botdream | 0:8b3857d4ce02 | 54 | #endif |
botdream | 0:8b3857d4ce02 | 55 | |
botdream | 0:8b3857d4ce02 | 56 | printf("ListCount=%d\r\n",GetListCount()); |
botdream | 0:8b3857d4ce02 | 57 | |
botdream | 0:8b3857d4ce02 | 58 | // deleting list elements and internal objects |
botdream | 0:8b3857d4ce02 | 59 | while(DeleteListFirstObject() != 0); |
botdream | 0:8b3857d4ce02 | 60 | |
botdream | 0:8b3857d4ce02 | 61 | printf("ListCount=%d\r\n",GetListCount()); |
botdream | 0:8b3857d4ce02 | 62 | */ |
botdream | 0:8b3857d4ce02 | 63 | //--------------------------------------------------------------------------------------------- |
botdream | 0:8b3857d4ce02 | 64 | // Global helper function |
botdream | 0:8b3857d4ce02 | 65 | //--------------------------------------------------------------------------------------------- |
botdream | 0:8b3857d4ce02 | 66 | uint8_t GetListCount() |
botdream | 0:8b3857d4ce02 | 67 | { |
botdream | 0:8b3857d4ce02 | 68 | return ListCount; |
botdream | 0:8b3857d4ce02 | 69 | } |
botdream | 0:8b3857d4ce02 | 70 | //--------------------------------------------------------------------------------------------- |
botdream | 0:8b3857d4ce02 | 71 | TList *GetListFirstObject() |
botdream | 0:8b3857d4ce02 | 72 | { |
botdream | 0:8b3857d4ce02 | 73 | return pListFirst; |
botdream | 0:8b3857d4ce02 | 74 | } |
botdream | 0:8b3857d4ce02 | 75 | //--------------------------------------------------------------------------------------------- |
botdream | 0:8b3857d4ce02 | 76 | uint8_t DeleteListFirstObject() |
botdream | 0:8b3857d4ce02 | 77 | { |
botdream | 0:8b3857d4ce02 | 78 | // verify if First Object is NULL |
botdream | 0:8b3857d4ce02 | 79 | if(pListFirst == NULL) |
botdream | 0:8b3857d4ce02 | 80 | return 0; //nothing to delete |
botdream | 0:8b3857d4ce02 | 81 | |
botdream | 0:8b3857d4ce02 | 82 | TList *ptemp = pListFirst->nextobject; |
botdream | 0:8b3857d4ce02 | 83 | if(ptemp == NULL) // first object doesn't link with other objects (unique) |
botdream | 0:8b3857d4ce02 | 84 | { |
botdream | 0:8b3857d4ce02 | 85 | #ifdef internaldebug |
botdream | 0:8b3857d4ce02 | 86 | printf("Deleting Unique Object\r\n"); |
botdream | 0:8b3857d4ce02 | 87 | #endif |
botdream | 0:8b3857d4ce02 | 88 | |
botdream | 0:8b3857d4ce02 | 89 | // removes inner object first |
botdream | 0:8b3857d4ce02 | 90 | delete pListFirst->cmdobject; |
botdream | 0:8b3857d4ce02 | 91 | pListFirst->cmdobject = NULL; |
botdream | 0:8b3857d4ce02 | 92 | |
botdream | 0:8b3857d4ce02 | 93 | #ifdef internaldebug |
botdream | 0:8b3857d4ce02 | 94 | printf("->removing inner object\r\n"); |
botdream | 0:8b3857d4ce02 | 95 | #endif |
botdream | 0:8b3857d4ce02 | 96 | |
botdream | 0:8b3857d4ce02 | 97 | // removes the outter list object |
botdream | 0:8b3857d4ce02 | 98 | delete pListFirst; |
botdream | 0:8b3857d4ce02 | 99 | pListFirst = NULL; |
botdream | 0:8b3857d4ce02 | 100 | pListLast = NULL; |
botdream | 0:8b3857d4ce02 | 101 | |
botdream | 0:8b3857d4ce02 | 102 | #ifdef internaldebug |
botdream | 0:8b3857d4ce02 | 103 | printf("->removing outter object\r\n"); |
botdream | 0:8b3857d4ce02 | 104 | #endif |
botdream | 0:8b3857d4ce02 | 105 | |
botdream | 0:8b3857d4ce02 | 106 | // no more objects - resets the list counter |
botdream | 0:8b3857d4ce02 | 107 | ListCount = 0; |
botdream | 0:8b3857d4ce02 | 108 | |
botdream | 0:8b3857d4ce02 | 109 | #ifdef internaldebug |
botdream | 0:8b3857d4ce02 | 110 | printf("->reseting Listcount\r\n"); |
botdream | 0:8b3857d4ce02 | 111 | #endif |
botdream | 0:8b3857d4ce02 | 112 | |
botdream | 0:8b3857d4ce02 | 113 | } |
botdream | 0:8b3857d4ce02 | 114 | else |
botdream | 0:8b3857d4ce02 | 115 | { |
botdream | 0:8b3857d4ce02 | 116 | #ifdef internaldebug |
botdream | 0:8b3857d4ce02 | 117 | printf("Deleting first object of List[%d]\r\n",ListCount); |
botdream | 0:8b3857d4ce02 | 118 | #endif |
botdream | 0:8b3857d4ce02 | 119 | |
botdream | 0:8b3857d4ce02 | 120 | // removes inner object first |
botdream | 0:8b3857d4ce02 | 121 | delete pListFirst->cmdobject; |
botdream | 0:8b3857d4ce02 | 122 | pListFirst->cmdobject = NULL; |
botdream | 0:8b3857d4ce02 | 123 | |
botdream | 0:8b3857d4ce02 | 124 | #ifdef internaldebug |
botdream | 0:8b3857d4ce02 | 125 | printf("->removing inner object\r\n"); |
botdream | 0:8b3857d4ce02 | 126 | #endif |
botdream | 0:8b3857d4ce02 | 127 | |
botdream | 0:8b3857d4ce02 | 128 | // removes the outter list object |
botdream | 0:8b3857d4ce02 | 129 | delete pListFirst; |
botdream | 0:8b3857d4ce02 | 130 | pListFirst = NULL; |
botdream | 0:8b3857d4ce02 | 131 | |
botdream | 0:8b3857d4ce02 | 132 | #ifdef internaldebug |
botdream | 0:8b3857d4ce02 | 133 | printf("->removing outter object\r\n"); |
botdream | 0:8b3857d4ce02 | 134 | #endif |
botdream | 0:8b3857d4ce02 | 135 | |
botdream | 0:8b3857d4ce02 | 136 | // sets the new header object |
botdream | 0:8b3857d4ce02 | 137 | pListFirst = ptemp; |
botdream | 0:8b3857d4ce02 | 138 | |
botdream | 0:8b3857d4ce02 | 139 | #ifdef internaldebug |
botdream | 0:8b3857d4ce02 | 140 | printf("->Setting new header object\r\n"); |
botdream | 0:8b3857d4ce02 | 141 | #endif |
botdream | 0:8b3857d4ce02 | 142 | |
botdream | 0:8b3857d4ce02 | 143 | // decreases list counter |
botdream | 0:8b3857d4ce02 | 144 | ListCount -= 1; |
botdream | 0:8b3857d4ce02 | 145 | |
botdream | 0:8b3857d4ce02 | 146 | #ifdef internaldebug |
botdream | 0:8b3857d4ce02 | 147 | printf("->Setting ListCount new value = %d\r\n",ListCount); |
botdream | 0:8b3857d4ce02 | 148 | #endif |
botdream | 0:8b3857d4ce02 | 149 | |
botdream | 0:8b3857d4ce02 | 150 | } |
botdream | 0:8b3857d4ce02 | 151 | return 1; |
botdream | 0:8b3857d4ce02 | 152 | } |
botdream | 0:8b3857d4ce02 | 153 | //--------------------------------------------------------------------------------------------- |
botdream | 0:8b3857d4ce02 | 154 | TList *SetListNextObject() |
botdream | 0:8b3857d4ce02 | 155 | { |
botdream | 0:8b3857d4ce02 | 156 | if(ListCount == 0) |
botdream | 0:8b3857d4ce02 | 157 | { |
botdream | 0:8b3857d4ce02 | 158 | // List is empty - initialize list |
botdream | 0:8b3857d4ce02 | 159 | pListFirst = new TList; |
botdream | 0:8b3857d4ce02 | 160 | pListLast = pListFirst; |
botdream | 0:8b3857d4ce02 | 161 | pListFirst->nextobject = NULL; |
botdream | 0:8b3857d4ce02 | 162 | |
botdream | 0:8b3857d4ce02 | 163 | ListCount++; |
botdream | 0:8b3857d4ce02 | 164 | } |
botdream | 0:8b3857d4ce02 | 165 | else |
botdream | 0:8b3857d4ce02 | 166 | { |
botdream | 0:8b3857d4ce02 | 167 | // list not empty, adds new object to the list and point the 'nextobject' |
botdream | 0:8b3857d4ce02 | 168 | // from previous object to the recently created object |
botdream | 0:8b3857d4ce02 | 169 | TList *ptemp = new TList; |
botdream | 0:8b3857d4ce02 | 170 | ptemp->nextobject = NULL; |
botdream | 0:8b3857d4ce02 | 171 | |
botdream | 0:8b3857d4ce02 | 172 | pListLast->nextobject = ptemp; |
botdream | 0:8b3857d4ce02 | 173 | |
botdream | 0:8b3857d4ce02 | 174 | pListLast = ptemp; |
botdream | 0:8b3857d4ce02 | 175 | |
botdream | 0:8b3857d4ce02 | 176 | ListCount++; |
botdream | 0:8b3857d4ce02 | 177 | } |
botdream | 0:8b3857d4ce02 | 178 | |
botdream | 0:8b3857d4ce02 | 179 | return pListLast; |
botdream | 0:8b3857d4ce02 | 180 | } |
botdream | 0:8b3857d4ce02 | 181 | //--------------------------------------------------------------------------------------------- |