|

楼主 |
发表于 2023-9-25 08:36:19
|
显示全部楼层
程序发你参考下,8266或者esp32
- // QQ2220807252,欢迎交流改进
- // 小白一个,写的时候各种崩溃,但是软件用起来还没啥毛病。如果各位用的开心还请多多赞助,谢谢!!
- #include "Arduino.h"
- #include <WiFi.h>
- #include <WebServer.h>
- #include <Wire.h>
- #define cxn010x (0x77)
- WebServer server(80);
- const char *ssid = "***********"; // 这边要修改!!!!!!!!!!!!!!!!!!!!!!!
- const char *password = "**********";
- String htmlPage;
- void buildHtmlPage();
- void buildHtmlPage2();
- void buildHtmlPage3();
- void buildHtmlPage4();
- void OptiAdjust();
- void OptiPlus();
- void OptiMinus();
- void OptiNoSave();
- void OptiSave();
- void BipiAdjust();
- void BipiPlus();
- void BipiMinus();
- void BipiNoSave();
- void BipiSave();
- void On();
- void Off();
- void Shutdown();
- void Reboot();
- void handleNotFound();
- void handleRoot();
- void Return();
- void Power();
- void Adjust();
- void Control();
- void handlePostForm();
- void setup()
- {
- Serial.begin(9600);
- Wire.begin();
- Serial.println();
- Serial.println();
- Serial.print("Connecting to WiFi...");
- WiFi.mode(WIFI_STA);
- WiFi.disconnect();
- delay(100);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- }
- Serial.println();
- Serial.println("WiFi connected.");
- Serial.print("IP: ");
- Serial.println(WiFi.localIP());
- server.on("/", handleRoot);
- server.onNotFound(handleNotFound);
- server.on("/postForm", handlePostForm);
- server.on("/Power", Power);
- server.on("/OptiAdjust", OptiAdjust);
- server.on("/OptiPlus", OptiPlus);
- server.on("/OptiMinus", OptiMinus);
- server.on("/OptiNoSave", OptiNoSave);
- server.on("/OptiSave", OptiSave);
- server.on("/BipiAdjust", BipiAdjust);
- server.on("/BipiPlus", BipiPlus);
- server.on("/BipiMinus", BipiMinus);
- server.on("/BipiNoSave", BipiNoSave);
- server.on("/BipiSave", BipiSave);
- server.on("/On", On);
- server.on("/Off", Off);
- server.on("/Shutdown", Shutdown);
- server.on("/Reboot", Reboot);
- server.on("/Adjust", Adjust);
- server.on("/Return", Return);
- server.on("/Control", Control);
- server.begin();
- Serial.println("HTTP server started");
- On();
- }
- void loop(void)
- {
- server.handleClient();
- }
- void buildHtmlPage()
- {
- htmlPage = "<!DOCTYPE html>";
- htmlPage += "<html>";
- htmlPage += "<head>";
- htmlPage += "<title>CXN010X ADJUSTMENTS</title>";
- htmlPage += "</head>";
- htmlPage += "<BODY bgcolor='#FFFFFF'>";
- htmlPage += "<style>html { font-family: Helvetica; font-size: 28px; display: inline-block; margin: 0px auto; text-align: center} button { font-family: Helvetica; font-size: 30px; background-color: #195B6A; border: none; color: white; padding: 45px 90px}</style>";
- htmlPage += "<p>CXN010X Optical and Bi-phase Adjustment Tool<br/>QQ2220807252<br/></p>";
- htmlPage += "<p>Optical Aligment Options</p>";
- htmlPage += "<a href="/Power"><button>Projector Power Controls</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/Control"><button>Projector Basic Controls</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/Adjust"><button>Optical and Bi-phase Alignments</button></a>";
- htmlPage += "</body>";
- htmlPage += "</html>";
- }
- void buildHtmlPage2()
- {
- htmlPage = "<!DOCTYPE html>";
- htmlPage += "<html>";
- htmlPage += "<head>";
- htmlPage += "<title>Basic Controls</title>";
- htmlPage += "</head>";
- htmlPage += "<BODY bgcolor='#FFFFFF'>";
- htmlPage += "<style>html { font-family: Helvetica; font-size: 28px; display: inline-block; margin: 0px auto; text-align: center} button { font-family: Helvetica; font-size: 30px; background-color: #195B6A; border: none; color: white; padding: 45px 90px}</style>";
- htmlPage += "<p>CXN010X Basic Controls<br/>QQ2220807252<br/></p>";
- htmlPage += "<a href="/On"><button>启动视频输入</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/Off"><button>关闭视频输入</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/Reboot"><button>重启投影机</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/Shutdown"><button>关闭投影机</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/Return"><button>返回主页</button></a>";
- htmlPage += "</body>";
- htmlPage += "</html>";
- }
- void buildHtmlPage3()
- {
- htmlPage = "<!DOCTYPE html>";
- htmlPage += "<html>";
- htmlPage += "<head>";
- htmlPage += "<title>CXN010X ADJUSTMENTS</title>";
- htmlPage += "</head>";
- htmlPage += "<BODY bgcolor='#FFFFFF'>";
- htmlPage += "<style>html { font-family: Helvetica; font-size: 28px; display: inline-block; margin: 0px auto; text-align: center} button { font-family: Helvetica; font-size: 30px; background-color: #195B6A; border: none; color: white; padding: 45px 90px}</style>";
- htmlPage += "<p>CXN010X Optical and Bi-phase Adjustment Tool<br/>QQ2220807252<br/></p>";
- htmlPage += "<p>Optical Aligment Options</p>";
- htmlPage += "<a href="/OptiAdjust"><button>Optical Adjustment Menu</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/OptiPlus"><button>++Plus Direction++</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/OptiMinus"><button>--Minus Direction--</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/OptiNoSave"><button>Quit Without Saving</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/OptiSave"><button>Quit And Save</button></a>";
- htmlPage += "<p>Bi-phase Aligment Options</p>";
- htmlPage += "<a href="/BipiAdjust"><button>Biphase Adjustment Menu</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/BipiPlus"><button>++Plus Direction++</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/BipiMinus"><button>--Minus Direction--</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/BipiNoSave"><button>Quit Without Saving</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/BipiSave"><button>Quit And Save Changes</button></a>";
- htmlPage += "<p> </p>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/Return"><button>Return to Mainpage</button></a>";
- htmlPage += "</body>";
- htmlPage += "</html>";
- }
- void buildHtmlPage4()
- {
- htmlPage = "<!DOCTYPE html>";
- htmlPage += "<html>";
- htmlPage += "<head>";
- htmlPage += "<title>CXN010X ADJUSTMENTS</title>";
- htmlPage += "</head>";
- htmlPage += "<BODY bgcolor='#FFFFFF'>";
- htmlPage += "<style>html { font-family: Helvetica; font-size: 28px; display: inline-block; margin: 0px auto; text-align: center} button { font-family: Helvetica; font-size: 30px; background-color: #195B6A; border: none; color: white; padding: 45px 90px}</style>";
- htmlPage += "<p>CXN010X Optical and Bi-phase Adjustment Tool<br/>QQ2220807252<br/></p>";
- htmlPage += "<form method="post" action="/postForm"><input type="value" name="Text1" value=""><input type="value" name="Text2" value=""><input type="submit" value="Submit Changes"></form>";
- htmlPage += "<p> </p>";
- htmlPage += "<p> </p>";
- htmlPage += "<a href="/Return"><button>Return to Mainpage</button></a>";
- htmlPage += "</body>";
- htmlPage += "</html>";
- }
- void OptiAdjust()
- {
- Serial.println("OptiAdjust");
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x32, 0x00};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Adjust");
- server.send(303);
- }
- void OptiPlus()
- {
- Serial.println("OptiPlus");
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x33, 0x00};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Adjust");
- server.send(303);
- }
- void OptiMinus()
- {
- Serial.println("OptiMinus");
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x34, 0x00};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Adjust");
- server.send(303);
- }
- void OptiNoSave()
- {
- Serial.println("OptiNoSave");
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x35, 0x01, 0x00};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Adjust");
- server.send(303);
- }
- void OptiSave()
- {
- Serial.println("OptiSave");
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x35, 0x01, 0x01};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Adjust");
- server.send(303);
- }
- void BipiAdjust()
- {
- Serial.println("BipiAdjust");
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x36, 0x00};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Adjust");
- server.send(303);
- }
- void BipiPlus()
- {
- Serial.println("BipiPlus");
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x37, 0x00};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Adjust");
- server.send(303);
- }
- void BipiMinus()
- {
- Serial.println("BipiMinus");
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x38, 0x00};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Adjust");
- server.send(303);
- }
- void BipiNoSave()
- {
- Serial.println("BipiNoSave");
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x39, 0x01, 0x00};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Adjust");
- server.send(303);
- }
- void BipiSave()
- {
- Serial.println("BipiSave");
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x39, 0x01, 0x01};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Adjust");
- server.send(303);
- }
- void On()
- {
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x01, 0x00};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Power");
- server.send(303);
- }
- void Off()
- {
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x02, 0x00};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Power");
- server.send(303);
- }
- void Shutdown()
- {
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x0B, 0x01, 0x00};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Power");
- server.send(303);
- }
- void Reboot()
- {
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x0B, 0x01, 0x01};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- server.sendHeader("Location", "Power");
- server.send(303);
- }
- void handleNotFound()
- {
- server.send(404, "text/plain", "404: Not found");
- }
- void handleRoot()
- {
- buildHtmlPage();
- server.send(200, "text/html", htmlPage);
- }
- void Return()
- {
- Serial.println("Return");
- buildHtmlPage();
- server.send(200, "text/html", htmlPage);
- }
- void Power()
- {
- buildHtmlPage2();
- server.send(200, "text/html", htmlPage);
- }
- void Adjust()
- {
- buildHtmlPage3();
- server.send(200, "text/html", htmlPage);
- }
- void Control()
- {
- buildHtmlPage4();
- server.send(200, "text/html", htmlPage);
- }
- void handlePostForm()
- {
- #define val1 server.arg("Text1")
- #define val2 server.arg("Text2")
- #define st1 val1.toInt()
- #define st2 val2.toInt()
- Wire.beginTransmission(cxn010x);
- uint8_t cmd[] = {0x26, 0x09, st1, st2, 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00};
- Wire.write(cmd, sizeof(cmd));
- Wire.endTransmission();
- Serial.println(st1);
- Serial.println(st2);
- server.sendHeader("Location", "Control");
- server.send(303);
- }
复制代码 |
|