Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses
Fork of REVO_Updated_Steering by
variables.h@35:b42afc973902, 2014-11-22 (annotated)
- Committer:
- palimar
- Date:
- Sat Nov 22 22:24:53 2014 +0000
- Revision:
- 35:b42afc973902
Added linked list, also graphics updates only when variables change.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| palimar | 35:b42afc973902 | 1 | #include "node.h" |
| palimar | 35:b42afc973902 | 2 | |
| palimar | 35:b42afc973902 | 3 | class variables{ |
| palimar | 35:b42afc973902 | 4 | |
| palimar | 35:b42afc973902 | 5 | public: |
| palimar | 35:b42afc973902 | 6 | |
| palimar | 35:b42afc973902 | 7 | variables(); |
| palimar | 35:b42afc973902 | 8 | ~variables(); |
| palimar | 35:b42afc973902 | 9 | void add(int i, int s); |
| palimar | 35:b42afc973902 | 10 | int get_screen(int i); |
| palimar | 35:b42afc973902 | 11 | char get_value(int i); |
| palimar | 35:b42afc973902 | 12 | int set_value(int i, char v); |
| palimar | 35:b42afc973902 | 13 | node * get_node(int i); |
| palimar | 35:b42afc973902 | 14 | |
| palimar | 35:b42afc973902 | 15 | |
| palimar | 35:b42afc973902 | 16 | int size; |
| palimar | 35:b42afc973902 | 17 | node * head; |
| palimar | 35:b42afc973902 | 18 | node * tail; |
| palimar | 35:b42afc973902 | 19 | |
| palimar | 35:b42afc973902 | 20 | }; |
| palimar | 35:b42afc973902 | 21 | |
| palimar | 35:b42afc973902 | 22 | variables::variables(){ |
| palimar | 35:b42afc973902 | 23 | size = 0; |
| palimar | 35:b42afc973902 | 24 | head = NULL; |
| palimar | 35:b42afc973902 | 25 | tail = NULL; |
| palimar | 35:b42afc973902 | 26 | } |
| palimar | 35:b42afc973902 | 27 | |
| palimar | 35:b42afc973902 | 28 | variables::~variables(){ |
| palimar | 35:b42afc973902 | 29 | |
| palimar | 35:b42afc973902 | 30 | node * curr = head; |
| palimar | 35:b42afc973902 | 31 | node * next = head; |
| palimar | 35:b42afc973902 | 32 | |
| palimar | 35:b42afc973902 | 33 | while(curr != NULL){ |
| palimar | 35:b42afc973902 | 34 | next = curr->next; |
| palimar | 35:b42afc973902 | 35 | delete(curr); |
| palimar | 35:b42afc973902 | 36 | curr = next; |
| palimar | 35:b42afc973902 | 37 | } |
| palimar | 35:b42afc973902 | 38 | |
| palimar | 35:b42afc973902 | 39 | head = NULL; |
| palimar | 35:b42afc973902 | 40 | tail = NULL; |
| palimar | 35:b42afc973902 | 41 | size = 0; |
| palimar | 35:b42afc973902 | 42 | } |
| palimar | 35:b42afc973902 | 43 | |
| palimar | 35:b42afc973902 | 44 | void variables::add(int i, int s){ |
| palimar | 35:b42afc973902 | 45 | |
| palimar | 35:b42afc973902 | 46 | if(head == NULL){ |
| palimar | 35:b42afc973902 | 47 | head = new node(i, s); |
| palimar | 35:b42afc973902 | 48 | tail = head; |
| palimar | 35:b42afc973902 | 49 | } |
| palimar | 35:b42afc973902 | 50 | |
| palimar | 35:b42afc973902 | 51 | else{ |
| palimar | 35:b42afc973902 | 52 | tail->next = new node(i,s); |
| palimar | 35:b42afc973902 | 53 | tail = tail->next; |
| palimar | 35:b42afc973902 | 54 | } |
| palimar | 35:b42afc973902 | 55 | size++; |
| palimar | 35:b42afc973902 | 56 | } |
| palimar | 35:b42afc973902 | 57 | |
| palimar | 35:b42afc973902 | 58 | node * variables::get_node(int i){ |
| palimar | 35:b42afc973902 | 59 | |
| palimar | 35:b42afc973902 | 60 | node * curr = head; |
| palimar | 35:b42afc973902 | 61 | |
| palimar | 35:b42afc973902 | 62 | while(curr != NULL){ |
| palimar | 35:b42afc973902 | 63 | if(curr->id == i){ |
| palimar | 35:b42afc973902 | 64 | return curr; |
| palimar | 35:b42afc973902 | 65 | } |
| palimar | 35:b42afc973902 | 66 | else{ |
| palimar | 35:b42afc973902 | 67 | curr = curr->next; |
| palimar | 35:b42afc973902 | 68 | } |
| palimar | 35:b42afc973902 | 69 | } |
| palimar | 35:b42afc973902 | 70 | return NULL; |
| palimar | 35:b42afc973902 | 71 | } |
| palimar | 35:b42afc973902 | 72 | |
| palimar | 35:b42afc973902 | 73 | int variables::get_screen(int i){ |
| palimar | 35:b42afc973902 | 74 | |
| palimar | 35:b42afc973902 | 75 | node * curr = head; |
| palimar | 35:b42afc973902 | 76 | |
| palimar | 35:b42afc973902 | 77 | while(curr != NULL){ |
| palimar | 35:b42afc973902 | 78 | if(curr->id == i){ |
| palimar | 35:b42afc973902 | 79 | return curr->screen; |
| palimar | 35:b42afc973902 | 80 | } |
| palimar | 35:b42afc973902 | 81 | else{ |
| palimar | 35:b42afc973902 | 82 | curr = curr->next; |
| palimar | 35:b42afc973902 | 83 | } |
| palimar | 35:b42afc973902 | 84 | } |
| palimar | 35:b42afc973902 | 85 | return -1; |
| palimar | 35:b42afc973902 | 86 | } |
| palimar | 35:b42afc973902 | 87 | |
| palimar | 35:b42afc973902 | 88 | int variables::set_value(int i, char v){ |
| palimar | 35:b42afc973902 | 89 | |
| palimar | 35:b42afc973902 | 90 | node * curr = head; |
| palimar | 35:b42afc973902 | 91 | |
| palimar | 35:b42afc973902 | 92 | while(curr != NULL){ |
| palimar | 35:b42afc973902 | 93 | if(curr->id == i){ |
| palimar | 35:b42afc973902 | 94 | curr->set_val(v); |
| palimar | 35:b42afc973902 | 95 | return 0; |
| palimar | 35:b42afc973902 | 96 | } |
| palimar | 35:b42afc973902 | 97 | else{ |
| palimar | 35:b42afc973902 | 98 | curr = curr->next; |
| palimar | 35:b42afc973902 | 99 | } |
| palimar | 35:b42afc973902 | 100 | } |
| palimar | 35:b42afc973902 | 101 | return -1; |
| palimar | 35:b42afc973902 | 102 | } |
| palimar | 35:b42afc973902 | 103 | |
| palimar | 35:b42afc973902 | 104 | char variables::get_value(int i){ |
| palimar | 35:b42afc973902 | 105 | |
| palimar | 35:b42afc973902 | 106 | node * curr = head; |
| palimar | 35:b42afc973902 | 107 | |
| palimar | 35:b42afc973902 | 108 | while(curr != NULL){ |
| palimar | 35:b42afc973902 | 109 | if(curr->id == i){ |
| palimar | 35:b42afc973902 | 110 | return curr->value; |
| palimar | 35:b42afc973902 | 111 | } |
| palimar | 35:b42afc973902 | 112 | else{ |
| palimar | 35:b42afc973902 | 113 | curr = curr->next; |
| palimar | 35:b42afc973902 | 114 | } |
| palimar | 35:b42afc973902 | 115 | } |
| palimar | 35:b42afc973902 | 116 | return 0; |
| palimar | 35:b42afc973902 | 117 | } |
