From 5dd1b7fdcc52a43867f924e8d220de8467af372a Mon Sep 17 00:00:00 2001
From: QuakeGod <quakegod@sina.com>
Date: 星期五, 12 四月 2024 14:27:26 +0800
Subject: [PATCH] Change KBus to OOP and Packge

---
 KBus/Src/main.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/KBus/Src/main.c b/KBus/Src/main.c
index a6e38f7..f925e53 100644
--- a/KBus/Src/main.c
+++ b/KBus/Src/main.c
@@ -132,6 +132,42 @@
 	return;
 }
 
+void * KBusCallBackFunc(int nChn, int nEvent, void *pBuf, int nLen1)
+{
+	switch (nEvent){
+		
+		case KBusEvNone:
+			break;
+		case KBusEvCreate:
+			break;
+		case KBusEvConnected:
+			break;
+		case KBusEvDisConnected:
+			break;
+		case KBusEvClosed:
+			break;
+		case KBusEvStateChange:
+			break;
+		case KBusEvTimeSync:
+			break;
+		case KBusEvDataUpdate:
+			if (KBus1.bMaster) {
+				KMem.WY[0]=KBusMem.WLX[0];			//KBus Master
+				KBusMem.WLY[0]=KMem.WX[0];
+			} else if (KBus1.bSlave) {
+				KMem.WY[0]=KBusMem.WLY[0];			//KBus Slave
+				KBusMem.WLX[0]=KMem.WX[0];
+			}
+			break;
+		case KBusEvCmdResponse:
+			break;
+		
+		default:
+			break;
+	}
+	return 0;
+}
+
 /* USER CODE END 0 */
 
 /**
@@ -234,6 +270,10 @@
 #endif
 	nChilds=nStationID;
 	nCurPollId=1;
+	
+	KBusInit(2, bKBusMaster, nChilds);	
+	KBusSetCallBackFunc(2, &KBusCallBackFunc),
+	
 	//if (KMem.EffJumperSW == 0x00)
 		Uart1Baud = DefaultUart1Baud;
   MX_USART1_UART_Init();
@@ -445,7 +485,9 @@
 //			BufferOut[1]=KMem.WX[0]&0xff;
 //			BufferOut[2]=(KMem.WX[0]>>8)&0xff;
 #endif
+				KBusMem.WLY[0]=KMem.WX[0];
 			if (nChilds>0) {		KBusMasterFunc(2); }
+				KMem.WY[0]=KBusMem.WLX[0];			//KBus Slave
 
 #if (BOARD_TYPE == 14)			
 //			KMem.WX[0]=BufferIn[1]+(BufferIn[2]<<8);
@@ -468,14 +510,15 @@
 		//	KMem.WY[0]=BufferIn[0];
 #else
 			KBusSlaveFunc(2);	
-			if (! KMem.RunStat) {BufferIn[0]=0;}
-			KMem.WLY[0]=BufferIn[0];
+//			if (! KMem.RunStat) {BufferIn[0]=0;}
+//			KMem.WLY[0]=BufferIn[0];
 #endif
 			if (nSlaveTick&0x00002000) SlowFlicker=1;
 			else SlowFlicker=0;
 			if (nSlaveTick&0x00000800) FastFlicker=1;
 			else FastFlicker=0;			
-
+			KBusMem.WLX[0]=KMem.WX[0];
+			KMem.WY[0]=KBusMem.WLY[0];
 		}
 
 //		KMem.WY[0]=nCount2>>5;
@@ -533,8 +576,8 @@
 		}
 //	KMem.WY[0]=KMem.WLY[0];
 #else
-		KMem.WLX[0]=KMem.WX[0];
-		KMem.WY[0]=KMem.WLY[0];
+//		KMem.WLX[0]=KMem.WX[0];
+//		KMem.WY[0]=KMem.WLY[0];
 #endif
 
 		us5=GetuS();

--
Gitblit v1.9.1