int ParseWeather(char* resp){ char* sub_str; uint32_t offs; int i; int j = 0; sub_str = strstr(ResponseJson, "conds:"); offs = (int) ((int) sub_str - (int)ResponseJson ); for(int i = offs; ResponseJson[i] != '\n'; i++){ ST7735_SetCursor(j,4); ST7735_OutChar(ResponseJson[i]); j++; } j = 0; sub_str = strstr(ResponseJson, "temp:"); offs = (int) ((int) sub_str - (int)ResponseJson ); for(int i = offs; ResponseJson[i] != '\n'; i++){ ST7735_SetCursor(j,5); ST7735_OutChar(ResponseJson[i]); j++; } return 0; }
int main(void){ //Initialize all below: TExaS_Init(); // Bus clock is 80 MHz ADC_Init(); // initialize to sample ADC1 ST7735_InitR(INITR_REDTAB); SysTick_Init(); UART_Init(); FiFo_Init(); PortF_Init(); EnableInterrupts(); while(1){ while(ADCStatus == 0){}; //Poll ADCStatus flag ADCStatus = 0; //clear flag //Prints from a full FIFO --> BUT must know when //we get to the end --> uses while loop to check this condition, //and a for loop to print 5 times ST7735_SetCursor(6,5); //Infinite loop if the fifo is empty / if returns fail while (FiFo_Get(&data) == 0) {}; FiFo_Get(&data); for(int i = 1; i <= 5; i++){ ST7735_OutChar(data); FiFo_Get(&data); } FiFo_Get(&data); FiFo_Get(&data); ST7735_SetCursor(12,5); ST7735_OutString(" cm"); // print " cm" } }
int ParseHeadline(char* resp){ char* sub_str; uint32_t offs; int i; int j = 0; int k = 4; sub_str = strstr(ResponseJson, "headline:"); offs = (int) ((int) sub_str - (int)ResponseJson ); for(int i = offs; ResponseJson[i] != '\n'; i++){ ST7735_SetCursor(j,k); ST7735_OutChar(ResponseJson[i]); j++; if(j>=20){ j = 0; k++; } } return 0; }
int main(void){ TExaS_Init(); ADC_Init(); // turn on ADC, set channel to 1 ST7735_InitR(INITR_REDTAB); PortF_Init(); SysTick_Init(); // This makes things work UART1_Init(); FIFO_Init(); unsigned char data; while(1){ while(data != 0x02){ FIFO_Get(&data); // Look for new data byte } ST7735_SetCursor(0,0); for(int i = 0; i<5; i++){ // Print next 5 elements FIFO_Get(&data); ST7735_OutChar(data); } ST7735_OutString(" cm"); // Print units } }
void ST7735_DecOut2(int32_t n){ char thousands_c = '0'; char hundreds_c = '0'; char tens_c = '0'; char units_c = '0'; int thousands; int hundreds; int tens; int units; int negative = 0; // if(n>999 || n < -999){ // printf(" *.**"); // return; // } // if(n<0){ n = n*(-1); // negative = 1; // } thousands = n/1000; hundreds = (n%1000)/100; tens = (n%100)/10; units = n%10; thousands_c = ((char) (thousands)) + 0x30; hundreds_c = ((char) (hundreds)) + 0x30; tens_c = ((char) (tens)) + 0x30; units_c = ((char) (units)) + 0x30; ST7735_SetCursor(2,2); ST7735_OutChar(thousands_c); ST7735_SetCursor(3,2); ST7735_OutChar(hundreds_c); ST7735_SetCursor(4,2); ST7735_OutChar('.'); ST7735_SetCursor(5,2); ST7735_OutChar(tens_c); ST7735_SetCursor(6,2); ST7735_OutChar(units_c); ST7735_SetCursor(7,2); ST7735_OutChar(' '); ST7735_SetCursor(8,2); ST7735_OutChar('C'); return; }
// this is used for printf to output to both the screen and the usb uart int fputc(int ch, FILE *f){ if (OUTPUT_SCREEN_ENABLED) ST7735_OutChar(ch); // output to screen if (OUTPUT_UART_ENABLED) USB_UART_PrintChar(ch); // output via usb uart return 1; }
void ST7735_printBuf(char buffer[], int length) { for (int i = 0; i < length; ++i) { ST7735_OutChar(buffer[i]); } }
int main(void){int32_t retVal; SlSecParams_t secParams; char *pConfig = NULL; INT32 ASize = 0; SlSockAddrIn_t Addr; ADC0_InitSWTriggerSeq3_Ch9(); // allow time to finish activating initClk(); // PLL 50 MHz Output_On(); UART_Init(); // Send data to PC, 115200 bps Timer1_Init(); LED_Init(); // initialize LaunchPad I/O UARTprintf("Weather App\n"); retVal = configureSimpleLinkToDefaultState(pConfig); // set policies if(retVal < 0)Crash(4000000); retVal = sl_Start(0, pConfig, 0); if((retVal < 0) || (ROLE_STA != retVal) ) Crash(8000000); secParams.Key = PASSKEY; secParams.KeyLen = strlen(PASSKEY); secParams.Type = SEC_TYPE; // OPEN, WPA, or WEP sl_WlanConnect(SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0); while((0 == (g_Status&CONNECTED)) || (0 == (g_Status&IP_AQUIRED))){ _SlNonOsMainLoopTask(); } UARTprintf("Connected\n"); while(1){ int i = 0; while(i < 10){ int sendc = 0; strcpy(HostName,"openweathermap.org"); retVal = sl_NetAppDnsGetHostByName(HostName, strlen(HostName),&DestinationIP, SL_AF_INET); if(retVal == 0){ Addr.sin_family = SL_AF_INET; Addr.sin_port = sl_Htons(80); Addr.sin_addr.s_addr = sl_Htonl(DestinationIP);// IP to big endian ASize = sizeof(SlSockAddrIn_t); SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); if( SockID >= 0 ){ retVal = sl_Connect(SockID, ( SlSockAddr_t *)&Addr, ASize); } if((SockID >= 0)&&(retVal >= 0)){ strcpy(SendBuff,REQUEST); sl_Send(SockID, SendBuff, strlen(SendBuff), 0);// Send the HTTP GET sl_Recv(SockID, Recvbuff, MAX_RECV_BUFF_SIZE, 0);// Receive response sl_Close(SockID); LED_GreenOn(); UARTprintf("\r\n\r\n"); UARTprintf(Recvbuff); UARTprintf("\r\n"); } } ST7735_OutUDec(sendc); ST7735_OutString("\n"); i++; } //while(Board_Input()==0){}; // wait for touch LED_GreenOff(); //Temp Part e getTemp(Recvbuff); ST7735_OutChar('T'); ST7735_OutChar('e'); ST7735_OutChar('m'); ST7735_OutChar('p'); ST7735_OutChar(' '); ST7735_OutChar('='); ST7735_OutChar(' '); for(int i = 0; i < 5; i++){ ST7735_OutChar(myArray[i]); } ST7735_OutChar('\n'); //ADC Part f ADC0_SAC_R = ADC_SAC_AVG_64X; //enable 64 times average before obtaining result int voltage = ADC0_InSeq3(); ST7735_OutString("Voltage~"); ST7735_sDecOut3(voltage); char* voltageString; char voltageStringNum[5]; sprintf(voltageStringNum, "%.1d.%.3d", voltage/1000, voltage%1000); //ST7735_OutString(voltageStringNum); char* sendString; char str1[173] = "GET /query?city=Austin%20Texas&id=Ty%20Winkler%20Jeremiah%20Bartlett&greet=Voltage%3D"; strcat(str1, voltageStringNum); strcat(str1, "V&edxcode=8086 HTTP/1.1\r\nUser-Agent: Keil\r\nHost: embsysmooc.appspot.com\r\n\r\n"); strcpy(HostName,"embsysmooc.appspot.com"); retVal = sl_NetAppDnsGetHostByName(HostName, strlen(HostName),&DestinationIP, SL_AF_INET); if(retVal == 0){ Addr.sin_family = SL_AF_INET; Addr.sin_port = sl_Htons(80); Addr.sin_addr.s_addr = sl_Htonl(DestinationIP);// IP to big endian ASize = sizeof(SlSockAddrIn_t); SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); if( SockID >= 0 ){ retVal = sl_Connect(SockID, ( SlSockAddr_t *)&Addr, ASize); } if((SockID >= 0)&&(retVal >= 0)){ strcpy(SendBuff, str1); count = 0; sl_Send(SockID, SendBuff, strlen(SendBuff), 0);// Send the HTTP GET sl_Recv(SockID, Recvbuff, MAX_RECV_BUFF_SIZE, 0);// Receive response sl_Close(SockID); LED_GreenOn(); UARTprintf("\r\n\r\n"); //ST7735_OutString(Recvbuff); UARTprintf("\r\n"); } } while(1); } }