Index: asp3_tinet_ecnl_arm/trunk/app4_aircon/src/echonet_main.c
===================================================================
--- asp3_tinet_ecnl_arm/trunk/app4_aircon/src/echonet_main.c	(revision 352)
+++ asp3_tinet_ecnl_arm/trunk/app4_aircon/src/echonet_main.c	(revision 364)
@@ -1,7 +1,7 @@
 /*
  *  TOPPERS ECHONET Lite Communication Middleware
- * 
+ *
  *  Copyright (C) 2014 Cores Co., Ltd. Japan
- * 
+ *
  *  上記著作権者は，以下の(1)～(4)の条件を満たす場合に限り，本ソフトウェ
  *  ア（本ソフトウェアを改変したものを含む．以下同じ）を使用・複製・改
@@ -26,5 +26,5 @@
  *      由に基づく請求からも，上記著作権者およびTOPPERSプロジェクトを
  *      免責すること．
- * 
+ *
  *  本ソフトウェアは，無保証で提供されているものである．上記著作権者お
  *  よびTOPPERSプロジェクトは，本ソフトウェアに関して，特定の使用目的
@@ -32,9 +32,9 @@
  *  アの利用により直接的または間接的に生じたいかなる損害に関しても，そ
  *  の責任を負わない．
- * 
+ *
  *  @(#) $Id$
  */
 
-/* 
+/*
  *  サンプルプログラム(1)の本体
  */
@@ -55,4 +55,12 @@
 #include "adafruit_st7735.h"
 #include "draw_font.h"
+#include <tinet_defs.h>
+#include <tinet_config.h>
+#include <netinet/in.h>
+#include <netinet/in_var.h>
+#include <net/ethernet.h>
+#include <net/if_var.h>
+
+extern uint8_t mac_addr[6];
 
 /* TODO: メーカーコードを設定 */
@@ -184,10 +192,10 @@
 
 	/* サイズが１以外は受け付けない */
-	if(size != 1)
+	if (size != 1)
 		return 0;
 
 	*anno = *((uint8_t *)item->exinf) != *((uint8_t *)src);
 
-	switch(*(uint8_t *)src){
+	switch (*(uint8_t *)src) {
 	/* ONの場合 */
 	case 0x30:
@@ -198,5 +206,5 @@
 		data[0] = 0x80;
 		ret = ecn_brk_wai(data, sizeof(data));
-		if(ret != E_OK){
+		if (ret != E_OK) {
 			syslog(LOG_ERROR, "ecn_brk_wai");
 			return 2;
@@ -217,10 +225,10 @@
 {
 	/* サイズが１以外は受け付けない */
-	if(size != 1)
+	if (size != 1)
 		return 0;
 
 	*anno = *((uint8_t *)item->exinf) != *((uint8_t *)src);
 
-	switch(*(uint8_t *)src){
+	switch (*(uint8_t *)src) {
 	/* 異常発生ありの場合 */
 	case 0x41:
@@ -246,8 +254,8 @@
 
 	/* サイズが1以外は受け付けない */
-	if(size != 1)
+	if (size != 1)
 		return 0;
 
-	switch(*(uint8_t *)src){
+	switch (*(uint8_t *)src) {
 	/* 自動の場合 */
 	case 0x41:
@@ -266,5 +274,5 @@
 		data[0] = 0xB0;
 		ret = ecn_brk_wai(data, sizeof(data));
-		if(ret != E_OK){
+		if (ret != E_OK) {
 			syslog(LOG_ERROR, "ecn_brk_wai");
 			return 2;
@@ -288,14 +296,14 @@
 
 	/* サイズが1以外は受け付けない */
-	if(size != 1)
+	if (size != 1)
 		return 0;
 
 	/* 0℃～50℃ */
-	if((*(uint8_t *)src >= 0x00) && (*(uint8_t *)src <= 0x32)){
+	if ((*(uint8_t *)src >= 0x00) && (*(uint8_t *)src <= 0x32)) {
 		*((uint8_t *)item->exinf) = *((uint8_t *)src);
 		/* メインタスクに通知 */
 		data[0] = 0xB3;
 		ret = ecn_brk_wai(data, sizeof(data));
-		if(ret != E_OK){
+		if (ret != E_OK) {
 			syslog(LOG_ERROR, "ecn_brk_wai");
 			return 2;
@@ -303,5 +311,5 @@
 	}
 	/* 上記以外は受け付けない */
-	else{
+	else {
 		return 0;
 	}
@@ -333,10 +341,10 @@
 
 	ret2 = get_tim(&now);
-	if (ret2 != E_OK){
+	if (ret2 != E_OK) {
 		syslog(LOG_ERROR, "get_tim");
 		return;
 	}
 
-	for(;;){
+	for (;;) {
 		prev = now;
 
@@ -346,5 +354,5 @@
 		/* 応答電文待ち */
 		ret = ecn_trcv_esv(&esv, timer);
-		if ((ret != E_OK) && (ret != E_BRK) && (ret != E_TMOUT)){
+		if ((ret != E_OK) && (ret != E_BRK) && (ret != E_TMOUT)) {
 			syslog(LOG_ERROR, "ecn_trcv_esv");
 			break;
@@ -352,5 +360,5 @@
 
 		ret2 = get_tim(&now);
-		if (ret2 != E_OK){
+		if (ret2 != E_OK) {
 			syslog(LOG_ERROR, "get_tim");
 			break;
@@ -367,5 +375,5 @@
 			/* 領域解放 */
 			ret = ecn_rel_esv(esv);
-			if (ret != E_OK){
+			if (ret != E_OK) {
 				syslog(LOG_ERROR, "ecn_rel_esv");
 				break;
@@ -376,5 +384,5 @@
 			/* 応答電文待ちの割り込みデータ取得 */
 			ret = ecn_get_brk_dat(esv, brkdat, sizeof(brkdat), &len);
-			if (ret != E_OK){
+			if (ret != E_OK) {
 				syslog(LOG_ERROR, "ecn_get_brk_dat");
 				break;
@@ -386,5 +394,5 @@
 			/* 領域解放 */
 			ret = ecn_rel_esv(esv);
-			if (ret != E_OK){
+			if (ret != E_OK) {
 				syslog(LOG_ERROR, "ecn_rel_esv");
 				break;
@@ -397,6 +405,4 @@
 }
 
-bool_t started = false;
-
 void echonet_change_netif_link(uint8_t link_up, uint8_t up)
 {
@@ -406,14 +412,10 @@
 		return;
 
-	if (up && !started) {
-		started = true;
-
-		/* ECHONETミドルウェアを起動 */
-		ret = ecn_sta_svc();
-		if (ret != E_OK)
-			return;
-
-		/* ECHONETミドルウェアを起動するのを待つ */
-		dly_tsk(100);
+	if (up) {
+		/* インスタンスリスト通知の送信 */
+		ret = ecn_ntf_inl();
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "ecn_ntf_inl");
+		}
 	}
 
@@ -421,5 +423,5 @@
 	uint8_t data[2];
 	data[0] = 0x01;
-	data[1] = up ? 0x01 : 0x02;
+	data[1] = (up ? 0x01 : 0x02) | (link_up ? 0x10 : 0x20);
 	ret = ecn_brk_wai(data, sizeof(data));
 	if (ret != E_OK) {
@@ -429,5 +431,6 @@
 }
 
-enum main_state_t{
+enum main_state_t {
+	main_state_start,
 	main_state_idle,
 	main_state_search,
@@ -440,5 +443,5 @@
 
 int main_timer = TMO_FEVR;
-enum main_state_t main_state = main_state_idle;
+enum main_state_t main_state = main_state_start;
 int16_t main_ave_templ;
 bool_t main_tmp_fan_on;
@@ -470,5 +473,5 @@
 LCD_DrawProp_t drawProp;
 
-enum main_rly_state_t{
+enum main_rly_state_t {
 	main_rly_state_off,
 	main_rly_state_on
@@ -486,5 +489,6 @@
 	uint8_t btn;
 
-	/* １秒後に温度センサーを探す */
+	/* ECHONETミドルウェアを起動するのを待つ */
+	main_state = main_state_start;
 	main_timer = 1000 * 1000;
 
@@ -505,5 +509,5 @@
 	spi_init(&lcd.hspi, P10_14, P10_15, P10_12, NC);
 	spi_format(&lcd.hspi, 8, 0, 0);
-	spi_frequency(&lcd.hspi, 1000000);
+	spi_frequency(&lcd.hspi, 4000000);
 
 	gpio_init_out(&lcd.cs_pin, P10_13);
@@ -524,4 +528,5 @@
 	main_lcd_timer = 1000 * 1000;
 
+	/* メインタスクを起動 */
 	ER ret = act_tsk(MAIN_TASK);
 	if (ret != E_OK) {
@@ -537,16 +542,16 @@
 	int result = main_timer;
 
-	if((result == TMO_FEVR)
-		|| ((main_btn_timer != TMO_FEVR) && (main_btn_timer < result))){
+	if ((result == TMO_FEVR)
+		|| ((main_btn_timer != TMO_FEVR) && (main_btn_timer < result))) {
 		result = main_btn_timer;
 	}
 
-	if((result == TMO_FEVR)
-		|| ((main_lcd_timer != TMO_FEVR) && (main_lcd_timer < result))){
+	if ((result == TMO_FEVR)
+		|| ((main_lcd_timer != TMO_FEVR) && (main_lcd_timer < result))) {
 		result = main_lcd_timer;
 	}
 
-	if((result == TMO_FEVR)
-		|| ((main_rly_timer != TMO_FEVR) && (main_rly_timer < result))){
+	if ((result == TMO_FEVR)
+		|| ((main_rly_timer != TMO_FEVR) && (main_rly_timer < result))) {
 		result = main_rly_timer;
 	}
@@ -560,28 +565,28 @@
 static void main_progress(int interval)
 {
-	if(main_timer != TMO_FEVR){
+	if (main_timer != TMO_FEVR) {
 		main_timer -= interval;
-		if(main_timer < 0){
+		if (main_timer < 0) {
 			main_timer = 0;
 		}
 	}
 
-	if(main_btn_timer != TMO_FEVR){
+	if (main_btn_timer != TMO_FEVR) {
 		main_btn_timer -= interval;
-		if(main_btn_timer < 0){
+		if (main_btn_timer < 0) {
 			main_btn_timer = 0;
 		}
 	}
 
-	if(main_lcd_timer != TMO_FEVR){
+	if (main_lcd_timer != TMO_FEVR) {
 		main_lcd_timer -= interval;
-		if(main_lcd_timer < 0){
+		if (main_lcd_timer < 0) {
 			main_lcd_timer = 0;
 		}
 	}
 
-	if(main_rly_timer != TMO_FEVR){
+	if (main_rly_timer != TMO_FEVR) {
 		main_rly_timer -= interval;
-		if(main_rly_timer < 0){
+		if (main_rly_timer < 0) {
 			main_rly_timer = 0;
 		}
@@ -605,19 +610,19 @@
 
 	eobjid = ecn_get_eobj(esv);
-	if(eobjid == EOBJ_NULL){
+	if (eobjid == EOBJ_NULL) {
 		syslog(LOG_ERROR, "ecn_get_eobj");
 	}
 
 	ret = ecn_itr_ini(&enm, esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_itr_ini");
 		return;
 	}
 
-	for(;;) {
-		while((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
+	for (;;) {
+		while ((ret = ecn_itr_nxt(&enm, &epc, &pdc, p_edt)) == E_OK) {
 			switch (epc) {
 			case 0xD6:
-				switch(main_state){
+				switch (main_state) {
 				case main_state_idle:
 				case main_state_search:
@@ -630,5 +635,5 @@
 				break;
 			case 0xE0:
-				switch(main_state){
+				switch (main_state) {
 				case main_state_survey_01:
 					/* 温度センサー２温度監視 */
@@ -660,9 +665,9 @@
 			}
 		}
-		if(ret != E_BOVR){
+		if (ret != E_BOVR) {
 			syslog(LOG_ERROR, "ecn_itr_nxt");
 			break;
 		}
-		if(enm.is_eof)
+		if (enm.is_eof)
 			break;
 	}
@@ -685,5 +690,5 @@
 	/* 温度センサー動作状態取得電文作成 */
 	ret = ecn_esv_get(&esv, senserids[no - 1], 0x80);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_get");
 		return;
@@ -692,9 +697,9 @@
 	/* 温度計測値取得追加 */
 	ret = ecn_add_epc(esv, 0xE0);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_add_epc");
 
 		ret = ecn_rel_esv(esv);
-		if(ret != E_OK){
+		if (ret != E_OK) {
 			syslog(LOG_ERROR, "ecn_rel_esv");
 		}
@@ -704,5 +709,5 @@
 	/* 電文送信 */
 	ret = ecn_snd_esv(esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 	}
@@ -717,20 +722,20 @@
 	int templ = 0;
 
-	if(temp_sensor_01_data.property80 == 0x30){
+	if (temp_sensor_01_data.property80 == 0x30) {
 		templ += ((((uint16_t)temp_sensor_01_data.propertyE0) & 0xFF) << 8)
 			| ((((uint16_t)temp_sensor_01_data.propertyE0) & 0xFF00) >> 8);
 		count++;
 	}
-	if(temp_sensor_02_data.property80 == 0x30){
+	if (temp_sensor_02_data.property80 == 0x30) {
 		templ += ((((uint16_t)temp_sensor_02_data.propertyE0) & 0xFF) << 8)
 			| ((((uint16_t)temp_sensor_02_data.propertyE0) & 0xFF00) >> 8);
 		count++;
 	}
-	if(temp_sensor_03_data.property80 == 0x30){
+	if (temp_sensor_03_data.property80 == 0x30) {
 		templ += ((((uint16_t)temp_sensor_03_data.propertyE0) & 0xFF) << 8)
 			| ((((uint16_t)temp_sensor_03_data.propertyE0) & 0xFF00) >> 8);
 		count++;
 	}
-	if(temp_sensor_04_data.property80 == 0x30){
+	if (temp_sensor_04_data.property80 == 0x30) {
 		templ += ((((uint16_t)temp_sensor_04_data.propertyE0) & 0xFF) << 8)
 			| ((((uint16_t)temp_sensor_04_data.propertyE0) & 0xFF00) >> 8);
@@ -738,9 +743,9 @@
 	}
 
-	if(count > 0){
+	if (count > 0) {
 		templ = templ / count;
-		if(templ < -2732)
+		if (templ < -2732)
 			main_ave_templ = 0x8000;
-		else if(templ > 32766)
+		else if (templ > 32766)
 			main_ave_templ = 0x7FFF;
 		else
@@ -748,6 +753,6 @@
 
 		/* FANが停止中の場合 */
-		if(!main_tmp_fan_on){
-			if(main_ave_templ > (10 * home_air_conditioner_data.propertyB3 + 5)){
+		if (!main_tmp_fan_on) {
+			if (main_ave_templ > (10 * home_air_conditioner_data.propertyB3 + 5)) {
 				main_tmp_fan_on = true;
 
@@ -758,6 +763,6 @@
 		}
 		/* FANが稼働中の場合 */
-		else{
-			if(main_ave_templ < (10 * home_air_conditioner_data.propertyB3 - 5)){
+		else {
+			if (main_ave_templ < (10 * home_air_conditioner_data.propertyB3 - 5)) {
 				main_tmp_fan_on = false;
 
@@ -777,25 +782,50 @@
 static void main_break_wait(uint8_t *brkdat, int32_t len)
 {
+	char mac_text[30] = "mac: ";
+	char ipaddr_text[30] = "ipadr: ";
+	const T_IN4_ADDR *ip4_addr;
+	int pos;
+	bool_t prev;
+
 	switch (brkdat[0]) {
 	case 0x01:
-		// Link up/down
+		switch (brkdat[1] >> 4) {
+		case 1:
+			break;
+		case 2:
+			break;
+		}
+
+		pos = str_macaddr(&mac_text[4], sizeof(mac_text) - 4, mac_addr, 0);
+		mac_text[pos + 4] = '\0';
+		lcd_drawString(&lcd, mac_text, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 11), ST7735_BLACK, ST7735_WHITE);
+
+		ip4_addr = in4_get_ifaddr(0);
+		pos = str_ipv4addr(&ipaddr_text[6], sizeof(ipaddr_text) - 6, ip4_addr, 0);
+		ipaddr_text[pos + 6] = '\0';
+		lcd_drawString(&lcd, ipaddr_text, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 12), ST7735_BLACK, ST7735_WHITE);
 		break;
 	}
 
 	/* 運転モードが送風の場合、温度によらずFANをON */
-	if (*brkdat == 0xB0) {
-		bool_t prev = main_ctl_fan_on;
+	switch (*brkdat) {
+	case 0x80:
+		if (main_ctl_fan_on) {
+			/* リレー出力をON/OFF */
+			main_rly_onoff(home_air_conditioner_data.property80 == 0x30);
+		}
+		break;
+	case 0xB0:
+		prev = main_ctl_fan_on;
 		main_ctl_fan_on = home_air_conditioner_data.propertyB0 == 0x45;
 
 		if (prev != main_ctl_fan_on) {
 			if (main_ctl_fan_on) {
-				/* リレー出力をON */
-				if (!main_tmp_fan_on)
-					main_rly_onoff(true);
+				/* リレー出力をON/OFF */
+				main_rly_onoff(home_air_conditioner_data.property80 == 0x30);
 			}
 			else {
-				/* リレー出力をOFF */
-				if (!main_tmp_fan_on)
-					main_rly_onoff(false);
+				/* リレー出力をON/OFF */
+				main_rly_onoff(main_tmp_fan_on);
 			}
 		}
@@ -813,17 +843,17 @@
 static void main_timeout()
 {
-	if(main_timer == 0){
+	if (main_timer == 0) {
 		main_ontimer();
 	}
 
-	if(main_btn_timer == 0){
+	if (main_btn_timer == 0) {
 		main_btn_ontimer();
 	}
 
-	if(main_lcd_timer == 0){
+	if (main_lcd_timer == 0) {
 		main_lcd_ontimer();
 	}
 
-	if(main_rly_timer == 0){
+	if (main_rly_timer == 0) {
 		main_rly_ontimer();
 	}
@@ -834,5 +864,18 @@
 static void main_ontimer()
 {
-	switch(main_state){
+	ER ret;
+
+	switch (main_state) {
+	case main_state_start:
+		/* ECHONETミドルウェアを起動 */
+		ret = ecn_sta_svc();
+		if (ret != E_OK) {
+			syslog(LOG_ERROR, "ecn_sta_svc");
+		}
+
+		/* １秒後に温度センサーを探す */
+		main_state = main_state_idle;
+		main_timer = 1000 * 1000;
+		break;
 	case main_state_idle:
 	case main_state_search:
@@ -891,5 +934,5 @@
 	/* 温度センサー検索 */
 	ret = ecn_esv_inf_req(&esv, EOBJ_NULL, 0xD6);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_inf_req");
 		return;
@@ -898,5 +941,5 @@
 	/* 電文送信 */
 	ret = ecn_snd_esv(esv);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 	}
@@ -919,5 +962,5 @@
 	if ((btn == BUTTON_LEFT) && !main_btn1_state) {
 		main_btn1_count++;
-		if(main_btn1_count > 10){
+		if (main_btn1_count > 10) {
 			main_btn1_count = 0;
 			main_btn1_state = true;
@@ -928,5 +971,5 @@
 	else if ((btn != BUTTON_LEFT) && main_btn1_state) {
 		main_btn1_count++;
-		if(main_btn1_count > 10){
+		if (main_btn1_count > 10) {
 			main_btn1_count = 0;
 			main_btn1_state = false;
@@ -939,5 +982,5 @@
 	if ((btn == BUTTON_RIGHT) && !main_btn2_state) {
 		main_btn2_count++;
-		if(main_btn2_count > 10){
+		if (main_btn2_count > 10) {
 			main_btn2_count = 0;
 			main_btn2_state = true;
@@ -948,5 +991,5 @@
 	else if ((btn != BUTTON_RIGHT) && main_btn2_state) {
 		main_btn2_count++;
-		if(main_btn2_count > 10){
+		if (main_btn2_count > 10) {
 			main_btn2_count = 0;
 			main_btn2_state = false;
@@ -963,5 +1006,5 @@
 	char temp2[] = "測定温度：+00.0℃";
 	char mode[] = "運転モード：自動  ";
-	char *mode_texts[] = { "自動  ", "冷房  ", "暖房  ", "除湿  ", "送風  ", "その他" };
+	char *mode_texts[] = { "その他", "自動  ", "冷房  ", "暖房  ", "除湿  ", "送風  " };
 	char *btn_texts[] = { "none  ", "down  ", "left  ", "select", "up    ", "right " };
 	int temp, btn;
@@ -979,5 +1022,5 @@
 			power[11] = 'f';
 		}
-		lcd_drawString(&lcd, &power[9], X_LINE_HALF_TO_PIX(&lcd, 6) + 10, Y_ROW_TO_PIX(&lcd, main_lcd_state + 4) + 10, ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, &power[9], X_LINE_HALF_TO_PIX(&lcd, 6), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), ST7735_BLACK, ST7735_WHITE);
 		main_lcd_state++;
 		break;
@@ -992,5 +1035,5 @@
 			temp = -temp;
 		temp1[17] = '0' + temp;
-		lcd_drawString(&lcd, &temp1[15], X_LINE_HALF_TO_PIX(&lcd, 10) + 10, Y_ROW_TO_PIX(&lcd, main_lcd_state + 4) + 10, ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, &temp1[15], X_LINE_HALF_TO_PIX(&lcd, 10), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), ST7735_BLACK, ST7735_WHITE);
 		main_lcd_state++;
 		break;
@@ -1009,10 +1052,10 @@
 			temp = -temp;
 		temp2[19] = '0' + temp;
-		lcd_drawString(&lcd, &temp2[15], X_LINE_HALF_TO_PIX(&lcd, 10) + 10, Y_ROW_TO_PIX(&lcd, main_lcd_state + 4) + 10, ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, &temp2[15], X_LINE_HALF_TO_PIX(&lcd, 10), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), ST7735_BLACK, ST7735_WHITE);
 		main_lcd_state++;
 		break;
 	case 3:
 		temp = home_air_conditioner_data.propertyB0 - 0x40;
-		lcd_drawString(&lcd, mode_texts[temp], X_LINE_HALF_TO_PIX(&lcd, 12) + 10, Y_ROW_TO_PIX(&lcd, main_lcd_state + 4) + 10, ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, mode_texts[temp], X_LINE_HALF_TO_PIX(&lcd, 12), Y_ROW_TO_PIX(&lcd, main_lcd_state + 2), ST7735_BLACK, ST7735_WHITE);
 		main_lcd_state++;
 		break;
@@ -1023,5 +1066,5 @@
 	case 6:
 		btn = main_read_button(&joystick);
-		lcd_drawString(&lcd, btn_texts[btn], X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 10) + 10, ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, btn_texts[btn], X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 9), ST7735_BLACK, ST7735_WHITE);
 		main_lcd_state++;
 		break;
@@ -1030,9 +1073,9 @@
 		break;
 	case 10:
-		lcd_drawString(&lcd, "エアコン", X_LINE_TO_PIX(&lcd, 9) + 10, Y_ROW_TO_PIX(&lcd, 0) + 10, ST7735_BLACK, ST7735_WHITE);
-		lcd_drawString(&lcd, power, X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 0 + 4) + 10, ST7735_BLACK, ST7735_WHITE);
-		lcd_drawString(&lcd, temp1, X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 1 + 4) + 10, ST7735_BLACK, ST7735_WHITE);
-		lcd_drawString(&lcd, temp2, X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 2 + 4) + 10, ST7735_BLACK, ST7735_WHITE);
-		lcd_drawString(&lcd, mode, X_LINE_TO_PIX(&lcd, 0) + 10, Y_ROW_TO_PIX(&lcd, 3 + 4) + 10, ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, "エアコン", X_LINE_TO_PIX(&lcd, 6), Y_ROW_TO_PIX(&lcd, 0), ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, power, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 0 + 2), ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, temp1, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 1 + 2), ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, temp2, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 2 + 2), ST7735_BLACK, ST7735_WHITE);
+		lcd_drawString(&lcd, mode, X_LINE_TO_PIX(&lcd, 0), Y_ROW_TO_PIX(&lcd, 3 + 2), ST7735_BLACK, ST7735_WHITE);
 		main_lcd_state = 0;
 		break;
@@ -1079,9 +1122,9 @@
 
 	/* 押されて戻った時に処理する */
-	if(push)
+	if (push)
 		return;
 
 	/* 設定温度 */
-	if(main_templ > 0)
+	if (main_templ > 0)
 		main_templ--;	/* - 1℃ */
 
@@ -1090,5 +1133,5 @@
 	/* プロパティ設定電文作成 */
 	ret = ecn_esv_seti(&esv, HOME_AIR_CONDITIONER_EOBJ, 0xB3, 1, p_edt);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_seti");
 		return;
@@ -1096,6 +1139,6 @@
 
 	/* 電文送信 */
-	ecn_snd_esv(esv);
-	if(ret != E_OK){
+	ret = ecn_snd_esv(esv);
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 	}
@@ -1112,9 +1155,9 @@
 
 	/* 押されて戻った時に処理する */
-	if(push)
+	if (push)
 		return;
 
 	/* 設定温度 */
-	if(main_templ < 50)
+	if (main_templ < 50)
 		main_templ++;	/* + 1.0℃ */
 
@@ -1123,5 +1166,5 @@
 	/* プロパティ設定電文作成 */
 	ret = ecn_esv_seti(&esv, HOME_AIR_CONDITIONER_EOBJ, 0xB3, 1, p_edt);
-	if(ret != E_OK){
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_esv_seti");
 		return;
@@ -1129,6 +1172,6 @@
 
 	/* 電文送信 */
-	ecn_snd_esv(esv);
-	if(ret != E_OK){
+	ret = ecn_snd_esv(esv);
+	if (ret != E_OK) {
 		syslog(LOG_ERROR, "ecn_snd_esv");
 	}
@@ -1137,9 +1180,9 @@
 static void main_rly_onoff(bool_t onoff)
 {
-	if(onoff){
+	if (onoff) {
 		/* リレー出力をON */
 		gpio_write(&relay_sw, 1);
 	}
-	else{
+	else {
 		/* リレー出力をOFF */
 		gpio_write(&relay_sw, 0);
@@ -1159,5 +1202,5 @@
 	/* 500msパルス出力 */
 	main_rly_state = main_rly_state_on;
-	main_rly_timer = 500;
+	main_rly_timer = 500 * 1000;
 }
 
@@ -1167,6 +1210,5 @@
 static void main_rly_ontimer()
 {
-	switch(main_rly_state)
-	{
+	switch (main_rly_state) {
 	case main_rly_state_off:
 		main_rly_timer = TMO_FEVR;
