Raspberry PI GPIO Scol plugin
plugin.cpp
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2016 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25/*
26 Raspberry PI GPIO library
27 First version : May 2016
28 Author : Bastien Bourineau
29*/
30
44#include "plugin.h"
45#include <scolMemoryHelper.hpp>
46
47#include "rpiservo.h"
48#include "rpilcd.h"
49#include "rpishiftdriver.h"
50#include "rpipin.h"
51#include "rpii2c.h"
52#include "rpiPCA9685.h"
53#include "rpiecho.h"
54
55#ifdef RPI
56 #include <unistd.h>
57 #include <wiringPi.h>
58#endif
59
60#ifdef SCOL_STATIC
61extern cbmachine ww;
62extern mmachine mm;
63#else
64cbmachine ww;
65mmachine mm;
66#endif
67
68//OBJECT
69int OBJ_GPIOPIN_SCOL;
70int GPIOPIN_NB_CB = 0;
71int OBJ_GPIOLCD_SCOL;
72int GPIOLCD_NB_CB =0;
73int OBJ_GPIOSERVO_SCOL;
74int GPIOSERVO_NB_CB = 0;
75int OBJ_GPIOSHIFTDRIVER_SCOL;
76int GPIOSHIFTDRIVER_NB_CB = 0;
77int OBJ_GPIOI2C_SCOL;
78int GPIOI2C_NB_CB = 0;
79int OBJ_GPIOPCA9685_SCOL;
80int GPIOPCA9685_NB_CB = 0;
81int OBJ_GPIOECHO_SCOL;
82int GPIOECHO_NB_CB = 0;
83
92int _GPIOdelay(mmachine m)
93{
94 int iDelay = MMget(m, 0);
95
96 if (iDelay == NIL)
97 iDelay = 0;
98 else
99 iDelay = MTOI(iDelay);
100
101#ifdef RPI
102 delay(iDelay);
103#endif
104
105 MMset(m, 0, ITOM(1));
106 return 0;
107}
108
118{
119 int iDelay = MMget(m, 0);
120
121 if (iDelay == NIL)
122 iDelay = 0;
123 else
124 iDelay = MTOI(iDelay);
125
126#ifdef RPI
127 delayMicroseconds(iDelay);
128#endif
129
130 MMset(m, 0, ITOM(1));
131 return 0;
132}
133
144int _crGPIOpin(mmachine m)
145{
146 int iMode = MMpull(m);
147 int iPin = MMpull(m);
148 int chn = MMget(m, 0);
149
150 if (chn == NIL)
151 {
152 MMechostr(MSKDEBUG, "_crGPIOpin error : channel is nil...\n");
153 return 0;
154 }
155
156 if (iPin == NIL || iMode == NIL)
157 {
158 MMechostr(MSKDEBUG, "_crGPIOpin error : pin or mode is nil...\n");
159 MMset(m, 0, NIL);
160 return 0;
161 }
162
163 iPin = MTOI(iPin);
164 iMode = MTOI(iMode);
165
166 if (iMode == GPIO_CLOCK && iPin != 4)
167 {
168 MMechostr(MSKDEBUG, "_setGPIOpinMode error : GPIO_CLOCK is only available for pin 4...\n");
169 MMset(m, 0, NIL);
170 return 0;
171 }
172
173 RpiPin* pinobj = new RpiPin(iPin, iMode);
174
175 // create
176 if ((MMpushPointer(m, pinobj) != 0))
177 {
178 SAFE_DELETE(pinobj);
179 MMset(m, 0, NIL);
180 return MERRMEM;
181 }
182
183 return OBJcreate(m, OBJ_GPIOPIN_SCOL, SCOL_PTR pinobj, NIL, 0);
184}
185
194int _dsGPIOpin(mmachine m)
195{
196#ifdef _SCOL_DEBUG_
197 MMechostr(MSKDEBUG, "_dsGPIOpin\n");
198#endif
199
200 int objtab = MMget(m, 0);
201 if (objtab == NIL)
202 {
203 MMechostr(MSKDEBUG, "_dsGPIOpin : ObjGpioPin is NIL\n");
204 MMset(m, 0, NIL);
205 return 0;
206 }
207
208 OBJdelTM(m, OBJ_GPIOPIN_SCOL, objtab);
209 MMset(m, 0, ITOM(0));
210
211#ifdef _SCOL_DEBUG_
212 MMechostr(MSKDEBUG, "ok\n");
213#endif
214 return 0;
215}
216
226int _setGPIOpinPullMode (mmachine m)
227{
228 int iMode = MMpull(m);
229 int iPinObj = MMget(m, 0);
230
231 if (iPinObj == NIL || iMode == NIL)
232 {
233 MMechostr (MSKDEBUG, "_setGPIOpinPullMode error : pin object or mode is nil...\n");
234 MMset(m, 0, NIL);
235 return 0;
236 }
237
238 iMode = MTOI(iMode);
239
240 RpiPin* gpioPinObj = MMgetPointer<RpiPin*>(m, MTOP(iPinObj));
241 if (gpioPinObj == 0)
242 {
243 MMset(m, 0, NIL);
244 return 0;
245 }
246
247 gpioPinObj->SetPullUpDnControl(iMode);
248
249 MMset(m, 0, ITOM(1));
250 return 0;
251}
252
262int _GPIOdigitalWrite (mmachine m)
263{
264 int iVal = MMpull(m);
265 int iPinObj = MMget(m, 0);
266
267 if (iPinObj == NIL || iVal == NIL)
268 {
269 MMechostr (MSKDEBUG, "_GPIOdigitalWrite error : pin object or value is nil...\n");
270 MMset(m, 0, NIL);
271 return 0;
272 }
273
274 iVal = MTOI(iVal);
275
276 if (iVal > 0)
277 iVal = HIGH;
278 else
279 iVal = LOW;
280
281 RpiPin* gpioPinObj = MMgetPointer<RpiPin*>(m, MTOP(iPinObj));
282 if (gpioPinObj == 0)
283 {
284 MMset(m, 0, NIL);
285 return 0;
286 }
287
288 gpioPinObj->DigitalWrite(iVal);
289
290 MMset(m, 0, ITOM(1));
291 return 0;
292}
293
302int _GPIOdigitalRead (mmachine m)
303{
304 int iPinObj = MMget(m, 0);
305
306 if (iPinObj == NIL)
307 {
308 MMechostr (MSKDEBUG, "_GPIOdigitalRead error : pin object is nil...\n");
309 MMset(m, 0, NIL);
310 return 0;
311 }
312
313 RpiPin* gpioPinObj = MMgetPointer<RpiPin*>(m, MTOP(iPinObj));
314 if (gpioPinObj == 0)
315 {
316 MMset(m, 0, NIL);
317 return 0;
318 }
319
320 MMset(m, 0, ITOM(gpioPinObj->DigitalRead()));
321 return 0;
322}
323
333int _GPIOanalogWrite (mmachine m)
334{
335 int iVal = MMpull(m);
336 int iPinObj = MMget(m, 0);
337
338 if (iPinObj == NIL || iVal == NIL)
339 {
340 MMechostr (MSKDEBUG, "_GPIOanalogWrite error : pin object or value is nil...\n");
341 MMset(m, 0, NIL);
342 return 0;
343 }
344
345 iVal = MTOI(iVal);
346
347 RpiPin* gpioPinObj = MMgetPointer<RpiPin*>(m, MTOP(iPinObj));
348 if (gpioPinObj == 0)
349 {
350 MMset(m, 0, NIL);
351 return 0;
352 }
353
354 gpioPinObj->AnalogWrite(iVal);
355
356 MMset(m, 0, ITOM(1));
357 return 0;
358}
359
368int _GPIOanalogRead (mmachine m)
369{
370 int iPinObj = MMget(m, 0);
371
372 if (iPinObj == NIL)
373 {
374 MMechostr (MSKDEBUG, "_GPIOanalogRead error : pin object is nil...\n");
375 MMset(m, 0, NIL);
376 return 0;
377 }
378
379 RpiPin* gpioPinObj = MMgetPointer<RpiPin*>(m, MTOP(iPinObj));
380 if (gpioPinObj == 0)
381 {
382 MMset(m, 0, NIL);
383 return 0;
384 }
385
386 MMset(m, 0, ITOM(gpioPinObj->AnalogRead()));
387 return 0;
388}
389
399int _GPIOpwmWrite(mmachine m)
400{
401 int iVal = MMpull(m);
402 int iPinObj = MMget(m, 0);
403
404 if (iPinObj == NIL || iVal == NIL)
405 {
406 MMechostr(MSKDEBUG, "_GPIOpwmWrite error : pin object or value is nil...\n");
407 MMset(m, 0, NIL);
408 return 0;
409 }
410
411 iVal = MTOI(iVal);
412
413 RpiPin* gpioPinObj = MMgetPointer<RpiPin*>(m, MTOP(iPinObj));
414 if (gpioPinObj == 0)
415 {
416 MMset(m, 0, NIL);
417 return 0;
418 }
419
420 gpioPinObj->PwmWrite(iVal);
421
422 MMset(m, 0, ITOM(1));
423 return 0;
424}
425
447int _crGPIOlcd(mmachine m)
448{
449 int iD7 = MMpull(m);
450 int iD6 = MMpull(m);
451 int iD5 = MMpull(m);
452 int iD4 = MMpull(m);
453 int iD3 = MMpull(m);
454 int iD2 = MMpull(m);
455 int iD1 = MMpull(m);
456 int iD0 = MMpull(m);
457 int iStrb = MMpull(m);
458 int iRs = MMpull(m);
459 int iBits = MMpull(m);
460 int iCols = MMpull(m);
461 int iRows = MMpull(m);
462 int chn = MMget(m, 0);
463
464 if (chn == NIL)
465 {
466 MMechostr(MSKDEBUG, "_crGPIOlcd error : channel is nil...\n");
467 return 0;
468 }
469
470 if (iRows == NIL || iCols == NIL || iBits == NIL || iRs == NIL || iStrb == NIL || iD0 == NIL || iD1 == NIL || iD2 == NIL || iD4 == NIL)
471 {
472 MMechostr(MSKDEBUG, "_crGPIOlcd error : missing parameter...\n");
473 MMset(m, 0, NIL);
474 return 0;
475 }
476
477 if (iD7 == NIL)
478 iD7 = 0;
479
480 if (iD6 == NIL)
481 iD6 = 0;
482
483 if (iD5 == NIL)
484 iD5 = 0;
485
486 if (iD4 == NIL)
487 iD4 = 0;
488
489 RpiLCD* lcdobj = new RpiLCD(MTOI(iRows), MTOI(iCols), MTOI(iBits), MTOI(iRs), MTOI(iStrb), MTOI(iD0), MTOI(iD1), MTOI(iD2), MTOI(iD3), MTOI(iD4), MTOI(iD5), MTOI(iD6), MTOI(iD7));
490
491 // create
492 if ((MMpushPointer(m, lcdobj) != 0))
493 {
494 SAFE_DELETE(lcdobj);
495 MMset(m, 0, NIL);
496 return MERRMEM;
497 }
498
499 return OBJcreate(m, OBJ_GPIOLCD_SCOL, SCOL_PTR lcdobj, NIL, 0);
500}
501
510int _dsGPIOlcd(mmachine m)
511{
512#ifdef _SCOL_DEBUG_
513 MMechostr(MSKDEBUG, "_dsGPIOlcd\n");
514#endif
515
516 int objtab = MMget(m, 0);
517 if (objtab == NIL)
518 {
519 MMechostr(MSKDEBUG, "_dsGPIOpin : ObjGpioLcd is NIL\n");
520 MMset(m, 0, NIL);
521 return 0;
522 }
523
524 OBJdelTM(m, OBJ_GPIOLCD_SCOL, objtab);
525 MMset(m, 0, ITOM(0));
526
527#ifdef _SCOL_DEBUG_
528 MMechostr(MSKDEBUG, "ok\n");
529#endif
530 return 0;
531}
532
541int _GPIOlcdHome(mmachine m)
542{
543 int iLcdObj = MMget(m, 0);
544
545 if (iLcdObj == NIL)
546 {
547 MMechostr(MSKDEBUG, "_GPIOlcdHome error : Lcd handle is nil...\n");
548 MMset(m, 0, NIL);
549 return 0;
550 }
551
552 RpiLCD* gpioLcdObj = MMgetPointer<RpiLCD*>(m, MTOP(iLcdObj));
553 if (gpioLcdObj == 0)
554 {
555 MMset(m, 0, NIL);
556 return 0;
557 }
558
559 gpioLcdObj->Home();
560
561 MMset(m, 0, ITOM(1));
562 return 0;
563}
564
573int _GPIOlcdClear(mmachine m)
574{
575 int iLcdObj = MMget(m, 0);
576
577 if (iLcdObj == NIL)
578 {
579 MMechostr(MSKDEBUG, "_GPIOlcdClear error : Lcd handle is nil...\n");
580 MMset(m, 0, NIL);
581 return 0;
582 }
583
584 RpiLCD* gpioLcdObj = MMgetPointer<RpiLCD*>(m, MTOP(iLcdObj));
585 if (gpioLcdObj == 0)
586 {
587 MMset(m, 0, NIL);
588 return 0;
589 }
590
591 gpioLcdObj->Clear();
592
593 MMset(m, 0, ITOM(1));
594 return 0;
595}
596
606int _GPIOlcdDisplay(mmachine m)
607{
608 int iState = MMpull(m);
609 int iLcdObj = MMget(m, 0);
610
611 if (iLcdObj == NIL)
612 {
613 MMechostr(MSKDEBUG, "_GPIOlcdDisplay error : Lcd handle is nil...\n");
614 MMset(m, 0, NIL);
615 return 0;
616 }
617
618 RpiLCD* gpioLcdObj = MMgetPointer<RpiLCD*>(m, MTOP(iLcdObj));
619 if (gpioLcdObj == 0)
620 {
621 MMset(m, 0, NIL);
622 return 0;
623 }
624
625 if (iState == NIL || MTOI(iState) <= 0)
626 iState = 0;
627 else
628 iState = 1;
629
630 gpioLcdObj->DisplayState(iState);
631
632 MMset(m, 0, ITOM(1));
633 return 0;
634}
635
645int _GPIOlcdCursor(mmachine m)
646{
647 int iState = MMpull(m);
648 int iLcdObj = MMget(m, 0);
649
650 if (iLcdObj == NIL)
651 {
652 MMechostr(MSKDEBUG, "_GPIOlcdDisplay error : Lcd handle is nil...\n");
653 MMset(m, 0, NIL);
654 return 0;
655 }
656
657 RpiLCD* gpioLcdObj = MMgetPointer<RpiLCD*>(m, MTOP(iLcdObj));
658 if (gpioLcdObj == 0)
659 {
660 MMset(m, 0, NIL);
661 return 0;
662 }
663
664 if (iState == NIL || MTOI(iState) <= 0)
665 iState = 0;
666 else
667 iState = 1;
668
669 gpioLcdObj->CursorState(iState);
670
671 MMset(m, 0, ITOM(1));
672 return 0;
673}
674
684int _GPIOlcdCursorBlink(mmachine m)
685{
686 int iState = MMpull(m);
687 int iLcdObj = MMget(m, 0);
688
689 if (iLcdObj == NIL)
690 {
691 MMechostr(MSKDEBUG, "_GPIOlcdDisplay error : Lcd handle is nil...\n");
692 MMset(m, 0, NIL);
693 return 0;
694 }
695
696 RpiLCD* gpioLcdObj = MMgetPointer<RpiLCD*>(m, MTOP(iLcdObj));
697 if (gpioLcdObj == 0)
698 {
699 MMset(m, 0, NIL);
700 return 0;
701 }
702
703 if (iState == NIL || MTOI(iState) <= 0)
704 iState = 0;
705 else
706 iState = 1;
707
708 gpioLcdObj->CursorBlink(iState);
709
710 MMset(m, 0, ITOM(1));
711 return 0;
712}
713
724int _GPIOlcdPosition(mmachine m)
725{
726 int iY = MMpull(m);
727 int iX = MMpull(m);
728 int iLcdObj = MMget(m, 0);
729
730 if (iLcdObj == NIL)
731 {
732 MMechostr(MSKDEBUG, "_GPIOlcdDisplay error : Lcd handle is nil...\n");
733 MMset(m, 0, NIL);
734 return 0;
735 }
736
737 RpiLCD* gpioLcdObj = MMgetPointer<RpiLCD*>(m, MTOP(iLcdObj));
738 if (gpioLcdObj == 0)
739 {
740 MMset(m, 0, NIL);
741 return 0;
742 }
743
744 if (iX == NIL || MTOI(iX) <= 0)
745 iX = 0;
746 else
747 iX = MTOI(iX);
748
749 if (iY == NIL || MTOI(iY) <= 0)
750 iY = 0;
751 else
752 iY = MTOI(iY);
753
754 gpioLcdObj->SetPosition(iX, iY);
755
756 MMset(m, 0, ITOM(1));
757 return 0;
758}
759
769int _GPIOlcdPuts(mmachine m)
770{
771 int iText = MMpull(m);
772 int iLcdObj = MMget(m, 0);
773
774 if (iLcdObj == NIL)
775 {
776 MMechostr(MSKDEBUG, "_GPIOlcdDisplay error : Lcd handle is nil...\n");
777 MMset(m, 0, NIL);
778 return 0;
779 }
780
781 RpiLCD* gpioLcdObj = MMgetPointer<RpiLCD*>(m, MTOP(iLcdObj));
782 if (gpioLcdObj == 0)
783 {
784 MMset(m, 0, NIL);
785 return 0;
786 }
787
788 std::string txtout = "";
789 if (iText != NIL)
790 txtout = MMstartstr(m, MTOP(iText));
791
792 if (txtout.empty())
793 {
794 MMechostr(MSKDEBUG, "_GPIOlcdPuts error : no text to print...\n");
795 MMset(m, 0, NIL);
796 return 0;
797 }
798
799 gpioLcdObj->Puts(txtout);
800
801 MMset(m, 0, ITOM(1));
802 return 0;
803}
804
805
816int _crGPIOservo(mmachine m)
817{
818 int iValue = MMpull(m);
819 int iPin = MMpull(m);
820 int chn = MMget(m, 0);
821
822 if (chn == NIL)
823 {
824 MMechostr(MSKDEBUG, "_crGPIOservo error : channel is nil...\n");
825 return 0;
826 }
827
828 if (iPin == NIL)
829 {
830 MMechostr(MSKDEBUG, "_crGPIOservo error : pin is nil...\n");
831 MMset(m, 0, NIL);
832 return 0;
833 }
834
835 iPin = MTOI(iPin);
836
837 float value = 90.0f;
838 if (iValue != NIL)
839 value = MTOF(iValue);
840
841 RpiServo* servoObj = new RpiServo(iPin, value);
842
843 // create
844 if ((MMpushPointer(m, servoObj) != 0))
845 {
846 SAFE_DELETE(servoObj);
847 MMset(m, 0, NIL);
848 return MERRMEM;
849 }
850
851 return OBJcreate(m, OBJ_GPIOSERVO_SCOL, SCOL_PTR servoObj, NIL, 0);
852}
853
862int _dsGPIOservo(mmachine m)
863{
864#ifdef _SCOL_DEBUG_
865 MMechostr(MSKDEBUG, "_dsGPIOservo\n");
866#endif
867
868 int objtab = MMget(m, 0);
869 if (objtab == NIL)
870 {
871 MMechostr(MSKDEBUG, "_dsGPIOservo : ObjGpioServo is NIL\n");
872 MMset(m, 0, NIL);
873 return 0;
874 }
875
876 OBJdelTM(m, OBJ_GPIOSERVO_SCOL, objtab);
877 MMset(m, 0, ITOM(0));
878
879#ifdef _SCOL_DEBUG_
880 MMechostr(MSKDEBUG, "ok\n");
881#endif
882 return 0;
883}
884
885
895int _setGPIOservoAngle(mmachine m)
896{
897 int iValue = MMpull(m);
898 int iServoObj = MMget(m, 0);
899
900 if (iServoObj == NIL)
901 {
902 MMechostr(MSKDEBUG, "_setGPIOservoAngle error : servo object is nil...\n");
903 MMset(m, 0, NIL);
904 return 0;
905 }
906
907 float value = 90.0f;
908 if (iValue != NIL)
909 value = MTOF(iValue);
910
911 RpiServo* servoObj = MMgetPointer<RpiServo*>(m, MTOP(iServoObj));
912 if (servoObj == 0)
913 {
914 MMset(m, 0, NIL);
915 return 0;
916 }
917
918 servoObj->WriteValue(value);
919
920 MMset(m, 0, ITOM(1));
921 return 0;
922}
923
924
937int _crGPIOshiftDriver(mmachine m)
938{
939 int iNbOut = MMpull(m);
940 int iLatch = MMpull(m);
941 int iClock = MMpull(m);
942 int iData = MMpull(m);
943 int chn = MMget(m, 0);
944
945 if (chn == NIL)
946 {
947 MMechostr(MSKDEBUG, "_crGPIOshiftDriver error : channel is nil...\n");
948 return 0;
949 }
950
951 if ((iData == NIL) || (iClock == NIL) || (iLatch == NIL))
952 {
953 MMechostr(MSKDEBUG, "_crGPIOshiftDriver error : pin is nil...\n");
954 MMset(m, 0, NIL);
955 return 0;
956 }
957
958 iData = MTOI(iData);
959 iClock = MTOI(iClock);
960 iLatch = MTOI(iLatch);
961 iNbOut = (iNbOut == NIL) ? 8 : MTOI(iNbOut);
962
963 RpiShiftDriver* shiftDriverObj = new RpiShiftDriver(iData, iClock, iLatch, iNbOut);
964
965 // create
966 if ((MMpushPointer(m, shiftDriverObj) != 0))
967 {
968 SAFE_DELETE(shiftDriverObj);
969 MMset(m, 0, NIL);
970 return MERRMEM;
971 }
972
973 return OBJcreate(m, OBJ_GPIOSHIFTDRIVER_SCOL, SCOL_PTR shiftDriverObj, NIL, 0);
974}
975
984int _dsGPIOshiftDriver(mmachine m)
985{
986#ifdef _SCOL_DEBUG_
987 MMechostr(MSKDEBUG, "_dsGPIOservo\n");
988#endif
989
990 int objtab = MMget(m, 0);
991 if (objtab == NIL)
992 {
993 MMechostr(MSKDEBUG, "_dsGPIOshiftDriver : ObjGpioShiftDriver is NIL\n");
994 MMset(m, 0, NIL);
995 return 0;
996 }
997
998 OBJdelTM(m, OBJ_GPIOSHIFTDRIVER_SCOL, objtab);
999 MMset(m, 0, ITOM(0));
1000
1001#ifdef _SCOL_DEBUG_
1002 MMechostr(MSKDEBUG, "ok\n");
1003#endif
1004 return 0;
1005}
1006
1007
1018{
1019 int iValues = MMpull(m);
1020 int iShiftRegisterObj = MMget(m, 0);
1021
1022 if (iShiftRegisterObj == NIL)
1023 {
1024 MMechostr(MSKDEBUG, "_setGPIOshiftDriverValues error : ObjGpioShiftDriver is nil...\n");
1025 MMset(m, 0, NIL);
1026 return 0;
1027 }
1028
1029 RpiShiftDriver* gpioShiftDriverObj = MMgetPointer<RpiShiftDriver*>(m, MTOP(iShiftRegisterObj));
1030 if (gpioShiftDriverObj == 0)
1031 {
1032 MMset(m, 0, NIL);
1033 return 0;
1034 }
1035
1036 std::vector<RpiShiftDriver::shiftValue> values;
1037
1038 if (iValues != NIL)
1039 {
1040 // Iterate through the recursive tuple
1041 int dataTuple;
1042 int val, tm;
1043 iValues = MTOP(iValues);
1044 while (iValues != NIL)
1045 {
1046 // Get values
1047 dataTuple = MTOP(MMfetch(m, iValues, 0));
1048 val = MTOI(MMfetch(m, dataTuple, 0));
1049 tm = MTOI(MMfetch(m, dataTuple, 1));
1050 iValues = MTOP(MMfetch(m, iValues, 1));
1051
1052 // Add data
1053 values.push_back(RpiShiftDriver::shiftValue(val, tm));
1054 }
1055 }
1056 gpioShiftDriverObj->SetValues(values);
1057
1058 MMset(m, 0, ITOM(1));
1059 return 0;
1060}
1061
1071int _crGPIOi2c(mmachine m)
1072{
1073 int iDeviceId = MMpull(m);
1074 int chn = MMget(m, 0);
1075
1076 if (chn == NIL)
1077 {
1078 MMechostr(MSKDEBUG, "_crGPIOi2c error : channel is nil...\n");
1079 return 0;
1080 }
1081
1082 if (iDeviceId == NIL)
1083 {
1084 MMechostr(MSKDEBUG, "_crGPIOi2c error : Device ID is nil...\n");
1085 MMset(m, 0, NIL);
1086 return 0;
1087 }
1088
1089 iDeviceId = MTOI(iDeviceId);
1090
1091 RpiI2C* pinobj = new RpiI2C(iDeviceId);
1092
1093 // create
1094 if ((MMpushPointer(m, pinobj) != 0))
1095 {
1096 SAFE_DELETE(pinobj);
1097 MMset(m, 0, NIL);
1098 return MERRMEM;
1099 }
1100
1101 return OBJcreate(m, OBJ_GPIOI2C_SCOL, SCOL_PTR pinobj, NIL, 0);
1102}
1103
1112int _dsGPIOi2c(mmachine m)
1113{
1114#ifdef _SCOL_DEBUG_
1115 MMechostr(MSKDEBUG, "_dsGPIOi2c\n");
1116#endif
1117
1118 int objtab = MMget(m, 0);
1119 if (objtab == NIL)
1120 {
1121 MMechostr(MSKDEBUG, "_dsGPIOi2c : ObjGpioI2C is NIL\n");
1122 MMset(m, 0, NIL);
1123 return 0;
1124 }
1125
1126 OBJdelTM(m, OBJ_GPIOI2C_SCOL, objtab);
1127 MMset(m, 0, ITOM(0));
1128
1129#ifdef _SCOL_DEBUG_
1130 MMechostr(MSKDEBUG, "ok\n");
1131#endif
1132 return 0;
1133}
1134
1144int _GPIOi2cWrite (mmachine m)
1145{
1146 int iVal = MMpull(m);
1147 int iI2CObj = MMget(m, 0);
1148
1149 if (iI2CObj == NIL || iVal == NIL)
1150 {
1151 MMechostr (MSKDEBUG, "_GPIOi2cWrite error : I2C object or value is nil...\n");
1152 MMset(m, 0, NIL);
1153 return 0;
1154 }
1155
1156 iVal = MTOI(iVal);
1157
1158 RpiI2C* gpioI2CObj = MMgetPointer<RpiI2C*>(m, MTOP(iI2CObj));
1159 if (gpioI2CObj == 0)
1160 {
1161 MMset(m, 0, NIL);
1162 return 0;
1163 }
1164
1165 gpioI2CObj->Write(iVal);
1166
1167 MMset(m, 0, ITOM(1));
1168 return 0;
1169}
1170
1179int _GPIOi2cRead (mmachine m)
1180{
1181 int iI2CObj = MMget(m, 0);
1182
1183 if (iI2CObj == NIL)
1184 {
1185 MMechostr (MSKDEBUG, "_GPIOi2cRead error : I2C object is nil...\n");
1186 MMset(m, 0, NIL);
1187 return 0;
1188 }
1189
1190 RpiI2C* gpioI2CObj = MMgetPointer<RpiI2C*>(m, MTOP(iI2CObj));
1191 if (gpioI2CObj == 0)
1192 {
1193 MMset(m, 0, NIL);
1194 return 0;
1195 }
1196
1197 MMset(m, 0, ITOM(gpioI2CObj->Read()));
1198 return 0;
1199}
1200
1211int _GPIOi2cWrite8 (mmachine m)
1212{
1213 int iVal = MMpull(m);
1214 int iReg = MMpull(m);
1215 int iI2CObj = MMget(m, 0);
1216
1217 if (iI2CObj == NIL || iVal == NIL)
1218 {
1219 MMechostr (MSKDEBUG, "_GPIOi2cWrite8 error : I2C object or value is nil...\n");
1220 MMset(m, 0, NIL);
1221 return 0;
1222 }
1223
1224 if (iReg == NIL)
1225 {
1226 MMechostr (MSKDEBUG, "_GPIOi2cWrite8 error : I2C register is nil...\n");
1227 MMset(m, 0, NIL);
1228 return 0;
1229 }
1230
1231 iReg = MTOI(iReg);
1232 iVal = MTOI(iVal);
1233
1234 RpiI2C* gpioI2CObj = MMgetPointer<RpiI2C*>(m, MTOP(iI2CObj));
1235 if (gpioI2CObj == 0)
1236 {
1237 MMset(m, 0, NIL);
1238 return 0;
1239 }
1240
1241 gpioI2CObj->WriteReg8(iReg, iVal);
1242
1243 MMset(m, 0, ITOM(1));
1244 return 0;
1245}
1246
1256int _GPIOi2cRead8 (mmachine m)
1257{
1258 int iReg = MMpull(m);
1259 int iI2CObj = MMget(m, 0);
1260
1261 if (iI2CObj == NIL)
1262 {
1263 MMechostr (MSKDEBUG, "_GPIOi2cRead8 error : I2C object object is nil...\n");
1264 MMset(m, 0, NIL);
1265 return 0;
1266 }
1267
1268 if (iReg == NIL)
1269 {
1270 MMechostr (MSKDEBUG, "_GPIOi2cRead8 error : I2C register is nil...\n");
1271 MMset(m, 0, NIL);
1272 return 0;
1273 }
1274
1275 iReg = MTOI(iReg);
1276
1277 RpiI2C* gpioI2CObj = MMgetPointer<RpiI2C*>(m, MTOP(iI2CObj));
1278 if (gpioI2CObj == 0)
1279 {
1280 MMset(m, 0, NIL);
1281 return 0;
1282 }
1283
1284 MMset(m, 0, ITOM(gpioI2CObj->ReadReg8(iReg)));
1285 return 0;
1286}
1287
1298int _GPIOi2cWrite16 (mmachine m)
1299{
1300 int iVal = MMpull(m);
1301 int iReg = MMpull(m);
1302 int iI2CObj = MMget(m, 0);
1303
1304 if (iI2CObj == NIL || iVal == NIL)
1305 {
1306 MMechostr (MSKDEBUG, "_GPIOi2cWrite16 error : I2C object or value is nil...\n");
1307 MMset(m, 0, NIL);
1308 return 0;
1309 }
1310
1311 if (iReg == NIL)
1312 {
1313 MMechostr (MSKDEBUG, "_GPIOi2cWrite16 error : I2C register is nil...\n");
1314 MMset(m, 0, NIL);
1315 return 0;
1316 }
1317
1318 iReg = MTOI(iReg);
1319 iVal = MTOI(iVal);
1320
1321 RpiI2C* gpioI2CObj = MMgetPointer<RpiI2C*>(m, MTOP(iI2CObj));
1322 if (gpioI2CObj == 0)
1323 {
1324 MMset(m, 0, NIL);
1325 return 0;
1326 }
1327
1328 gpioI2CObj->WriteReg16(iReg, iVal);
1329
1330 MMset(m, 0, ITOM(1));
1331 return 0;
1332}
1333
1343int _GPIOi2cRead16 (mmachine m)
1344{
1345 int iReg = MMpull(m);
1346 int iI2CObj = MMget(m, 0);
1347
1348 if (iI2CObj == NIL)
1349 {
1350 MMechostr (MSKDEBUG, "_GPIOi2cRead16 error : I2C object object is nil...\n");
1351 MMset(m, 0, NIL);
1352 return 0;
1353 }
1354
1355 if (iReg == NIL)
1356 {
1357 MMechostr (MSKDEBUG, "_GPIOi2cRead16 error : I2C register is nil...\n");
1358 MMset(m, 0, NIL);
1359 return 0;
1360 }
1361
1362 iReg = MTOI(iReg);
1363
1364 RpiI2C* gpioI2CObj = MMgetPointer<RpiI2C*>(m, MTOP(iI2CObj));
1365 if (gpioI2CObj == 0)
1366 {
1367 MMset(m, 0, NIL);
1368 return 0;
1369 }
1370
1371 MMset(m, 0, ITOM(gpioI2CObj->ReadReg16(iReg)));
1372 return 0;
1373}
1374
1386int _crGPIOpca9685(mmachine m)
1387{
1388 int iFrequency = MMpull(m);
1389 int iPinBase = MMpull(m);
1390 int iDeviceId = MMpull(m);
1391 int chn = MMget(m, 0);
1392
1393 if (chn == NIL)
1394 {
1395 MMechostr(MSKDEBUG, "_crGPIOpca9685 error : channel is nil...\n");
1396 return 0;
1397 }
1398
1399 if (iDeviceId == NIL)
1400 {
1401 MMechostr(MSKDEBUG, "_crGPIOpca9685 error : Device ID is nil...\n");
1402 MMset(m, 0, NIL);
1403 return 0;
1404 }
1405
1406 iDeviceId = MTOI(iDeviceId);
1407
1408 if (iPinBase == NIL)
1409 iPinBase = 300;
1410 else
1411 iPinBase = MTOI(iPinBase);
1412
1413 if (iFrequency == NIL)
1414 iFrequency = 50;
1415 else
1416 iFrequency = MTOI(iFrequency);
1417
1418 RpiPCA9685* pca9685Obj = new RpiPCA9685(iDeviceId, iPinBase, iFrequency);
1419
1420 // create
1421 if ((MMpushPointer(m, pca9685Obj) != 0))
1422 {
1423 SAFE_DELETE(pca9685Obj);
1424 MMset(m, 0, NIL);
1425 return MERRMEM;
1426 }
1427
1428 return OBJcreate(m, OBJ_GPIOPCA9685_SCOL, SCOL_PTR pca9685Obj, NIL, 0);
1429}
1430
1439int _dsGPIOpca9685(mmachine m)
1440{
1441#ifdef _SCOL_DEBUG_
1442 MMechostr(MSKDEBUG, "_dsGPIOpca9685\n");
1443#endif
1444
1445 int objtab = MMget(m, 0);
1446 if (objtab == NIL)
1447 {
1448 MMechostr(MSKDEBUG, "_dsGPIOpca9685 : ObjGpioPCA9685 is NIL\n");
1449 MMset(m, 0, NIL);
1450 return 0;
1451 }
1452
1453 OBJdelTM(m, OBJ_GPIOPCA9685_SCOL, objtab);
1454 MMset(m, 0, ITOM(0));
1455
1456#ifdef _SCOL_DEBUG_
1457 MMechostr(MSKDEBUG, "ok\n");
1458#endif
1459 return 0;
1460}
1461
1462
1473int _GPIOpca9685Write (mmachine m)
1474{
1475 int iVal = MMpull(m);
1476 int iPin = MMpull(m);
1477 int iPCA9685 = MMget(m, 0);
1478
1479 if (iPCA9685 == NIL || iPin == NIL || iVal == NIL)
1480 {
1481 MMechostr (MSKDEBUG, "_GPIOpca9685Write error : I2C object, pin or value is nil...\n");
1482 MMset(m, 0, NIL);
1483 return 0;
1484 }
1485
1486 iPin = MTOI(iPin);
1487 iVal = MTOI(iVal);
1488
1489 RpiPCA9685* gpioI2CObj = MMgetPointer<RpiPCA9685*>(m, MTOP(iPCA9685));
1490 if (gpioI2CObj == 0)
1491 {
1492 MMset(m, 0, NIL);
1493 return 0;
1494 }
1495
1496 gpioI2CObj->PwmWrite(iPin, iVal);
1497
1498 MMset(m, 0, ITOM(1));
1499 return 0;
1500}
1501
1511int _GPIOpca9685Read (mmachine m)
1512{
1513 int iPin = MMpull(m);
1514 int iPCA9685 = MMget(m, 0);
1515
1516 if (iPCA9685 == NIL || iPin == NIL)
1517 {
1518 MMechostr (MSKDEBUG, "_GPIOpca9685Read error : I2C object or pin is nil...\n");
1519 MMset(m, 0, NIL);
1520 return 0;
1521 }
1522
1523 RpiPCA9685* gpioI2CObj = MMgetPointer<RpiPCA9685*>(m, MTOP(iPCA9685));
1524 if (gpioI2CObj == 0)
1525 {
1526 MMset(m, 0, NIL);
1527 return 0;
1528 }
1529
1530 iPin = MTOI(iPin);
1531
1532 MMset(m, 0, ITOM(gpioI2CObj->PwmRead(iPin)));
1533 return 0;
1534}
1535
1544int _GPIOpca9685Reset (mmachine m)
1545{
1546 int iPCA9685 = MMget(m, 0);
1547
1548 if (iPCA9685 == NIL)
1549 {
1550 MMechostr (MSKDEBUG, "_GPIOpca9685Reset error : I2C object is nil...\n");
1551 MMset(m, 0, NIL);
1552 return 0;
1553 }
1554
1555 RpiPCA9685* gpioI2CObj = MMgetPointer<RpiPCA9685*>(m, MTOP(iPCA9685));
1556 if (gpioI2CObj == 0)
1557 {
1558 MMset(m, 0, NIL);
1559 return 0;
1560 }
1561
1562 gpioI2CObj->Reset();
1563
1564 MMset(m, 0, ITOM(1));
1565 return 0;
1566}
1567
1578{
1579 int iFrequency = MMpull(m);
1580 int iPCA9685 = MMget(m, 0);
1581
1582 if (iPCA9685 == NIL)
1583 {
1584 MMechostr (MSKDEBUG, "_GPIOpca9685SetFrequency error : I2C object is nil...\n");
1585 MMset(m, 0, NIL);
1586 return 0;
1587 }
1588
1589 if (iFrequency == NIL)
1590 iFrequency = 50;
1591 else
1592 iFrequency = MTOI(iFrequency);
1593
1594 RpiPCA9685* gpioI2CObj = MMgetPointer<RpiPCA9685*>(m, MTOP(iPCA9685));
1595 if (gpioI2CObj == 0)
1596 {
1597 MMset(m, 0, NIL);
1598 return 0;
1599 }
1600
1601 gpioI2CObj->SetFrequency(iFrequency);
1602
1603 MMset(m, 0, ITOM(1));
1604 return 0;
1605}
1606
1607
1608
1620int _crGPIOecho(mmachine m)
1621{
1622 int iEchoPin = MMpull(m);
1623 int iTriggerPin = MMpull(m);
1624 int chn = MMget(m, 0);
1625
1626 if (chn == NIL)
1627 {
1628 MMechostr(MSKDEBUG, "_crGPIOecho error : channel is nil...\n");
1629 return 0;
1630 }
1631
1632 if (iTriggerPin == NIL || iEchoPin == NIL)
1633 {
1634 MMechostr(MSKDEBUG, "_crGPIOecho error : pin is nil...\n");
1635 MMset(m, 0, NIL);
1636 return 0;
1637 }
1638
1639 iTriggerPin = MTOI(iTriggerPin);
1640 iEchoPin = MTOI(iEchoPin);
1641
1642 RpiEcho* echoObj = new RpiEcho(iTriggerPin, iEchoPin);
1643
1644 // create
1645 if ((MMpushPointer(m, echoObj) != 0))
1646 {
1647 SAFE_DELETE(echoObj);
1648 MMset(m, 0, NIL);
1649 return MERRMEM;
1650 }
1651
1652 return OBJcreate(m, OBJ_GPIOECHO_SCOL, SCOL_PTR echoObj, NIL, 0);
1653}
1654
1663int _dsGPIOecho(mmachine m)
1664{
1665#ifdef _SCOL_DEBUG_
1666 MMechostr(MSKDEBUG, "_dsGPIOecho\n");
1667#endif
1668
1669 int objtab = MMget(m, 0);
1670 if (objtab == NIL)
1671 {
1672 MMechostr(MSKDEBUG, "_dsGPIOecho : ObjGpioEcho is NIL\n");
1673 MMset(m, 0, NIL);
1674 return 0;
1675 }
1676
1677 OBJdelTM(m, OBJ_GPIOECHO_SCOL, objtab);
1678 MMset(m, 0, ITOM(0));
1679
1680#ifdef _SCOL_DEBUG_
1681 MMechostr(MSKDEBUG, "ok\n");
1682#endif
1683 return 0;
1684}
1685
1686
1695int _getGPIOechoValue(mmachine m)
1696{
1697 int iEchoObj = MMget(m, 0);
1698
1699 if (iEchoObj == NIL)
1700 {
1701 MMechostr(MSKDEBUG, "_getGPIOechoValue error : echo object is nil...\n");
1702 MMset(m, 0, NIL);
1703 return 0;
1704 }
1705
1706 RpiEcho* echoObj = MMgetPointer<RpiEcho*>(m, MTOP(iEchoObj));
1707 if (echoObj == 0)
1708 {
1709 MMset(m, 0, NIL);
1710 return 0;
1711 }
1712
1713 MMset(m, 0, ITOM((int)echoObj->ReadValue()));
1714 return 0;
1715}
1716
1717NativeDefinition rpiGPIOEngine[] =
1718{
1719 { "ObjGpioI2C", TYPTYPE, NULL, NULL },
1720 { "ObjGpioPCA9685", TYPTYPE, NULL, NULL },
1721 { "ObjGpioShiftDriver", TYPTYPE, NULL, NULL },
1722 { "ObjGpioServo", TYPTYPE, NULL, NULL },
1723 { "ObjGpioLcd", TYPTYPE, NULL, NULL },
1724 { "ObjGpioPin", TYPTYPE, NULL, NULL },
1725 { "GPIO_DIGITAL_INPUT", TYPVAR, "I", SCOL_TYPTYPE(SOFT_DIGITAL_INPUT) },
1726 { "GPIO_INPUT", TYPVAR, "I", SCOL_TYPTYPE(INPUT) },
1727 { "GPIO_OUTPUT", TYPVAR, "I", SCOL_TYPTYPE(OUTPUT) },
1728 { "GPIO_CLOCK", TYPVAR, "I", SCOL_TYPTYPE(GPIO_CLOCK) },
1729 { "GPIO_PWM_OUTPUT", TYPVAR, "I", SCOL_TYPTYPE(PWM_OUTPUT) },
1730 { "GPIO_HIGH", TYPVAR, "I", SCOL_TYPTYPE(HIGH) },
1731 { "GPIO_LOW", TYPVAR, "I", SCOL_TYPTYPE(LOW) },
1732 { "GPIO_PUD_DOWN", TYPVAR, "I", SCOL_TYPTYPE(PUD_DOWN) },
1733 { "GPIO_PUD_UP", TYPVAR, "I", SCOL_TYPTYPE(PUD_UP) },
1734 { "GPIO_PUD_OFF", TYPVAR, "I", SCOL_TYPTYPE(PUD_OFF) },
1735 { "_GPIOdelay", 1, "fun [I] I", _GPIOdelay },
1736 { "_GPIOdelayMicroseconds", 1, "fun [I] I", _GPIOdelayMicroseconds },
1737
1738 { "_crGPIOpin", 3, "fun [Chn I I] ObjGpioPin", _crGPIOpin },
1739 { "_dsGPIOpin", 1, "fun [ObjGpioPin] I", _dsGPIOpin },
1740 { "_setGPIOpinPullMode", 2, "fun [ObjGpioPin I] I", _setGPIOpinPullMode },
1741 { "_GPIOdigitalWrite", 2, "fun [ObjGpioPin I] I", _GPIOdigitalWrite },
1742 { "_GPIOdigitalRead", 1, "fun [ObjGpioPin] I", _GPIOdigitalRead },
1743 { "_GPIOanalogWrite", 2, "fun [ObjGpioPin I] I", _GPIOanalogWrite },
1744 { "_GPIOanalogRead", 1, "fun [ObjGpioPin] I", _GPIOanalogRead },
1745 { "_GPIOpwmWrite", 2, "fun [ObjGpioPin I] I", _GPIOpwmWrite },
1746
1747 { "_crGPIOlcd", 14, "fun [Chn I I I I I I I I I I I I I] ObjGpioLcd", _crGPIOlcd },
1748 { "_dsGPIOlcd", 1, "fun [ObjGpioLcd] I", _dsGPIOlcd },
1749 { "_GPIOlcdHome", 1, "fun [ObjGpioLcd] I", _GPIOlcdHome },
1750 { "_GPIOlcdClear", 1, "fun [ObjGpioLcd] I", _GPIOlcdClear },
1751 { "_GPIOlcdDisplay", 2, "fun [ObjGpioLcd I] I", _GPIOlcdDisplay },
1752 { "_GPIOlcdCursor", 2, "fun [ObjGpioLcd I] I", _GPIOlcdCursor },
1753 { "_GPIOlcdCursorBlink", 2, "fun [ObjGpioLcd I] I", _GPIOlcdCursorBlink },
1754 { "_GPIOlcdPosition", 3, "fun [ObjGpioLcd I I] I", _GPIOlcdPosition },
1755 { "_GPIOlcdPuts", 2, "fun [ObjGpioLcd S] I", _GPIOlcdPuts },
1756
1757 { "_crGPIOservo", 3, "fun [Chn I F] ObjGpioServo", _crGPIOservo },
1758 { "_dsGPIOservo", 1, "fun [ObjGpioServo] I", _dsGPIOservo },
1759 { "_setGPIOservoAngle", 2, "fun [ObjGpioServo F] I", _setGPIOservoAngle },
1760
1761 { "_crGPIOshiftDriver", 5, "fun [Chn I I I I] ObjGpioShiftDriver", _crGPIOshiftDriver },
1762 { "_dsGPIOshiftDriver", 1, "fun [ObjGpioShiftDriver] I", _dsGPIOshiftDriver },
1763 { "_setGPIOshiftDriverValues", 2, "fun [ObjGpioShiftDriver [[I I] r1]] I", _setGPIOshiftDriverValues },
1764
1765 { "_crGPIOi2c", 2, "fun [Chn I] ObjGpioI2C", _crGPIOi2c },
1766 { "_dsGPIOi2c", 1, "fun [ObjGpioI2C] I", _dsGPIOi2c },
1767 { "_GPIOi2cWrite", 2, "fun [ObjGpioI2C I] I", _GPIOi2cWrite },
1768 { "_GPIOi2cRead", 1, "fun [ObjGpioI2C] I", _GPIOi2cRead },
1769 { "_GPIOi2cWrite8", 3, "fun [ObjGpioI2C I I] I", _GPIOi2cWrite8 },
1770 { "_GPIOi2cRead8", 2, "fun [ObjGpioI2C I] I", _GPIOi2cRead8 },
1771 { "_GPIOi2cWrite16", 3, "fun [ObjGpioI2C I] I", _GPIOi2cWrite16 },
1772 { "_GPIOi2cRead16", 2, "fun [ObjGpioI2C I] I", _GPIOi2cRead16 },
1773
1774 { "_crGPIOpca9685", 4, "fun [Chn I I I] ObjGpioPCA9685", _crGPIOpca9685 },
1775 { "_dsGPIOpca9685", 1, "fun [ObjGpioPCA9685] I", _dsGPIOpca9685 },
1776 { "_GPIOpca9685Write", 3, "fun [ObjGpioPCA9685 I I] I", _GPIOpca9685Write },
1777 { "_GPIOpca9685Read", 2, "fun [ObjGpioPCA9685 I] I", _GPIOpca9685Read },
1778 { "_GPIOpca9685Reset", 1, "fun [ObjGpioPCA9685] I", _GPIOpca9685Reset },
1779 { "_GPIOpca9685SetFrequency", 2, "fun [ObjGpioPCA9685 I] I", _GPIOpca9685SetFrequency },
1780
1781 { "_crGPIOecho", 3, "fun [Chn I I] ObjGpioEcho", _crGPIOecho },
1782 { "_dsGPIOecho", 1, "fun [ObjGpioEcho] I", _dsGPIOecho },
1783 { "_getGPIOechoValue", 1, "fun [ObjGpioEcho] I", _getGPIOechoValue }
1784};
1785
1786
1788int destroyGPIOpin(mmachine m, SCOL_PTR_TYPE handsys, int objtab)
1789{
1790 RpiPin* gpioPinObj = MMgetPointer<RpiPin*>(m, MTOP(objtab));
1791 SAFE_DELETE(gpioPinObj);
1792 MMsetPointer<RpiPin*>(m, MTOP(objtab), 0);
1793
1794 return 0;
1795}
1796
1798int destroyGPIOlcd(mmachine m, SCOL_PTR_TYPE handsys, int objtab)
1799{
1800 RpiLCD* gpioLcdObj = MMgetPointer<RpiLCD*>(m, MTOP(objtab));
1801 SAFE_DELETE(gpioLcdObj);
1802 MMsetPointer<RpiLCD*>(m, MTOP(objtab), 0);
1803
1804 return 0;
1805}
1806
1808int destroyGPIOservo(mmachine m, SCOL_PTR_TYPE handsys, int objtab)
1809{
1810 RpiServo* gpioServoObj = MMgetPointer<RpiServo*>(m, MTOP(objtab));
1811 SAFE_DELETE(gpioServoObj);
1812 MMsetPointer<RpiServo*>(m, MTOP(objtab), 0);
1813
1814 return 0;
1815}
1816
1818int destroyGPIOshiftDriver(mmachine m, SCOL_PTR_TYPE handsys, int objtab)
1819{
1820 RpiShiftDriver* gpioShiftDriverObj = MMgetPointer<RpiShiftDriver*>(m, MTOP(objtab));
1821 SAFE_DELETE(gpioShiftDriverObj);
1822 MMsetPointer<RpiServo*>(m, MTOP(objtab), 0);
1823
1824 return 0;
1825}
1826
1828int destroyGPIOi2c(mmachine m, SCOL_PTR_TYPE handsys, int objtab)
1829{
1830 RpiI2C* gpioI2CObj = MMgetPointer<RpiI2C*>(m, MTOP(objtab));
1831 SAFE_DELETE(gpioI2CObj);
1832 MMsetPointer<RpiI2C*>(m, MTOP(objtab), 0);
1833
1834 return 0;
1835}
1836
1838int destroyGPIOpca9685(mmachine m, SCOL_PTR_TYPE handsys, int objtab)
1839{
1840 RpiPCA9685* gpioPCA9685Obj = MMgetPointer<RpiPCA9685*>(m, MTOP(objtab));
1841 SAFE_DELETE(gpioPCA9685Obj);
1842 MMsetPointer<RpiPCA9685*>(m, MTOP(objtab), 0);
1843
1844 return 0;
1845}
1846
1848int destroyGPIOecho(mmachine m, SCOL_PTR_TYPE handsys, int objtab)
1849{
1850 RpiEcho* gpioEchoObj = MMgetPointer<RpiEcho*>(m, MTOP(objtab));
1851 SAFE_DELETE(gpioEchoObj);
1852 MMsetPointer<RpiEcho*>(m, MTOP(objtab), 0);
1853
1854 return 0;
1855}
1856
1857// Everything inside _cond and _endcond is ignored by doxygen
1859
1863int LoadGPIO(mmachine m)
1864{
1865 int k;
1866
1867#ifdef RPI
1868 if (getuid())
1869 {
1870 MMechostr(MSKDEBUG, "Init GPIO with sys mode, note that you need root privilieges for full support.\n");
1871 wiringPiSetupSys();
1872 }
1873 else
1874 {
1875 MMechostr(MSKDEBUG, "Init GPIO, with root privilieges and full support.\n");
1876 wiringPiSetupGpio();
1877 }
1878#endif
1879
1880 OBJ_GPIOPIN_SCOL = OBJregister(GPIOPIN_NB_CB, 0, destroyGPIOpin, "GPIOPin");
1881 OBJ_GPIOLCD_SCOL = OBJregister(GPIOLCD_NB_CB, 0, destroyGPIOlcd, "GPIOLcd");
1882 OBJ_GPIOSERVO_SCOL = OBJregister(GPIOSERVO_NB_CB, 0, destroyGPIOservo, "GPIOServo");
1883 OBJ_GPIOSHIFTDRIVER_SCOL = OBJregister(GPIOSHIFTDRIVER_NB_CB, 0, destroyGPIOshiftDriver, "GPIOShiftDriver");
1884 OBJ_GPIOI2C_SCOL = OBJregister(GPIOI2C_NB_CB, 0, destroyGPIOi2c, "GPIOI2C");
1885 OBJ_GPIOPCA9685_SCOL = OBJregister(GPIOPCA9685_NB_CB, 0, destroyGPIOpca9685, "GPIOPca9685");
1886 OBJ_GPIOECHO_SCOL = OBJregister(GPIOECHO_NB_CB, 0, destroyGPIOecho, "GPIOecho");
1887
1888 k = PKhardpak2(m, "RPIGPIO.pkg", sizeof(rpiGPIOEngine) / sizeof(rpiGPIOEngine[0]), rpiGPIOEngine);
1889 MMechostr(MSKDEBUG, " > Successfully Loaded\n\n");
1890 return k;
1891}
1893
1897#ifndef SCOL_STATIC
1898extern "C" SCOL_EXPORT int ScolLoadPlugin(mmachine m, cbmachine w)
1899#else
1900extern "C" SCOL_EXPORT int ScolGPIOLoadPlugin(mmachine m, cbmachine w)
1901#endif
1902{
1903 int k = 0;
1904 SCOLinitplugin(w);
1905 LoadGPIO(m);
1906 return k;
1907}
1908
1912#ifndef SCOL_STATIC
1913extern "C" SCOL_EXPORT int ScolUnloadPlugin()
1914#else
1915extern "C" SCOL_EXPORT int ScolGPIOUnloadPlugin()
1916#endif
1917{
1918 return 0;
1919}
1920
Definition rpii2c.h:6
int _GPIOlcdCursor(mmachine m)
_GPIOlcdCursor : This function change the cursor state On/Off of an lcd display
Definition plugin.cpp:645
int _GPIOi2cRead16(mmachine m)
_GPIOi2cRead16 : This function read the value on a GPIO I2C device 16bits register
Definition plugin.cpp:1343
int _setGPIOpinPullMode(mmachine m)
_setGPIOpinPullMode : This function set the pull-up or pull-down resistor mode on a GPIO pin
Definition plugin.cpp:226
int _GPIOanalogRead(mmachine m)
_GPIOanalogRead : This function read an analogic value on a GPIO pin
Definition plugin.cpp:368
int _GPIOpca9685Read(mmachine m)
_GPIOpca9685Read : This function read the value on a GPIO I2C PCA9685 device
Definition plugin.cpp:1511
int _GPIOlcdDisplay(mmachine m)
_GPIOlcdDisplay : This function change the display state On/Off of an lcd display
Definition plugin.cpp:606
int _GPIOpwmWrite(mmachine m)
_GPIOpwmWrite : This function write a value on a PWM GPIO pin (pin 18 on RPI), use softPWM for other ...
Definition plugin.cpp:399
int _crGPIOservo(mmachine m)
_crGPIOservo : This function create a GPIO servo motor object
Definition plugin.cpp:816
int _GPIOlcdHome(mmachine m)
_GPIOlcdHome : This function set the cursor to home state on lcd display
Definition plugin.cpp:541
int _GPIOlcdCursorBlink(mmachine m)
_GPIOlcdCursorBlink : This function change the cursor blink state On/Off of an lcd display
Definition plugin.cpp:684
int _crGPIOecho(mmachine m)
_crGPIOecho : This function create a GPIO echo object It allows to read a sensor value with a trigger...
Definition plugin.cpp:1620
int _GPIOlcdClear(mmachine m)
_GPIOlcdClear : This function clear an lcd display
Definition plugin.cpp:573
int _GPIOi2cWrite8(mmachine m)
_GPIOi2cWrite8 : This function write a value on a GPIO I2C device 8bits register
Definition plugin.cpp:1211
int _dsGPIOecho(mmachine m)
_dsGPIOecho : This function destroy a GPIO echo object
Definition plugin.cpp:1663
int _GPIOpca9685Reset(mmachine m)
_GPIOpca9685Reset : This function reset a GPIO I2C PCA9685 device
Definition plugin.cpp:1544
int _GPIOi2cWrite(mmachine m)
_GPIOi2cWrite : This function write a value on a GPIO I2C device
Definition plugin.cpp:1144
int _GPIOdigitalWrite(mmachine m)
_GPIOdigitalWrite : This function write a high or low value on a GPIO pin
Definition plugin.cpp:262
int _dsGPIOpin(mmachine m)
_dsGPIOpin : This function destroy a GPIO pin object
Definition plugin.cpp:194
int _crGPIOi2c(mmachine m)
_crGPIOi2c : This function create a GPIO I2C object
Definition plugin.cpp:1071
int _GPIOpca9685SetFrequency(mmachine m)
_GPIOpca9685SetFrequency : This function change the PWM frequency on a GPIO I2C PCA9685 device
Definition plugin.cpp:1577
int _GPIOlcdPosition(mmachine m)
_GPIOlcdPosition : This function set the cursor position for next text input of an lcd display
Definition plugin.cpp:724
int _GPIOanalogWrite(mmachine m)
_GPIOanalogWrite : This function write an analogic value on a GPIO pin
Definition plugin.cpp:333
int _crGPIOshiftDriver(mmachine m)
_crGPIOshiftDriver : This function create a GPIO shift driver, it can change a shift register values ...
Definition plugin.cpp:937
int _dsGPIOpca9685(mmachine m)
_dsGPIOpca9685 : This function destroy a GPIO I2C PCA9685 object
Definition plugin.cpp:1439
int _GPIOpca9685Write(mmachine m)
_GPIOpca9685Write : This function write a value on a GPIO I2C PCA9685 device
Definition plugin.cpp:1473
int _GPIOi2cRead(mmachine m)
_GPIOi2cRead : This function read the value on a GPIO I2C device
Definition plugin.cpp:1179
int _GPIOi2cWrite16(mmachine m)
_GPIOi2cWrite16 : This function write a value on a GPIO I2C device 16bits register
Definition plugin.cpp:1298
int _dsGPIOshiftDriver(mmachine m)
_dsGPIOshiftDriver : This function destroy a GPIO shift driver object
Definition plugin.cpp:984
int _GPIOdelayMicroseconds(mmachine m)
_GPIOdelayMicroseconds : This function make a delay in microsecond
Definition plugin.cpp:117
int _dsGPIOlcd(mmachine m)
_dsGPIOlcd : This function destroy a GPIO LCD object
Definition plugin.cpp:510
int _GPIOlcdPuts(mmachine m)
_GPIOlcdPuts : This function add text at the current cursor position of an lcd display
Definition plugin.cpp:769
int _getGPIOechoValue(mmachine m)
_getGPIOechoValue : This function read the distance of an echo object
Definition plugin.cpp:1695
int _crGPIOpin(mmachine m)
_crGPIOpin : This function create a GPIO pin object
Definition plugin.cpp:144
int _GPIOi2cRead8(mmachine m)
_GPIOi2cRead8 : This function read the value on a GPIO I2C device 8bits register
Definition plugin.cpp:1256
int _GPIOdelay(mmachine m)
_GPIOdelay : This function make a delay in millisecond
Definition plugin.cpp:92
int _setGPIOshiftDriverValues(mmachine m)
_setGPIOshiftDriverValues : This function set a servo motor angle
Definition plugin.cpp:1017
int _dsGPIOi2c(mmachine m)
_dsGPIOi2c : This function destroy a GPIO I2C object
Definition plugin.cpp:1112
int _crGPIOpca9685(mmachine m)
_crGPIOpca9685 : This function create a GPIO I2C PCA9685 object
Definition plugin.cpp:1386
int _setGPIOservoAngle(mmachine m)
_setGPIOservoAngle : This function set a servo motor angle
Definition plugin.cpp:895
int _dsGPIOservo(mmachine m)
_dsGPIOservo : This function destroy a GPIO servo motor object
Definition plugin.cpp:862
int _GPIOdigitalRead(mmachine m)
_GPIOdigitalRead : This function read a high or low value on a GPIO pin
Definition plugin.cpp:302
int _crGPIOlcd(mmachine m)
_crGPIOlcd : This function initialize a 4bits or 8 bits display based in Hitachi (HD44780U)
Definition plugin.cpp:447