KhadasApi interface description

khadas_api_demo code and apk Download or:

Edge:

git clone https://github.com/khadas/khadas_api_demo -b edge

Vim3:

git clone https://github.com/khadas/khadas_api_demo -b vim3

1.Su permission to run shell commands

Function:public String execSuCmd(String cmd)
Parameter:cmd: shell commands
Return:Returns the string value after the input command
example:

getKhadasApi.execSuCmd("cat /data/misc/wifi/WifiConfigStore.xml");//WifiConfigStore.xml Default permissions 600
getKhadasApi.execSuCmd("screencap -p /sdcard/screenshot.png");	//screenshot

2.GPIO control

Function:public boolean gpioCrtl(String gpioStr, String direction, int level)
Parameter:gpioStr:GPIO descriptor
direction:in, out, high, low high/low
level:1/0
Return:true: OK, false: NG
example:

boolean success = getKhadasApi.gpioCtrl("GPIOAO_6","out",1);

3.Get GPIO status

Function:public int gpioRead(String gpioStr)
Parameter:gpioStr:GPIO descriptor
Return:-1: Read NG
example:

int gpioValue = getKhadasApi.gpioRead("GPIOAO_6");

4.I2C read function

Function:public int i2c_read_byte_data(int bus, int addr, int reg)
Parameter:bus: Device mounted I2C bus addr: Device I2C address reg: Device register
Return:Returns the read register value
example:

int Value = getKhadasApi().i2c_read_byte_data(4, 0x0e, 0x60);

5.I2C write function

Function:public int i2c_write_byte_data(int bus, int addr, int reg, int value)
Parameter:bus: Device mounted I2C bus addr: Device I2C address reg: Device register value: Value to set
Return:-1: NG 0: OK
example:

int propertiesValue = getKhadasApi().i2c_write_byte_data(4,0x0e, 0x60, 96);

6.Save system log

Function:LogcatHelper.getInstance(mContext).start(String path_name)
Parameter:path_name: Directory and file name (no corresponding directory can be created first)
Note:Log of Android layer and kernel layer. Quit catch log by suicide.
example:

LogcatHelper.getInstance(mContext).start("/mnt/sdcard/123.log");

close log:

android.os.Process.killProcess(android.os.Process.myPid());

7.System shutdown

Function:public void shutdown()
example:

getKhadasApi.shutdown();   

8.System reboot

Function:public void reboot()
example:

getKhadasApi.reboot();   

9.System sleep

Function:public void sleep()
example:

getKhadasApi.sleep();   

10.System wake up

Function:public void wakeup()
example:

getKhadasApi.wakeup(); 

11.App silent install

Function:public boolean silentInstall(String apkPath)
Parameter:apkPath: apk path
Return:true: the installation is successful
example:

getKhadasApi.silentInstall("/sdcard/xxx.apk");

12.App silent uninstall

Function:public boolean silentUnInstall(String package_name)
Parameter:package_name: the name of the package
Return:true: OK, false: NG
Note:Only the installed app can be uninstalled, not the built-in app
example:

getKhadasApi.silentUnInstall("com.android.yyy");

13.Set led mode

Function:public void setLedMode(int type, int mode)
Parameter:type: led selection (0,white_led 1,red_led)
mode: led status(0,heartbeat 1,on 2,off)
example:

getKhadasApi.setLedMode(1,0);

14.Get LED status

Function:public int getLedMode(int type)
Parameter:type: led selection (0,white_led 1,red_led)
Return:led status(0,heartbeat 1,on 2,off)
example:

int mode = getKhadasApi.getLedMode(0);

15.Set fan mode

Function:public void setFanMode(int mode)
Parameter:mode: fan status (0, auto;1, level 1 speed; 2, level 2 speed;3, level 3 speed;4, level 4 speed;5, level 5 speed;6, off)
example:

getKhadasApi.setFanMode(2);

16.Get fan status

Function:public int getFanMode()
Return:fan status (0, auto 1, low speed 2, medium speed 3, high speed 4, off)
example:

int mode = getKhadasApi.getFanMode();

17.Set Wol mode

Function:public void setWolMode(boolean mode)
Parameter:mode: Wol status(0,on 1,off)
example:

getKhadasApi.setWolMode(0);

18.Get Wol status

Function:public boolean getWolMode()
Return:Wol status(0,on 1,off)
example:

boolean mode = getKhadasApi.getWolMode();

19.Screen RGB adjustment

Function:public void setRgbColor(int mode)
Parameter:mode: Screen RGB color status (0, off 1, standard 2, warm 3, cool)
example:

getKhadasApi.setRgbColor(2);

20.Get screen RGB color mode

Function:public int getRgbColor()
Return:Screen RGB color status (0, off 1, standard 2, warm 3, cool)
example:

int mode = getKhadasApi.getRgbColor();

21.Set the system time

Function:public boolean setTime(int year, int month, int day, int hour, int minute, int second)
Return:true: OK, false: NG
example:

getKhadasApi.setTime(2020,11,13,15,33,06);	

22.Local OTA package upgrade

Function:public void installPackage(String path_name)
Note: will restart for OTA package upgrade, 1, USB flash disk: /udisk/update.zip 2. SD card: /sdcard/update.zip 3. Internal EMMC: /data/update.zip
Parameter:path_name:Absolute pathname of OTA package
example:

getKhadasApi.installPackage("/udisk/update.zip"); //USB flash disk
getKhadasApi.installPackage("/sdcard/update.zip"); //SD card
getKhadasApi.installPackage("/data/update.zip"); //Internal EMMC

23.Set HDMI resolution output

Function:public void setResolution(String resolution)
Parameter:resolution: HDMI resolution
example:

getKhadasApi.setResolution("1080p60hz");

24.Turn off or turn on the best resolution output

Function:public void switchBestResolution(boolean enable)
Parameter:enable: 0,off 1,on
example:

getKhadasApi.switchBestResolution(true);

25.Get the current HDMI resolution

Function:public String getCurrentResolution()
Return:Returns the resolution of the current HDMI display
example:

String resolutionValue = getKhadasApi.getCurrentResolution();

26.Get the resolution currently supported by HDMI

Function:public String getValidResolution()
Return:Returns the resolution currently supported by HDMI
example:

String resolutionValue = getKhadasApi.getValidResolution();

27.Set properties integer value

Function:public void setSystemProperties_int(String name, int value)
Parameter:name: properties name. value: Set the corresponding integer value
example:

getKhadasApi.setSystemProperties_int("persist.sys.test1", 1);

28.Get properties integer value

Function:public int getSystemProperties_int(String name, int value)
Parameter:name: properties name. value: There is no corresponding value. Return this value by default
Return:Return properties integer value
example:

int propertiesValue = getKhadasApi.getSystemProperties_int("persist.sys.test1",0);

29.Set properties string value

Function:public void setSystemProperties(String name, String val)
Parameter:name: properties name. val: Set the corresponding string value
example:

getKhadasApi.setSystemProperties("persist.sys.test2", "1");

30.Get properties string value

Function:public String getSystemProperties(String name, String val)
Parameter:name: properties name. val: There is no corresponding String. Return this String by default
Return:Return properties integer value
example:

String propertiesval = getKhadasApi.getSystemProperties("persist.sys.test2", "UNKNOWN");

31.Recording screen

Function:public int screenrecord(String path_name, int seconds)
Note:: this function takes time and needs to be run under thread. Please refer to demo app
Parameter:path_name: Absolute path to save seconds: Video for a few seconds
Return:-1: NG 0: OK
example:

int ret = getKhadasApi().screenrecord("/sdcard/demo.mp4",6);

32.System language switch

Function:public void switchLanguage(String language, String country)
Parameter:language: language country: Countries and regions
Note:This function requires system permission and APK needs signature
1)Import khadas_api.jks file
2)AndroidManifest.xml Import android:sharedUserId=“android.uid.system”
3)build.gradle add the following configuration:

    signingConfigs {
        release {
            storeFile file("khadas_api.jks")
            storePassword 'khadas'
            keyAlias 'platform'
            keyPassword 'khadas'
        }

        debug {
            storeFile file("khadas_api.jks")
            storePassword 'khadas'
            keyAlias 'platform'
            keyPassword 'khadas'
        }
    }

example:

getKhadasApi().switchLanguage("en","US");

33.serial port

1)Import so library file
libkhadas_serial_port_jni.so

2)Import header file

import com.wesion.khadasapi.serialport.SerialPortConfig;
import com.wesion.khadasapi.serialport.SerialPortHelper;
import com.wesion.khadasapi.serialport.SphCmdEntity;
import com.wesion.khadasapi.serialport.SphResultCallback;

3)Open the serial port according to the path and baud rate, and set the callback function

	private boolean openSerialPort(String path,int baudrate){
		SerialPortConfig serialPortConfig = new SerialPortConfig();
		serialPortConfig.mode = 0;
		serialPortConfig.path = path;
		serialPortConfig.baudRate = baudrate;
		serialPortConfig.dataBits = 8;
		serialPortConfig.parity   = 'N';
		serialPortConfig.stopBits = 1;

		// Initialization serial port
		serialPortHelper = new SerialPortHelper(16);
		// set serial port parameter
		serialPortHelper.setConfigInfo(serialPortConfig);
		// open serial port
		isOpen = serialPortHelper.openDevice();
		if(!isOpen){
			return false;
		}
		serialPortHelper.setSphResultCallback(new SphResultCallback() {
			@Override
			public void onSendData(SphCmdEntity sendCom) {
				Log.d(TAG, "send command:" + sendCom.commandsHex);
			}

			@Override
			public void onReceiveData(SphCmdEntity data) {
				final String result = data.commandsHex;
				Log.d(TAG, "onDataReceived:"+data.commandsHex);
				if(data.commandsHex != null && data.commandsHex.trim().length() > 0)
					mInfoView.post(new Runnable() {

						@Override
						public void run() {
							// TODO Auto-generated method stub
							mInfoView.append(result);
						}
					});
			}

			@Override
			public void onComplete() {
				Log.d(TAG, "finish");
			}
		});

		return true;
	}

4)Send string to serial port

String sendTxt = "123456789abcdef0";
serialPortHelper.addCommands(sendTxt);

5)close serial port

serialPortHelper.closeDevice();
3 Likes