Ejemplo n.º 1
0
static void syslog_send_cb_P(void *data) 
{
  strcpy_P(uip_appdata, data);
  uip_udp_send(strlen_P(data));
}
	int PortMapClass::getExternalIpRequest()
	{

		if (_apmClient.connect(igdIp(), igdPort()))
		{
        	char * buffer = (char *) malloc (256);
    		memset(buffer, 0, 256);
            char * smallbuffer = (char *) malloc (8);
            memset(smallbuffer, 0,8);

        	// Make a HTTP request:

        	strcpy_P(buffer, EXTIP_HEADER1A);

            // convert control URL from string to char array and append to buffer contents
            String controlUrlString = igdControlUrl();
            char controlUrlStringArray[controlUrlString.length()+1];
            controlUrlString.toCharArray(controlUrlStringArray, sizeof(controlUrlStringArray));
            strcat(buffer, controlUrlStringArray);

            strcat_P(buffer, EXTIP_HEADER1B);

            // convert igd IP address to char array and append to buffer contents
            IPAddress igdIpAddress = igdIp();
            strcat(buffer, itoa(igdIpAddress[0], smallbuffer, 10));
            memset(smallbuffer, 0,8);
            strcat(buffer, ".");
            strcat(buffer, itoa(igdIpAddress[1], smallbuffer, 10));
            memset(smallbuffer, 0,8);
            strcat(buffer, ".");
            strcat(buffer, itoa(igdIpAddress[2], smallbuffer, 10));
            memset(smallbuffer, 0,8);
            strcat(buffer, ".");
            strcat(buffer, itoa(igdIpAddress[3], smallbuffer, 10));
            memset(smallbuffer, 0,8);
            strcat(buffer, ":");
            
            // convert igd port number to char array and append
            uint16_t igdPortNumber = igdPort();
            strcat(buffer, itoa(igdPortNumber, smallbuffer, 10));
            memset(smallbuffer, 0,8);

            strcat_P(buffer, EXTIP_HEADER1C);

			strcat_P(buffer, EXTIP_BODY1);

        	strcat_P(buffer, EXTIP_BODY2);

        	strcat_P(buffer, EXTIP_BODY3);

        	strcat_P(buffer, EXTIP_BODY4);

        	strcat_P(buffer, EXTIP_BODY5);

        	strcat_P(buffer, EXTIP_BODY6);
        	_apmClient.print(buffer);

        	free(buffer);
            free(smallbuffer);

        	return parseExternalIpResponse();
    	} else {
        	// if you didn't get a connection to the server:
        	_apmClient.stop();
        	return 0;
    	}
	}
Ejemplo n.º 3
0
char* monthStr(uint8_t month)
{
    strcpy_P(buffer, (PGM_P)pgm_read_word(&(monthNames_P[month])));
        return buffer;
}
Ejemplo n.º 4
0
/** Application callback routine, executed each time the TCP processing task runs. This callback determines what request
 *  has been made (if any), and serves up appropriate responses.
 *
 *  \param[in] ConnectionState  Pointer to a TCP Connection State structure giving connection information
 *  \param[in,out] Buffer       Pointer to the application's send/receive packet buffer
 */
void Webserver_ApplicationCallback(TCP_ConnectionState_t* const ConnectionState,
                                   TCP_ConnectionBuffer_t* const Buffer)
{
	char*          BufferDataStr = (char*)Buffer->Data;
	static uint8_t PageBlock     = 0;

	/* Check to see if a packet has been received on the HTTP port from a remote host */
	if (TCP_APP_HAS_RECEIVED_PACKET(Buffer))
	{
		if (IsHTTPCommand(Buffer->Data, "GET"))
		{
			if (IsHTTPCommand(Buffer->Data, "GET / "))
			{
				PageBlock = 0;

				/* Copy the HTTP 200 response header into the packet buffer */
				strcpy_P(BufferDataStr, HTTP200Header);

				/* Send the buffer contents to the host */
				TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr));

				/* Lock the buffer to Device->Host transmissions only while we send the page contents */
				TCP_APP_CAPTURE_BUFFER(Buffer);
			}
			else
			{
				/* Copy the HTTP 404 response header into the packet buffer */
				strcpy_P(BufferDataStr, HTTP404Header);

				/* Send the buffer contents to the host */
				TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr));

				/* All data sent, close the connection */
				TCP_APP_CLOSECONNECTION(ConnectionState);
			}
		}
		else if (IsHTTPCommand(Buffer->Data, "HEAD"))
		{
			if (IsHTTPCommand(Buffer->Data, "HEAD / "))
			{
				/* Copy the HTTP response header into the packet buffer */
				strcpy_P(BufferDataStr, HTTP200Header);

				/* Send the buffer contents to the host */
				TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr));
			}
			else
			{
				/* Copy the HTTP response header into the packet buffer */
				strcpy_P(BufferDataStr, HTTP404Header);

				/* Send the buffer contents to the host */
				TCP_APP_SEND_BUFFER(Buffer, strlen(BufferDataStr));
			}

			/* All data sent, close the connection */
			TCP_APP_CLOSECONNECTION(ConnectionState);
		}
		else if (IsHTTPCommand(Buffer->Data, "TRACE"))
		{
			/* Echo the host's query back to the host */
			TCP_APP_SEND_BUFFER(Buffer, Buffer->Length);

			/* All data sent, close the connection */
			TCP_APP_CLOSECONNECTION(ConnectionState);
		}
		else
		{
			/* Unknown request, just clear the buffer (drop the packet) */
			TCP_APP_CLEAR_BUFFER(Buffer);
		}
	}
	else if (TCP_APP_HAVE_CAPTURED_BUFFER(Buffer))
	{
		uint16_t RemLength = strlen_P(&HTTPPage[PageBlock * HTTP_REPLY_BLOCK_SIZE]);
		uint16_t Length;

		/* Determine the length of the loaded block */
		Length = ((RemLength > HTTP_REPLY_BLOCK_SIZE) ? HTTP_REPLY_BLOCK_SIZE : RemLength);

		/* Copy the next buffer sized block of the page to the packet buffer */
		strncpy_P(BufferDataStr, &HTTPPage[PageBlock * HTTP_REPLY_BLOCK_SIZE], Length);

		/* Send the buffer contents to the host */
		TCP_APP_SEND_BUFFER(Buffer, Length);

		/* Check to see if the entire page has been sent */
		if (PageBlock++ == (sizeof(HTTPPage) / HTTP_REPLY_BLOCK_SIZE))
		{
			/* Unlock the buffer so that the host can fill it with future packets */
			TCP_APP_RELEASE_BUFFER(Buffer);

			/* Close the connection to the host */
			TCP_APP_CLOSECONNECTION(ConnectionState);
		}
	}
}
void lcd_sd_menu_details_callback(uint8_t nr)
{
    if (nr == 0)
    {
        return;
    }
    for(uint8_t idx=0; idx<LCD_CACHE_COUNT; idx++)
    {
        if (LCD_CACHE_ID(idx) == nr)
        {
            if (LCD_CACHE_TYPE(idx) == 1)
            {
                lcd_lib_draw_string_centerP(53, PSTR("Folder"));
            }else{
                char buffer[64];
                if (LCD_DETAIL_CACHE_ID() != nr)
                {
                    card.getfilename(nr - 1);
                    if (card.errorCode())
                    {
                        card.clearError();
                        return;
                    }
                    LCD_DETAIL_CACHE_ID() = nr;
                    LCD_DETAIL_CACHE_TIME() = 0;
                    for(uint8_t e=0; e<EXTRUDERS; e++)
                        LCD_DETAIL_CACHE_MATERIAL(e) = 0;
                    card.openFile(card.filename, true);
                    if (card.isFileOpen())
                    {
                        for(uint8_t n=0;n<8;n++)
                        {
                            card.fgets(buffer, sizeof(buffer));
                            buffer[sizeof(buffer)-1] = '\0';
                            while (strlen(buffer) > 0 && buffer[strlen(buffer)-1] < ' ') buffer[strlen(buffer)-1] = '\0';
                            if (strncmp_P(buffer, PSTR(";TIME:"), 6) == 0)
                                LCD_DETAIL_CACHE_TIME() = atol(buffer + 6);
                            else if (strncmp_P(buffer, PSTR(";MATERIAL:"), 10) == 0)
                                LCD_DETAIL_CACHE_MATERIAL(0) = atol(buffer + 10);
#if EXTRUDERS > 1
                            else if (strncmp_P(buffer, PSTR(";MATERIAL2:"), 11) == 0)
                                LCD_DETAIL_CACHE_MATERIAL(1) = atol(buffer + 11);
#endif
                        }
                    }
                    if (card.errorCode())
                    {
                        //On a read error reset the file position and try to keep going. (not pretty, but these read errors are annoying as hell)
                        card.clearError();
                        LCD_DETAIL_CACHE_ID() = 255;
                    }
                }
                
                if (LCD_DETAIL_CACHE_TIME() > 0)
                {
                    char* c = buffer;
                    if (led_glow_dir)
                    {
                        strcpy_P(c, PSTR("Time: ")); c += 6;
                        c = int_to_time_string(LCD_DETAIL_CACHE_TIME(), c);
                    }else{
                        strcpy_P(c, PSTR("Material: ")); c += 10;
                        float length = float(LCD_DETAIL_CACHE_MATERIAL(0)) / (M_PI * (material[0].diameter / 2.0) * (material[0].diameter / 2.0));
                        if (length < 10000)
                            c = float_to_string(length / 1000.0, c, PSTR("m"));
                        else
                            c = int_to_string(length / 1000.0, c, PSTR("m"));
#if EXTRUDERS > 1
                        if (LCD_DETAIL_CACHE_MATERIAL(1))
                        {
                            *c++ = '/';
                            float length = float(LCD_DETAIL_CACHE_MATERIAL(1)) / (M_PI * (material[1].diameter / 2.0) * (material[1].diameter / 2.0));
                            if (length < 10000)
                                c = float_to_string(length / 1000.0, c, PSTR("m"));
                            else
                                c = int_to_string(length / 1000.0, c, PSTR("m"));
                        }
#endif
                    }
                    lcd_lib_draw_string(3, 53, buffer);
                }else{
                    lcd_lib_draw_stringP(3, 53, PSTR("No info available"));
                }
            }
        }
    }
}
Ejemplo n.º 6
0
portBASE_TYPE prvCanCmd( int8_t *pcWriteBuffer,
						size_t xWriteBufferLen,
						const int8_t *pcCommandString )
{
portCHAR *pcParameter;
portBASE_TYPE lParameterStringLength;
static portSHORT xArgL1;
static portSHORT xArgL2;
static portSHORT xArgL3;
static portUCHAR xArgMsg[8];
static portUCHAR xMsgIdx;
static xCanCmdStates_t xState;
static portBASE_TYPE lParameterNumber = 0;
static xCanCmdElement_t xCanCmdElement;

	(void) xWriteBufferLen;
	pcWriteBuffer[ 0 ] = 0x00;
	portBASE_TYPE xReturn = pdPASS;
	
    if( lParameterNumber == 0 )
    {
		//entering can command parser
        xState = STATE_Z;
		lParameterNumber = 1L;
	} else 
	{
		pcParameter = ( portCHAR * ) FreeRTOS_CLIGetParameter ( pcCommandString,
														lParameterNumber,
														&lParameterStringLength
		);	
		
		if (pcParameter) 
		{
			lParameterNumber++;
			switch (xState) 
			{
			case STATE_Z: //first arg ena dis open close baud mob 
				if (!strncmp(pcParameter, CCC_RESET, CCC_RESET_L)) 
				{
					xState = STATE_RESET;
				} else 
				if (!strncmp(pcParameter, CCC_ENA, CCC_ENA_L)) 
				{
					xState = STATE_ENA;
				} else 
				if (!strncmp(pcParameter, CCC_DIS, CCC_DIS_L)) 
				{
					xState = STATE_DIS;
				} else
				if (!strncmp(pcParameter, CCC_CONF, CCC_CONF_L)) 
				{
					xState = STATE_CONF1;
				} else 
				if (!strncmp(pcParameter, CCC_CLOSE, CCC_CLOSE_L)) 
				{
					xState = STATE_CLOSE;
				} else
				if (!strncmp(pcParameter, CCC_BAUD, CCC_BAUD_L)) 
				{
					xState = STATE_BAUD1;
				} else
				if (!strncmp(pcParameter, CCC_MOB, CCC_MOB_L)) 
				{
					xState = STATE_MOB1;
				} else
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_ENA: //arg: listen
				if (!strncmp(pcParameter, CCC_LISTEN, CCC_LISTEN_L)) 
				{
					xState = STATE_ENALISTEN;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_CONF1: //arg: #conf
				xArgL1 = strtol(pcParameter,NULL,16);
				xState = STATE_CONFVALUE;
			break;
			case STATE_BAUD1: //arg: auto set get
				if (!strncmp(pcParameter, CCC_AUTO, CCC_AUTO_L)) 
				{
					xState = STATE_BAUDAUTO;
				} else 				
				if (!strncmp(pcParameter, CCC_GET, CCC_GET_L)) 
				{
					xState = STATE_BAUDGET;
				} else 				
				if (!strncmp(pcParameter, CCC_SET, CCC_SET_L)) 
				{
					xState = STATE_BAUDSET1;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_BAUDSET1: //arg: 0<=val<0xFFF
				xArgL1 = strtol(pcParameter,NULL,16);
				if ((xArgL1<=0xFFF) && (xArgL1>=0x000)) 
				{
					xState = STATE_BAUDSETVAL1;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_BAUDSETVAL1: //arg: 0<=val<0xFFF
				xArgL2 = strtol(pcParameter,NULL,16);
				if ((xArgL2<=0xFFF) && (xArgL2>=0x000)) 
				{
					xState = STATE_BAUDSETVAL2;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_BAUDSETVAL2: //arg: 0<=val<0xFFF
				xArgL3 = strtol(pcParameter,NULL,16);
				if ((xArgL3<=0xFFF) && (xArgL3>=0x000))
				{
					xState = STATE_BAUDSETVALS;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOB1: //arg: 0<=val<15
				xArgL1 = strtol(pcParameter,NULL,16);
				if ((xArgL1<15) && (xArgL1>=0)) 
				{
					xState = STATE_MOB2;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOB2: //arg: rd, wr, dump, undump
				if (!strncmp(pcParameter, CCC_RD, CCC_RD_L)) 
				{
					xState = STATE_MOBRD1;
				} else 				
				if (!strncmp(pcParameter, CCC_WR, CCC_WR_L)) 
				{
					xState = STATE_MOBWR1;
				} else 				
				if (!strncmp(pcParameter, CCC_DUMP, CCC_DUMP_L)) 
				{
					xState = STATE_MOBDUMP;
				} else 				
				if (!strncmp(pcParameter, CCC_UNDUMP, CCC_UNDUMP_L)) 
				{
					xState = STATE_MOBUNDUMP;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOBRD1: //arg: 0x000<=tag<0xFFF
				xArgL2 = strtol(pcParameter,NULL,16);
				if ((xArgL2<=0xFFF) && (xArgL2>=0x000)) 
				{
					xState = STATE_MOBRDTAG1;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOBWR1: //arg: 0x000<=tag<0xFFF
				xArgL2 = strtol(pcParameter,NULL,16);
				if ((xArgL2<=0xFFF) && (xArgL2>=0x000)) 
				{
					xMsgIdx = 0;
					xState = STATE_MOBWRTAG1;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOBRDTAG1: //arg: 0x000<=msk<0xFFF
				xArgL3 = strtol(pcParameter,NULL,16);
				if ((xArgL3<=0xFFF) && (xArgL3>=0x000)) 
				{
					xState = STATE_MOBRDTAGMASK;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOBWRTAG1: //arg: 0x0<=len<0x08
				xArgL3 = strtol(pcParameter,NULL,16);
				if ((xArgL3<=0x1F) && (xArgL3>=0))
				{ 
					xState = STATE_MOBWRTAGLEN1;
				} else 				
				{
					xState = STATE_FAIL;
					xReturn = pdFAIL;
				}
			break;
			case STATE_MOBWRTAGLEN1: //arg: 0x00<=data<=0xFF
				xArgMsg[xMsgIdx] = strtol(pcParameter,NULL,16);
				{
					++xMsgIdx;
					if (xMsgIdx == xArgL3)
					{
						xState = STATE_MOBWRTAGLENMSG;
					}
				}
			break;
			//...
			default:
				xState = STATE_FAIL;
				xReturn = pdFAIL;
			}
		} else //no more params
		{
			xReturn = pdFALSE;
			lParameterNumber = 0;
			pcWriteBuffer[ 0 ] = 0x00;
			
			switch (xState) 
			{
			case STATE_RESET:
				xCanCmdElement.xCanCmd = CMD_CAN_RESET;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			/*case STATE_CLOSE:
				xCanCmdElement.xCanCmd = CMD_CAN_OPEN;
				xCanCmdElement.ucCloseOpen = 0;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;*/
			case STATE_CONFVALUE:
				xCanCmdElement.xCanCmd = CMD_CAN_CONF;
				xCanCmdElement.ucDefaultConfig = xArgL1;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_DIS:
				xCanCmdElement.xCanCmd = CMD_CAN_ENA;
				xCanCmdElement.ucDisEnaListen = CMD_CAN_DIS_VAL;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_ENA:
				xCanCmdElement.xCanCmd = CMD_CAN_ENA;
				xCanCmdElement.ucDisEnaListen = CMD_CAN_ENA_VAL;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_ENALISTEN:
				xCanCmdElement.xCanCmd = CMD_CAN_ENA;
				xCanCmdElement.ucDisEnaListen = CMD_CAN_ENA_LISTEN_VAL;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_BAUDAUTO:
				xCanCmdElement.xCanCmd = CMD_CAN_BAUD;
				xCanCmdElement.ucGetSetAuto = CMD_CAN_BAUD_AUTO_VAL;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_BAUDGET:
				xCanCmdElement.xCanCmd = CMD_CAN_BAUD;
				xCanCmdElement.ucGetSetAuto = CMD_CAN_BAUD_GET_VAL;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_BAUDSETVALS:
				xCanCmdElement.xCanCmd = CMD_CAN_BAUD;
				xCanCmdElement.ucGetSetAuto = CMD_CAN_BAUD_SET_VAL;
				xCanCmdElement.xArgMsg[0] = xArgL1;
				xCanCmdElement.xArgMsg[1] = xArgL2;
				xCanCmdElement.xArgMsg[2] = xArgL3;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_MOBDUMP:
				xCanCmdElement.xCanCmd = CMD_CAN_MOB_DUMP;
				xCanCmdElement.ucUndumpDump = CMD_CAN_DUMP;
				xCanCmdElement.cMobNum = xArgL1;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_MOBUNDUMP:
				xCanCmdElement.xCanCmd = CMD_CAN_MOB_DUMP;
				xCanCmdElement.ucUndumpDump = CMD_CAN_UNDUMP;
				xCanCmdElement.cMobNum = xArgL1;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_MOBRDTAGMASK:
				xCanCmdElement.xCanCmd = CMD_CAN_MOB_RDWR;
				xCanCmdElement.ucReadWrite = CMD_CAN_RD_VAL;
				xCanCmdElement.cMobNum = xArgL1;
				xCanCmdElement.sTag = xArgL2;
				xCanCmdElement.sMask = xArgL3;
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_MOBWRTAGLENMSG:
				xCanCmdElement.xCanCmd = CMD_CAN_MOB_RDWR;
				xCanCmdElement.ucReadWrite = CMD_CAN_WR_VAL;
				xCanCmdElement.cMobNum = xArgL1;
				xCanCmdElement.sTag = xArgL2;
				xCanCmdElement.sLen = xArgL3&0x0F;
				xCanCmdElement.cRtr = xArgL3&0x10;
				memcpy(xCanCmdElement.xArgMsg,xArgMsg,8);
				xQueueSend(xCanCmdQueue, &xCanCmdElement, portMAX_DELAY );
			break;
			case STATE_FAIL:
			default:
			{}
			}
		}
	}
	if ( STATE_FAIL == xState ) 
	{
		lParameterNumber = 0;
		strcpy_P((portCHAR*)pcWriteBuffer, pm_cstr_INVALID );
		
	}
	return xReturn;
}
Ejemplo n.º 7
0
static uint8_t tui_pgm_menupart_printer(unsigned char* buf, int32_t val) {
	strcpy_P((char*)buf, (PGM_P)pgm_read_word(&(tui_pgm_menu_table[val])));
	return strlen((char*)buf);
}
Ejemplo n.º 8
0
char* rps(const char* progString) {
  static char buf[21];
  strcpy_P(buf, progString);
  return buf;
}
Ejemplo n.º 9
0
static inline void pgmCopy(const __FlashStringHelper *ifsh) {
	strcpy_P(pgbuf, (char*)ifsh);
}
Ejemplo n.º 10
0
int main (void) {            // (2)
   ledidx_t i;

   DDRB  = 0xFF;  // Port B: 1 = output
   PORTB = 0x01;  //bootup 1

   //_delay_ms(1000);

   // Initialize LCD Display
   DDRC |= (1<<PC1) | (1<<PC3); //PC1 = R/W, PC3 = Backlight control
   PORTC &= ~(1<<PC1);
   //Switch Backlight on:
   PORTC |= (1<<PC3);

   _delay_ms(10); lcd_init();

   PORTB = 0x02;  //bootup 2
   _delay_ms(100);
   lcd_string_P(PSTR("blinkylight 0.3 "));
   lcd_setcursor(0,2);
   lcd_string_P(PSTR("Booting ...     "));
   //PORTB = 0x03;  //bootup 3
   //_delay_ms(1000);

   uart_init();
   uart_putc('p'); uart_putc('w'); uart_putc('r'); uart_putc('O'); uart_putc('N'); uart_putc('\n');
   //PORTB = 0x04;  //bootup 4



   //PORTB = 0x05;  //bootup 5

   // Enable Interrupts
   sei();
   PORTB = 0x06;  //bootup 6

   // muss vor ws2801_init stehen, da dieser PA1 und PA2 als output schaltet
   DDRA  = 0x00; // Port A: 0 = input
   PORTA = 0x00;  //        0 = pull-ups off

   //PORTB = 0x0a;  //bootup a


   PORTB = 0x00;  //bootup d
   lcd_setcursor(0,2);
   lcd_string_P(PSTR("Boot complete  "));
   _delay_ms(10);

   //Switch Backlight off:
   PORTC &= ~(1<<PC3);

   // Enter main loop
   uint8_t dezisek = 0;
#define DEZISEKTHRES 4
   while(1) {                // (5)
     /* "leere" Schleife*/   // (6)
     _delay_ms(25);
     //pb_scroll <<= 1;
     //if (pb_scroll == 0b00010000) pb_scroll = 0b00000001;
     //PORTB &= 0b11110000;
     //PORTB |= pb_scroll;
     PORTB ^= (1<<PB2);
     if (dezisek > DEZISEKTHRES) {
       if (relay_timer > 0) {
         relay_timer --;
         if (relay_timer == 0) relay_reset = 1;
         else {
           PORTB ^= ( 1 << PB5 )|(1<<PB6)|(1<<PB7);
         }
       }
     }
     dezisek++;
     if (disp_set) {
       lcd_clear();
       lcd_home();

       for(i=0;i<16;i++)lcd_data(disp_buf[i]);
       lcd_setcursor(0,2);
       for(;i<32;i++)lcd_data(disp_buf[i]);

       disp_set = 0;
       _delay_ms(250);
     }
     if (relay_set) {
       PORTB |= (1<<PB4);
       PORTB |= (1<<PB5)|(1<<PB6)|(1<<PB7);
       relay_set = 0;
     }
     if (relay_reset) {
       PORTB &= ~(1<<PB4);
       PORTB &= ~((1<<PB5)|(1<<PB6)|(1<<PB7));
       relay_reset = 0; relay_timer = 0;
     }
     if (PINA & (1<<PA7)) {
       uart_putc('5');
     }
     if (PINA & (1<<PA6)) {
       uart_putc('4');
     }
     if (PINA & (1<<PA5)) {
       uart_putc('3');
     }
     if (PINA & (1<<PA4)) {
       uart_putc('2');
     }
     if (measure_temp == 1) {
       //PORTC ^= (1<<PC3);
       uint8_t sensor_id[OW_ROMCODE_SIZE];
       uint8_t diff = OW_SEARCH_FIRST;
       ow_reset();
       DS18X20_find_sensor(&diff, &sensor_id[0]);
       if (diff == OW_PRESENCE_ERR)
           strcpy_P(&disp_tmp_buf[0], PSTR("Err:Presence     "));
       else if (diff == OW_DATA_ERR)
           strcpy_P(&disp_tmp_buf[0], PSTR("Err:Data         "));
       else {
         if ( DS18X20_start_meas( DS18X20_POWER_PARASITE, NULL ) == DS18X20_OK) {
           _delay_ms( DS18B20_TCONV_12BIT );
           int16_t decicelsius;
           if ( DS18X20_read_decicelsius( &sensor_id[0], &decicelsius) == DS18X20_OK ) {
             disp_tmp_buf[0]='T'; disp_tmp_buf[1]='e'; disp_tmp_buf[2]='m'; disp_tmp_buf[3]='p'; disp_tmp_buf[4]=':'; disp_tmp_buf[5]=' ';
             DS18X20_format_from_decicelsius( decicelsius, &disp_tmp_buf[6], 8 );
           } else {
             strcpy_P(&disp_tmp_buf[0], PSTR("Err: Read        "));
           }
         } else {
             strcpy_P(&disp_tmp_buf[0], PSTR("Err: StartMeasure"));
         }
       }
       sprintf(&disp_tmp_buf[16], "%d bytes recv.", recv_len);
       //disp_show_buf(&disp_tmp_buf[0]);
       for(i=0;i<20;i++) uart_putc(disp_tmp_buf[i]);
       measure_temp=0;
     }
     if (PINA & (1<<PA3)) {
       relay_set = 1;
       relay_timer = 10;
       uart_putc('1');
     }
     //uart_putc('+');
//     uart_putc('\n');
   }                         // (7)
   /* wird nie erreicht */
   return 0;                 // (8)
}
Ejemplo n.º 11
0
int main(void)
{
	unsigned int sockaddr;
	unsigned char mysocket;
	unsigned int rsize;

	/* Initialize the UART for ATmega168 96008N1    */
	uart_init();

	stdout = &uart_stdout;	//Required for printf init

	mysocket = 0;		// magic number! declare the socket number we will us
	sockaddr = W5100_SKT_BASE(mysocket);	// calc address of W5100 register set for this socket

	puts("AVR Ethernet\r\n");
/*
 *  Initialize the ATmega168 SPI subsystem
 */
	CS_PORT |= (1 << CS_BIT);	// pull CS pin high
	CS_DDR |= (1 << CS_BIT);	// now make it an output

	SPI_PORT = SPI_PORT | (1 << PORTB2);	// make sure SS is high
	SPI_DDR = (1 << PORTB3) | (1 << PORTB5) | (1 << PORTB2);	// set MOSI, SCK and SS as output, others as input
	SPCR = (1 << SPE) | (1 << MSTR);	// enable SPI, master mode 0
	SPSR |= (1 << SPI2X);	// set the clock rate fck/2

/*
 *  Load up the callback block, then initialize the Wiznet W5100
 */
	my_callbacks._select = &my_select;	// callback for selecting the W5100
	my_callbacks._xchg = &my_xchg;	// callback for exchanging data
	my_callbacks._deselect = &my_deselect;	// callback for deselecting the W5100
	my_callbacks._reset = &my_reset;	// callback for hardware-reset of the W5100

	W51_register(&my_callbacks);	// register our target-specific W5100 routines with the W5100 library
	W51_init();		// now initialize the W5100

/*
 *  Configure the W5100 device to handle PING requests.
 *  This requires configuring the chip, not a specific socket.
 */
	W51_config(&my_cfg);	// config the W5100 (MAC, TCP address, subnet, etc

	puts("Debug: AVR Ethernet after W5100 config\r\n");

/*
 *  The main loop.  Control stays in this loop forever, processing any received packets
 *  and sending any requested data.
 */
	while (1) {
		switch (W51_read(sockaddr + W5100_SR_OFFSET))	// based on current status of socket...
		{
		case W5100_SKT_SR_CLOSED:	// if socket is closed...
			if (OpenSocket(mysocket, W5100_SKT_MR_TCP, HTTP_PORT) == mysocket)	// if successful opening a socket...
			{
				Listen(mysocket);
				_delay_ms(1);
			}
			break;

		case W5100_SKT_SR_ESTABLISHED:	// if socket connection is established...
			rsize = ReceivedSize(mysocket);	// find out how many bytes
			if (rsize > 0) {
				if (Receive(mysocket, buf, rsize) != W5100_OK)
					break;	// if we had problems, all done
/*
 *  Add code here to process the payload from the packet.
 *
 *  For now, we just ignore the payload and send a canned HTML page so the client at least
 *  knows we are alive.
 */
				strcpy_P((char *)buf,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
				strcat_P((char *)buf,PSTR("<html>\r\n<body>\r\n"));
				strcat_P((char *)buf,PSTR("<title>Title</title>\r\n"));
				strcat_P((char *)buf,PSTR("<p>Hello world</p>\r\n"));
				strcat_P((char *)buf,PSTR("</body>\r\n</html>\r\n"));
				if (Send(mysocket, buf, strlen((char *)buf)) == W5100_FAIL) break;	// just throw out the packet for now

				DisconnectSocket(mysocket);
			} else	// no data yet...
			{
				_delay_us(10);
			}
			break;

		case W5100_SKT_SR_FIN_WAIT:
		case W5100_SKT_SR_CLOSING:
		case W5100_SKT_SR_TIME_WAIT:
		case W5100_SKT_SR_CLOSE_WAIT:
		case W5100_SKT_SR_LAST_ACK:
			CloseSocket(mysocket);
			break;
		}
	}

	return 0;
}
Ejemplo n.º 12
0
/* ----------------------------------------------------------------------------
 * initialization of Art-Net
 */
void artnet_init(void) {

    ARTNET_DEBUG("Init\n");
 /* read Art-Net port */
//  eeprom_read_block(&artnet_port, (unsigned char *)ARTNET_PORT_EEPROM_STORE, 2);
//  if (artnet_port == 0xFFFF) {
  artnet_port = PORT_DEFAULT;
//  }

 /* read netconfig */
//  artnet_netConfig = eeprom_read_byte((unsigned char *)ARTNET_NETCONFIG_EEPROM_STORE);
//  if (artnet_netConfig == 0xFF) {
  artnet_netConfig = NETCONFIG_DEFAULT;
//  }

 /* read subnet */
//  artnet_subNet = eeprom_read_byte((unsigned char *)ARTNET_SUBNET_EEPROM_STORE);
//  if (artnet_subNet == 0xFF) {
  artnet_subNet = SUBNET_DEFAULT;
//  }

 /* read nr. of input universe */
//  artnet_inputUniverse1 = eeprom_read_byte((unsigned char *)ARTNET_INUNIVERSE_EEPROM_STORE);
//  if (artnet_inputUniverse1 == 0xFF) {
  artnet_inputUniverse1 = INUNIVERSE_DEFAULT;
//  }

 /* read nr. of output universe */
//  artnet_outputUniverse1 = eeprom_read_byte((unsigned char *)ARTNET_OUTUNIVERSE_EEPROM_STORE);
//  if (artnet_outputUniverse1 == 0xFF) {
  artnet_outputUniverse1 = OUTUNIVERSE_DEFAULT;
//  }

 /* read short name */
//  eeprom_read_block(&artnet_shortName, (unsigned char *)ARTNET_SHORTNAME_EEPROM_STORE, SHORT_NAME_LENGTH);
//  if ((*((unsigned long*)&artnet_shortName[0])) == 0xFFFFFFFF) {
  /* fill with zeroes */
  for (unsigned char i = 0; i < SHORT_NAME_LENGTH; i++) {
   artnet_shortName[i] = 0;
  }
  strcpy_P(artnet_shortName, PSTR("AvrArtNode"));
//  }
 artnet_shortName[SHORT_NAME_LENGTH - 1] = 0;

 /* read long name */
//  eeprom_read_block(&artnet_longName, (unsigned char *)ARTNET_LONGNAME_EEPROM_STORE, LONG_NAME_LENGTH);
//  if ((*((unsigned long*)&artnet_longName[0])) == 0xFFFFFFFF) {
  /* fill with zeroes */
  for (unsigned char i = 0; i < LONG_NAME_LENGTH; i++) {
   artnet_longName[i] = 0;
  }
  strcpy_P(artnet_longName, PSTR("AVR based Art-Net node"));
//  }
 artnet_longName[LONG_NAME_LENGTH - 1] = 0;

//  ARTNET_DEBUG("net init\n");
 artnet_netInit();

 /* annouce that we are here  */
 ARTNET_DEBUG("send PollReply\n");
 artnet_sendPollReply();

 /* enable PollReply on changes */
 artnet_sendPollReplyOnChange = TRUE;

 ARTNET_DEBUG("init complete\n");
 return;
}
Ejemplo n.º 13
0
static void
mysql_send_data (uint8_t send_state)
{
    MYDEBUG ("send_data: %d\n", send_state);

    switch (send_state) {
	struct mysql_login_request_t *lr;
	struct mysql_request_packet_t *rp;

    case MYSQL_SEND_LOGIN:
	/* Clear packet until username field. */
	memset (uip_sappdata, 0, 36);

	lr = uip_sappdata;
	lr->packet_id = STATE->packetid;

	/* Long password support (0x01), connect with database set (0x08)*/
	lr->capabilities[0] = 0x09;
	/* We speek 4.1 protocol (0x02), we are an interactive client (not
	   really, but otherwise our times out after 10sec) (0x04),
	   we do 4.1 authentication (0x80) */
	lr->capabilities[1] = 0x86;
	/* Max. packet size = 256 byte */
	lr->max_packet_size[0] = 0xFF;
	lr->charset = 8;	/* Latin1 charset. */

	char *ptr = uip_sappdata + 36;
	strcpy_P (ptr, PSTR (CONF_MYSQL_USERNAME));
	ptr += sizeof (CONF_MYSQL_USERNAME);

	*(ptr ++) = 20;
	mysql_password_hash (ptr);
	ptr += 20;

	strcpy_P (ptr, PSTR (CONF_MYSQL_SCHEMA));
	ptr += sizeof (CONF_MYSQL_SCHEMA);

	lr->packet_len[0] = (ptr - (char*)uip_sappdata) - 4;
	uip_send (uip_sappdata, ptr - (char*) uip_sappdata);
	break;

    case MYSQL_CONNECTED:
	if (!*STATE->u.stmtbuf) {
	    MYDEBUG ("no queries pending.\n");
	    break;
	}

	rp = uip_sappdata;
	rp->packet_len[0] = 1 + strlen (STATE->u.stmtbuf);
	rp->packet_len[1] = 0;
	rp->packet_len[2] = 0;
	rp->packet_id = STATE->packetid = 0;
	rp->command_id = 3;	/* Query */
	strcpy (rp->arg, STATE->u.stmtbuf);

	uip_send (uip_sappdata, 4 + rp->packet_len[0]);
	break;

    default:
	MYDEBUG ("eeek, what?\n");
	uip_abort ();
	break;
    }

    STATE->sent = send_state;
    STATE->packetid ++;
}
Ejemplo n.º 14
0
void
Clock::lcdInfo(){
  char buff[BUFF_LCD_MSG];
  byte t;

  // read values
  dht22->loadFromSensor();
  switch(dht22->error()){
    case DHT_ERROR_NONE:
    case DHT_ERROR_TOOQUICK:
      break;
    default:
      // FIXME better error reporting
      ledMatrix->fill(RED);
      ledMatrix->show();
      while(1);
      break;
  }
  bmp085->loadFromSensor();
  humidityInside.loadFromSensor();
  // LCD
  lcd->firstPage();
  do {
    byte x;
    byte y;
    // Week day
    y=-2;
    lcd->setFont(u8g_font_6x12);
    lcd->setFontPosTop();
    x=lcd->getWidth()/2-lcd->getStrWidthP((u8g_pgm_uint8_t *)time->getWeekDayName())/2;
    lcd->drawStrP(x, y, (const u8g_pgm_uint8_t*)time->getWeekDayName());
    // Date
    strcpy_P(buff, time->getMonthName());
    t=strlen(buff);
    buff[t++]=' ';
    itoa(date.mday, buff+t, 10);
    t=strlen(buff);
    buff[t++]=' ';
    itoa(date.year, buff+t, 10);
    y+=lcd->getFontAscent()+2;
    x=lcd->getWidth()/2-lcd->getStrWidth(buff)/2;
    lcd->drawStr(x, y, buff);
    // Pressure
    ltoa(pressure.getPa(), buff, 10);
    t=strlen(buff);
    buff[t++]='P';
    buff[t++]='a';
    buff[t++]=' ';
    buff[t++]='(';
    double d=pressure.getPa()-pressure.expectedPressure(AVERAGE_SEA_LEVEL_PRESSURE, ALTITUDE);
    if(d>0)
      buff[t++]='+';
    ltoa(d, buff+t, 10);
    t=strlen(buff);
    buff[t++]='P';
    buff[t++]='a';
    buff[t++]=')';
    buff[t]='\0';
    y+=lcd->getFontAscent()+1;
    lcd->setFont(u8g_font_7x13B);
    lcd->setFontPosTop();
    x=lcd->getWidth()/2-lcd->getStrWidth(buff)/2;
    lcd->drawStr(x, y, buff);
    // Temperature names
    y+=lcd->getFontAscent()+1;
    lcd->setFont(u8g_font_5x7);
    lcd->setFontPosTop();
    x=lcd->getWidth()/4-lcd->getStrWidthP(U8G_PSTR("Outside"))/2;
    lcd->drawStrP(x, y, U8G_PSTR("Outside"));
    x=lcd->getWidth()*3/4-lcd->getStrWidthP(U8G_PSTR("Inside"))/2;
    lcd->drawStrP(x, y, U8G_PSTR("Inside"));
    // Temperature outside
    x=0;
    y+=lcd->getFontAscent()+1;
    lcd->setFont(u8g_font_fub14);
    lcd->setFontPosTop();
    lcd->drawStr(x, y, dtostrf(temperatureOutside.getC(), -2, 1, buff));
    x+=lcd->getStrWidth(dtostrf(temperatureOutside.getC(), -2, 1, buff));
    buff[0]=176;
    buff[1]='C';
    buff[2]='\0';
    lcd->drawStr(x, y, buff);
    // Temperature inside
    dtostrf(temperatureInside.getC(), -2, 1, buff);
    t=strlen(buff);
    buff[t++]=176;
    buff[t++]='C';
    buff[t]='\0';
    x=lcd->getWidth()-lcd->getStrWidth(buff);
    lcd->drawStr(x, y, buff);
    // Humidity outside
    y+=lcd->getFontAscent()+1;
    ltoa(humidityOutside.getRH(), buff, 10);
    t=strlen(buff);
    buff[t++]='%';
    buff[t]='\0';
    x=lcd->getWidth()/4-lcd->getStrWidth(buff)/2;
    lcd->drawStr(x, y, buff);
    // Humidity inside
    ltoa(humidityInside.getRH(), buff, 10);
    t=strlen(buff);
    buff[t++]='%';
    buff[t]='\0';
    x=lcd->getWidth()*3/4-lcd->getStrWidth(buff)/2;
    lcd->drawStr(x, y, buff);
  } 
  while( lcd->nextPage() );
}
Ejemplo n.º 15
0
static void chb_radio_init()
{
    U8 ieee_addr[8];
    U8 part_num;

    // disable intps while we config the radio
    chb_reg_write(IRQ_MASK, 0);

    // force transceiver off while we configure the intps
    chb_reg_read_mod_write(TRX_STATE, CMD_FORCE_TRX_OFF, 0x1F);
    chb_delay_us(TIME_P_ON_TO_TRX_OFF);

    // set radio cfg parameters
    // **note** uncomment if these will be set to something other than default
    //chb_reg_read_mod_write(XAH_CTRL_0, CHB_MAX_FRAME_RETRIES << CHB_MAX_FRAME_RETRIES_POS, 0xF << CHB_MAX_FRAME_RETRIES_POS);
    //chb_reg_read_mod_write(XAH_CTRL_0, CHB_MAX_CSMA_RETRIES << CHB_MAX_CSMA_RETIRES_POS, 0x7 << CHB_MAX_CSMA_RETIRES_POS);
    //chb_reg_read_mod_write(CSMA_SEED_1, CHB_MIN_BE << CHB_MIN_BE_POS, 0x3 << CHB_MIN_BE_POS);     
    //chb_reg_read_mod_write(CSMA_SEED_1, CHB_CSMA_SEED1 << CHB_CSMA_SEED1_POS, 0x7 << CHB_CSMA_SEED1_POS);
    //chb_ret_write(CSMA_SEED0, CHB_CSMA_SEED0);     
    //chb_reg_read_mod_write(PHY_CC_CCA, CHB_CCA_MODE << CHB_CCA_MODE_POS,0x3 << CHB_CCA_MODE_POS);
    //chb_reg_write(CCA_THRES, CHB_CCA_ED_THRES);
    //chb_reg_read_mod_write(PHY_TX_PWR, CHB_TX_PWR, 0xf);


    // identify device
    part_num = chb_reg_read(PART_NUM);

    switch (part_num)
    {
    case CHB_AT86RF230:
        // set default channel
        chb_set_channel(CHB_2_4GHZ_DEFAULT_CHANNEL);

#if (CHIBI_PROMISCUOUS == 0)
    // set autocrc mode
    chb_reg_read_mod_write(PHY_TX_PWR, 1 << CHB_AUTO_CRC_POS, 1 << CHB_AUTO_CRC_POS);
#endif
        break;

    case CHB_AT86RF231:
        // set default channel
        chb_set_channel(CHB_2_4GHZ_DEFAULT_CHANNEL);

#if (CHIBI_PROMISCUOUS == 0)
    // set autocrc mode
    chb_reg_read_mod_write(PHY_TX_PWR, 1 << CHB_AUTO_CRC_POS, 1 << CHB_AUTO_CRC_POS);
#endif
        break;

    case CHB_AT86RF212:
        // set mode to OQPSK or BPSK depending on setting
        chb_set_mode(CHB_INIT_MODE);

        // set default channel and tx power to max
        chb_set_channel(CHB_900MHZ_DEFAULT_CHANNEL);
        chb_reg_read_mod_write(PHY_TX_PWR, CHB_900MHZ_TX_PWR, 0xf);

#if (CHIBI_PROMISCUOUS == 0)
    // set autocrc mode
    chb_reg_read_mod_write(TRX_CTRL1, 1 << CHB_AUTO_CRC_POS, 1 << CHB_AUTO_CRC_POS);
#endif
        break;

    default:
        Serial.print("ERROR: Unknown radio detected.\n");
        break;
    }

    // set transceiver's fsm state
    chb_set_state(RX_STATE);

    // set pan ID
    chb_reg_write16(PAN_ID_0, CHB_PAN_ID);

    // set short addr
    // NOTE: Possibly get this from EEPROM
    chb_reg_write16(SHORT_ADDR_0, chb_get_short_addr());

    // set long addr
    // NOTE: Possibly get this from EEPROM
    chb_get_ieee_addr(ieee_addr);
    chb_reg_write64(IEEE_ADDR_0, ieee_addr);

    // do a read of the interrupt register to clear the interrupt bits
    chb_reg_read(IRQ_STATUS);

    // re-enable intps while we config the radio
    chb_reg_write(IRQ_MASK, 0x8);

    // enable mcu intp pin on INT6 for rising edge
    CFG_CHB_INTP();

    if (chb_get_state() != RX_STATE)
    {
        // ERROR occurred initializing the radio. Print out error message.
        char buf[50];

        // grab the error message from flash & print it out
        strcpy_P(buf, chb_err_init);
        Serial.print(buf);
    }
}
Ejemplo n.º 16
0
//*******************************************************************************
void	GetFontDef_Rowmand(short tableIndex, char *fontDefString)
{
    strcpy_P(fontDefString, (char*)pgm_read_word(&(gHershyRowmandFontTable[tableIndex])));
}
Ejemplo n.º 17
0
/**********************************************************
 * Calibrate
 *  Performs a chip calibration
 *
 * @return bool - The calibration result
 **********************************************************/
bool LibCompass::Calibrate(void) {
    char out[100];
    char inChar;

    Serial.begin(9600);

    strcpy_P(out, PSTR("Calibration Mode."));
    Serial.println(out);

    strcpy_P(out, PSTR("You'll need to rotate the sensor 720 degrees"));
    Serial.println(out);

    strcpy_P(out, PSTR("Send a 'C' to begin or 'Q' to quit"));
    Serial.println(out);

    //wait for a character
    while(1) {
        if(Serial.available()) {
            if (Serial.read() == 'C')  {
                //Calibrate!
                strcpy_P(out, PSTR("Start rotating..."));
                Serial.println(out);
                break;
            } else {
                //Don't Calibrate
                strcpy_P(out, PSTR("Quiting."));
                Serial.println(out);
                delay(3000);
                return false;
            }
        }
    }

    //Enter Cal mode
    Wire.beginTransmission(hmc6352_Address);
    Wire.send(hmc6352_EnterCal);
    Wire.endTransmission();

    delay(3000); //give them some time

    strcpy_P(out, PSTR("Send a 'E' character when finished"));
    Serial.println(out);

    //wait for a character
    while(1) {
        if(Serial.available()) {
            if (Serial.read() == 'E') {
                break;
            }
        }
    }

    //Exit Cal Mode
    Wire.beginTransmission(hmc6352_Address);
    Wire.send(hmc6352_ExitCal);
    Wire.endTransmission();

    strcpy_P(out, PSTR("Done."));
    Serial.println(out);
    delay(3000);

    return true;
}
Ejemplo n.º 18
0
void stringsLoad(char* buffer, const char* progmemAddress)
{
	strcpy_P(buffer, progmemAddress);
}
Ejemplo n.º 19
0
static const char * get_text(byte lang, TranslatableText tt) {
  static char buffer[128];
  strcpy_P(buffer, (char*)pgm_read_word(&(translations[lang][tt])));
  return buffer;
  //return translations[currentLang][tt];
}
Ejemplo n.º 20
0
void game_over(void)
{
    strcpy_P(tempStr, strOptGameOver);
    putString(32,3,tempStr,0);
    game_running = 0;
}
Ejemplo n.º 21
0
void gui_list_draw()
{
	char tmp_text[64];
	char tmp_sub_text[32];

	uint8_t flags;

	disp.LoadFont(F_TEXT_M);
	uint8_t t_h = disp.GetTextHeight();

	int16_t y = gui_list_y_offset;
	int8_t height;
	int16_t total_height = 0;
	uint8_t sub_height;

	//emulate middle click
	if (button_in_reset(B_MIDDLE))
	{
		if (task_get_ms_tick() - gui_list_middle_hold > BUTTON_LONG)
		{
			gui_switch_task(gui_list_back);
			if ((config.gui.menu_audio_flags & CFG_AUDIO_MENU_BUTTONS) && gui_buttons_override == false)
				seq_start(&snd_menu_exit, config.gui.menu_volume);
		}
	}
	else
		gui_list_middle_hold = task_get_ms_tick();

	for (uint8_t i = 0; i < gui_list_size; i++)
	{

		flags = 0;
		if (i < gui_list_size - 1)
		{
			gui_list_gen_f(i, tmp_text, &flags, tmp_sub_text);
		}
		else
		{
			strcpy_P(tmp_text, PSTR("back"));
			flags = GUI_LIST_BACK;
		}

		uint8_t x_val = 5;

		switch(flags & GUI_LIST_T_MASK)
		{
			case(GUI_LIST_FOLDER):
				x_val = 5;
			break;

			case(GUI_LIST_BACK):
				x_val = 2;
			break;

			case(GUI_LIST_TITLE):
				x_val = 1;
				disp.LoadFont(F_TEXT_S);
				t_h = disp.GetTextHeight();
			break;

		}

		height = 1 + t_h;

		if ((flags & GUI_LIST_T_MASK) == GUI_LIST_SUB_TEXT)
		{
			sub_height = disp.GetTextHeight();
			height += sub_height;
		}

		if (gui_list_index[gui_task] == i)
		{
			if (y < 0)
				gui_list_y_offset = -total_height;

			if (y > GUI_DISP_HEIGHT - height)
				gui_list_y_offset = -total_height + GUI_DISP_HEIGHT - height;
		}

		if (y > GUI_DISP_HEIGHT)
			continue;

		disp.GotoXY(x_val, y + 1);
		fprintf_P(lcd_out, PSTR("%s"), tmp_text);

		//sub text
		if ((flags & GUI_LIST_T_MASK) == GUI_LIST_SUB_TEXT)
			gui_raligh_text(tmp_sub_text, GUI_DISP_WIDTH - 3, y + t_h + 1);

		//tick
		if ((flags & GUI_LIST_T_MASK) == GUI_LIST_CHECK_OFF || (flags & GUI_LIST_T_MASK) == GUI_LIST_CHECK_ON)
		{
			disp.DrawRectangle(GUI_DISP_WIDTH - 9, y + 1, GUI_DISP_WIDTH - 3, y + 7, 1, 0);
			if ((flags & GUI_LIST_T_MASK) == GUI_LIST_CHECK_ON)
			{
				disp.DrawLine(GUI_DISP_WIDTH - 8, y + 5, GUI_DISP_WIDTH - 7, y + 6, 1);
				disp.DrawLine(GUI_DISP_WIDTH - 6, y + 5, GUI_DISP_WIDTH - 4, y + 3, 1);
			}
		}

		//disabled entry
		if (flags & GUI_LIST_DISABLED)
		{
			for (uint8_t cx = 0; cx < GUI_DISP_WIDTH - 1; cx++)
				for (uint8_t cy = y + cx % 2 + 1; cy < y + t_h; cy += 2)
					disp.PutPixel(cx, cy, 0);
		}

		//selector
		if (gui_list_index[gui_task] == i)
		{
			disp.Invert(0, y, GUI_DISP_WIDTH - 1, y + height - 1);
			disp.PutPixel(0, y, 0);
			disp.PutPixel(GUI_DISP_WIDTH - 1, y, 0);
			disp.PutPixel(GUI_DISP_WIDTH - 1, y + height - 1, 0);
			disp.PutPixel(0, y + height - 1, 0);
		}

		if ((flags & GUI_LIST_T_MASK) == GUI_LIST_TITLE)
		{
			//restore font
			disp.LoadFont(F_TEXT_M);
			t_h = disp.GetTextHeight();
		}

		y += height;
		total_height += height;
	}
}
Ejemplo n.º 22
0
// ---------------------------------------------------------------------------
// --- Main loop update ------------------------------------------------------
// ---------------------------------------------------------------------------
void PLabFileServer::update() {
	// Main loop.
	// Check if we have any new connections
	EthernetClient client = available();
	if (client) {
		if (out) {
			out->println();
			// Buffer is initially considered empty
			strcpy_P(bigBuf, plabRequest);
			out->println(bigBuf);
			out->println();
		}

		if (filter) {
			filter->start();
		}

		// We should now start parsing our request
		RequestState_t state = REQ_START;
		RequestMethod_t method = METH_NOT_SUPPORTED;
		int indexTracker = 0;
		// While we still have an open connection to the client
		while (client.connected()) {
			if (client.available()) {
				char c = client.read();
				if (out) {
					out->write(c);
				}
				state = reqStateTransition(state, c, indexTracker, method);
			}
			// By default we assume we have answered.
			bool answered = true;
			// Configuring answer, if we have any yet.
			switch (state) {
			case REQ_MESSAGE_BODY:
				if (out) {
					out->println();
					// Safe to overwrite buffer: it should not contain anything
					strcpy_P(bigBuf, plabResponse);
					out->println(bigBuf);
					out->println();
				}
				// GET and HEAD discard request body in this server
				// Currently this (HEAD and GET) covers every possibility.
				if (method == METH_HEAD || method == METH_GET) {
					if (userControlledResponse) {
						if (filter)
							filter->writeResponse(client);
					}
					else {
						// The exact same header
						strcpy_P(bigBuf, plabHeaderHttp);
						if (filter)
							filter->filterResponseHeader(bigBuf, client);
						cPrint(bigBuf, client);
						strcpy_P(bigBuf, plab200OK);
						if (filter)
							filter->filterResponseHeader(bigBuf, client);
						cPrintln(bigBuf, client);
						if (internalMIMEIndex >= 0) {
							strcpy_P(bigBuf, plabContentType);
							if (filter)
								filter->filterResponseHeader(bigBuf, client);
							cPrint(bigBuf, client);
							strcpy_P(bigBuf, (char*)pgm_read_word(&(plabMIMETypeTable[internalMIMEIndex])));
							if (filter)
								filter->filterResponseHeader(bigBuf, client);
							cPrintln(bigBuf, client);
						}
						strcpy_P(bigBuf, plabConnectionClose);
						if (filter)
							filter->filterResponseHeader(bigBuf, client);
						cPrintln(bigBuf, client);
						// TODO Additional user defined header fields
						cPrintln("", client);	// HEADER stop
						if (method == METH_GET) {
							// Rediricting file location
							if (filter)
								filter->redirectReplyFile(sdFile);
#ifdef PLAB_DEBUG
							if (out)
								out->println("GET response");
#endif // PLAB_DEBUG
							// ONLY get has message body
							// TODO User defined body write
							if (sdFile) {
								while (sdFile.available()) {
									char c = sdFile.read();
									if (filter) {
										if (filter->filterResponse(c, client))
											cWrite(c, client);
									}
									else
										cWrite(c, client);
								}
								sdFile.close();
							}
#ifdef PLAB_DEBUG
							else if (out)
								out->println("File not open!");
#endif // PLAB_DEBUG
						}
					}
				}
				break;

				// TODO Better error treatment
			case BAD_REQ_400:
				printDefaultError(400, client);
				break;
			case NOT_FOUND_404:
				printDefaultError(404, client);
				break;
			case METHOD_NOT_ALLOWED_405:
				printDefaultError(405, client);
				break;
			case REQUEST_URI_TOO_LONG_414:
				printDefaultError(414, client);
				break;
			case INTERNAL_SERVER_ERROR_500:
				printDefaultError(500, client);
				break;
			case NOT_IMPLEMENTED_501:
				printDefaultError(501, client);
				break;
			case HTTP_VERSION_NOT_SUPPORTED_505:
				printDefaultError(505, client);
				break;

			default:
				// No other state (as of yet) produces an answer
				answered = false;
			}

			// Clean, if need be
			if (answered) {
				if (sdFile) {
					sdFile.close();
				}

				// Client should have some time to process answer
				delay(1);

				client.stop();
				client.flush();
			}
		}
		if (filter)
			filter->end();
	}
}
Ejemplo n.º 23
0
void vCommandConsoleTask( void *pvParameters )
{
(void)pvParameters;
unsigned portCHAR cRxedChar, cInputIndex = 0;
portBASE_TYPE xMoreDataToFollow;
/* The input and output buffers are declared static to keep them off the stack. */
portCHAR *pcOutputString;
static unsigned portCHAR pcInputString[ MAX_INPUT_LENGTH ];

    /* This code assumes the peripheral being used as the console has already 
    been opened and configured, and is passed into the task as the task
    parameter.  Cast the task parameter to the correct type. */
	pcOutputString = (portCHAR *) FreeRTOS_CLIGetOutputBuffer();

	strcpy_P(pcOutputString, pm_cstr_WelcomeMessage);
	
    /* Send a welcome message to the user knows they are connected. */
    FreeRTOS_write( pcOutputString, strlen(pcOutputString) );

    for( ;; )
    {
        /* This implementation reads a single character at a time.  Wait in the
        Blocked state until a character is received. */
        FreeRTOS_read( &cRxedChar, sizeof( cRxedChar ) );

        if( cRxedChar == '\n' )
        {
            /* A newline character was received, so the input command stirng is
            complete and can be processed.  Transmit a line separator, just to 
            make the output easier to read. */
            FreeRTOS_write( "\r\n", strlen( "\r\n" ));

            /* The command interpreter is called repeatedly until it returns 
            pdFALSE.  See the "Implementing a command" documentation for an 
            exaplanation of why this is. */
            do
            {
                /* Send the command string to the command interpreter.  Any
                output generated by the command interpreter will be placed in the 
                pcOutputString buffer. */
				FreeRTOS_CLITakeOutputBuffer();
                xMoreDataToFollow = FreeRTOS_CLIProcessCommand
                              (     
                                  (const int8_t * const)pcInputString,   /* The command string.*/
                                  (int8_t *)pcOutputString,  /* The output buffer. */
                                  configCOMMAND_INT_MAX_OUTPUT_SIZE/* The size of the output buffer. */
                              );

                /* Write the output generated by the command interpreter to the 
                console. */
                FreeRTOS_write( pcOutputString, strlen(pcOutputString ) );
				FreeRTOS_CLIGiveOutputBuffer();
            } while( xMoreDataToFollow != pdFALSE );

            /* All the strings generated by the input command have been sent.
            Processing of the command is complete.  Clear the input string ready 
            to receive the next command. */
            cInputIndex = 0;
            memset( pcInputString, 0x00, MAX_INPUT_LENGTH );
        }
        else
        {
            /* The if() clause performs the processing after a newline character
            is received.  This else clause performs the processing if any other
            character is received. */
		
            if( cRxedChar == '\r' )
            {
                /* Ignore carriage returns. */
            }
            else if( cRxedChar == '\b' )
            {
                /* Backspace was pressed.  Erase the last character in the input
                buffer - if there are any. */
                if( cInputIndex > 0 )
                {
                    cInputIndex--;
                    pcInputString[ cInputIndex ] = '\0';
                }
            }
            else
            {
                /* A character was entered.  It was not a new line, backspace
                or carriage return, so it is accepted as part of the input and
                placed into the input buffer.  When a \n is entered the complete
                string will be passed to the command interpreter. */
                if( cInputIndex < MAX_INPUT_LENGTH )
                {
                    pcInputString[ cInputIndex ] = cRxedChar;
                    cInputIndex++;
                }
            }
        }
    }
}        
Ejemplo n.º 24
0
void PLabFileServer::printDefaultError(int errorCode, EthernetClient &client) {
	if (out) {
		out->println();
		strcpy_P(bigBuf, plabResponse);
		out->println(bigBuf);
		out->println();
	}
	// Load error code and message
	switch (errorCode) {
	case 400:
		strcpy_P(bigBuf, plab400BadRequest);
		break;
	case 404:
		strcpy_P(bigBuf, plab404NotFound);
		break;
	case 405:
		strcpy_P(bigBuf, plab405MethodNotAllowed);
		break;
	case 414:
		strcpy_P(bigBuf, plab414RequestUriTooLarge);
		break;
	case 501:
		strcpy_P(bigBuf, plab501NotImplemented);
		break;
	case 505:
		strcpy_P(bigBuf, plab505HttpVersionNotSupported);
		break;
	case 500:
		// Fallthrough
	default:
		strcpy_P(bigBuf, plab500InternalServerError);
		break;
	}
	// Find end of string. We know the first character is not empty
	char *htmlString = bigBuf;
	// Postfix increment: point to first element AFTER \0 character
	while (*(htmlString++) != '\0');

	// Header
	strcpy_P(htmlString, plabHeaderHttp);
	cPrint(htmlString, client);
	cPrintln(bigBuf, client);
	strcpy_P(htmlString, plabContentType);
	cPrint(htmlString, client);
	strcpy_P(htmlString, plabHtmlMIMEType);
	cPrintln(htmlString, client);
	strcpy_P(htmlString, plabConnectionClose);
	cPrintln(htmlString, client);
	cPrintln("", client);

	// html
	strcpy_P(htmlString, plabHtml1);
	cPrintln(htmlString, client);
	cPrintln(bigBuf, client);
	strcpy_P(htmlString, plabHtml2);
	cPrintln(htmlString, client);
	cPrintln(bigBuf, client);
	strcpy_P(htmlString, plabHtml3);
	cPrintln(htmlString, client);
}
Ejemplo n.º 25
0
static char* tune_item_callback(uint8_t nr)
{
    char* c = (char*)lcd_cache;
    if (nr == 0)
        strcpy_P(c, PSTR("< RETURN"));
    else if (nr == 1)
    {
        if (!card.pause)
        {
            if (movesplanned() > 0)
                strcpy_P(c, PSTR("Pause"));
            else
                strcpy_P(c, PSTR("Can not pause"));
        }
        else
        {
            if (movesplanned() < 1)
                strcpy_P(c, PSTR("Resume"));
            else
                strcpy_P(c, PSTR("Pausing..."));
        }
    }
    else if (nr == 2)
        strcpy_P(c, PSTR("Speed"));
    else if (nr == 3)
        strcpy_P(c, PSTR("Temperature"));
#if EXTRUDERS > 1
    else if (nr == 4)
        strcpy_P(c, PSTR("Temperature 2"));
#endif
    else if (nr == 3 + EXTRUDERS)
        strcpy_P(c, PSTR("Buildplate temp."));
    else if (nr == 4 + EXTRUDERS)
        strcpy_P(c, PSTR("Fan speed"));
    else if (nr == 5 + EXTRUDERS)
        strcpy_P(c, PSTR("Material flow"));
#if EXTRUDERS > 1
    else if (nr == 6 + EXTRUDERS)
        strcpy_P(c, PSTR("Material flow 2"));
#endif
    else if (nr == 5 + EXTRUDERS * 2)
        strcpy_P(c, PSTR("Retraction"));
    else if (nr == 6 + EXTRUDERS * 2)
        strcpy_P(c, PSTR("LED Brightness"));
    return c;
}
Ejemplo n.º 26
0
void IIClcd::print_P(const char * str) { // print a string stored in PROGMEM
	char buf[21]; // create buffer in RAM
	strcpy_P(buf, str); // copy string to RAM
	print(buf); // print from RAM
}
	int PortMapClass::addPortMapRequest(IPAddress myIP, uint16_t requestedIntPort, uint16_t requestedExtPort)
	{

		if (_apmClient.connect(igdIp(), igdPort()))
		{
			char * buffer = (char *) malloc (448);
            memset(buffer, 0, 448);
            char * smallbuffer = (char *) malloc (8);
    		memset(smallbuffer, 0,8);

    		strcpy_P(buffer, PM_HEADER1A);

            // convert control URL from string to char array and append to buffer contents
            String controlUrlString = igdControlUrl();
            char controlUrlStringArray[controlUrlString.length()+1];
            controlUrlString.toCharArray(controlUrlStringArray, sizeof(controlUrlStringArray));
            strcat(buffer, controlUrlStringArray);

            strcat_P(buffer, PM_HEADER1B);

            // convert igd IP address to char array and append to buffer contents
            IPAddress igdIpAddress = igdIp();
            strcat(buffer, itoa(igdIpAddress[0], smallbuffer, 10));
            memset(smallbuffer, 0,8);
            strcat(buffer, ".");
            strcat(buffer, itoa(igdIpAddress[1], smallbuffer, 10));
            memset(smallbuffer, 0,8);
            strcat(buffer, ".");
            strcat(buffer, itoa(igdIpAddress[2], smallbuffer, 10));
            memset(smallbuffer, 0,8);
            strcat(buffer, ".");
            strcat(buffer, itoa(igdIpAddress[3], smallbuffer, 10));
            memset(smallbuffer, 0,8);
            strcat(buffer, ":");
            
            // convert igd port number to char array and append
            uint16_t igdPortNumber = igdPort();
            strcat(buffer, itoa(igdPortNumber, smallbuffer, 10));
            memset(smallbuffer, 0,8);

            strcat_P(buffer, PM_HEADER1C);

			strcat_P(buffer, PM_BODY1);

			strcat_P(buffer, PM_BODY2);

			strcat_P(buffer, PM_BODY3);

			strcat_P(buffer, PM_BODY4);

			strcat_P(buffer, PM_BODY5);
			
			strcat_P(buffer, PM_BODY6A);

            strcat(buffer, itoa(requestedExtPort, smallbuffer, 10));
            memset(smallbuffer, 0,8);
			
			strcat_P(buffer, PM_BODY6B);

            strcat_P(buffer, PM_BODY7);

            strcat_P(buffer, PM_BODY8A);

            strcat(buffer, itoa(requestedIntPort, smallbuffer, 10));
            memset(smallbuffer, 0,8);
           
            strcat_P(buffer, PM_BODY8B);

            strcat_P(buffer, PM_BODY9A);

            strcat(buffer, itoa(myIP[0], smallbuffer, 10));
            memset(smallbuffer, 0,8);
            strcat(buffer, ".");
            strcat(buffer, itoa(myIP[1], smallbuffer, 10));
            memset(smallbuffer, 0,8);
            strcat(buffer, ".");
            strcat(buffer, itoa(myIP[2], smallbuffer, 10));
            memset(smallbuffer, 0,8);
            strcat(buffer, ".");
            strcat(buffer, itoa(myIP[3], smallbuffer, 10));
            memset(smallbuffer, 0,8);

            strcat_P(buffer, PM_BODY9B);
            _apmClient.print(buffer);
            memset(buffer, 0,448);

            strcpy_P(buffer, PM_BODY10);
            
            strcat_P(buffer, PM_BODY11);

            strcat_P(buffer, PM_BODY12);

            strcat_P(buffer, PM_BODY13);

            strcat_P(buffer, PM_BODY14);

            strcat_P(buffer, PM_BODY15);
            _apmClient.print(buffer);

			free(buffer);
            free(smallbuffer);

			return parsePortMapResponse(requestedIntPort, requestedExtPort);

		} else {
        	// if you didn't get a connection to the server:
        	_apmClient.stop();
        	return 0;
    	}
	}
void egg_bus_get_sensor_units(uint8_t sensor_index, char * target_buffer){
    strcpy_P(target_buffer, (PGM_P)pgm_read_word(&(egg_bus_sensor_units[sensor_index])));
}
Ejemplo n.º 29
0
char* dayStr(uint8_t day) 
{
   strcpy_P(buffer, (PGM_P)pgm_read_word(&(dayNames_P[day])));
   return buffer;
}
Ejemplo n.º 30
0
/* Function: 	This function reads the data from satellites
 * Parameters:	parse.	0 to return the data string in buffer_GPRS
 * 						1 to parse data and update GPS variables
 * Returns 		1 if success
 * 				-1 if timeout
 * 				-2 if error
*/
int8_t WaspGPRS_SIM928A::getGPSData(bool parse)
{

	int8_t answer;
	int aux, counter;
	long previous;
	char aux_str[25];
	int8_t x;
	char* aux_ptr;
	
	serialFlush(_socket);
	
	strcpy_P(str_aux1, (char*)pgm_read_word(&(table_GPS[1])));		//GNSS_INFO
	snprintf(str_aux2, sizeof(str_aux2), "%s: ", str_aux1);
	answer = sendCommand2(str_aux1, str_aux2, ERROR);	
	
	if (answer == 1)
	{
		previous = millis();
		answer = 0;
		counter = 0;
		do{
			// Gets number of available bytes 
			do{
				aux = serialAvailable(_socket);
				
				//avoid millis overflow problem
				if( millis() < previous ) previous = millis(); 
				
			}while((aux == 0) && ((millis()-previous) < 3000));
			
			#if GPRS_debug_mode>0
				USB.print(F("Available bytes: "));
				USB.println(aux, DEC);
			#endif
				
			// Gets available bytes
			while (aux > 0){
				
				if (counter < 0)
				{
					// Skips first 2 bytes (\r\n)
					serialRead(_socket);
				}
				else if(counter < BUFFER_SIZE)
				{
					buffer_GPRS[counter] = serialRead(_socket);
				}
				else
				{
					serialRead(_socket);	
				}
				counter++;
				aux--;
			}
			
			buffer_GPRS[counter] = '\0';
			
			// check if the buffer_GPRS contains "OK"
			if (strstr(buffer_GPRS, "OK") != NULL)    
			{
					answer = 1;
			}
			
			//avoid millis overflow problem
			if( millis() < previous ) previous = millis(); 
				
		}while((answer == 0) && ((millis()-previous) < 3000));
		
		
		
	}
	else if (answer == 2)
	{
		return -2;
	}
	else
	{
		return -1;
	}

	buffer_GPRS[counter - 4] = '\0';

	if (parse == 1)
	{			
		#if GPRS_debug_mode>0
			USB.println(buffer_GPRS);
		#endif
		GPS_status = atoi(strtok(buffer_GPRS, ",")); // Gets fix status
		fix_status = atoi(strtok(NULL, ",")); // Gets fix status
		strcpy(aux_str,strtok(NULL, ",")); // Gets date and time
		
		memset(date, '\0', sizeof(date));
		strncpy(date, aux_str, 8);		
		memset(UTC_time, '\0', sizeof(UTC_time));
		strncpy(UTC_time, aux_str+ 8, 6);
		
		latitude = atof(strtok(NULL, ",")); // Gets latitude
		longitude = atof(strtok(NULL, ",")); // Gets longitude
		altitude = atof(strtok(NULL, ",")); // Gets altitude
		speedOG = atof(strtok(NULL, ",")); // Gets speed over ground. Unit is knots.
		courseOG = atof(strtok(NULL, ",")); // Gets course
		
		mode = atoi(strtok(NULL, ",")); // Gets mode
		
		HDOP = atof(strtok(NULL, ",")); // Gets HDOP
		PDOP = atof(strtok(NULL, ",")); // Gets PDOP
		VDOP = atof(strtok(NULL, ",")); // Gets VDOP
		
		sats_in_view = atoi(strtok(NULL, ",")); // Gets sats_in_view
		sats_in_use = atoi(strtok(NULL, ",")); // Gets sats_in_use
		SNR = atoi(strtok(NULL, ",")); // Gets SNR
		
		#if GPRS_debug_mode>0
			USB.print(F("GPS_status: "));
			USB.println(GPS_status, DEC);
			USB.print(F("fix_status: "));
			USB.println(fix_status, DEC);
		
			USB.print(F("Latitude (in degrees): "));
			USB.println(latitude);
			USB.print(F("Longitude (in degrees): "));
			USB.println(longitude);
			USB.print(F("Date: "));
			USB.print(date);
			USB.print(F("   UTC_time: "));
			USB.println(UTC_time);
			USB.print(F("Altitude: "));
			USB.println(altitude);
			USB.print(F("SpeedOG: "));
			USB.println(speedOG);
			USB.print(F("Course: "));
			USB.println(courseOG);

			USB.print(F("Satellites in view: "));
			USB.println(sats_in_view, DEC); 
			USB.print(F("Satellites in use: "));
			USB.println(sats_in_use, DEC);


			USB.print(F("Mode: "));
			USB.println(mode,DEC);   
			USB.print(F("SNR: "));
			USB.println(SNR,DEC);      


			USB.print("PDOP: ");
			USB.println(PDOP);
			USB.print("HDOP: ");
			USB.println(HDOP);
			USB.print("VDOP: ");
			USB.println(VDOP);
		#endif
	}
	
	return 1;	
}