[Control widgets]
Object Functions
Switch object.

Switch Properties.

Identifier:
- ID: Unique number that identifies the object.
- Name: User-definable name for the object. It can be used with 86HMI API.
Content:
- Checked: Default Switch state.
Geometry:
- X: Object X coordinate.
- Y: Object Y coordinate.
- Width: Object width.
- Height: Object height.
Options:
- ObjColor: Choose from 4 themed colors. For font configuration instructions, please refer to Theme Management.
- Enable: Select the default state of the object, enable or disable.
- Order: Object order. It can adjust the object order by up/down, which can be viewed on the Object List.
API Functions
setSwitchState()
描述
Set Switch state.
語法
void setSwitchState(lv_obj_t* id, bool checked);
void setSwitchState(char* name, bool checked);
參數
[in] id
Object ID.[in] name
Object Name.[in] checked
Bool. Switch state, Checked or Unchecked.
Return
無
範例
#include "myhmi.h"
void setup() {
Hmi.begin();
// put your setup code here, to run once:
Hmi.setSwitchState(p1sw1, true);
}
void loop() {
// ...
}getSwitchState()
描述
Get Switch state.
語法
bool getSwitchState(lv_obj_t* id);
bool getSwitchState(char* name);
參數
[in] id
Object ID.[in] name
Object Name.
Return
Switch state.
範例
#include "myhmi.h"
void setup() {
Hmi.begin();
// put your setup code here, to run once:
}
void loop() {
if (Hmi.getSwitchState(p1sw1)) {
// do something.
}
}switchOn()
The following Event Functions are written between BEGIN_HMI_EVENT_PROC 以及 END_HMI_EVENT_PROC.
描述
Determine Switch is on.
語法
bool switchOn(lv_obj_t* id);
bool switchOn(char* name);
參數
[in] id
Object ID.[in] name
Object Name.
Return
Bool. Determine Switch is on.
範例
#include "myhmi.h"
void setup() {
Hmi.begin();
// put your setup code here, to run once:
}
void loop() {
BEGIN_HMI_EVENT_PROC
{
if (Hmi.switchOn(p1sw1))
{
// do something.
}
if (Hmi.switchOff(p1sw1))
{
// do something.
}
}
END_HMI_EVENT_PROC
}switchOff()
The following Event Functions are written between BEGIN_HMI_EVENT_PROC 以及 END_HMI_EVENT_PROC.
描述
Determine Switch is off.
語法
bool switchOff(lv_obj_t* id);
bool switchOff(char* name);
參數
[in] id
Object ID.[in] name
Object Name.
Return
Bool. Determine Switch is off.
範例
#include "myhmi.h"
void setup() {
Hmi.begin();
// put your setup code here, to run once:
}
void loop() {
BEGIN_HMI_EVENT_PROC
{
if (Hmi.switchOn(p1sw1))
{
// do something.
}
if (Hmi.switchOff(p1sw1))
{
// do something.
}
}
END_HMI_EVENT_PROC
}Please see the 86HMI Editor使用手冊 for more instructions on 86HMI widgets and API usage.