Guest User

Untitled

a guest
Sep 2nd, 2016
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.28 KB | None | 0 0
  1. #include <SPI.h>
  2.  
  3. #include <malloc.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6.  
  7. #define CTE_DUE_SHIELD
  8. extern char _end;
  9. extern "C" char *sbrk(int i);
  10. char *ramstart = (char *)0x20070000;
  11. char *ramend = (char *)0x20088000;
  12.  
  13. #include <Wire.h>
  14. #include <EasyTransferI2C_NL.h>
  15. #include <Time.h>
  16. #include <TimeLib.h>
  17. #include "Timezone.h"
  18. TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240}; //Eastern Daylight Time = UTC - 4 hours
  19. TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300}; //Eastern Standard Time = UTC - 5 hours
  20. Timezone usET(usEDT, usEST);
  21. EasyTransferI2C_NL toESP;
  22. EasyTransferI2C_NL toDUE;
  23. #include <UTFT.h>
  24. //#include <UTFT_CTE.h>
  25. #include <UTFT_GHL.h>
  26. #include <UTouch.h>
  27. #include <UTFT_Geometry.h>
  28. #include <FastLED.h>
  29.  
  30. #define NUM_LEDS 20
  31. #define DATA_PIN A7
  32. CRGB leds[NUM_LEDS]
  33.  
  34. #include <Encoder.h>
  35. #include <Button.h>
  36. #define encoderA 12
  37. #define encoderB 11
  38. #define encoderSw 19
  39. #define encoderRed 8
  40. #define encoderBlue 9
  41. #define encoderGreen 10
  42.  
  43. Button select(encoderSw, false, true, 20);
  44. Encoder navigation(encoderA, encoderB);
  45. #define ENCODER_USE_INTERRUPTS
  46. extern uint8_t Ubuntu[];
  47. extern uint8_t timeFont[];
  48. extern uint8_t arial_normal[];
  49.  
  50. UTFT myGLCD(CTE70CPLD, 25, 26, 27, 28);
  51. UTouch myTouch(6, 5, 32, 3, 2);
  52. UTFT_GHL CTE_LCD(&myGLCD);
  53. UTFT_Geometry geo(&myGLCD);
  54.  
  55. byte LCDpage;
  56. byte LCDpageActive;
  57. bool redraw;
  58. bool drawFlag;
  59.  
  60. bool confirmed;
  61.  
  62. byte timerArray[9][7];
  63.  
  64. #define onMinutes 0
  65. #define onHours 1
  66. #define offMinutes 2
  67. #define offHours 3
  68. #define amPMon 4
  69. #define amPMoff 5
  70. #define hasBeenSet 6
  71.  
  72. //Program Settings Screen
  73. bool SetColorFlag = 1;
  74. bool SetSpeedFlag = 1;
  75. bool SetDimFlag = 1;
  76.  
  77. bool ColorInit = 1;
  78. bool SpeedInit = 1;
  79. bool DimInit = 1;
  80. int RGBred;
  81. int RGBblue;
  82. int RGBgreen;
  83. int ProgramSpeed;
  84. int ProgramDim;
  85.  
  86. bool timerOnceOn = 1;
  87. bool timerOnceOff = 1;
  88.  
  89. #define FLASH_CS_PIN 9
  90. int touchArray[2];
  91. #define xVal 0
  92. #define yVal 1
  93. byte touchDebounceTime = 250;
  94. unsigned int touchDebounce = 0;
  95. /*
  96. Reset 38
  97. WR 39
  98. RS 40
  99. CS 42
  100. SD_CS 41
  101. F_CS 43
  102. t_CS 45
  103. t_IRQ 46
  104. */
  105. unsigned int dayLightsSavings = 3600;
  106. byte currentTemp;
  107. char P0weather[25];
  108. unsigned int P0weatherIcon = 338;
  109. byte currentFeel;
  110. char windDirection[10];
  111. byte windSpeed;
  112. byte windGust;
  113. byte todayHigh;
  114. byte todayLow;
  115. char P1weather[25];
  116. unsigned int P1weatherIcon = 338;
  117. byte tomorrowLow;
  118. byte tomorrowHigh;
  119. char P2weather[25];
  120. unsigned int P2weatherIcon = 338;
  121. byte ledArray[9];
  122. #define zoneSelect 0
  123. #define program 1
  124. #define colorR 2
  125. #define colorG 3
  126. #define colorB 4
  127. #define value 5
  128. #define pSpeed 6
  129. #define isON 7
  130. #define setupFunction 8
  131. //screens
  132. #define zoneScreen 0
  133. #define catagoryScreen 1
  134. #define programScreen 2
  135.  
  136. byte catagory = 0;
  137. byte HolidaySelection;
  138.  
  139. struct Weather_Icons {
  140. const unsigned int chanceFlurries = 296;
  141. const unsigned int chanceRain = 294;
  142. const unsigned int chanceSleet = 273;
  143. const unsigned int chanceSnow = 296;
  144. const unsigned int chanceTstorms = 293;
  145. const unsigned int clearW = 287;
  146. const unsigned int cloudy = 281;
  147. const unsigned int flurries = 268;
  148. const unsigned int fog = 275;
  149. const unsigned int hazy = 274;
  150. const unsigned int mostlyCloudy = 283;
  151. const unsigned int mostlySunny = 289;
  152. const unsigned int nightChFlurries = 301;
  153. const unsigned int nightChRain = 300;
  154. const unsigned int nightChSleet = 273;
  155. const unsigned int nightChSnow = 301;
  156. const unsigned int nightChTstorms = 302;
  157. const unsigned int nightClear = 286;
  158. const unsigned int nightCloudy = 281;
  159. const unsigned int nightFlurry = 268;
  160. const unsigned int nightFog = 275;
  161. const unsigned int nightHazy = 276;
  162. const unsigned int nightMostlyCloudy = 282;
  163. const unsigned int nightPartlyCloudy = 284;
  164. const unsigned int nightRain = 295;
  165. const unsigned int nightSleet = 273;
  166. const unsigned int nightSnow = 271;
  167. const unsigned int nightTstorms = 272;
  168. const unsigned int unknown = 303;
  169. const unsigned int partlyCloudy = 285;
  170. const unsigned int partlySunny = 285;
  171. const unsigned int rain = 295;
  172. const unsigned int sleet = 273;
  173. const unsigned int snow = 271;
  174. const unsigned int tStorms = 290;
  175. } weatherIcons;
  176.  
  177. struct RECEIVE_DATA_STRUCTURE {
  178. unsigned long unixTime;
  179. bool ESPreply;
  180. byte weatherArray[12];
  181. bool ledsOn[8];
  182. //byte switchDataReturn[3];
  183. //byte recieverDataReturn[3];
  184. };
  185.  
  186. //give a name to the group of data
  187. RECEIVE_DATA_STRUCTURE toDUEData;
  188.  
  189.  
  190. struct SEND_DATA_STRUCTURE {
  191. byte espProgramArray[9];
  192. bool ledsOn[8];
  193. } __attribute__((packed));
  194.  
  195. SEND_DATA_STRUCTURE toESPdata;
  196. //define slave i2c address
  197. #define I2C_SLAVE_ADDRESS 42
  198.  
  199. void setup() {
  200. for(int i = 0; i < 9; i++){
  201. for(int j = 0; j < 7; j++){
  202. timerArray[i][j] = 0;
  203. }
  204. }
  205. LCDpageActive = 1;
  206. redraw = 1;
  207. toESPdata.espProgramArray[zoneSelect] = 9;
  208. myGLCD.InitLCD();
  209. myGLCD.clrScr();
  210. myGLCD.setColor(0, 255, 0);
  211. myGLCD.setBackColor(0, 0, 0);
  212. myGLCD.setFont(timeFont);
  213. myGLCD.print("Loading", 0, 0);
  214. CTE_LCD.SPI_Flash_init(52);
  215. myTouch.InitTouch();
  216. myTouch.setPrecision(PREC_HI);
  217. Serial.begin(115200);
  218. delay(500);
  219. Serial.println("Touscreen RX 0.9");
  220.  
  221. Wire.begin(I2C_SLAVE_ADDRESS);
  222. // Wire.setClockStretchLimit(1500);
  223. Wire.setClock(5000L);
  224. Wire.onRequest(request);
  225. toDUE.begin(details(toDUEData), &Wire);
  226. toESP.begin(details(toESPdata), &Wire);
  227. //define handler function on receiving data
  228. Wire.onReceive(receive);
  229.  
  230. pinMode(EncoderSw, INPUT);
  231. FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  232.  
  233. for(int i = 0; i < NUM_LEDS; i++){
  234. leds[i].setHSV{0, 0, 128);
  235. }
  236. FastLED.show();
  237. }
  238.  
  239. void watchdogSetup()
  240. {
  241. watchdogEnable(2000);
  242. }
  243.  
  244. void loop() {
  245. watchdogReset();
  246. //check and see if a data packet has come in.
  247. receiveandprint();
  248. if (drawFlag) {
  249. drawFlag = 0;
  250. drawScreen();
  251. }
  252. //handleTouches
  253. touchSense();
  254. if (millis() > 59999) {
  255. timerHandler();
  256. }
  257. /*char *heapend=sbrk(0);
  258. register char * stack_ptr asm ("sp");
  259. struct mallinfo mi=mallinfo();
  260. printf("\nDynamic ram used: %d\n",mi.uordblks);
  261. printf("Program static ram used %d\n",&_end - ramstart);
  262. printf("Stack ram used %d\n\n",ramend - stack_ptr);
  263. printf("My guess at free mem: %d\n",stack_ptr - heapend + mi.fordblks);
  264. */
  265. };
Advertisement
Add Comment
Please, Sign In to add comment