Пример #1
0
/**
 * \brief Main entry of example application
 */
int main(void)
{
	/**
	 * Starts off by initializing the system clock before configuring the
	 * board and the monochrome graphical system.
	 */
	system_init();
	gfx_mono_init();

	uint8_t start_line_address = 0;
	uint8_t scroll = 0;
	uint32_t line = 0;

	/**
	 * After initialization the example will write the Star Wars opening scrolling text.
	 * Use the system font sysfont. Afterwards the text will be scrolled forever.
	 */

	while (true) {
		if (++start_line_address%8 == 0) {
			scroll = 1;
			gfx_mono_draw_string(string[line%LINES],0, ((line)%8)*8, &sysfont);
			line++;
		} else if (start_line_address % 7 != 0) {
			delay_ms(100);
		}

		if ( scroll != 0 ) {
			ssd1306_set_display_start_line_address(start_line_address-8);
		} else {
			gfx_mono_draw_string(string[line%LINES],0, ((line)%8)*8, &sysfont);
			line++;
		}
	}
}
Пример #2
0
/**
 * \brief Initialize SSD1306 controller and LCD display.
 * It will also write the graphic controller RAM to all zeroes.
 *
 * \note This function will clear the contents of the display.
 */
void gfx_mono_ssd1306_init(void)
{
	uint8_t page;
	uint8_t column;

#ifdef CONFIG_SSD1306_FRAMEBUFFER
	gfx_mono_set_framebuffer(framebuffer);
#endif

	/* Initialize the low-level display controller. */
	ssd1306_init();

	/* Set display to output data from line 0 */
	ssd1306_set_display_start_line_address(0);

	/* Clear the contents of the display.
	 * If using a framebuffer (SPI interface) it will both clear the
	 * controller memory and the framebuffer.
	 */
	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		for (column = 0; column < GFX_MONO_LCD_WIDTH; column++) {
			gfx_mono_ssd1306_put_byte(page, column, 0x00, true);
		}
	}
}
Пример #3
0
 int main(void)
 {
     uint8_t page_address;
     uint8_t column_address;
     uint8_t start_line_address = 0;
     volatile uint16_t delay = 10000;
 
     board_init();
     sysclk_init();
 
     // Initialize SPI and SSD1306 controller
     ssd1306_init();
 
     // set addresses at beginning of display
     ssd1306_set_page_address(0);
     ssd1306_set_column_address(0);
 
     // fill display with lines
     for (page_address = 0; page_address <= 4; page_address++) {
         ssd1306_set_page_address(page_address);
         for (column_address = 0; column_address < 128; column_address++) {
             ssd1306_set_column_address(column_address);
             /* fill every other pixel in the display. This will produce
             horizontal lines on the display. */
             ssd1306_write_data(0x6F);
         }
     }
 
     // scroll the display using hardware support in the LCD controller
     while (true) {
         ssd1306_set_display_start_line_address(start_line_address++);
        clock_delay_msec(250);
     }
 }
Пример #4
0
int main(void)
{
	//! the page address to write to
	uint8_t page_address;
	//! the column address, or the X pixel.
	uint8_t column_address;
	//! store the LCD controller start draw line
	uint8_t start_line_address = 0;

	board_init();
	sysclk_init();

	// Initialize SPI and SSD1306 controller
	ssd1306_init();

	// set addresses at beginning of display
	ssd1306_set_page_address(0);
	ssd1306_set_column_address(0);

	// fill display with lines
	for (page_address = 0; page_address <= 7; page_address++) {
		ssd1306_set_page_address(page_address);
		for (column_address = 0; column_address < 128; column_address++) {
			ssd1306_set_column_address(column_address);
			/* fill every other pixel in the display. This will produce
			horizontal lines on the display. */
			ssd1306_write_data(0x6F);
		}
	}

	// scroll the display using hardware support in the LCD controller
	while (true) {
		ssd1306_set_display_start_line_address(start_line_address++);
		delay_ms(250);
	}
}
Пример #5
0
/**
 * \brief Main demo task
 *
 * This task keeps track of which screen the user has selected, which tasks
 * to resume/suspend to draw the selected screen, and also draws the menu bar.
 *
 * The menu bar shows which screens the user can select by clicking the
 * corresponding buttons on the OLED1 Xplained Pro:
 * - \ref graph_task() "graph" (selected at start-up)
 * - \ref terminal_task() "term."
 * - \ref about_task() "about"
 *
 * \param params Parameters for the task. (Not used.)
 */
static void main_task(void *params)
{
	bool graph_buffer_initialized = false;
	bool selection_changed = true;
	bool select_graph_buffer;
	enum menu_items current_selection = MENU_ITEM_GRAPH;
	gfx_coord_t x, y, display_y_offset;
	xTaskHandle temp_task_handle = NULL;

	for(;;) {
		// Show that task is executing
		oled1_set_led_state(&oled1, OLED1_LED3_ID, true);

		// Check buttons to see if user changed the selection
		if (oled1_get_button_state(&oled1, OLED1_BUTTON1_ID)
					&& (current_selection != MENU_ITEM_GRAPH)) {
			current_selection = MENU_ITEM_GRAPH;
			selection_changed = true;
		} else if (oled1_get_button_state(&oled1, OLED1_BUTTON2_ID)
					&& (current_selection != MENU_ITEM_TERMINAL)) {
			current_selection = MENU_ITEM_TERMINAL;
			selection_changed = true;
		} else if (oled1_get_button_state(&oled1, OLED1_BUTTON3_ID)
					&& (current_selection != MENU_ITEM_ABOUT)) {
			current_selection = MENU_ITEM_ABOUT;
			selection_changed = true;
		}

		// If selection changed, handle the selection
		if (selection_changed) {
			// Wait for and take the display semaphore before doing any changes.
			xSemaphoreTake(display_mutex, portMAX_DELAY);

			// We can now safely suspend the previously resumed task
			if (temp_task_handle) {
				vTaskSuspend(temp_task_handle);
				temp_task_handle = NULL;
			}

			// Select the new drawing task and corresponding display buffer
			switch (current_selection) {
			case MENU_ITEM_GRAPH:
				// Graph task runs continuously, no need to set task handle
				select_graph_buffer = true;
				break;

			case MENU_ITEM_TERMINAL:
				temp_task_handle = terminal_task_handle;
				select_graph_buffer = false;
				break;

			default:
			case MENU_ITEM_ABOUT:
				temp_task_handle = about_task_handle;
				select_graph_buffer = false;
			}

			// Select and initialize display buffer to use.
			display_y_offset = select_graph_buffer ? CANVAS_GRAPH_Y_OFFSET : 0;

			// Draw the menu bar (only needs to be done once for graph)
			if (!select_graph_buffer || !graph_buffer_initialized) {
				// Clear the selected display buffer first
				gfx_mono_draw_filled_rect(0, display_y_offset,
						GFX_MONO_LCD_WIDTH, GFX_MONO_LCD_HEIGHT / 2,
						GFX_PIXEL_CLR);

				// Draw menu lines, each item with height MENU_HEIGHT pixels
				y = display_y_offset + CANVAS_HEIGHT;
				gfx_mono_draw_horizontal_line(0, y, GFX_MONO_LCD_WIDTH,
						GFX_PIXEL_SET);

				x = MENU_ITEM_WIDTH;
				y++;

				for (uint8_t i = 0; i < (MENU_NUM_ITEMS - 1); i++) {
					gfx_mono_draw_vertical_line(x, y, MENU_HEIGHT,
							GFX_PIXEL_SET);
					x += 1 + MENU_ITEM_WIDTH;
				}

				// Highlight the current selection
				gfx_mono_draw_rect(current_selection * (1 + MENU_ITEM_WIDTH), y,
						MENU_ITEM_WIDTH, MENU_HEIGHT, GFX_PIXEL_SET);

				// Draw the menu item text
				x = (MENU_ITEM_WIDTH / 2) - ((5 * SYSFONT_WIDTH) / 2);
				y += (MENU_HEIGHT / 2) - (SYSFONT_HEIGHT / 2);

				for (uint8_t i = 0; i < MENU_NUM_ITEMS; i++) {
					gfx_mono_draw_string(menu_items_text[i], x, y, &sysfont);
					x += 1 + MENU_ITEM_WIDTH;
				}

				graph_buffer_initialized = true;
			}

			// Set display controller to output the new buffer
			ssd1306_set_display_start_line_address(display_y_offset);

			// We are done modifying the display, so give back the mutex
			xSemaphoreGive(display_mutex);

			selection_changed = false;

			// If a task handle was specified, resume it now
			if (temp_task_handle) {
				vTaskResume(temp_task_handle);
			}
		}

		// Show that task is done
		oled1_set_led_state(&oled1, OLED1_LED3_ID, false);

		vTaskDelay(MAIN_TASK_DELAY);
	}
}
Пример #6
0
int main(void)
{
	//
	asm("nop");
	rtc_init();


	//changing the clock to 32MHz
	enable_oscillator(OSC_RC32MEN_bm);
	sysclk_prescaler(CLK_PSADIV_1_gc,CLK_PSBCDIV_1_1_gc);
	sysclk_source(CLK_SCLKSEL_RC32M_gc);

	usart_config(&USARTC0,&PORTC,USART_CMODE_ASYNCHRONOUS_gc,USART_PMODE_DISABLED_gc,USART_CHSIZE_8BIT_gc,false,false);
	usart_baud(&USARTC0,9600,-3);
	FILE my_stdio;
	create_file_stream(&my_stdio,&USARTC0_putchar,&USARTC0_getchar);
	set_stdio_stream(&my_stdio);



	port_direction_set_mask(&PORTR,1<<0);

	uint8_t page;
	uint8_t column;

	gfx_mono_set_framebuffer(framebuffer);

	ssd1306_init();
	ssd1306_clear();

	ssd1306_set_display_start_line_address(0);


	for (page = 0; page < GFX_MONO_LCD_PAGES; page++) {
		for (column = 0; column < GFX_MONO_LCD_WIDTH; column++) {
			gfx_mono_ssd1306_put_byte(page, column, 0x00, 1);
		}
	}

	ssd1306_set_page_address(0);
	ssd1306_write_text("EMON");

	rtc_ms_delay(1000);

	lcd_line_print(0,"EMON YOU ROCK");

	esp8266_serial_init();

	printf("starting system\n");
	
	printf("-----------------------------------------------------------\n");

#define mqtt_callback_on_message "function(conn, topic, data) print(topic .. \":\" ) if data ~= nil then print(data) end end"

// 
	//esp8266_getmode();
	esp8266_setmode(ESP8266_WIFI_MODE_STATION);
	esp8266_available_AP_t myAPdata[10];
	int n = esp8266_sta_getap(3000,myAPdata);
	
	for(int i=0;i<n;i++){
		printf("available ssid : %s\n" , myAPdata[i].BSSID);
	}
	
	
	esp8266_sta_config("Emon","19031992",NULL,NULL);
	printf("\nthe wifi mode is %d\n", esp8266_getmode());
	esp8266_sta_getmac();

 
  	//esp8266_uart_setup(0,9600,8,ESP8266_UART_PARITY_NONE,ESP8266_UART_STOPBITS_1,0);
// 
 	esp8266_sta_getip();
 	esp8266_sta_get_status();
	lcd_line_print(0,"HABIBUR RAHMAN");
// 	
	esp8266_mqtt_create_client("m","clientid", 30 , "user", "password");
	esp8266_mqtt_client_connect("m","emon.dlinkddns.com",9000,0,"function(conn) print(\"m:connected\") end");
	esp8266_mqtt_client_subscribe("m","sky2",0,"function(conn) print(\"subscribed\") end");
	esp8266_mqtt_client_callback_on_message("m",mqtt_callback_on_message);
	
	
	esp8266_mqtt_create_client("n","clientid", 30 , "user", "password");
	esp8266_mqtt_client_connect("n","broker.hivemq.com",1883,0,"function(conn) print(\"n:connected\") end");
	esp8266_mqtt_client_subscribe("n","dog",0,"function(conn) print(\"subscribed\") end");
	esp8266_mqtt_client_callback_on_message("n",mqtt_callback_on_message);
	
	int i=0;
	char numstr[30];
	char mydata[100];  
	char mydata2[100]; 
	
	char tempcmd[50]; 
	char tempdata[100];  
	while (1)
    {

		esp8266_rx_buff_receive(mydata);
		if(!strcmp(mydata, "sky2:\r\nkaminey\r\n")){
			printf("\n\n******f**k you*****\n\n");
			
			esp8266_mqtt_client_publish("m","sky","test reply .. by emon",0,0,"function(conn) print(\"sent\") end");
			printf(mydata2);
		}
		else if(!strcmp(mydata, "m:connected\r\n")){
			printf("RECONNECTING NOWWWWW!!!");
			
			esp8266_mqtt_client_subscribe("m","sky2",0,"function(conn) print(\"subscribed\") end");

		}
		else if(!strcmp(mydata, "n:connected\r\n")){
			printf("RECONNECTING NOW!!!");
					
			esp8266_mqtt_client_subscribe("n","dog",0,"function(conn) print(\"subscribed\") end");

		}
		printf(mydata);
		ssd1306_clear();
		ssd1306_set_page_address(0);
		ssd1306_write_text(mydata);
		
		
	}

}