DPC Module:DPC Console under Linux

From LEXWiKi

(Difference between revisions)
Jump to: navigation, search
Current revision (14:35, 11 April 2024) (edit) (undo)
 
(44 intermediate revisions not shown.)
Line 2: Line 2:
== The Sample code source you can download form ==
== The Sample code source you can download form ==
-
Binary file:<br />
+
<Google Drive>
-
[ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/DPC_release/Windows_base/DPCv4.2.2W_bin.zip ???DPCv4.2.2W_bin.zip]<br />
+
-
[ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/DPC_release/Windows_base/DPC_LightSensor_4.2.2W_bin.zip ???DPC_LightSensor_4.2.2W_bin.zip]<br />
+
-
== How to compile source code ==
+
Binary file: [https://drive.google.com/file/d/1qDvLZ8Me8DYVjdxNL8qo6lRZ_ZWNZikP/view?usp=sharing DPC_Console_v1.0.0.4L_Bin_x64]
-
*Compile source code with Code::Blocks
+
Source file: [https://drive.google.com/file/d/1uxaz9TtNEYYu0cHcVEHZslW0YmGxEGny/view?usp=sharing DPC_Console_v1.0.0.4L_Src_x64] <br />
-
*#Download and install the Code::Block with command "apt-get install codeblocks" <br/>
+
(Include DPC、Light sensor、GPIO module)
-
*#Open an exist project(DPC_Console.cbp) in Code::Blocks, click the compile button <br/>
+
-
<br/>
 
-
*Compile source code with "make"
+
Source file: [https://drive.google.com/file/d/1e3UNMdZIIBLuZL58uSql5O5ZfitY2-02/view?usp=sharing DPC_Console_Simple_Sample] <br />
-
*#cd DPC_Console <br/>
+
(Only DPC module)
-
*#key in command "make" <br/>
+
-
Before you make it, you need to install : "make" "make-guile" "pkg-config" "gcc" "gtk2.0"
 
-
== How to use the DPC console application ==
+
<FTP>
-
When the DPC utility starts, it will hide in the notification area (like below picture),<br />
+
Binary file: [ftp://ftp.lex.com.tw/Engineer/SoftSupport/AP_Module/DPC_release/Console_Linux/DPC_Console_v1.0.0.4L_x64bin.zip DPC_Console_v1.0.0.4L_Bin_x64]
-
and double click the tray icon (shown as the red square below), 'DPC v3.0w.exe', it will show.
+
-
[[Image:DPC_AP_1.jpg]]<br />
+
== How to compile source code ==
 +
(Develop Environment: UBUNTU 18.04)
-
[[Image:DPCv4.1.8.jpg]]<br />
+
*Step1: Install compile packages
 +
*#Install "'''GCC Ver.7.5.0'''". You could install "'''build-essential'''" include it.
 +
Command: "'''apt install build-essential'''". <br />
 +
*#Install "'''gtk2.0'''".
 +
Command: "'''apt install libgtk2.0-dev'''". <br />
-
1. Frequency of panel selection
+
*Step2: Compile source code with CodeBlocks.
 +
*#Download and install the "'''CodeBlocks'''".
 +
Command: "'''apt-get install codeblocks'''". <br />
 +
*#Open an exist project('''DPC_Console.cbp''') in CodeBlocks, click the compile button. <br />
-
2. Confirm the panel which selected
 
-
3. If you choose to save DPC setting , the setting of frequency and duty cycle will be reserved.
+
*Or compile source code with "make"
 +
*#cd '''DPC_Console''' <br />
 +
Command: "'''make'''". <br />
-
4. It will show the MCU version of DPC.
+
== How to use the DPC console application ==
-
5. Brightness control , you can choose : 10,20,30,40,50,60,70,80,90,100.
+
#Install resource before execute application. "'''.\install.sh'''" <br />
 +
#Execute the application. "'''.\DPC_Console'''". <br /> [[Image:DPC_Info_01.jpg]] <br />
 +
#Dump DPC information with command "'''-i'''". <br />
 +
#Print DPC help menu with command "'''-h'''". <br />
 +
#Set brightness from 10 to 100 with command "'''-d'''". Ex: Set brightness 50 with command "'''-d50'''". <br />
 +
#Select panel what you try to adjust with command "'''-t'''". Ex: Select 200 Hz with command "'''-t0'''". <br />(0 = 200 Hz, 1 = 275 Hz, 2 = 380 Hz, 3 = 20 Hz, 4 = 25 Hz) <br />
 +
#Select range what you add / subtract brightness with command "'''-r'''". Ex: Select 10 Sz with command "'''-r4'''". <br />(0 = 1 Sz, 1 = 2 Sz, 2 = 3 Sz, 3 = 5 Sz, 4 = 10 Sz) <br />
 +
#Step add / subtract brightness with keyboard : "'''Up arrow key'''" / "'''Down arrow key'''". <br />
 +
#Turn off screen backlight with command "'''-f'''". Duty cycle value will be modify to 0. <br />
 +
#Fixed hot key to turn on screen backlight with hot key "'''Ctrl + n'''". Duty cycle value will be modify to 50. <br />
 +
#Clear terminal screen with command "'''Clear'''".
 +
#Quit DPC application with command "'''Exit'''". <br />
-
6. Show the brightness data which you choose.
+
== If you have LEX light sensor module. How to use light sensor module ==
-
7. When click the LightOff button , the panel will become darkest.
+
[[Image:DPC_Info_02.jpg]] <br />
 +
#Print light sensor help menu with command "'''-hl'''". <br />
 +
#Turn on/off light sensor to modify duty cycle value automaticaly. With command "'''-la'''". Ex: Turn off light sensor active with command "'''-la0'''". <br />(0 = Off, 1 = On) <br /> Attention: If active light sensor module, GPIO module will be turned off. <br />
 +
#Select light sensor mode with command "'''-lm'''". Ex: Select ALS mode with command "'''-lm0'''". <br />(0 = Measures ALS continuously, 1 = Measures IR continuously) <br />
 +
#Select light sensor range with command "'''-lr'''". Ex: Select range 1000 with command "'''-lr0'''". <br />(0 = 1000, 1 = 4000, 2 = 16000, 3 = 64000) <br />
 +
#Turn on/off using custom bounding range with command "'''-lc'''". Ex: Turn on custom bounding range with command "'''-lc1'''". <br />(0 = Use, 1 = Not use) <br />
 +
#Set a custom value for light sensor maximum range with command "'''-lmax'''". Ex: Set 100 for maximum range with command "-lmax9". <br />(0 = 10, 1 = 20, 2 = 30, 3 = 40, 4 = 50, 5 = 60, 6 = 70, 7 = 80, 8 = 90, 9 = 100) <br />
 +
#Set a custom value for light sensor median range with command "'''-lmed'''". Ex: Set 50 for median range with command "'''-lmed4'''". <br />(0 = 10, 1 = 20, 2 = 30, 3 = 40, 4 = 50, 5 = 60, 6 = 70, 7 = 80, 8 = 90, 9 = 100) <br />
 +
#Set a custom value for light sensor minimum range with command "'''-lmin'''". Ex: Set 10 for minimum range with command "'''-lmin0'''". <br />(0 = 10, 1 = 20, 2 = 30, 3 = 40, 4 = 50, 5 = 60, 6 = 70, 7 = 80, 8 = 90, 9 = 100) <br />
-
8. Record mouse position for go to 50 when LightOff. If click the button , 13 will show , you can click anywhere which you want for light on.
+
== Sample code Introduction ==
 +
=== Step1. Initial SMBUS. ===
 +
if( SMBus_Install() == false )
 +
printf( "Initial SMBUS failed!!! \n" );
-
9. Record hotkey for go to 10 when LightOff. If click the button , The Record Hot Key window will show.
+
=== Step2. Check DPC device is exist from SMBUS. ===
 +
#define DPC_ADD 0xb0
-
10. When click minimized , DPC will hide and show in the notification area.
+
if(!SMBus_CheckDevice(DPC_ADDR))
 +
printf( "DPC device is not exist!!! \n" );
-
11. Reset the record of hot key and position.
+
=== Step3. Setup frequency type of panel. ===
 +
#define PWMFeq 0x01
 +
BYTE pbCmd = PWMFeq;
 +
(itype = 1: 200 Hz, itype = 2: 275 Hz, itype = 3: 380 Hz, itype = 4: 20 Hz, itype = 5: 25 Hz)
 +
int nValue = itype;
-
[[Image:DPC_AP_3.jpg]]<br />
+
if(SMBus_WriteByte( DPC_ADDR, pbCmd, (BYTE)nValue ) == true)
 +
printf( "Setup panel type success. \n" );
-
12. The light on mouse position and hotkay can not use together , after you record hotkey , you can't use the position anymore.
+
=== If you need to get current frequency type of panel. ===
 +
BYTE byteCmd = PWMFeq;
 +
BYTE byteVale = 0x0;
-
[[Image:DPC_AP_4.jpg]]<br />
+
SMBus_ReadByte(DPC_ADDR, byteCmd, &byteVale);
-
13. First key of hotkey
+
=== Step4. Setup DPC brightness level. ===
 +
BYTE pbCmd = PWMDuty;
-
15. Second key of hotkey
+
(iduty = level 0 ~ 100)
 +
int iduty = 50;
-
16. Third key hotkey
+
if(SMBus_WriteByte( DPC_ADDR, pbCmd, (BYTE)iduty) == true)
 +
printf( "Setup brightness level success. \n" );
-
17. Confirm the hotkey which you entered
+
=== If you need to get current brightness level. ===
 +
BYTE byteCmd = PWMDuty;
 +
BYTE byteVale = 0x0;
-
18. Show hotkey which you set.
+
SMBus_ReadByte(DPC_ADDR, byteCmd, &byteVale);
-
19. Hotkey will show here.
+
=== Final Step. Release SMBUS resource before closing program. ===
 +
SMBus_Uninstall();
-
[[Image:DPC_AP_5.jpg]]<br />
 
-
20. If you want to exit DPC , you should click right button of mouse on the icon and choose exit.
+
== SMBUS.c Introduction ==
 +
=== Define SMBus register ===
 +
typedef unsigned char BYTE;
 +
typedef unsigned short WORD;
 +
typedef unsigned int DWORD;
 +
//----------------------------------------------------------------------------------
 +
#define SMBHSTSTS 0x00 // SMBus Host Status Register Offset
 +
#define SMBHSTCNT 0x02 // SMBus Host Contorl Register Offset
 +
#define SMBHSTCMD 0x03 // SMBus Host Command Register Offset
 +
#define SMBHSTADD 0x04 // SMBus Host Address Register Offset
 +
#define SMBHSTDAT0 0x05 // SMBus Host Data0 Register Offset
-
[[Image:DPCv4.1.8.jpg]]<br />
+
#define SMBHSTCNT_START 0x40 // SMBus Host Contorl -> 0100 0000 Start
 +
#define SMBHSTCNT_BYTE 0x08 // SMBus Host Contorl -> 0000 1000 Byte Data
 +
//----------------------------------------------------------------------------------
 +
#define DPC_ADD 0xb0
 +
#define PWMFeq 0x01
 +
#define PWMDuty 0x02
-
21. Check this grid program will automatically grab the light size to adjust the DPC light and dark
+
=== SMBusIoWrite ===
-
 
+
void SMBusIoWrite(BYTE byteOffset, BYTE byteData)
-
22. Showing the device name
+
{
-
 
+
outb( byteData , (g_SMBusMapIoAddr + byteOffset) );
-
23. Showing the mode in use
+
}
-
 
+
-
24. Showing the range in used
+
-
 
+
-
25. Showing calculated LUX values
+
-
 
+
-
26. Mode and Range detail settings
+
-
 
+
-
[[Image:DPCv4.1.5setting.jpg]]
+
-
 
+
-
27. Choose which mode to use
+
-
 
+
-
28. Choose which range to use
+
-
 
+
-
29. Custom DPC Max brightness
+
-
 
+
-
30. Set the DPC brightness intermediate reference value
+
-
 
+
-
31. Custom DPC Min brightness
+
-
 
+
-
32. Complete the settings button but without leaving the window
+
-
 
+
-
33. Complete the settings button and exit leaving the window
+
-
 
+
-
34. exit leaving the window
+
-
 
+
-
 
+
-
== Sample code Introduction ==
+
-
===Define SMBus regester===
+
-
#define SMBUSPORT 0x0500
+
-
#define HST_STS SMBUSPORT+0x00
+
-
#define HST_CNT SMBUSPORT+0x02
+
-
#define HST_CMD SMBUSPORT+0x03
+
-
#define XMIT_SLVA SMBUSPORT+0x04
+
-
#define HST_D0 SMBUSPORT+0x05
+
-
#define bSize 1
+
-
#define SADD 0xb0
+
-
#define PWMFeq 0x01
+
-
#define PWMDuty 0x02
+
-
===Set Frequency data===
+
=== SMBusIoRead ===
-
DWORD dwPortVal;
+
BYTE SMBusIoRead(BYTE byteOffset)
-
bool bResult;
+
{
-
bResult = InitializeWinIo();
+
DWORD dwAddrVal;
-
+
dwAddrVal = inb((g_SMBusMapIoAddr + byteOffset));
-
if (bResult){
+
return (BYTE)(dwAddrVal & 0x0FF);
-
SetPortVal(HST_STS, 0xFE, bSize); //start
+
}
-
Sleep(20);
+
-
SetPortVal(XMIT_SLVA, SADD, bSize); //set
+
-
Sleep(20);
+
-
SetPortVal(HST_CMD, PWMFeq, bSize); //set frequency
+
-
Sleep(20);
+
-
GetPortVal(HST_STS, &dwPortVal, bSize);
+
-
Sleep(20);
+
-
dwPortVal = dwPortVal & 0x01;
+
-
if (dwPortVal == 0){
+
-
SetPortVal(HST_D0, fvalue, bSize); //write data into frequency
+
-
Sleep(20);
+
-
SetPortVal(HST_CNT, 0x48, bSize); //stop
+
-
Sleep(20);
+
-
ShutdownWinIo();
+
-
}
+
-
else
+
-
ShutdownWinIo();
+
-
}
+
-
ShutdownWinIo();
+
-
===Set Duty data===
+
=== SMBus_WriteByte ===
-
UpdateData(TRUE);
+
bool SMBus_WriteByte(BYTE byteSlave, BYTE pCmd, BYTE pByte)
-
DWORD dwPortVal;
+
{
-
bool bResult;
+
SMBusIoWrite(SMBHSTADD , byteSlave & ~1 );
-
bResult = InitializeWinIo();
+
SMBusIoWrite(SMBHSTCMD , pCmd );
-
+
SMBusIoWrite(SMBHSTDAT0 , pByte );
-
if (bResult){
+
SMBusIoWrite(SMBHSTCNT , SMBHSTCNT_START | SMBHSTCNT_BYTE);
-
SetPortVal(HST_STS, 0xFE, bSize); //start
+
return true;
-
Sleep(20);
+
}
-
SetPortVal(XMIT_SLVA, SADD, bSize); //set
+
-
Sleep(20);
+
-
SetPortVal(HST_CMD, PWMDuty, bSize); //set duty
+
-
Sleep(20);
+
-
GetPortVal(HST_STS, &dwPortVal, bSize);
+
-
Sleep(20);
+
-
dwPortVal = dwPortVal & 0x01;
+
-
if (dwPortVal == 0){
+
-
if (inverter == false)
+
-
SetPortVal(HST_D0, dvalue * 10 , bSize); //write data into data
+
-
else if (inverter == true)
+
-
SetPortVal(HST_D0, (10 - dvalue) * 10 , bSize);
+
-
Sleep(20);
+
-
SetPortVal(HST_CNT, 0x48, bSize); //stop
+
-
Sleep(20);
+
-
ShutdownWinIo();
+
-
}
+
-
else
+
-
ShutdownWinIo();
+
-
}
+
-
ShutdownWinIo();
+

Current revision

Contents

The Sample code source you can download form

<Google Drive>

Binary file: DPC_Console_v1.0.0.4L_Bin_x64

Source file: DPC_Console_v1.0.0.4L_Src_x64
(Include DPC、Light sensor、GPIO module)


Source file: DPC_Console_Simple_Sample
(Only DPC module)


<FTP>

Binary file: DPC_Console_v1.0.0.4L_Bin_x64

How to compile source code

(Develop Environment: UBUNTU 18.04)

  • Step1: Install compile packages
    1. Install "GCC Ver.7.5.0". You could install "build-essential" include it.
Command: "apt install build-essential". 
    1. Install "gtk2.0".
Command: "apt install libgtk2.0-dev". 


  • Step2: Compile source code with CodeBlocks.
    1. Download and install the "CodeBlocks".
Command: "apt-get install codeblocks". 
    1. Open an exist project(DPC_Console.cbp) in CodeBlocks, click the compile button.


  • Or compile source code with "make"
    1. cd DPC_Console
Command: "make". 

How to use the DPC console application

  1. Install resource before execute application. ".\install.sh"
  2. Execute the application. ".\DPC_Console".
    Image:DPC_Info_01.jpg
  3. Dump DPC information with command "-i".
  4. Print DPC help menu with command "-h".
  5. Set brightness from 10 to 100 with command "-d". Ex: Set brightness 50 with command "-d50".
  6. Select panel what you try to adjust with command "-t". Ex: Select 200 Hz with command "-t0".
    (0 = 200 Hz, 1 = 275 Hz, 2 = 380 Hz, 3 = 20 Hz, 4 = 25 Hz)
  7. Select range what you add / subtract brightness with command "-r". Ex: Select 10 Sz with command "-r4".
    (0 = 1 Sz, 1 = 2 Sz, 2 = 3 Sz, 3 = 5 Sz, 4 = 10 Sz)
  8. Step add / subtract brightness with keyboard : "Up arrow key" / "Down arrow key".
  9. Turn off screen backlight with command "-f". Duty cycle value will be modify to 0.
  10. Fixed hot key to turn on screen backlight with hot key "Ctrl + n". Duty cycle value will be modify to 50.
  11. Clear terminal screen with command "Clear".
  12. Quit DPC application with command "Exit".

If you have LEX light sensor module. How to use light sensor module

Image:DPC_Info_02.jpg

  1. Print light sensor help menu with command "-hl".
  2. Turn on/off light sensor to modify duty cycle value automaticaly. With command "-la". Ex: Turn off light sensor active with command "-la0".
    (0 = Off, 1 = On)
    Attention: If active light sensor module, GPIO module will be turned off.
  3. Select light sensor mode with command "-lm". Ex: Select ALS mode with command "-lm0".
    (0 = Measures ALS continuously, 1 = Measures IR continuously)
  4. Select light sensor range with command "-lr". Ex: Select range 1000 with command "-lr0".
    (0 = 1000, 1 = 4000, 2 = 16000, 3 = 64000)
  5. Turn on/off using custom bounding range with command "-lc". Ex: Turn on custom bounding range with command "-lc1".
    (0 = Use, 1 = Not use)
  6. Set a custom value for light sensor maximum range with command "-lmax". Ex: Set 100 for maximum range with command "-lmax9".
    (0 = 10, 1 = 20, 2 = 30, 3 = 40, 4 = 50, 5 = 60, 6 = 70, 7 = 80, 8 = 90, 9 = 100)
  7. Set a custom value for light sensor median range with command "-lmed". Ex: Set 50 for median range with command "-lmed4".
    (0 = 10, 1 = 20, 2 = 30, 3 = 40, 4 = 50, 5 = 60, 6 = 70, 7 = 80, 8 = 90, 9 = 100)
  8. Set a custom value for light sensor minimum range with command "-lmin". Ex: Set 10 for minimum range with command "-lmin0".
    (0 = 10, 1 = 20, 2 = 30, 3 = 40, 4 = 50, 5 = 60, 6 = 70, 7 = 80, 8 = 90, 9 = 100)

Sample code Introduction

Step1. Initial SMBUS.

if( SMBus_Install() == false )
   printf( "Initial SMBUS failed!!! \n" );

Step2. Check DPC device is exist from SMBUS.

#define DPC_ADD  0xb0
if(!SMBus_CheckDevice(DPC_ADDR))
   printf( "DPC device is not exist!!! \n" );   

Step3. Setup frequency type of panel.

#define PWMFeq  0x01
BYTE pbCmd = PWMFeq;
(itype = 1: 200 Hz, itype = 2: 275 Hz, itype = 3: 380 Hz, itype = 4: 20 Hz, itype = 5: 25 Hz)
int nValue = itype;
if(SMBus_WriteByte( DPC_ADDR, pbCmd, (BYTE)nValue ) == true)
   printf( "Setup panel type success. \n" );

If you need to get current frequency type of panel.

BYTE byteCmd = PWMFeq;
BYTE byteVale = 0x0;
SMBus_ReadByte(DPC_ADDR, byteCmd, &byteVale);

Step4. Setup DPC brightness level.

BYTE pbCmd = PWMDuty;
(iduty = level 0 ~ 100)
int iduty = 50;
if(SMBus_WriteByte( DPC_ADDR, pbCmd, (BYTE)iduty) == true)    
    printf( "Setup brightness level success. \n" );   

If you need to get current brightness level.

BYTE byteCmd = PWMDuty;
BYTE byteVale = 0x0;
SMBus_ReadByte(DPC_ADDR, byteCmd, &byteVale);

Final Step. Release SMBUS resource before closing program.

SMBus_Uninstall();


SMBUS.c Introduction

Define SMBus register

 typedef unsigned char  BYTE;
 typedef unsigned short WORD;
 typedef unsigned int   DWORD;
 //----------------------------------------------------------------------------------
 #define SMBHSTSTS     0x00	// SMBus Host Status        Register Offset
 #define SMBHSTCNT     0x02	// SMBus Host Contorl       Register Offset
 #define SMBHSTCMD     0x03	// SMBus Host Command 	    Register Offset
 #define SMBHSTADD     0x04	// SMBus Host Address	    Register Offset
 #define SMBHSTDAT0    0x05	// SMBus Host Data0         Register Offset
 #define SMBHSTCNT_START 0x40   // SMBus Host Contorl -> 0100 0000 Start
 #define SMBHSTCNT_BYTE  0x08   // SMBus Host Contorl -> 0000 1000 Byte Data
 //----------------------------------------------------------------------------------
 #define DPC_ADD       0xb0
 #define PWMFeq        0x01
 #define PWMDuty       0x02

SMBusIoWrite

 void SMBusIoWrite(BYTE byteOffset, BYTE byteData)
 {
     outb( byteData , (g_SMBusMapIoAddr + byteOffset) );
 }

SMBusIoRead

 BYTE SMBusIoRead(BYTE byteOffset)
 {
     DWORD dwAddrVal;
     dwAddrVal = inb((g_SMBusMapIoAddr + byteOffset));
     return (BYTE)(dwAddrVal & 0x0FF);
 }

SMBus_WriteByte

 bool SMBus_WriteByte(BYTE byteSlave, BYTE pCmd, BYTE pByte)
 {
     SMBusIoWrite(SMBHSTADD  , byteSlave & ~1 );
     SMBusIoWrite(SMBHSTCMD  , pCmd );
     SMBusIoWrite(SMBHSTDAT0 , pByte );
     SMBusIoWrite(SMBHSTCNT  , SMBHSTCNT_START | SMBHSTCNT_BYTE);
     return true;
 }
Personal tools