From 4a70db146533beeb4dbaabb7ad6ea9db33656ec8 Mon Sep 17 00:00:00 2001 From: lyon1998 Date: Thu, 14 Apr 2022 23:31:47 +0800 Subject: [PATCH] add default val in __init__ for SPI --- package/PikaStdDevice/PikaStdDevice_SPI.c | 42 +++++++++++-------- .../PikaStdDevice/PikaStdDevice_SPI.c | 42 +++++++++++-------- 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/package/PikaStdDevice/PikaStdDevice_SPI.c b/package/PikaStdDevice/PikaStdDevice_SPI.c index 31e613514..2416bc395 100644 --- a/package/PikaStdDevice/PikaStdDevice_SPI.c +++ b/package/PikaStdDevice/PikaStdDevice_SPI.c @@ -1,76 +1,84 @@ #include "PikaStdDevice_SPI.h" #include "BaseObj.h" #include "PikaObj.h" -void PikaStdDevice_SPI___init__(PikaObj *self){ +void PikaStdDevice_SPI___init__(PikaObj* self) { + obj_setInt(self, "baudRate", 1000); + obj_setInt(self, "id", 0); + obj_setStr(self, "name", "none"); + obj_setInt(self, "name", 0); + obj_setStr(self, "MISOpin", "none"); + obj_setStr(self, "MOSIpin", "none"); + obj_setStr(self, "SCKpin", "none"); + obj_setInt(self, "polarity", 0); } -void PikaStdDevice_SPI_disable(PikaObj *self){ +void PikaStdDevice_SPI_disable(PikaObj* self) { obj_runNativeMethod(self, "platformDisable", NULL); } -void PikaStdDevice_SPI_enable(PikaObj *self){ +void PikaStdDevice_SPI_enable(PikaObj* self) { obj_runNativeMethod(self, "platformEnable", NULL); } -void PikaStdDevice_SPI_write(PikaObj *self, char * data){ +void PikaStdDevice_SPI_write(PikaObj* self, char* data) { obj_setStr(self, "writeData", data); obj_runNativeMethod(self, "platformWrite", NULL); } -char * PikaStdDevice_SPI_read(PikaObj *self, int length){ +char* PikaStdDevice_SPI_read(PikaObj* self, int length) { obj_setInt(self, "length", length); obj_runNativeMethod(self, "platformRead", NULL); return obj_getStr(self, "readData"); } -void PikaStdDevice_SPI_setBaudRate(PikaObj *self, int baudRate){ +void PikaStdDevice_SPI_setBaudRate(PikaObj* self, int baudRate) { obj_setInt(self, "baudRate", baudRate); } -void PikaStdDevice_SPI_setId(PikaObj *self, int id){ +void PikaStdDevice_SPI_setId(PikaObj* self, int id) { obj_setInt(self, "id", id); } -void PikaStdDevice_SPI_setName(PikaObj *self, char * name){ +void PikaStdDevice_SPI_setName(PikaObj* self, char* name) { obj_setStr(self, "name", name); } -void PikaStdDevice_SPI_setPhase(PikaObj *self, int phase){ +void PikaStdDevice_SPI_setPhase(PikaObj* self, int phase) { obj_setInt(self, "name", phase); } -void PikaStdDevice_SPI_setPinMISO(PikaObj *self, char * pin){ +void PikaStdDevice_SPI_setPinMISO(PikaObj* self, char* pin) { obj_setStr(self, "MISOpin", pin); } -void PikaStdDevice_SPI_setPinMOSI(PikaObj *self, char * pin){ +void PikaStdDevice_SPI_setPinMOSI(PikaObj* self, char* pin) { obj_setStr(self, "MOSIpin", pin); } -void PikaStdDevice_SPI_setPinSCK(PikaObj *self, char * pin){ +void PikaStdDevice_SPI_setPinSCK(PikaObj* self, char* pin) { obj_setStr(self, "SCKpin", pin); } -void PikaStdDevice_SPI_setPolarity(PikaObj *self, int polarity){ +void PikaStdDevice_SPI_setPolarity(PikaObj* self, int polarity) { obj_setInt(self, "polarity", polarity); } -void PikaStdDevice_SPI_platformDisable(PikaObj *self){ +void PikaStdDevice_SPI_platformDisable(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } -void PikaStdDevice_SPI_platformEnable(PikaObj *self){ +void PikaStdDevice_SPI_platformEnable(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } -void PikaStdDevice_SPI_platformWrite(PikaObj *self){ +void PikaStdDevice_SPI_platformWrite(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } -void PikaStdDevice_SPI_platformRead(PikaObj *self){ +void PikaStdDevice_SPI_platformRead(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } diff --git a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/PikaStdDevice_SPI.c b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/PikaStdDevice_SPI.c index 31e613514..2416bc395 100644 --- a/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/PikaStdDevice_SPI.c +++ b/port/linux/package/pikascript/pikascript-lib/PikaStdDevice/PikaStdDevice_SPI.c @@ -1,76 +1,84 @@ #include "PikaStdDevice_SPI.h" #include "BaseObj.h" #include "PikaObj.h" -void PikaStdDevice_SPI___init__(PikaObj *self){ +void PikaStdDevice_SPI___init__(PikaObj* self) { + obj_setInt(self, "baudRate", 1000); + obj_setInt(self, "id", 0); + obj_setStr(self, "name", "none"); + obj_setInt(self, "name", 0); + obj_setStr(self, "MISOpin", "none"); + obj_setStr(self, "MOSIpin", "none"); + obj_setStr(self, "SCKpin", "none"); + obj_setInt(self, "polarity", 0); } -void PikaStdDevice_SPI_disable(PikaObj *self){ +void PikaStdDevice_SPI_disable(PikaObj* self) { obj_runNativeMethod(self, "platformDisable", NULL); } -void PikaStdDevice_SPI_enable(PikaObj *self){ +void PikaStdDevice_SPI_enable(PikaObj* self) { obj_runNativeMethod(self, "platformEnable", NULL); } -void PikaStdDevice_SPI_write(PikaObj *self, char * data){ +void PikaStdDevice_SPI_write(PikaObj* self, char* data) { obj_setStr(self, "writeData", data); obj_runNativeMethod(self, "platformWrite", NULL); } -char * PikaStdDevice_SPI_read(PikaObj *self, int length){ +char* PikaStdDevice_SPI_read(PikaObj* self, int length) { obj_setInt(self, "length", length); obj_runNativeMethod(self, "platformRead", NULL); return obj_getStr(self, "readData"); } -void PikaStdDevice_SPI_setBaudRate(PikaObj *self, int baudRate){ +void PikaStdDevice_SPI_setBaudRate(PikaObj* self, int baudRate) { obj_setInt(self, "baudRate", baudRate); } -void PikaStdDevice_SPI_setId(PikaObj *self, int id){ +void PikaStdDevice_SPI_setId(PikaObj* self, int id) { obj_setInt(self, "id", id); } -void PikaStdDevice_SPI_setName(PikaObj *self, char * name){ +void PikaStdDevice_SPI_setName(PikaObj* self, char* name) { obj_setStr(self, "name", name); } -void PikaStdDevice_SPI_setPhase(PikaObj *self, int phase){ +void PikaStdDevice_SPI_setPhase(PikaObj* self, int phase) { obj_setInt(self, "name", phase); } -void PikaStdDevice_SPI_setPinMISO(PikaObj *self, char * pin){ +void PikaStdDevice_SPI_setPinMISO(PikaObj* self, char* pin) { obj_setStr(self, "MISOpin", pin); } -void PikaStdDevice_SPI_setPinMOSI(PikaObj *self, char * pin){ +void PikaStdDevice_SPI_setPinMOSI(PikaObj* self, char* pin) { obj_setStr(self, "MOSIpin", pin); } -void PikaStdDevice_SPI_setPinSCK(PikaObj *self, char * pin){ +void PikaStdDevice_SPI_setPinSCK(PikaObj* self, char* pin) { obj_setStr(self, "SCKpin", pin); } -void PikaStdDevice_SPI_setPolarity(PikaObj *self, int polarity){ +void PikaStdDevice_SPI_setPolarity(PikaObj* self, int polarity) { obj_setInt(self, "polarity", polarity); } -void PikaStdDevice_SPI_platformDisable(PikaObj *self){ +void PikaStdDevice_SPI_platformDisable(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } -void PikaStdDevice_SPI_platformEnable(PikaObj *self){ +void PikaStdDevice_SPI_platformEnable(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } -void PikaStdDevice_SPI_platformWrite(PikaObj *self){ +void PikaStdDevice_SPI_platformWrite(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } -void PikaStdDevice_SPI_platformRead(PikaObj *self){ +void PikaStdDevice_SPI_platformRead(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); }