pikapython/package/PikaStdDevice/PikaStdDevice_GPIO.c

110 lines
3.1 KiB
C
Raw Normal View History

2021-10-01 20:00:15 +08:00
#include "BaseObj.h"
#include "PikaStdDevice_GPIO.h"
void PikaStdDevice_GPIO_init(PikaObj* self) {
obj_setInt(self, "isEnable", 0);
obj_setStr(self, "pin", "PA0");
obj_setStr(self, "mode", "out");
obj_setInt(self, "isOn", 0);
2021-10-25 20:16:08 +08:00
obj_setStr(self, "pull", "none");
2021-10-01 20:00:15 +08:00
}
2021-12-10 23:02:40 +08:00
void PikaStdDevice_GPIO___init__(PikaObj* self) {
PikaStdDevice_GPIO_init(self);
}
2021-10-01 20:00:15 +08:00
void PikaStdDevice_GPIO_disable(PikaObj* self) {
obj_setInt(self, "isEnable", 0);
obj_run(self, "platformDisable()");
}
void PikaStdDevice_GPIO_enable(PikaObj* self) {
obj_setInt(self, "isEnable", 1);
obj_run(self, "platformEnable()");
}
char* PikaStdDevice_GPIO_getMode(PikaObj* self) {
return obj_getStr(self, "mode");
}
char* PikaStdDevice_GPIO_getPin(PikaObj* self) {
return obj_getStr(self, "pin");
}
void PikaStdDevice_GPIO_low(PikaObj* self) {
obj_setInt(self, "isOn", 0);
obj_run(self, "platformLow()");
}
void PikaStdDevice_GPIO_high(PikaObj* self) {
obj_setInt(self, "isOn", 1);
obj_run(self, "platformHigh()");
}
2021-10-25 20:16:08 +08:00
int PikaStdDevice_GPIO_read(PikaObj *self){
2021-11-14 19:40:06 +08:00
obj_run(self, "platformRead()");
2021-10-25 20:16:08 +08:00
return obj_getInt(self, "readBuff");
}
2021-10-01 20:00:15 +08:00
void PikaStdDevice_GPIO_setMode(PikaObj* self, char* mode) {
if(strEqu(mode, "out")||strEqu(mode, "in")){
obj_setStr(self, "mode", mode);
2021-11-23 00:38:53 +08:00
obj_run(self, "platformSetMode()");
}else{
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] GPIO mode should be 'out' or 'in'.");
}
2021-10-01 20:00:15 +08:00
}
2021-10-25 20:16:08 +08:00
void PikaStdDevice_GPIO_setPull(PikaObj *self, char * pull){
if(strEqu(pull, "up")||strEqu(pull, "down")||strEqu(pull, "none")){
obj_setStr(self, "pull", pull);
}else{
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] GPIO pull should be 'up', 'down' or 'none'.");
}
}
2021-11-14 19:40:06 +08:00
void PikaStdDevice_GPIO_setPin(PikaObj* self, char *pinName) {
2021-10-01 20:00:15 +08:00
obj_setStr(self, "pin", pinName);
}
void PikaStdDevice_GPIO_platformDisable(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_GPIO_platformEnable(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_GPIO_platformLow(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_GPIO_platformHigh(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
2021-11-14 19:40:06 +08:00
void PikaStdDevice_GPIO_platformSetMode(PikaObj* self) {
2021-10-01 20:00:15 +08:00
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_GPIO_platformOff(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
void PikaStdDevice_GPIO_platformOn(PikaObj* self) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
}
2021-10-25 20:16:08 +08:00
2021-11-14 19:40:06 +08:00
void PikaStdDevice_GPIO_platformRead(PikaObj *self){
2021-10-25 20:16:08 +08:00
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] platform method need to be override.");
2022-01-11 09:39:35 +08:00
}