最终实现:利用python和web.py写一个页面,从而达到,在手机端页面上点击按钮可以控制投影仪的操作。
前提:树莓派已经可以控制投影仪,在之前的文章中写过。
(25条消息) 树莓派驱动DLPDLCR230NPEVM+framebuffer显示图片_L_Y000的博客-CSDN博客
手机端界面如下。如图,点击“开始”按键,即可打开投影仪投射树莓派桌面。
网页端利用python的web.py搭建。
总体文件夹如下图。
其中api文件夹、i2c、linuxi2c是投影仪调用的文件。
static文件夹如下。
app.py
import web
import program
urls = (
'/start', 'start'
)
app = web.application(urls, globals())
class start:
def GET(self):
return program.something()
if __name__ == "__main__":
app.run()
program.py(将之前的init_parallel_mode.py改写进来就好),即program.py的功能就是按键按下所需要实现的功能。
import struct
import time
from enum import Enum
import sys, os.path
python_dir = (os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
sys.path.append(python_dir)
from api.dlpc343x_xpr4 import *
from api.dlpc343x_xpr4_evm import *
from linuxi2c import *
import i2c
class Set(Enum):
Disabled = 0
Enabled = 1
def something():
'''
Initializes the Raspberry Pi's GPIO lines to communicate with the DLPDLCR230NPEVM,
and configures the DLPDLCR230NPEVM to project RGB666 parallel video input received from the Raspberry Pi.
It is recommended to execute this script upon booting the Raspberry Pi.
'''
gpio_init_enable = True # Set to FALSE to disable default initialization of Raspberry Pi GPIO pinouts. TRUE by default.
i2c_time_delay_enable = False # Set to FALSE to prevent I2C commands from waiting. May lead to I2C bus hangups with some commands if FALSE.
i2c_time_delay = 0.8 # Lowering this value will speed up I2C commands. Too small delay may lead to I2C bus hangups with some commands.
protocoldata = ProtocolData()
def WriteCommand(writebytes, protocoldata):
'''
Issues a command over the software I2C bus to the DLPDLCR230NP EVM.
Set to write to Bus 7 by default
Some commands, such as Source Select (splash mode) may perform asynchronous access to the EVM's onboard flash memory.
If such commands are used, it is recommended to provide appropriate command delay to prevent I2C bus hangups.
'''
# print ("Write Command writebytes ", [hex(x) for x in writebytes])
if(i2c_time_delay_enable):
time.sleep(i2c_time_delay)
i2c.write(writebytes)
return
def ReadCommand(readbytecount, writebytes, protocoldata):
'''
Issues a read command over the software I2C bus to the DLPDLCR230NP EVM.
Set to read from Bus 7 by default
Some commands, such as Source Select (splash mode) may perform asynchronous access to the EVM's onboard flash memory.
If such commands are used, it is recommended to provide appropriate command delay to prevent I2C bus hangups.
'''
# print ("Read Command writebytes ", [hex(x) for x in writebytes])
if(i2c_time_delay_enable):
time.sleep(i2c_time_delay)
i2c.write(writebytes)
readbytes = i2c.read(readbytecount)
return readbytes
# ##### ##### Initialization for I2C ##### #####
# register the Read/Write Command in the Python library
DLPC343X_XPR4init(ReadCommand, WriteCommand)
i2c.initialize()
if(gpio_init_enable):
InitGPIO()
# ##### ##### Command call(s) start here ##### #####
print("Setting DLPC3436 Input Source to Raspberry Pi...")
Summary = WriteDisplayImageCurtain(1,Color.Black)
Summary = WriteSourceSelect(Source.ExternalParallelPort, Set.Disabled)
#Summary = WriteInputImageSize(1920, 1080)
print("Configuring DLPC3436 Source Settings for Raspberry Pi...")
#Summary = WriteActuatorGlobalDacOutputEnable(Set.Enabled)
#Summary = WriteExternalVideoSourceFormatSelect(ExternalVideoFormat.Rgb666)
#Summary = WriteVideoChromaChannelSwapSelect(ChromaChannelSwap.Cbcr)
#Summary = WriteParallelVideoControl(ClockSample.FallingEdge, Polarity.ActiveHigh, Polarity.ActiveLow, Polarity.ActiveLow)
#Summary = WriteColorCoordinateAdjustmentControl(0)
#Summary, BitRate, PixelMapMode = ReadFpdLinkConfiguration()
#Summary = WriteDelay(50)
time.sleep(1)
Summary = WriteDisplayImageCurtain(0,Color.Black)
return "completed"
# ##### ##### Command call(s) end here ##### #####
i2c.terminate()
index.html如下。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<a href="/start">开始</a>
<button onclick="start()">开始</button>
<h1 id="result"></h1>
<script>
function start(){
console.log("start")
fetch("/start").then(response => response.text())
.then(data => {
console.log(data)
document.getElementById("result").innerText=data;
});
}
</script>
<form onsubmit="return reload(this)" >
<input type="submit" value="显示图片" />
</form>
<img src="image.jpg" id="showViewImg" />
<script>
function reload() {
const showImg = document.getElementById('showViewImg');
const ts=(new Date()).getTime();
showImg.src=`image.jpg?ts=${ts}`;
return false;
}
</script>
<form onsubmit="return reload2(this)" >
<input type="submit" value="显示图片2" />
</form>
<img src="image2.jpg" id="showViewImg2" />
<script>
function reload2() {
const showImg = document.getElementById('showViewImg2');
const ts=(new Date()).getTime();
showImg.src=`image2.jpg?ts=${ts}`;
return false;
}
</script>
<script>
setInterval(reload,1000);
</script>
</body>
</html>