/*
-----------------------------------------------------------------------------
This source file is part of OpenSpace3D
For the latest info, see http://www.openspace3d.com
Copyright (c) 2016 I-maginer
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/copyleft/lesser.txt
-----------------------------------------------------------------------------
*/
/*
Version : 1.0
First version : 05/29/2016
Author : Bourineau Bastien
*/
struct PlugGPIOlcd = [
GPIOLCD_hLcd : ObjGpioLcd,
GPIOLCD_iCols : I,
GPIOLCD_iRows : I,
GPIOLCD_iAlign : I,
GPIOLCD_iScroll : I,
GPIOLCD_sText : S,
GPIOLCD_bState : I,
GPIOLCD_iXpos : I,
GPIOLCD_iLastTick : I
]mkPlugGPIOlcd;;
/*! \brief Callback on instance destruction
*
* Prototype: fun [PInstance PlugGPIOlcd] I
*
* \param PInstance : destroyed plugIT instance
* \param PlugGPIOlcd : gpio structure
*
* \return I : 0
**/
fun deleteOb(inst, obstr)=
_GPIOlcdClear obstr.GPIOLCD_hLcd;
_GPIOlcdHome obstr.GPIOLCD_hLcd;
_dsGPIOlcd obstr.GPIOLCD_hLcd;
setPluginInstanceCbScenePreRender inst nil;
0;;
fun addWhiteSpace(text, nbp)=
let 0 -> i in
while (i < nbp) do
(
set i = i + 1;
set text = strcat " " text;
);;
fun cbPreRender(inst, sessionstr, etime, obstr)=
let if etime < 1000 then 1 else etime / 1000 -> etime in
let 1000 / (abs obstr.GPIOLCD_iScroll) -> fspeed in
let obstr.GPIOLCD_iLastTick + (max 1 etime) -> acctime in
if (acctime >= fspeed) then
(
let strlen obstr.GPIOLCD_sText -> tsize in
(
set obstr.GPIOLCD_iXpos = obstr.GPIOLCD_iXpos - 1;
if (obstr.GPIOLCD_iXpos < (-tsize)) then
set obstr.GPIOLCD_iXpos = obstr.GPIOLCD_iCols;
_GPIOlcdClear obstr.GPIOLCD_hLcd;
let if (obstr.GPIOLCD_iXpos < 0) then 0 else obstr.GPIOLCD_iXpos -> rpos in
let substr obstr.GPIOLCD_sText (if (obstr.GPIOLCD_iXpos < 0) then abs obstr.GPIOLCD_iXpos else 0) obstr.GPIOLCD_iCols - rpos -> ftext in
(
_GPIOlcdPosition obstr.GPIOLCD_hLcd rpos 0;
_GPIOlcdPuts obstr.GPIOLCD_hLcd ftext;
);
//addLogMessage (substr obstr.GPIOLCD_sText (if (obstr.GPIOLCD_iXpos < 0) then abs obstr.GPIOLCD_iXpos else 0) obstr.GPIOLCD_iCols - obstr.GPIOLCD_iXpos);
);
set obstr.GPIOLCD_iLastTick = 0;
)
else
(
set obstr.GPIOLCD_iLastTick = acctime;
);
0;;
/*! \brief Callback on "Set text" dms action
*
* Set param link data on LCD screen
*
* Prototype: fun [PInstance DMI S S I PlugGPIOlcd] I
*
* \param PInstance : plugIT instance
* \param DMI : DMS module who call the action (not used)
* \param S : name of the launched action
* \param S : data posted in DMS action link
* \param I : reply flag (not used)
* \param PlugGPIOlcd : gpio structure
*
* \return I : 0
**/
fun cbSetText(inst, from, action, param, reply, obstr)=
_GPIOlcdClear obstr.GPIOLCD_hLcd;
_GPIOlcdHome obstr.GPIOLCD_hLcd;
let if (obstr.GPIOLCD_iAlign == 1) then
((obstr.GPIOLCD_iCols - (strlen param)) / 2)
else if (obstr.GPIOLCD_iAlign == 2) then
(obstr.GPIOLCD_iCols - (strlen param))
else 0
-> initpos in
if (obstr.GPIOLCD_iScroll != 0) then
(
_GPIOlcdPosition obstr.GPIOLCD_hLcd obstr.GPIOLCD_iXpos 0;
)
else
(
_GPIOlcdPosition obstr.GPIOLCD_hLcd initpos 0;
set obstr.GPIOLCD_iXpos = initpos;
);
_GPIOlcdPuts obstr.GPIOLCD_hLcd substr param 0 (obstr.GPIOLCD_iCols * obstr.GPIOLCD_iRows);
set obstr.GPIOLCD_sText = param;
0;;
/*! \brief Callback on "Add text" dms action
*
* Add param link data on LCD screen
*
* Prototype: fun [PInstance DMI S S I PlugGPIOlcd] I
*
* \param PInstance : plugIT instance
* \param DMI : DMS module who call the action (not used)
* \param S : name of the launched action
* \param S : data posted in DMS action link
* \param I : reply flag (not used)
* \param PlugGPIOlcd : gpio structure
*
* \return I : 0
**/
fun cbAddText(inst, from, action, param, reply, obstr)=
_GPIOlcdPuts obstr.GPIOLCD_hLcd param;
set obstr.GPIOLCD_sText = strcat obstr.GPIOLCD_sText param;
0;;
/*! \brief Callback on "Clear" dms action
*
* Clear LCD screen
*
* Prototype: fun [PInstance DMI S S I PlugGPIOlcd] I
*
* \param PInstance : plugIT instance
* \param DMI : DMS module who call the action (not used)
* \param S : name of the launched action
* \param S : data posted in DMS action link
* \param I : reply flag (not used)
* \param PlugGPIOlcd : gpio structure
*
* \return I : 0
**/
fun cbClear(inst, from, action, param, reply, obstr)=
_GPIOlcdClear obstr.GPIOLCD_hLcd;
_GPIOlcdHome obstr.GPIOLCD_hLcd;
set obstr.GPIOLCD_sText = "";
0;;
/*! \brief Callback on "Enable" dms action
*
* Enable LCD screen
*
* Prototype: fun [PInstance DMI S S I PlugGPIOlcd] I
*
* \param PInstance : plugIT instance
* \param DMI : DMS module who call the action (not used)
* \param S : name of the launched action
* \param S : data posted in DMS action link
* \param I : reply flag (not used)
* \param PlugGPIOlcd : gpio structure
*
* \return I : 0
**/
fun cbEnable(inst, from, action, param, reply, obstr)=
_GPIOlcdDisplay obstr.GPIOLCD_hLcd 1;
set obstr.GPIOLCD_bState = 1;
cbSetText inst nil nil obstr.GPIOLCD_sText nil obstr;
if (obstr.GPIOLCD_iScroll == 0) then nil else
setPluginInstanceCbScenePreRender inst mkfun4 @cbPreRender obstr;
0;;
/*! \brief Callback on "Disable" dms action
*
* Disable LCD screen
*
* Prototype: fun [PInstance DMI S S I PlugGPIOlcd] I
*
* \param PInstance : plugIT instance
* \param DMI : DMS module who call the action (not used)
* \param S : name of the launched action
* \param S : data posted in DMS action link
* \param I : reply flag (not used)
* \param PlugGPIOlcd : gpio structure
*
* \return I : 0
**/
fun cbDisable(inst, from, action, param, reply, obstr)=
_GPIOlcdClear obstr.GPIOLCD_hLcd;
_GPIOlcdHome obstr.GPIOLCD_hLcd;
_GPIOlcdDisplay obstr.GPIOLCD_hLcd 0;
set obstr.GPIOLCD_bState = 0;
setPluginInstanceCbScenePreRender inst nil;
0;;
/*! \brief Callback on new plugIT instance
*
* Read the parameters from editor values and init LCD display
*
* Prototype: fun [PInstance] I
*
* \param PInstance : plugIT instance
*
* \return I : 0
**/
fun newOb(inst)=
let atoi (getPluginInstanceParam inst "cols") -> cols in
let if cols == nil then 16 else cols -> cols in
let atoi (getPluginInstanceParam inst "rows") -> rows in
let if rows == nil then 2 else rows -> rows in
let atoi (getPluginInstanceParam inst "bits") -> bits in
let if bits == nil then 4 else bits -> bits in
let atoi (getPluginInstanceParam inst "rs") -> rs in
let if rs == nil then 14 else rs -> rs in
let atoi (getPluginInstanceParam inst "strb") -> strb in
let if strb == nil then 15 else strb -> strb in
let atoi (getPluginInstanceParam inst "d0") -> d0 in
let if d0 == nil then 18 else d0 -> d0 in
let atoi (getPluginInstanceParam inst "d1") -> d1 in
let if d1 == nil then 17 else d1 -> d1 in
let atoi (getPluginInstanceParam inst "d2") -> d2 in
let if d2 == nil then 27 else d2 -> d2 in
let atoi (getPluginInstanceParam inst "d3") -> d3 in
let if d3 == nil then 22 else d3 -> d3 in
let atoi (getPluginInstanceParam inst "d4") -> d4 in
let if d4 == nil then 25 else d4 -> d4 in
let atoi (getPluginInstanceParam inst "d5") -> d5 in
let if d5 == nil then 8 else d5 -> d5 in
let atoi (getPluginInstanceParam inst "d6") -> d6 in
let if d6 == nil then 7 else d6 -> d6 in
let atoi (getPluginInstanceParam inst "d7") -> d7 in
let if d7 == nil then 10 else d7 -> d7 in
let atoi (getPluginInstanceParam inst "scroll") -> scroll in
let if scroll == nil then 0 else scroll -> scroll in
let atoi (getPluginInstanceParam inst "textalign") -> textalign in
let if textalign == nil then 0 else textalign -> textalign in
let (getPluginInstanceParam inst "text") -> text in
let if text == nil then "" else text -> text in
let atoi (getPluginInstanceParam inst "init") -> init in
let if init == nil then 1 else init -> init in
let if (bits == 4) then
_crGPIOlcd _channel rows cols bits rs strb d0 d1 d2 d3 0 0 0 0
else
_crGPIOlcd _channel rows cols bits rs strb d0 d1 d2 d3 d4 d5 d6 d7
-> hlcd in
let mkPlugGPIOlcd [hlcd cols rows textalign scroll text init 0 0] -> obstr in
(
PluginRegisterAction inst "Set text" mkfun6 @cbSetText obstr;
PluginRegisterAction inst "Add text" mkfun6 @cbAddText obstr;
PluginRegisterAction inst "Clear" mkfun6 @cbClear obstr;
PluginRegisterAction inst "Enable" mkfun6 @cbEnable obstr;
PluginRegisterAction inst "Disable" mkfun6 @cbDisable obstr;
if (!init) then
cbDisable inst nil nil nil nil obstr
else
cbEnable inst nil nil nil nil obstr;
setPluginInstanceCbDel inst mkfun2 @deleteOb obstr;
);
0;;
/*! \brief Global plugIT function to initialize the plugIT callbacks
*
* Prototype: fun [S] I
*
* \param S : plugIT file path
*
* \return I : 0
**/
fun IniPlug(file)=
PlugRegister @newOb nil;
setPluginEditor @dynamicedit;
0;;