1 #include 2 #include 3 #include 4 std::string state[] = {"\e[1;32mgreen\e[1;0m","\e[1;33myellow\e[1;0m","\e[1;31mred\e[1;0m"}; 5 uint32_t debug_timing = 500000; 6 int timing[] = {0,5,25}; 7 std::string location[] = {"north","south","east","west"}; 8 std::string tab = " "; 9 int pid[] = {0,0}; 10 int light_states[] = {2,2,2,2}; 11 int count = 0; 12 void clear_screen(){ 13 std::cout << "\033[H\033[2J\033[3J"; 14 } 15 void state_addrs(){ 16 count = 0; 17 while(count < 3){ 18 std::string* p = &state[count]; 19 std::cout << "state[" << count << "]:" << tab << tab << p << tab << state[count] << '\n'; 20 count++; 21 } 22 return; 23 } 24 void debug_timing_addrs(){ 25 count = 0; 26 while(count < 1){ 27 uint32_t* q = &debug_timing; 28 std::cout << "debug_timing:" << tab << tab << q << tab << debug_timing << '\n'; 29 count++; 30 } 31 return; 32 } 33 void timing_addrs(){ 34 count = 0; 35 while(count < 3){ 36 int* r = &timing[count]; 37 std::cout << "timing[" << count << "]:" << tab << tab << r << tab << timing[count] << '\n'; 38 count++; 39 } 40 return; 41 } 42 void location_addrs(){ 43 count = 0; 44 while(count < 4){ 45 std::string* s = &location[count]; 46 std::cout << "location[" << count << "]:" << tab << tab << s << tab << location[count] << '\n'; 47 count++; 48 } 49 return; 50 } 51 void tab_addrs(){ 52 count = 0; 53 while(count < 1){ 54 std::string* t = &tab; 55 std::cout << "tab:" << tab << tab << tab << t << tab << "[tab]" << '\n'; 56 count++; 57 } 58 return; 59 } 60 void pid_addrs(){ 61 count = 0; 62 while(count < 2){ 63 int* u = &pid[count]; 64 std::cout << "pid[" << count << "]:" << tab << tab << tab << u << tab << pid[count] << '\n'; 65 count++; 66 } 67 return; 68 } 69 void light_states_addrs(){ 70 count = 0; 71 while(count < 4){ 72 int* v = &light_states[count]; 73 std::cout << "light_states[" << count << "]:" << tab << v << tab << light_states[count] << '\n'; 74 count++; 75 } 76 return; 77 } 78 void dump_addrs(){ 79 state_addrs(); 80 debug_timing_addrs(); 81 timing_addrs(); 82 location_addrs(); 83 tab_addrs(); 84 pid_addrs(); 85 light_states_addrs(); 86 } 87 void display_light_states(){ 88 int count = 0; 89 while(count < 4){ 90 std::cout << location[count] << tab << state[light_states[count]] << "\n"; 91 count++; 92 93 } 94 return; 95 } 96 void _xor(int &a){ 97 a = a ^ a; 98 } 99 void _inc(int &a){ 100 a++; 101 } 102 void display_pids(){ 103 std::cout << "PID:" << tab << std::hex << pid[0] << "\n"; 104 std::cout << "Cycle:" << tab << std::hex << pid[1] << "\n"; 105 } 106 void green_func(int a, int b){ 107 _inc(pid[0]); 108 _xor(light_states[a]); 109 _xor(light_states[b]); 110 clear_screen(); 111 display_light_states(); 112 display_pids(); 113 dump_addrs(); 114 //sleep(timing[2]); 115 usleep(debug_timing); 116 } 117 void ry_func(int a, int b){ 118 _inc(pid[0]); 119 _inc(light_states[a]); 120 _inc(light_states[b]); 121 clear_screen(); 122 display_light_states(); 123 display_pids(); 124 dump_addrs(); 125 //sleep(timing[1]); 126 usleep(debug_timing); 127 } 128 void half_cycle(int a, int b){ 129 green_func(a,b); 130 ry_func(a,b); 131 ry_func(a,b); 132 } 133 int main(){ 134 _xor(pid[1]); 135 while(true){ 136 _xor(pid[0]); 137 half_cycle(0,1); 138 half_cycle(2,3); 139 _inc(pid[1]); 140 } 141 return 0; 142 }