Skip to content

Commit e461c41

Browse files
committed
Add files via upload
1 parent bbe2c84 commit e461c41

9 files changed

Lines changed: 839 additions & 0 deletions

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
file : HTMLSerialMonitor.cpp
3+
created: 26 May 2016
4+
version: 27 May 2016
5+
author : Nard Janssens
6+
license: Attribution-NonCommercial-ShareAlike 2.5 Generic (CC BY-NC-SA 2.5)
7+
*/
8+
9+
#include "Arduino.h"
10+
#include "HTMLSerialMonitor.h"
11+
12+
void HTMLSerialMonitor::waitForMonitor(){
13+
monFnd=false;
14+
while (!monFnd) {hndlRemoteCmd();}
15+
}
16+
17+
int HTMLSerialMonitor::hndlRemoteCmd(){
18+
while (Serial.available()) {
19+
hndlRemoteCmd(Serial.read());
20+
}
21+
}
22+
23+
int HTMLSerialMonitor::hndlRemoteCmd(int inByte){
24+
char inChar=(char) inByte;
25+
char outByte=-1;
26+
inputString += inChar;
27+
if (inChar=='[') inCmd=true;
28+
if (!inCmd) outByte=inByte;
29+
if (inChar == '\n') { //so all data after command close bracket up until \n is ignored and discarded
30+
inCmd=false;
31+
if (inputString.substring(0,7).equals("[reset]")) asm volatile (" jmp 0");
32+
if (inputString.substring(0,7).equals("[start]")) {monFnd=true;}
33+
if (inputString.substring(0,7).equals("[pause]")) {
34+
Serial.flush();
35+
inputString="";
36+
while (!inputString.substring(0,7).equals("[play]")){
37+
if (Serial.available()) hndlRemoteCmd(Serial.read());
38+
}
39+
}
40+
inputString="";
41+
}
42+
//we should remove bytes belonging to cmd
43+
return outByte;
44+
}
45+
46+
boolean HTMLSerialMonitor::available(){
47+
if (!Serial.available()) return false;
48+
int newByte=Serial.peek();
49+
if ((inCmd) || (newByte=='[')) {
50+
while ((inCmd) || (Serial.peek()=='[')) {
51+
hndlRemoteCmd(Serial.read());
52+
}
53+
return false;
54+
}
55+
return true;
56+
}
57+
int HTMLSerialMonitor::read(){
58+
return hndlRemoteCmd(Serial.read());
59+
}
60+
61+
//following functions are for more complete replacement of Serial functions
62+
int HTMLSerialMonitor::peek() {return Serial.peek();}
63+
void HTMLSerialMonitor::begin(int baud) {Serial.begin(baud);}
64+
void HTMLSerialMonitor::end() {Serial.end();}
65+
66+
void HTMLSerialMonitor::println(byte val) {Serial.println(val);}
67+
void HTMLSerialMonitor::println(char val) {Serial.println(val);}
68+
void HTMLSerialMonitor::println(int val) {Serial.println(val);}
69+
void HTMLSerialMonitor::println(long val) {Serial.println(val);}
70+
void HTMLSerialMonitor::println(float val) {Serial.println(val);}
71+
void HTMLSerialMonitor::println(double val){Serial.println(val);}
72+
void HTMLSerialMonitor::println(String val){Serial.println(val);}
73+
void HTMLSerialMonitor::println() {Serial.println();}
74+
void HTMLSerialMonitor::println(String id,String val) {
75+
String cmd="[";
76+
cmd+=id;
77+
cmd+=":";
78+
cmd+=val;
79+
cmd+="]";
80+
Serial.println(cmd);
81+
}
82+
void HTMLSerialMonitor::println(String id,String prop,String val){
83+
String cmd="[";
84+
cmd+=id;
85+
cmd+=".";
86+
cmd+=prop;
87+
cmd+=":";
88+
cmd+=val;
89+
cmd+="]";
90+
Serial.println(cmd);
91+
}
92+
93+
void HTMLSerialMonitor::print(byte val) {Serial.print(val);}
94+
void HTMLSerialMonitor::print(char val) {Serial.print(val);}
95+
void HTMLSerialMonitor::print(int val) {Serial.print(val);}
96+
void HTMLSerialMonitor::print(long val) {Serial.print(val);}
97+
void HTMLSerialMonitor::print(float val) {Serial.print(val);}
98+
void HTMLSerialMonitor::print(double val){Serial.print(val);}
99+
void HTMLSerialMonitor::print(String val){Serial.print(val);}
100+
void HTMLSerialMonitor::print(String id,String val) {
101+
String cmd="[";
102+
cmd+=id;
103+
cmd+=":";
104+
cmd+=val;
105+
cmd+="]";
106+
Serial.print(cmd);
107+
}
108+
void HTMLSerialMonitor::print(String id,String prop,String val){
109+
String cmd="[";
110+
cmd+=id;
111+
cmd+=".";
112+
cmd+=prop;
113+
cmd+=":";
114+
cmd+=val;
115+
cmd+="]";
116+
Serial.print(cmd);
117+
}
118+
119+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
file : HTMLSerialMonitor.h
3+
created: 26 May 2016
4+
version: 27 May 2016
5+
author : Nard Janssens
6+
license: Attribution-NonCommercial-ShareAlike 2.5 Generic (CC BY-NC-SA 2.5)
7+
*/
8+
#ifndef HTMLSerialMonitor_h
9+
#define HTMLSerialMonitor_h
10+
11+
#include "Arduino.h"
12+
13+
class HTMLSerialMonitor{
14+
private:
15+
String inputString="";
16+
boolean monFnd=true;
17+
boolean inCmd=false;
18+
19+
public:
20+
21+
void waitForMonitor();
22+
23+
int hndlRemoteCmd();
24+
25+
int hndlRemoteCmd(int inByte);
26+
27+
boolean available();
28+
29+
int read();
30+
31+
//following functions are for more complete replacement of Serial functions
32+
int peek();
33+
void begin(int baud);
34+
void end();
35+
36+
void println(byte val);
37+
void println(char val);
38+
void println(int val);
39+
void println(long val);
40+
void println(float val);
41+
void println(double val);
42+
void println(String val);
43+
void println(String id,String val);
44+
void println(String id,String prop,String val);
45+
void println();
46+
47+
void print(byte val);
48+
void print(char val);
49+
void print(int val);
50+
void print(long val);
51+
void print(float val);
52+
void print(double val);
53+
void print(String val);
54+
void print(String id,String val);
55+
void print(String id,String prop,String val);
56+
57+
};
58+
59+
#endif
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Bare_DecoratedText.ino - Sample sketch part of HTMLSerialMonitor package
3+
No library used, demonstrates simple html text decoration
4+
created: 26 May 2016
5+
version: 27 May 2016
6+
author : Nard Janssens
7+
license: Attribution-NonCommercial-ShareAlike 2.5 Generic (CC BY-NC-SA 2.5)
8+
*/
9+
10+
void setup(){
11+
Serial.begin(9600);
12+
}
13+
14+
void loop(){
15+
int valueD3=random(0,1024); // randomfrom 0 to 1024
16+
String red="Value is: <b style='color:red;'>";
17+
String grn="Value is: <b style='color:green;'>";
18+
String eol="</b>";
19+
if (valueD3<512) Serial.println(red+valueD3+eol);
20+
if (valueD3>=512) Serial.println(grn+valueD3+eol);
21+
delay (300);
22+
}
23+
24+
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
Bare_PageRedraw.ino - Sample sketch part of HTMLSerialMonitor package
3+
No library used, demonstrates simple animation
4+
by redrawing page each loop
5+
created: 26 May 2016
6+
version: 29 May 2016
7+
author : Nard Janssens
8+
license: Attribution-NonCommercial-ShareAlike 2.5 Generic (CC BY-NC-SA 2.5)
9+
*/
10+
11+
String divTitle ="<div style='width:490px;line-height:48px;text-align:center;font-size:32px'>Arduino Weather Station</div>";
12+
String divBlock ="<div style='width:200px;height:200px;margin:16px;padding:8px; background-color:#2222AA;float:left;color:#EEEEFF;font-family:Tahoma;'>";
13+
String divBHeader="<div style='line-height:32px; font-size:32px'>";
14+
String divBBody ="<div style='text-align:center;line-height:136px;font-size:64px;color:white'>";
15+
String divBFooter="<div style='text-align:right;line-height:32px; font-size:32px' >";
16+
String divClose ="</div>";
17+
String nextRow ="<div style='clear:both;'></div>";
18+
String symbSunny ="&#9728";
19+
String symbCloudy="&#9729";
20+
String symbUp ="&#8673";
21+
String symbDown ="&#8675";
22+
String symbDeg ="&deg;C";
23+
unsigned long hrOff=10;
24+
unsigned long minOff=12;
25+
unsigned long secOff=56;
26+
27+
void setup(){
28+
Serial.begin(9600);
29+
}
30+
31+
void loop(){
32+
//Time would have to be set at start of arduino, or you could use a clock sensor.
33+
//Without this implemented, we make up a time below
34+
int speedup=60; //for demonistration we make time faster/more dynamic
35+
unsigned long s=millis()/1000*speedup;
36+
unsigned long offset=hrOff*3600+minOff*60+secOff;
37+
s=s+offset;
38+
unsigned long hours=s/3600;
39+
hours=hours % 24;
40+
s=s-hours*3600;
41+
unsigned long minutes=s/60;
42+
s=s-minutes*60;
43+
unsigned long seconds=s;
44+
String timef=dblDig(hours)+":"+dblDig(minutes);
45+
46+
int temp=7; // you would read this from your pressure sensor
47+
int prevPressure=1000; // this would be the pressure of a day ago or something like that
48+
int pressure=1001; // you would read this from your pressure sensor
49+
50+
//forecast is very simplistic and probably false, but for demonstration purposes...
51+
String trend=symbDown;
52+
String forecast=symbCloudy;
53+
if (pressure>prevPressure) {
54+
trend=symbUp;
55+
forecast=symbSunny;
56+
}
57+
58+
//we print html using Serial.print.
59+
//only if end of line (Serial.println) is received, the html is processed.
60+
61+
//page header
62+
Serial.print("[cls]");
63+
Serial.print(divTitle);
64+
65+
//time
66+
Serial.print(divBlock);
67+
Serial.print(divBHeader+"TIME"+divClose);
68+
Serial.print(divBBody+timef+divClose);
69+
Serial.print(divBFooter+divClose);
70+
Serial.print(divClose);
71+
72+
//temp
73+
Serial.print(divBlock);
74+
Serial.print(divBHeader+"OUTSIDE"+divClose);
75+
Serial.print(divBBody+temp+symbDeg+divClose);
76+
Serial.print(divBFooter+divClose);
77+
Serial.print(divClose);
78+
79+
//next row
80+
Serial.print(nextRow);
81+
82+
//pressure
83+
Serial.print(divBlock);
84+
Serial.print(divBHeader+"PRESSURE"+divClose);
85+
Serial.print(divBBody+pressure+trend+divClose);
86+
Serial.print(divBFooter+"bar"+divClose);
87+
Serial.print(divClose);
88+
89+
//forecast
90+
Serial.print(divBlock);
91+
Serial.print(divBHeader+"FORECAST"+divClose);
92+
Serial.print(divBBody+"<big><big><big><big>"+forecast+"</big></big></big></big>"+divClose);
93+
Serial.print(divBFooter+divClose);
94+
Serial.print(divClose);
95+
96+
//explanation regarding refreshrate
97+
Serial.print(nextRow);
98+
Serial.print("<i><h4><b>Refreshrate</b>: <small>This page updates much slower than the refreshrate of the data. <br>");
99+
Serial.print("The page is refreshed fully on each data update which takes a lot of time.</small></h4></i>");
100+
Serial.println("");
101+
102+
//when refreshing whole pages the browser needs to have time to keep up,
103+
//so we loop only each each five second.
104+
delay (5000);
105+
}
106+
107+
String dblDig(int s){
108+
String out="0"+String(s);
109+
out=out.substring(out.length()-2,out.length());
110+
return out;
111+
}
112+
113+

0 commit comments

Comments
 (0)