pikapython/package/PikaStdDevice/PikaStdDevice_GPIO.c

113 lines
3.0 KiB
C
Raw Normal View History

2021-10-01 20:00:15 +08:00
#include "PikaStdDevice_GPIO.h"
2022-02-26 14:40:56 +08:00
#include "BaseObj.h"
2021-10-01 20:00:15 +08:00
void PikaStdDevice_GPIO_init(PikaObj* self) {
obj_setInt(self, "isEnable", 0);
2022-03-19 09:49:19 +08:00
obj_setStr(self, "pin", "none");
2021-10-01 20:00:15 +08:00
obj_setStr(self, "mode", "out");
obj_setInt(self, "isOn", 0);
2021-10-25 20:16:08 +08:00
obj_setStr(self, "pull", "none");
2022-03-19 09:49:19 +08:00
obj_setInt(self, "id", -999);
}
int PikaStdDevice_GPIO_getId(PikaObj* self) {
return obj_getInt(self, "id");
}
void PikaStdDevice_GPIO_setId(PikaObj* self, int id) {
obj_setInt(self, "id", id);
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_runNativeMethod(self, "platformDisable", NULL);
2021-10-01 20:00:15 +08:00
}
void PikaStdDevice_GPIO_enable(PikaObj* self) {
obj_setInt(self, "isEnable", 1);
obj_runNativeMethod(self, "platformEnable", NULL);
2021-10-01 20:00:15 +08:00
}
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_runNativeMethod(self, "platformLow", NULL);
2021-10-01 20:00:15 +08:00
}
void PikaStdDevice_GPIO_high(PikaObj* self) {
obj_setInt(self, "isOn", 1);
obj_runNativeMethod(self, "platformHigh", NULL);
2021-10-01 20:00:15 +08:00
}
2022-02-26 14:40:56 +08:00
int PikaStdDevice_GPIO_read(PikaObj* self) {
obj_runNativeMethod(self, "platformRead", NULL);
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) {
2022-02-26 14:40:56 +08:00
if (strEqu(mode, "out") || strEqu(mode, "in")) {
obj_setStr(self, "mode", mode);
obj_runNativeMethod(self, "platformSetMode", NULL);
2022-02-26 14:40:56 +08:00
} else {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] GPIO mode should be 'out' or 'in'.");
}
2021-10-01 20:00:15 +08:00
}
2022-02-26 14:40:56 +08:00
void PikaStdDevice_GPIO_setPull(PikaObj* self, char* pull) {
if (strEqu(pull, "up") || strEqu(pull, "down") || strEqu(pull, "none")) {
2021-10-25 20:16:08 +08:00
obj_setStr(self, "pull", pull);
2022-02-26 14:40:56 +08:00
} else {
2021-10-25 20:16:08 +08:00
obj_setErrorCode(self, 1);
2022-02-26 14:40:56 +08:00
obj_setSysOut(self,
"[error] GPIO pull should be 'up', 'down' or 'none'.");
2021-10-25 20:16:08 +08:00
}
}
2022-02-26 14:40:56 +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) {
2022-08-26 19:41:25 +08:00
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
2021-10-01 20:00:15 +08:00
}
void PikaStdDevice_GPIO_platformEnable(PikaObj* self) {
2022-08-26 19:41:25 +08:00
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
2021-10-01 20:00:15 +08:00
}
2022-08-16 11:05:19 +08:00
2021-10-01 20:00:15 +08:00
void PikaStdDevice_GPIO_platformLow(PikaObj* self) {
2022-08-26 19:41:25 +08:00
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
2021-10-01 20:00:15 +08:00
}
void PikaStdDevice_GPIO_platformHigh(PikaObj* self) {
2022-08-26 19:41:25 +08:00
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
2021-10-01 20:00:15 +08:00
}
2021-11-14 19:40:06 +08:00
void PikaStdDevice_GPIO_platformSetMode(PikaObj* self) {
2022-08-26 19:41:25 +08:00
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
2021-10-01 20:00:15 +08:00
}
void PikaStdDevice_GPIO_platformOff(PikaObj* self) {
2022-08-26 19:41:25 +08:00
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
2021-10-01 20:00:15 +08:00
}
void PikaStdDevice_GPIO_platformOn(PikaObj* self) {
2022-08-26 19:41:25 +08:00
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
2021-10-01 20:00:15 +08:00
}
2021-10-25 20:16:08 +08:00
2022-02-26 14:40:56 +08:00
void PikaStdDevice_GPIO_platformRead(PikaObj* self) {
2022-08-26 19:41:25 +08:00
ABSTRACT_METHOD_NEED_OVERRIDE_ERROR();
2022-03-19 09:49:19 +08:00
}