mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-01-29 17:22:56 +08:00
add std device
This commit is contained in:
parent
33db5cf1f4
commit
347ebe0dc0
60
src/package/pikascript/PikaStdDeivce.py
Normal file
60
src/package/pikascript/PikaStdDeivce.py
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
from PikaObj import *
|
||||||
|
|
||||||
|
|
||||||
|
class GPIO(TinyObj):
|
||||||
|
def init():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setPin(pinName: str):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def getPin() -> str:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def setMode(mode: str):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def getMode() -> str:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def enable():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def disable():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def high():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def low():
|
||||||
|
pass
|
||||||
|
|
||||||
|
# need be overrid
|
||||||
|
def platformHigh():
|
||||||
|
pass
|
||||||
|
|
||||||
|
# need override
|
||||||
|
def platformLow():
|
||||||
|
pass
|
||||||
|
|
||||||
|
# need override
|
||||||
|
def platformEnable():
|
||||||
|
pass
|
||||||
|
|
||||||
|
# need override
|
||||||
|
def platformDisable():
|
||||||
|
pass
|
||||||
|
|
||||||
|
# need override
|
||||||
|
def platformSetMode(mode: str):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Time(TinyObj):
|
||||||
|
# need override
|
||||||
|
def sleep_s(s: int):
|
||||||
|
pass
|
||||||
|
|
||||||
|
# need override
|
||||||
|
def sleep_ms(ms: int):
|
||||||
|
pass
|
@ -0,0 +1,96 @@
|
|||||||
|
#include "BaseObj.h"
|
||||||
|
#include "PikaStdDeivce_GPIO.h"
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_init(PikaObj *self)
|
||||||
|
{
|
||||||
|
obj_setInt(self, "isEnable", 0);
|
||||||
|
obj_setStr(self, "pin", "PA0");
|
||||||
|
obj_setStr(self, "mode", "out");
|
||||||
|
obj_setInt(self, "isOn", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_disable(PikaObj *self)
|
||||||
|
{
|
||||||
|
obj_setInt(self, "isEnable", 0);
|
||||||
|
obj_run(self, "platformDisable()");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_enable(PikaObj *self)
|
||||||
|
{
|
||||||
|
obj_setInt(self, "isEnable", 1);
|
||||||
|
obj_run(self, "platformEnable()");
|
||||||
|
}
|
||||||
|
|
||||||
|
char *PikaStdDeivce_GPIO_getMode(PikaObj *self)
|
||||||
|
{
|
||||||
|
return obj_getStr(self, "mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
char *PikaStdDeivce_GPIO_getPin(PikaObj *self)
|
||||||
|
{
|
||||||
|
return obj_getStr(self, "pin");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_low(PikaObj *self)
|
||||||
|
{
|
||||||
|
obj_setInt(self, "isOn", 0);
|
||||||
|
obj_run(self, "platformLow()");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_high(PikaObj *self)
|
||||||
|
{
|
||||||
|
obj_setInt(self, "isOn", 1);
|
||||||
|
obj_run(self, "platformHigh()");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_setMode(PikaObj *self, char *mode)
|
||||||
|
{
|
||||||
|
obj_setStr(self, "mode", mode);
|
||||||
|
obj_run(self, "platformSetMode(mode)");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_setPin(PikaObj *self, char *pinName)
|
||||||
|
{
|
||||||
|
obj_setStr(self, "pin", pinName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_platformDisable(PikaObj *self)
|
||||||
|
{
|
||||||
|
obj_setErrorCode(self, 1);
|
||||||
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_platformEnable(PikaObj *self)
|
||||||
|
{
|
||||||
|
obj_setErrorCode(self, 1);
|
||||||
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||||
|
}
|
||||||
|
void PikaStdDeivce_GPIO_platformLow(PikaObj *self)
|
||||||
|
{
|
||||||
|
obj_setErrorCode(self, 1);
|
||||||
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_platformHigh(PikaObj *self)
|
||||||
|
{
|
||||||
|
obj_setErrorCode(self, 1);
|
||||||
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_platformSetMode(PikaObj *self, char *mode)
|
||||||
|
{
|
||||||
|
obj_setErrorCode(self, 1);
|
||||||
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_platformOff(PikaObj *self)
|
||||||
|
{
|
||||||
|
obj_setErrorCode(self, 1);
|
||||||
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void PikaStdDeivce_GPIO_platformOn(PikaObj *self)
|
||||||
|
{
|
||||||
|
obj_setErrorCode(self, 1);
|
||||||
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
#include "BaseObj.h"
|
||||||
|
#include "PikaStdDeivce_Time.h"
|
||||||
|
|
||||||
|
void PikaStdDeivce_Time_sleep_ms(PikaObj *self, int ms)
|
||||||
|
{
|
||||||
|
obj_setErrorCode(self, 1);
|
||||||
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||||
|
}
|
||||||
|
void PikaStdDeivce_Time_sleep_s(PikaObj *self, int s)
|
||||||
|
{
|
||||||
|
obj_setErrorCode(self, 1);
|
||||||
|
obj_setSysOut(self, "[error] platform method need to be override.");
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user