-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Open
Description
I've written a berry script for the AirGradient Pro to print the same/nice UI on the display as the official firmware does (including displaying a full screen warning on high co2 / particles).
Would it be nice to add this to the template? If so, how? Guess it's a bit big to just add another code block
Script could probably be cleaned up a bit more more (at least extract the warning thresholds in a var)
>D
p:bright=35
p:inv=0
res=0
i2c=0
contrast=0
precharge=0
comdetect=0
don=1; Whether display is on
ddur=10; Duration between screen changes
diter=0; Display update iteration
dtype=0; Current display type
dtypes=3; Number of display types
temp=0
hum=0
pm25=0
pm10=0
pb03=0
co2=0
tvoc=0
haswarn=0
varlen=0; Length of string var
upd_bright=0; Force brightness update
upd_inv=0;
>B
i2c=ia(0x3c)
if i2c==0 {
print Device not present
} else {
=setbright(1, 1)
}
>T
temp=SHT3X#Temperature
hum=SHT3X#Humidity
co2=S8#CarbonDioxide
pm25=PMS5003#PM2.5
pm10=PMS5003#PM10
pb03=PMS5003#PB0.3
tvoc=SGP40#TVOC
>S
=#setbright(chg[bright] chg[inv])
if (don>=1) {
diter+=1
if (diter>=ddur) {
dt [zD0d]
diter=0
dtype+=1
if (dtype>=dtypes) {
dtype=0
}
haswarn=0
if (co2>=1000 or pm25>=100) {
haswarn=1
}
if (dtype==2 and haswarn<1) {
dtype=0
}
if (dtype==1 and haswarn>=1 {
dtype=2
}
}
if (dtype==2) {
dp0
dt [s1x27y18r74:29]
dt [s1x26y17r76:31]
dt [s1x25y16r78:33]
dt [s1x22y13r84:39]
dt [s1x21y12r86:41]
dt [s1x19y10r90:45]
if (co2>=1000) {
dt [s1x18y0f1D2]CO2
dt [s2x31y22f2D0]%co2%
dt [s1x94y55f3]ppm
} else {
varlen=sl(s(pm25))
dt [s1x18y0f1D2]PM2.5
if (varlen>3) {
dt [s2x31y22f2D0]%pm25%
} else {
dt [s2x41y22f2D0]%pm25%
}
dt [s1x94y55f3]ppm
}
} else {
dp1
dt [s1x1y0f1]%temp%
dt [s1x32y2k1]
dt [s1x35y0]C
if (dtype==1) {
dt [s1l1c14t]
} else {
varlen=sl(s(hum))
if (varlen==3) {
dt [s1l1c15]%hum%%%
} else {
dt [s1l1c14]%hum%%%
}
}
dp0
dt [s1x1y16]CO2
dt [s2x1y30]%co2%
dt [s1x1y54f3]ppm
if (dtype==1) {
dt [s1x60y16f1]PM10
dt [s2x60y30]%pm10%
} else {
dt [s1x60y16f1]PM25
dt [s2x60y30]%pm25%
}
dt [s1x60y54f3]ug/m3
dt [s1x97y16f1]TVOC
dt [s1x97y30]%tvoc%
dt [x1y13L128,13]; Horizontal
dt [x58y14L58,64]; Vertical 1
dt [x95y14L95,64]; Vertical 2
}
dt [d]
}
#setbright(upd_bright upd_inv)
if i2c>0 {
if (upd_bright>0) {
contrast=int(bright*1.171)
if (bright>=128) {
contrast=contrast-43
}
precharge=241; 0xF1
if (bright==0) {
precharge=0
}
comdetect=int(bright/8)
res=0xD900|precharge
iw2(0x4000 res); 0x4000 = control
res=0x8100|contrast
iw2(0x4000 res)
res=0xDB00|comdetect
iw2(0x4000 res)
iw(0 0xA4)
iw(0 0xA6)
iw(0 0xAF)
print Setting brightness to %bright% => pre: %precharge% contr: %contrast% comdtct: %comdetect%
}
if (upd_inv>0) {
if inv==0 {
iw(0 0xa6)
} else {
iw(0 0xa7)
}
print Setting display invert
}
}
>ti1
don=1
dt [O]
>ti2
don=0
dt [o]
>W
sl(0 255 bright "0" "brightness" "255")
ck(inv "invert ")Metadata
Metadata
Assignees
Labels
No labels