Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.36 KB | None | 0 0
  1. Connection * shell; ///Declared for ADK.h this class and ADK both use shell and connection
  2. Connection * connection;
  3.  
  4.  
  5.  
  6. char HEADS_RED_ON = 'A';
  7. char HEADS_RED_OFF = 'a';
  8. char HEADS_WHITE_ON = 'B';
  9. char HEADS_WHITE_OFF = 'b';
  10. char HEADS_BOTH_ON = 'C';
  11. char HEADS_BOTH_OFF = 'c';
  12.  
  13. char FOGS_RED_ON = 'D';
  14. char FOGS_RED_OFF = 'd';
  15. char FOGS_WHITE_ON = 'E';
  16. char FOGS_WHITE_OFF = 'e';
  17. char FOGS_BOTH_ON = 'F';
  18. char FOGS_BOTH_OFF = 'f';
  19.  
  20. char FOGS_ON = 'G';
  21. char FOGS_OFF = 'g';
  22. char INTERIOR_ON = 'H';
  23. char INTERIOR_OFF = 'h';
  24.  
  25. char BRIGHTNESS_UP = '+';
  26. char BRIGHTNESS_DOWN = '-';
  27.  
  28. char B_HALOS = 'A';
  29. char B_INTERIOR = 'B';
  30. char B_FOGS = 'C';
  31.  
  32. int BRIGHTNESS_HALOS = 220;
  33. int BRIGHTNESS_INTERIOR = 220;
  34. int BRIGHTNESS_FOGS = 220;
  35.  
  36. //PRESETS
  37. const char Emergency1= 'Z';
  38. const char Emergency2= 'Y';
  39. const char Emergency3= 'X';
  40. const char Emergency4= 'W';
  41. const char HeartBeatRed= 'V';
  42. const char HeartBeatWhite= 'U';
  43. const char HaloFollowRPMMix= 'T';
  44. const char HaloFollowRPMWHITE= 'S';
  45. const char HaloFollowRPMRED= 'R';
  46. const char HaloFollowRPMWHITESMOOTH= 'Q';
  47. const char HaloFollowRPMREDSMOOTH= 'P';
  48. const char Emergency3OnlyWhite= 'O';
  49. const char Emergency4OnlyRed= 'N';
  50.  
  51.  
  52.  
  53.  
  54. boolean HeadHalosRedOn = false;
  55. boolean FogHalosRedOn = false;
  56. boolean HeadHalosWhiteOn = false;
  57. boolean FogHalosWhiteOn = false;
  58.  
  59. boolean InteriorOn = false;
  60. boolean FogsOn = false;
  61.  
  62. int headlightHaloWHITEPIN = 12;
  63. int headlightHaloREDPIN = 11;
  64. int foglightHaloWHITEPIN = 10;
  65. int foglightHaloREDPIN = 9;
  66.  
  67. int headlightHaloPIN = headlightHaloWHITEPIN; // DEFAULT pin for white halo
  68. int foglightHaloPIN = foglightHaloWHITEPIN; // DEFAULT pin for white halo
  69.  
  70. int foglightPIN = 8;
  71. int interiorLight = 7;
  72. //This is a character buffer that will store the data from the serial port
  73.  
  74.  
  75. //Keep track of old values with a copy of above values
  76. int BRIGHTNESS_HALOS2 = 170;
  77. int BRIGHTNESS_INTERIOR2 = 220;
  78. int BRIGHTNESS_FOGS2 = 170;
  79.  
  80. bool HeadHalosRedOn2 = false;
  81. bool FogHalosRedOn2 = false;
  82. bool HeadHalosWhiteOn2 = false;
  83. bool FogHalosWhiteOn2 = false;
  84.  
  85. bool InteriorOn2 = false;
  86. bool FogsOn2 = false;
  87.  
  88. void turnON(int led, int itsBright){
  89. int Bright = 0;
  90. while(Bright < itsBright){
  91. Bright++;
  92. analogWrite(led, Bright);
  93. delay(1);
  94. }
  95. }
  96. void turnOFF(int led, int itsBright){
  97. int Bright = itsBright;
  98. while(Bright > 0){
  99. Bright--;
  100. analogWrite(led, Bright);
  101. delay(1);
  102. }
  103. }
  104.  
  105. void allLEDOFFFADE(){
  106. if(HeadHalosWhiteOn) turnOFF(headlightHaloWHITEPIN, BRIGHTNESS_HALOS);
  107. if(HeadHalosRedOn) turnOFF(headlightHaloREDPIN, BRIGHTNESS_HALOS);
  108. if(FogHalosWhiteOn) turnOFF(foglightHaloWHITEPIN, BRIGHTNESS_HALOS);
  109. if(FogHalosRedOn) turnOFF(foglightHaloREDPIN, BRIGHTNESS_HALOS);
  110. analogWrite(interiorLight, LOW);
  111. analogWrite(foglightPIN, LOW);
  112. }
  113. void allLEDOFF(){
  114. analogWrite(headlightHaloWHITEPIN, LOW);
  115. analogWrite(headlightHaloREDPIN, LOW);
  116. analogWrite(foglightHaloWHITEPIN, LOW);
  117. analogWrite(foglightHaloREDPIN, LOW);
  118. analogWrite(interiorLight, LOW);
  119. analogWrite(foglightPIN, LOW);
  120. }
  121. void allBool(boolean f){
  122. HeadHalosRedOn = f;
  123. FogHalosRedOn = f;
  124. HeadHalosWhiteOn = f;
  125. FogHalosWhiteOn = f;
  126. InteriorOn = f;
  127. FogsOn = f;
  128. }
  129.  
  130.  
  131. void notifyAllConnections(char string[]){
  132. Serial.println(string);
  133. Serial2.println(string);
  134. connection->writeString(string);
  135. }
  136.  
  137.  
  138.  
  139. void notifyHeadHaloState(){
  140. if(HeadHalosRedOn && HeadHalosWhiteOn){
  141. notifyAllConnections("DT:S:HB:1");
  142. delay(10);
  143. }
  144. else if(!HeadHalosRedOn && !HeadHalosWhiteOn){
  145. notifyAllConnections("DT:S:HB:0");
  146. delay(10);
  147. }
  148. else{
  149. if(HeadHalosRedOn){
  150. notifyAllConnections("DT:S:HR:1");
  151. delay(10);
  152. }
  153. else if(HeadHalosWhiteOn){
  154. notifyAllConnections("DT:S:HW:1");
  155. delay(10);
  156. }
  157. }
  158. }
  159. void notifyFogHaloState(){
  160. if(FogHalosRedOn && FogHalosWhiteOn){
  161. notifyAllConnections("DT:S:FB:1");
  162. delay(10);
  163. }
  164. else if(!FogHalosRedOn && !FogHalosWhiteOn){
  165. notifyAllConnections("DT:S:FB:0");
  166. delay(10);
  167. }
  168. else{
  169. if(FogHalosRedOn){
  170. notifyAllConnections("DT:S:FR:1");
  171. delay(10);
  172. }
  173. else if(FogHalosWhiteOn){
  174. notifyAllConnections("DT:S:FW:1");
  175. delay(10);
  176. }
  177. }
  178. }
  179. void notifyInteriorState(){
  180. if(InteriorOn){
  181. notifyAllConnections("DT:S:IN:1");
  182. delay(10);
  183. }
  184. else{
  185. notifyAllConnections("DT:S:IN:0");
  186. delay(10);
  187. }
  188. }
  189. void notifyFogState(){
  190. if(FogsOn){
  191. notifyAllConnections("DT:S:FS:1");
  192. delay(10);
  193. }
  194. else{
  195. notifyAllConnections("DT:S:FS:0");
  196. delay(10);
  197. }
  198. }
  199. char* getString(String s1, int s2){
  200. String newString = s1;
  201. newString+=s2;
  202. char charBuff[newString.length()];
  203. newString.toCharArray(charBuff, newString.length());
  204. return charBuff;
  205. }
  206. void notifyHaloBrightness(){
  207. String s = "DT:B:HB:";
  208. int s2 = BRIGHTNESS_HALOS;
  209. notifyAllConnections(getString(s, s2));
  210.  
  211.  
  212. delay(10);
  213. }
  214. void notifyInteriorBrightness(){
  215. String s = "DT:B:IB:";
  216. int s2 = BRIGHTNESS_INTERIOR;
  217. notifyAllConnections(getString(s, s2));
  218. delay(10);
  219. }
  220. void notifyFogBrightness(){
  221. String s = "DT:B:FB:";
  222. int s2 = BRIGHTNESS_FOGS;
  223. notifyAllConnections(getString(s, s2));
  224. delay(10);
  225. }
  226. void notifyBrightness(){
  227. if(BRIGHTNESS_HALOS2 != BRIGHTNESS_HALOS){
  228. BRIGHTNESS_HALOS2 = BRIGHTNESS_HALOS;
  229. notifyHaloBrightness();
  230. }
  231. if(BRIGHTNESS_INTERIOR2 != BRIGHTNESS_INTERIOR){
  232. notifyInteriorBrightness();
  233. BRIGHTNESS_INTERIOR2 = BRIGHTNESS_INTERIOR;
  234. }
  235. if(BRIGHTNESS_FOGS2 != BRIGHTNESS_FOGS){
  236. BRIGHTNESS_FOGS2 = BRIGHTNESS_FOGS;
  237. notifyFogBrightness();
  238. }
  239. }
  240.  
  241.  
  242.  
  243.  
  244.  
  245. void checkForChange(){
  246. if(BRIGHTNESS_HALOS2 != BRIGHTNESS_HALOS){
  247. delay(100);
  248. notifyHaloBrightness();
  249. }
  250. if(BRIGHTNESS_INTERIOR2 != BRIGHTNESS_INTERIOR){
  251. delay(100);
  252. notifyInteriorBrightness();
  253. }
  254. if(BRIGHTNESS_FOGS2 != BRIGHTNESS_FOGS){
  255. delay(100);
  256. notifyFogBrightness();
  257. }
  258. if(HeadHalosRedOn2 != HeadHalosRedOn || HeadHalosWhiteOn2 != HeadHalosWhiteOn){
  259. delay(100);
  260. notifyHeadHaloState();
  261. }
  262. if(FogHalosRedOn2 != FogHalosRedOn || FogHalosWhiteOn2 != FogHalosWhiteOn){
  263. delay(100);
  264. notifyFogHaloState();
  265. }
  266. if(InteriorOn2 != InteriorOn){
  267. delay(100);
  268. notifyInteriorState();
  269. }
  270. if(FogsOn2 != FogsOn){
  271. delay(100);
  272. notifyFogState();
  273. }
  274. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement