Raspberry PI GPIO Scol plugin
rpilcd.cpp
1
2#include "rpilcd.h"
3#include "plugin.h"
4
5#include <string>
6#include <algorithm>
7#include <iostream>
8
9#ifdef RPI
10#include <wiringPi.h>
11#include <lcd.h>
12#endif
13
14//
15//Class RpiLCD
16//
17
18RpiLCD::RpiLCD()
19{
20
21}
22
23RpiLCD::RpiLCD(int rows, int cols, int bits, int rs, int strb, int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7) :
24 mRs(rs),
25 mStrb(strb),
26 mD0(d0),
27 mD1(d1),
28 mD2(d2),
29 mD3(d3),
30 mD4(d4),
31 mD5(d5),
32 mD6(d6),
33 mD7(d7)
34{
35#ifdef RPI
36 mLcdHandle = lcdInit(rows, cols, bits, mRs, mStrb, mD0, mD1, mD2, mD3, mD4, mD5, mD6, mD7);
37#else
38 mLcdHandle = -1;
39#endif
40}
41
42RpiLCD::~RpiLCD()
43{
44#ifdef RPI
45 lcdDisplay(mLcdHandle, 0);
46 digitalWrite(mRs, 0);
47 digitalWrite(mStrb, 0);
48 digitalWrite(mD0, 0);
49 digitalWrite(mD1, 0);
50 digitalWrite(mD2, 0);
51 digitalWrite(mD3, 0);
52 digitalWrite(mD4, 0);
53 digitalWrite(mD5, 0);
54 digitalWrite(mD6, 0);
55 digitalWrite(mD7, 0);
56#endif
57}
58
59void RpiLCD::Home()
60{
61#ifdef RPI
62 lcdHome(mLcdHandle);
63#endif
64}
65
66void RpiLCD::Clear()
67{
68#ifdef RPI
69 lcdClear(mLcdHandle);
70#endif
71}
72
73void RpiLCD::DisplayState(int state)
74{
75#ifdef RPI
76 lcdDisplay(mLcdHandle, state);
77#endif
78}
79
80void RpiLCD::CursorState(int state)
81{
82#ifdef RPI
83 lcdCursor(mLcdHandle, state);
84#endif
85}
86
87void RpiLCD::CursorBlink(int state)
88{
89#ifdef RPI
90 lcdCursorBlink(mLcdHandle, state);
91#endif
92}
93
94void RpiLCD::SetPosition(int x, int y)
95{
96#ifdef RPI
97 lcdPosition(mLcdHandle, x, y);
98#endif
99}
100
101void RpiLCD::Puts(std::string text)
102{
103#ifdef RPI
104 lcdPuts(mLcdHandle, text.c_str());
105#endif
106}