diff --git a/esp32_fw/.vscode/settings.json b/esp32_fw/.vscode/settings.json index 5f294ebf..ea185af3 100644 --- a/esp32_fw/.vscode/settings.json +++ b/esp32_fw/.vscode/settings.json @@ -1,3 +1,55 @@ { - "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0}" + "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, ColumnLimit: 0}", + "files.associations": { + "array": "cpp", + "atomic": "cpp", + "*.tcc": "cpp", + "bitset": "cpp", + "cctype": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "cstring": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "unordered_map": "cpp", + "unordered_set": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "map": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "regex": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iomanip": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "cinttypes": "cpp", + "typeinfo": "cpp" + } } \ No newline at end of file diff --git a/esp32_fw/data/alignment.bmp b/esp32_fw/data/alignment.bmp new file mode 100644 index 00000000..3e302cbe Binary files /dev/null and b/esp32_fw/data/alignment.bmp differ diff --git a/esp32_fw/data/fonts/calibrib50.vlw b/esp32_fw/data/fonts/calibrib50.vlw new file mode 100644 index 00000000..6c0b0dd1 Binary files /dev/null and b/esp32_fw/data/fonts/calibrib50.vlw differ diff --git a/esp32_fw/data/fonts/calibrib62.vlw b/esp32_fw/data/fonts/calibrib62.vlw new file mode 100644 index 00000000..97ea7ad3 Binary files /dev/null and b/esp32_fw/data/fonts/calibrib62.vlw differ diff --git a/esp32_fw/data/fonts/numbers1-1.vlw b/esp32_fw/data/fonts/numbers1-1.vlw new file mode 100644 index 00000000..e5e2e87a Binary files /dev/null and b/esp32_fw/data/fonts/numbers1-1.vlw differ diff --git a/esp32_fw/data/fonts/numbers1-2.vlw b/esp32_fw/data/fonts/numbers1-2.vlw new file mode 100644 index 00000000..c6f615be Binary files /dev/null and b/esp32_fw/data/fonts/numbers1-2.vlw differ diff --git a/esp32_fw/data/fonts/numbers2-1.vlw b/esp32_fw/data/fonts/numbers2-1.vlw new file mode 100644 index 00000000..1dbfa21b Binary files /dev/null and b/esp32_fw/data/fonts/numbers2-1.vlw differ diff --git a/esp32_fw/data/fonts/numbers2-2.vlw b/esp32_fw/data/fonts/numbers2-2.vlw new file mode 100644 index 00000000..60ade58b Binary files /dev/null and b/esp32_fw/data/fonts/numbers2-2.vlw differ diff --git a/esp32_fw/data/fonts/numbers3-1.vlw b/esp32_fw/data/fonts/numbers3-1.vlw new file mode 100644 index 00000000..fff661e3 Binary files /dev/null and b/esp32_fw/data/fonts/numbers3-1.vlw differ diff --git a/esp32_fw/data/fonts/numbers3-2.vlw b/esp32_fw/data/fonts/numbers3-2.vlw new file mode 100644 index 00000000..1dbfa21b Binary files /dev/null and b/esp32_fw/data/fonts/numbers3-2.vlw differ diff --git a/esp32_fw/data/index.html b/esp32_fw/data/index.html deleted file mode 100644 index 8a65efa4..00000000 --- a/esp32_fw/data/index.html +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - -Solum - alternative proto AP - - - -
- -
- -
- -
- - -
- - - - -
-
- DST: - Filename: - Next check-in: min - -
-
- -
-
- DST: - Filename: - -
-
- -
-
- DST: - -
-
- -
-
    -
- -
-
- - -
- - - - - - - - - \ No newline at end of file diff --git a/esp32_fw/data/jquery.js b/esp32_fw/data/jquery.js deleted file mode 100644 index ee381345..00000000 --- a/esp32_fw/data/jquery.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! jQuery v2.0.3 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license -//@ sourceMappingURL=jquery.min.map -*/ -(function(e,undefined){var t,n,r=typeof undefined,i=e.location,o=e.document,s=o.documentElement,a=e.jQuery,u=e.$,l={},c=[],p="2.0.3",f=c.concat,h=c.push,d=c.slice,g=c.indexOf,m=l.toString,y=l.hasOwnProperty,v=p.trim,x=function(e,n){return new x.fn.init(e,n,t)},b=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,w=/\S+/g,T=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,C=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,k=/^-ms-/,N=/-([\da-z])/gi,E=function(e,t){return t.toUpperCase()},S=function(){o.removeEventListener("DOMContentLoaded",S,!1),e.removeEventListener("load",S,!1),x.ready()};x.fn=x.prototype={jquery:p,constructor:x,init:function(e,t,n){var r,i;if(!e)return this;if("string"==typeof e){if(r="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:T.exec(e),!r||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof x?t[0]:t,x.merge(this,x.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:o,!0)),C.test(r[1])&&x.isPlainObject(t))for(r in t)x.isFunction(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return i=o.getElementById(r[2]),i&&i.parentNode&&(this.length=1,this[0]=i),this.context=o,this.selector=e,this}return e.nodeType?(this.context=this[0]=e,this.length=1,this):x.isFunction(e)?n.ready(e):(e.selector!==undefined&&(this.selector=e.selector,this.context=e.context),x.makeArray(e,this))},selector:"",length:0,toArray:function(){return d.call(this)},get:function(e){return null==e?this.toArray():0>e?this[this.length+e]:this[e]},pushStack:function(e){var t=x.merge(this.constructor(),e);return t.prevObject=this,t.context=this.context,t},each:function(e,t){return x.each(this,e,t)},ready:function(e){return x.ready.promise().done(e),this},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(0>e?t:0);return this.pushStack(n>=0&&t>n?[this[n]]:[])},map:function(e){return this.pushStack(x.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:h,sort:[].sort,splice:[].splice},x.fn.init.prototype=x.fn,x.extend=x.fn.extend=function(){var e,t,n,r,i,o,s=arguments[0]||{},a=1,u=arguments.length,l=!1;for("boolean"==typeof s&&(l=s,s=arguments[1]||{},a=2),"object"==typeof s||x.isFunction(s)||(s={}),u===a&&(s=this,--a);u>a;a++)if(null!=(e=arguments[a]))for(t in e)n=s[t],r=e[t],s!==r&&(l&&r&&(x.isPlainObject(r)||(i=x.isArray(r)))?(i?(i=!1,o=n&&x.isArray(n)?n:[]):o=n&&x.isPlainObject(n)?n:{},s[t]=x.extend(l,o,r)):r!==undefined&&(s[t]=r));return s},x.extend({expando:"jQuery"+(p+Math.random()).replace(/\D/g,""),noConflict:function(t){return e.$===x&&(e.$=u),t&&e.jQuery===x&&(e.jQuery=a),x},isReady:!1,readyWait:1,holdReady:function(e){e?x.readyWait++:x.ready(!0)},ready:function(e){(e===!0?--x.readyWait:x.isReady)||(x.isReady=!0,e!==!0&&--x.readyWait>0||(n.resolveWith(o,[x]),x.fn.trigger&&x(o).trigger("ready").off("ready")))},isFunction:function(e){return"function"===x.type(e)},isArray:Array.isArray,isWindow:function(e){return null!=e&&e===e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?l[m.call(e)]||"object":typeof e},isPlainObject:function(e){if("object"!==x.type(e)||e.nodeType||x.isWindow(e))return!1;try{if(e.constructor&&!y.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}return!0},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw Error(e)},parseHTML:function(e,t,n){if(!e||"string"!=typeof e)return null;"boolean"==typeof t&&(n=t,t=!1),t=t||o;var r=C.exec(e),i=!n&&[];return r?[t.createElement(r[1])]:(r=x.buildFragment([e],t,i),i&&x(i).remove(),x.merge([],r.childNodes))},parseJSON:JSON.parse,parseXML:function(e){var t,n;if(!e||"string"!=typeof e)return null;try{n=new DOMParser,t=n.parseFromString(e,"text/xml")}catch(r){t=undefined}return(!t||t.getElementsByTagName("parsererror").length)&&x.error("Invalid XML: "+e),t},noop:function(){},globalEval:function(e){var t,n=eval;e=x.trim(e),e&&(1===e.indexOf("use strict")?(t=o.createElement("script"),t.text=e,o.head.appendChild(t).parentNode.removeChild(t)):n(e))},camelCase:function(e){return e.replace(k,"ms-").replace(N,E)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,t,n){var r,i=0,o=e.length,s=j(e);if(n){if(s){for(;o>i;i++)if(r=t.apply(e[i],n),r===!1)break}else for(i in e)if(r=t.apply(e[i],n),r===!1)break}else if(s){for(;o>i;i++)if(r=t.call(e[i],i,e[i]),r===!1)break}else for(i in e)if(r=t.call(e[i],i,e[i]),r===!1)break;return e},trim:function(e){return null==e?"":v.call(e)},makeArray:function(e,t){var n=t||[];return null!=e&&(j(Object(e))?x.merge(n,"string"==typeof e?[e]:e):h.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:g.call(t,e,n)},merge:function(e,t){var n=t.length,r=e.length,i=0;if("number"==typeof n)for(;n>i;i++)e[r++]=t[i];else while(t[i]!==undefined)e[r++]=t[i++];return e.length=r,e},grep:function(e,t,n){var r,i=[],o=0,s=e.length;for(n=!!n;s>o;o++)r=!!t(e[o],o),n!==r&&i.push(e[o]);return i},map:function(e,t,n){var r,i=0,o=e.length,s=j(e),a=[];if(s)for(;o>i;i++)r=t(e[i],i,n),null!=r&&(a[a.length]=r);else for(i in e)r=t(e[i],i,n),null!=r&&(a[a.length]=r);return f.apply([],a)},guid:1,proxy:function(e,t){var n,r,i;return"string"==typeof t&&(n=e[t],t=e,e=n),x.isFunction(e)?(r=d.call(arguments,2),i=function(){return e.apply(t||this,r.concat(d.call(arguments)))},i.guid=e.guid=e.guid||x.guid++,i):undefined},access:function(e,t,n,r,i,o,s){var a=0,u=e.length,l=null==n;if("object"===x.type(n)){i=!0;for(a in n)x.access(e,t,a,n[a],!0,o,s)}else if(r!==undefined&&(i=!0,x.isFunction(r)||(s=!0),l&&(s?(t.call(e,r),t=null):(l=t,t=function(e,t,n){return l.call(x(e),n)})),t))for(;u>a;a++)t(e[a],n,s?r:r.call(e[a],a,t(e[a],n)));return i?e:l?t.call(e):u?t(e[0],n):o},now:Date.now,swap:function(e,t,n,r){var i,o,s={};for(o in t)s[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=s[o];return i}}),x.ready.promise=function(t){return n||(n=x.Deferred(),"complete"===o.readyState?setTimeout(x.ready):(o.addEventListener("DOMContentLoaded",S,!1),e.addEventListener("load",S,!1))),n.promise(t)},x.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){l["[object "+t+"]"]=t.toLowerCase()});function j(e){var t=e.length,n=x.type(e);return x.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}t=x(o),function(e,undefined){var t,n,r,i,o,s,a,u,l,c,p,f,h,d,g,m,y,v="sizzle"+-new Date,b=e.document,w=0,T=0,C=st(),k=st(),N=st(),E=!1,S=function(e,t){return e===t?(E=!0,0):0},j=typeof undefined,D=1<<31,A={}.hasOwnProperty,L=[],q=L.pop,H=L.push,O=L.push,F=L.slice,P=L.indexOf||function(e){var t=0,n=this.length;for(;n>t;t++)if(this[t]===e)return t;return-1},R="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",W="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",$=W.replace("w","w#"),B="\\["+M+"*("+W+")"+M+"*(?:([*^$|!~]?=)"+M+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+$+")|)|)"+M+"*\\]",I=":("+W+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+B.replace(3,8)+")*)|.*)\\)|)",z=RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),_=RegExp("^"+M+"*,"+M+"*"),X=RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=RegExp(M+"*[+~]"),Y=RegExp("="+M+"*([^\\]'\"]*)"+M+"*\\]","g"),V=RegExp(I),G=RegExp("^"+$+"$"),J={ID:RegExp("^#("+W+")"),CLASS:RegExp("^\\.("+W+")"),TAG:RegExp("^("+W.replace("w","w*")+")"),ATTR:RegExp("^"+B),PSEUDO:RegExp("^"+I),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:RegExp("^(?:"+R+")$","i"),needsContext:RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Q=/^[^{]+\{\s*\[native \w/,K=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,Z=/^(?:input|select|textarea|button)$/i,et=/^h\d$/i,tt=/'|\\/g,nt=RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),rt=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:0>r?String.fromCharCode(r+65536):String.fromCharCode(55296|r>>10,56320|1023&r)};try{O.apply(L=F.call(b.childNodes),b.childNodes),L[b.childNodes.length].nodeType}catch(it){O={apply:L.length?function(e,t){H.apply(e,F.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function ot(e,t,r,i){var o,s,a,u,l,f,g,m,x,w;if((t?t.ownerDocument||t:b)!==p&&c(t),t=t||p,r=r||[],!e||"string"!=typeof e)return r;if(1!==(u=t.nodeType)&&9!==u)return[];if(h&&!i){if(o=K.exec(e))if(a=o[1]){if(9===u){if(s=t.getElementById(a),!s||!s.parentNode)return r;if(s.id===a)return r.push(s),r}else if(t.ownerDocument&&(s=t.ownerDocument.getElementById(a))&&y(t,s)&&s.id===a)return r.push(s),r}else{if(o[2])return O.apply(r,t.getElementsByTagName(e)),r;if((a=o[3])&&n.getElementsByClassName&&t.getElementsByClassName)return O.apply(r,t.getElementsByClassName(a)),r}if(n.qsa&&(!d||!d.test(e))){if(m=g=v,x=t,w=9===u&&e,1===u&&"object"!==t.nodeName.toLowerCase()){f=gt(e),(g=t.getAttribute("id"))?m=g.replace(tt,"\\$&"):t.setAttribute("id",m),m="[id='"+m+"'] ",l=f.length;while(l--)f[l]=m+mt(f[l]);x=U.test(e)&&t.parentNode||t,w=f.join(",")}if(w)try{return O.apply(r,x.querySelectorAll(w)),r}catch(T){}finally{g||t.removeAttribute("id")}}}return kt(e.replace(z,"$1"),t,r,i)}function st(){var e=[];function t(n,r){return e.push(n+=" ")>i.cacheLength&&delete t[e.shift()],t[n]=r}return t}function at(e){return e[v]=!0,e}function ut(e){var t=p.createElement("div");try{return!!e(t)}catch(n){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function lt(e,t){var n=e.split("|"),r=e.length;while(r--)i.attrHandle[n[r]]=t}function ct(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&(~t.sourceIndex||D)-(~e.sourceIndex||D);if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function pt(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function ft(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function ht(e){return at(function(t){return t=+t,at(function(n,r){var i,o=e([],n.length,t),s=o.length;while(s--)n[i=o[s]]&&(n[i]=!(r[i]=n[i]))})})}s=ot.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},n=ot.support={},c=ot.setDocument=function(e){var t=e?e.ownerDocument||e:b,r=t.defaultView;return t!==p&&9===t.nodeType&&t.documentElement?(p=t,f=t.documentElement,h=!s(t),r&&r.attachEvent&&r!==r.top&&r.attachEvent("onbeforeunload",function(){c()}),n.attributes=ut(function(e){return e.className="i",!e.getAttribute("className")}),n.getElementsByTagName=ut(function(e){return e.appendChild(t.createComment("")),!e.getElementsByTagName("*").length}),n.getElementsByClassName=ut(function(e){return e.innerHTML="
",e.firstChild.className="i",2===e.getElementsByClassName("i").length}),n.getById=ut(function(e){return f.appendChild(e).id=v,!t.getElementsByName||!t.getElementsByName(v).length}),n.getById?(i.find.ID=function(e,t){if(typeof t.getElementById!==j&&h){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},i.filter.ID=function(e){var t=e.replace(nt,rt);return function(e){return e.getAttribute("id")===t}}):(delete i.find.ID,i.filter.ID=function(e){var t=e.replace(nt,rt);return function(e){var n=typeof e.getAttributeNode!==j&&e.getAttributeNode("id");return n&&n.value===t}}),i.find.TAG=n.getElementsByTagName?function(e,t){return typeof t.getElementsByTagName!==j?t.getElementsByTagName(e):undefined}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},i.find.CLASS=n.getElementsByClassName&&function(e,t){return typeof t.getElementsByClassName!==j&&h?t.getElementsByClassName(e):undefined},g=[],d=[],(n.qsa=Q.test(t.querySelectorAll))&&(ut(function(e){e.innerHTML="",e.querySelectorAll("[selected]").length||d.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll(":checked").length||d.push(":checked")}),ut(function(e){var n=t.createElement("input");n.setAttribute("type","hidden"),e.appendChild(n).setAttribute("t",""),e.querySelectorAll("[t^='']").length&&d.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll(":enabled").length||d.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),d.push(",.*:")})),(n.matchesSelector=Q.test(m=f.webkitMatchesSelector||f.mozMatchesSelector||f.oMatchesSelector||f.msMatchesSelector))&&ut(function(e){n.disconnectedMatch=m.call(e,"div"),m.call(e,"[s!='']:x"),g.push("!=",I)}),d=d.length&&RegExp(d.join("|")),g=g.length&&RegExp(g.join("|")),y=Q.test(f.contains)||f.compareDocumentPosition?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},S=f.compareDocumentPosition?function(e,r){if(e===r)return E=!0,0;var i=r.compareDocumentPosition&&e.compareDocumentPosition&&e.compareDocumentPosition(r);return i?1&i||!n.sortDetached&&r.compareDocumentPosition(e)===i?e===t||y(b,e)?-1:r===t||y(b,r)?1:l?P.call(l,e)-P.call(l,r):0:4&i?-1:1:e.compareDocumentPosition?-1:1}:function(e,n){var r,i=0,o=e.parentNode,s=n.parentNode,a=[e],u=[n];if(e===n)return E=!0,0;if(!o||!s)return e===t?-1:n===t?1:o?-1:s?1:l?P.call(l,e)-P.call(l,n):0;if(o===s)return ct(e,n);r=e;while(r=r.parentNode)a.unshift(r);r=n;while(r=r.parentNode)u.unshift(r);while(a[i]===u[i])i++;return i?ct(a[i],u[i]):a[i]===b?-1:u[i]===b?1:0},t):p},ot.matches=function(e,t){return ot(e,null,null,t)},ot.matchesSelector=function(e,t){if((e.ownerDocument||e)!==p&&c(e),t=t.replace(Y,"='$1']"),!(!n.matchesSelector||!h||g&&g.test(t)||d&&d.test(t)))try{var r=m.call(e,t);if(r||n.disconnectedMatch||e.document&&11!==e.document.nodeType)return r}catch(i){}return ot(t,p,null,[e]).length>0},ot.contains=function(e,t){return(e.ownerDocument||e)!==p&&c(e),y(e,t)},ot.attr=function(e,t){(e.ownerDocument||e)!==p&&c(e);var r=i.attrHandle[t.toLowerCase()],o=r&&A.call(i.attrHandle,t.toLowerCase())?r(e,t,!h):undefined;return o===undefined?n.attributes||!h?e.getAttribute(t):(o=e.getAttributeNode(t))&&o.specified?o.value:null:o},ot.error=function(e){throw Error("Syntax error, unrecognized expression: "+e)},ot.uniqueSort=function(e){var t,r=[],i=0,o=0;if(E=!n.detectDuplicates,l=!n.sortStable&&e.slice(0),e.sort(S),E){while(t=e[o++])t===e[o]&&(i=r.push(o));while(i--)e.splice(r[i],1)}return e},o=ot.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=o(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r];r++)n+=o(t);return n},i=ot.selectors={cacheLength:50,createPseudo:at,match:J,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(nt,rt),e[3]=(e[4]||e[5]||"").replace(nt,rt),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||ot.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&ot.error(e[0]),e},PSEUDO:function(e){var t,n=!e[5]&&e[2];return J.CHILD.test(e[0])?null:(e[3]&&e[4]!==undefined?e[2]=e[4]:n&&V.test(n)&&(t=gt(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(nt,rt).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=C[e+" "];return t||(t=RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&C(e,function(e){return t.test("string"==typeof e.className&&e.className||typeof e.getAttribute!==j&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=ot.attr(r,e);return null==i?"!="===t:t?(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i+" ").indexOf(n)>-1:"|="===t?i===n||i.slice(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),s="last"!==e.slice(-4),a="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,u){var l,c,p,f,h,d,g=o!==s?"nextSibling":"previousSibling",m=t.parentNode,y=a&&t.nodeName.toLowerCase(),x=!u&&!a;if(m){if(o){while(g){p=t;while(p=p[g])if(a?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;d=g="only"===e&&!d&&"nextSibling"}return!0}if(d=[s?m.firstChild:m.lastChild],s&&x){c=m[v]||(m[v]={}),l=c[e]||[],h=l[0]===w&&l[1],f=l[0]===w&&l[2],p=h&&m.childNodes[h];while(p=++h&&p&&p[g]||(f=h=0)||d.pop())if(1===p.nodeType&&++f&&p===t){c[e]=[w,h,f];break}}else if(x&&(l=(t[v]||(t[v]={}))[e])&&l[0]===w)f=l[1];else while(p=++h&&p&&p[g]||(f=h=0)||d.pop())if((a?p.nodeName.toLowerCase()===y:1===p.nodeType)&&++f&&(x&&((p[v]||(p[v]={}))[e]=[w,f]),p===t))break;return f-=i,f===r||0===f%r&&f/r>=0}}},PSEUDO:function(e,t){var n,r=i.pseudos[e]||i.setFilters[e.toLowerCase()]||ot.error("unsupported pseudo: "+e);return r[v]?r(t):r.length>1?(n=[e,e,"",t],i.setFilters.hasOwnProperty(e.toLowerCase())?at(function(e,n){var i,o=r(e,t),s=o.length;while(s--)i=P.call(e,o[s]),e[i]=!(n[i]=o[s])}):function(e){return r(e,0,n)}):r}},pseudos:{not:at(function(e){var t=[],n=[],r=a(e.replace(z,"$1"));return r[v]?at(function(e,t,n,i){var o,s=r(e,null,i,[]),a=e.length;while(a--)(o=s[a])&&(e[a]=!(t[a]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),!n.pop()}}),has:at(function(e){return function(t){return ot(e,t).length>0}}),contains:at(function(e){return function(t){return(t.textContent||t.innerText||o(t)).indexOf(e)>-1}}),lang:at(function(e){return G.test(e||"")||ot.error("unsupported lang: "+e),e=e.replace(nt,rt).toLowerCase(),function(t){var n;do if(n=h?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===f},focus:function(e){return e===p.activeElement&&(!p.hasFocus||p.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeName>"@"||3===e.nodeType||4===e.nodeType)return!1;return!0},parent:function(e){return!i.pseudos.empty(e)},header:function(e){return et.test(e.nodeName)},input:function(e){return Z.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||t.toLowerCase()===e.type)},first:ht(function(){return[0]}),last:ht(function(e,t){return[t-1]}),eq:ht(function(e,t,n){return[0>n?n+t:n]}),even:ht(function(e,t){var n=0;for(;t>n;n+=2)e.push(n);return e}),odd:ht(function(e,t){var n=1;for(;t>n;n+=2)e.push(n);return e}),lt:ht(function(e,t,n){var r=0>n?n+t:n;for(;--r>=0;)e.push(r);return e}),gt:ht(function(e,t,n){var r=0>n?n+t:n;for(;t>++r;)e.push(r);return e})}},i.pseudos.nth=i.pseudos.eq;for(t in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})i.pseudos[t]=pt(t);for(t in{submit:!0,reset:!0})i.pseudos[t]=ft(t);function dt(){}dt.prototype=i.filters=i.pseudos,i.setFilters=new dt;function gt(e,t){var n,r,o,s,a,u,l,c=k[e+" "];if(c)return t?0:c.slice(0);a=e,u=[],l=i.preFilter;while(a){(!n||(r=_.exec(a)))&&(r&&(a=a.slice(r[0].length)||a),u.push(o=[])),n=!1,(r=X.exec(a))&&(n=r.shift(),o.push({value:n,type:r[0].replace(z," ")}),a=a.slice(n.length));for(s in i.filter)!(r=J[s].exec(a))||l[s]&&!(r=l[s](r))||(n=r.shift(),o.push({value:n,type:s,matches:r}),a=a.slice(n.length));if(!n)break}return t?a.length:a?ot.error(e):k(e,u).slice(0)}function mt(e){var t=0,n=e.length,r="";for(;n>t;t++)r+=e[t].value;return r}function yt(e,t,n){var i=t.dir,o=n&&"parentNode"===i,s=T++;return t.first?function(t,n,r){while(t=t[i])if(1===t.nodeType||o)return e(t,n,r)}:function(t,n,a){var u,l,c,p=w+" "+s;if(a){while(t=t[i])if((1===t.nodeType||o)&&e(t,n,a))return!0}else while(t=t[i])if(1===t.nodeType||o)if(c=t[v]||(t[v]={}),(l=c[i])&&l[0]===p){if((u=l[1])===!0||u===r)return u===!0}else if(l=c[i]=[p],l[1]=e(t,n,a)||r,l[1]===!0)return!0}}function vt(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function xt(e,t,n,r,i){var o,s=[],a=0,u=e.length,l=null!=t;for(;u>a;a++)(o=e[a])&&(!n||n(o,r,i))&&(s.push(o),l&&t.push(a));return s}function bt(e,t,n,r,i,o){return r&&!r[v]&&(r=bt(r)),i&&!i[v]&&(i=bt(i,o)),at(function(o,s,a,u){var l,c,p,f=[],h=[],d=s.length,g=o||Ct(t||"*",a.nodeType?[a]:a,[]),m=!e||!o&&t?g:xt(g,f,e,a,u),y=n?i||(o?e:d||r)?[]:s:m;if(n&&n(m,y,a,u),r){l=xt(y,h),r(l,[],a,u),c=l.length;while(c--)(p=l[c])&&(y[h[c]]=!(m[h[c]]=p))}if(o){if(i||e){if(i){l=[],c=y.length;while(c--)(p=y[c])&&l.push(m[c]=p);i(null,y=[],l,u)}c=y.length;while(c--)(p=y[c])&&(l=i?P.call(o,p):f[c])>-1&&(o[l]=!(s[l]=p))}}else y=xt(y===s?y.splice(d,y.length):y),i?i(null,s,y,u):O.apply(s,y)})}function wt(e){var t,n,r,o=e.length,s=i.relative[e[0].type],a=s||i.relative[" "],l=s?1:0,c=yt(function(e){return e===t},a,!0),p=yt(function(e){return P.call(t,e)>-1},a,!0),f=[function(e,n,r){return!s&&(r||n!==u)||((t=n).nodeType?c(e,n,r):p(e,n,r))}];for(;o>l;l++)if(n=i.relative[e[l].type])f=[yt(vt(f),n)];else{if(n=i.filter[e[l].type].apply(null,e[l].matches),n[v]){for(r=++l;o>r;r++)if(i.relative[e[r].type])break;return bt(l>1&&vt(f),l>1&&mt(e.slice(0,l-1).concat({value:" "===e[l-2].type?"*":""})).replace(z,"$1"),n,r>l&&wt(e.slice(l,r)),o>r&&wt(e=e.slice(r)),o>r&&mt(e))}f.push(n)}return vt(f)}function Tt(e,t){var n=0,o=t.length>0,s=e.length>0,a=function(a,l,c,f,h){var d,g,m,y=[],v=0,x="0",b=a&&[],T=null!=h,C=u,k=a||s&&i.find.TAG("*",h&&l.parentNode||l),N=w+=null==C?1:Math.random()||.1;for(T&&(u=l!==p&&l,r=n);null!=(d=k[x]);x++){if(s&&d){g=0;while(m=e[g++])if(m(d,l,c)){f.push(d);break}T&&(w=N,r=++n)}o&&((d=!m&&d)&&v--,a&&b.push(d))}if(v+=x,o&&x!==v){g=0;while(m=t[g++])m(b,y,l,c);if(a){if(v>0)while(x--)b[x]||y[x]||(y[x]=q.call(f));y=xt(y)}O.apply(f,y),T&&!a&&y.length>0&&v+t.length>1&&ot.uniqueSort(f)}return T&&(w=N,u=C),b};return o?at(a):a}a=ot.compile=function(e,t){var n,r=[],i=[],o=N[e+" "];if(!o){t||(t=gt(e)),n=t.length;while(n--)o=wt(t[n]),o[v]?r.push(o):i.push(o);o=N(e,Tt(i,r))}return o};function Ct(e,t,n){var r=0,i=t.length;for(;i>r;r++)ot(e,t[r],n);return n}function kt(e,t,r,o){var s,u,l,c,p,f=gt(e);if(!o&&1===f.length){if(u=f[0]=f[0].slice(0),u.length>2&&"ID"===(l=u[0]).type&&n.getById&&9===t.nodeType&&h&&i.relative[u[1].type]){if(t=(i.find.ID(l.matches[0].replace(nt,rt),t)||[])[0],!t)return r;e=e.slice(u.shift().value.length)}s=J.needsContext.test(e)?0:u.length;while(s--){if(l=u[s],i.relative[c=l.type])break;if((p=i.find[c])&&(o=p(l.matches[0].replace(nt,rt),U.test(u[0].type)&&t.parentNode||t))){if(u.splice(s,1),e=o.length&&mt(u),!e)return O.apply(r,o),r;break}}}return a(e,f)(o,t,!h,r,U.test(e)),r}n.sortStable=v.split("").sort(S).join("")===v,n.detectDuplicates=E,c(),n.sortDetached=ut(function(e){return 1&e.compareDocumentPosition(p.createElement("div"))}),ut(function(e){return e.innerHTML="","#"===e.firstChild.getAttribute("href")})||lt("type|href|height|width",function(e,t,n){return n?undefined:e.getAttribute(t,"type"===t.toLowerCase()?1:2)}),n.attributes&&ut(function(e){return e.innerHTML="",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||lt("value",function(e,t,n){return n||"input"!==e.nodeName.toLowerCase()?undefined:e.defaultValue}),ut(function(e){return null==e.getAttribute("disabled")})||lt(R,function(e,t,n){var r;return n?undefined:(r=e.getAttributeNode(t))&&r.specified?r.value:e[t]===!0?t.toLowerCase():null}),x.find=ot,x.expr=ot.selectors,x.expr[":"]=x.expr.pseudos,x.unique=ot.uniqueSort,x.text=ot.getText,x.isXMLDoc=ot.isXML,x.contains=ot.contains}(e);var D={};function A(e){var t=D[e]={};return x.each(e.match(w)||[],function(e,n){t[n]=!0}),t}x.Callbacks=function(e){e="string"==typeof e?D[e]||A(e):x.extend({},e);var t,n,r,i,o,s,a=[],u=!e.once&&[],l=function(p){for(t=e.memory&&p,n=!0,s=i||0,i=0,o=a.length,r=!0;a&&o>s;s++)if(a[s].apply(p[0],p[1])===!1&&e.stopOnFalse){t=!1;break}r=!1,a&&(u?u.length&&l(u.shift()):t?a=[]:c.disable())},c={add:function(){if(a){var n=a.length;(function s(t){x.each(t,function(t,n){var r=x.type(n);"function"===r?e.unique&&c.has(n)||a.push(n):n&&n.length&&"string"!==r&&s(n)})})(arguments),r?o=a.length:t&&(i=n,l(t))}return this},remove:function(){return a&&x.each(arguments,function(e,t){var n;while((n=x.inArray(t,a,n))>-1)a.splice(n,1),r&&(o>=n&&o--,s>=n&&s--)}),this},has:function(e){return e?x.inArray(e,a)>-1:!(!a||!a.length)},empty:function(){return a=[],o=0,this},disable:function(){return a=u=t=undefined,this},disabled:function(){return!a},lock:function(){return u=undefined,t||c.disable(),this},locked:function(){return!u},fireWith:function(e,t){return!a||n&&!u||(t=t||[],t=[e,t.slice?t.slice():t],r?u.push(t):l(t)),this},fire:function(){return c.fireWith(this,arguments),this},fired:function(){return!!n}};return c},x.extend({Deferred:function(e){var t=[["resolve","done",x.Callbacks("once memory"),"resolved"],["reject","fail",x.Callbacks("once memory"),"rejected"],["notify","progress",x.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return x.Deferred(function(n){x.each(t,function(t,o){var s=o[0],a=x.isFunction(e[t])&&e[t];i[o[1]](function(){var e=a&&a.apply(this,arguments);e&&x.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[s+"With"](this===r?n.promise():this,a?[e]:arguments)})}),e=null}).promise()},promise:function(e){return null!=e?x.extend(e,r):r}},i={};return r.pipe=r.then,x.each(t,function(e,o){var s=o[2],a=o[3];r[o[1]]=s.add,a&&s.add(function(){n=a},t[1^e][2].disable,t[2][2].lock),i[o[0]]=function(){return i[o[0]+"With"](this===i?r:this,arguments),this},i[o[0]+"With"]=s.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=d.call(arguments),r=n.length,i=1!==r||e&&x.isFunction(e.promise)?r:0,o=1===i?e:x.Deferred(),s=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?d.call(arguments):r,n===a?o.notifyWith(t,n):--i||o.resolveWith(t,n)}},a,u,l;if(r>1)for(a=Array(r),u=Array(r),l=Array(r);r>t;t++)n[t]&&x.isFunction(n[t].promise)?n[t].promise().done(s(t,l,n)).fail(o.reject).progress(s(t,u,a)):--i;return i||o.resolveWith(l,n),o.promise()}}),x.support=function(t){var n=o.createElement("input"),r=o.createDocumentFragment(),i=o.createElement("div"),s=o.createElement("select"),a=s.appendChild(o.createElement("option"));return n.type?(n.type="checkbox",t.checkOn=""!==n.value,t.optSelected=a.selected,t.reliableMarginRight=!0,t.boxSizingReliable=!0,t.pixelPosition=!1,n.checked=!0,t.noCloneChecked=n.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!a.disabled,n=o.createElement("input"),n.value="t",n.type="radio",t.radioValue="t"===n.value,n.setAttribute("checked","t"),n.setAttribute("name","t"),r.appendChild(n),t.checkClone=r.cloneNode(!0).cloneNode(!0).lastChild.checked,t.focusinBubbles="onfocusin"in e,i.style.backgroundClip="content-box",i.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===i.style.backgroundClip,x(function(){var n,r,s="padding:0;margin:0;border:0;display:block;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box",a=o.getElementsByTagName("body")[0];a&&(n=o.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",a.appendChild(n).appendChild(i),i.innerHTML="",i.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%",x.swap(a,null!=a.style.zoom?{zoom:1}:{},function(){t.boxSizing=4===i.offsetWidth}),e.getComputedStyle&&(t.pixelPosition="1%"!==(e.getComputedStyle(i,null)||{}).top,t.boxSizingReliable="4px"===(e.getComputedStyle(i,null)||{width:"4px"}).width,r=i.appendChild(o.createElement("div")),r.style.cssText=i.style.cssText=s,r.style.marginRight=r.style.width="0",i.style.width="1px",t.reliableMarginRight=!parseFloat((e.getComputedStyle(r,null)||{}).marginRight)),a.removeChild(n))}),t):t}({});var L,q,H=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,O=/([A-Z])/g;function F(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=x.expando+Math.random()}F.uid=1,F.accepts=function(e){return e.nodeType?1===e.nodeType||9===e.nodeType:!0},F.prototype={key:function(e){if(!F.accepts(e))return 0;var t={},n=e[this.expando];if(!n){n=F.uid++;try{t[this.expando]={value:n},Object.defineProperties(e,t)}catch(r){t[this.expando]=n,x.extend(e,t)}}return this.cache[n]||(this.cache[n]={}),n},set:function(e,t,n){var r,i=this.key(e),o=this.cache[i];if("string"==typeof t)o[t]=n;else if(x.isEmptyObject(o))x.extend(this.cache[i],t);else for(r in t)o[r]=t[r];return o},get:function(e,t){var n=this.cache[this.key(e)];return t===undefined?n:n[t]},access:function(e,t,n){var r;return t===undefined||t&&"string"==typeof t&&n===undefined?(r=this.get(e,t),r!==undefined?r:this.get(e,x.camelCase(t))):(this.set(e,t,n),n!==undefined?n:t)},remove:function(e,t){var n,r,i,o=this.key(e),s=this.cache[o];if(t===undefined)this.cache[o]={};else{x.isArray(t)?r=t.concat(t.map(x.camelCase)):(i=x.camelCase(t),t in s?r=[t,i]:(r=i,r=r in s?[r]:r.match(w)||[])),n=r.length;while(n--)delete s[r[n]]}},hasData:function(e){return!x.isEmptyObject(this.cache[e[this.expando]]||{})},discard:function(e){e[this.expando]&&delete this.cache[e[this.expando]]}},L=new F,q=new F,x.extend({acceptData:F.accepts,hasData:function(e){return L.hasData(e)||q.hasData(e)},data:function(e,t,n){return L.access(e,t,n)},removeData:function(e,t){L.remove(e,t)},_data:function(e,t,n){return q.access(e,t,n)},_removeData:function(e,t){q.remove(e,t)}}),x.fn.extend({data:function(e,t){var n,r,i=this[0],o=0,s=null;if(e===undefined){if(this.length&&(s=L.get(i),1===i.nodeType&&!q.get(i,"hasDataAttrs"))){for(n=i.attributes;n.length>o;o++)r=n[o].name,0===r.indexOf("data-")&&(r=x.camelCase(r.slice(5)),P(i,r,s[r]));q.set(i,"hasDataAttrs",!0)}return s}return"object"==typeof e?this.each(function(){L.set(this,e)}):x.access(this,function(t){var n,r=x.camelCase(e);if(i&&t===undefined){if(n=L.get(i,e),n!==undefined)return n;if(n=L.get(i,r),n!==undefined)return n;if(n=P(i,r,undefined),n!==undefined)return n}else this.each(function(){var n=L.get(this,r);L.set(this,r,t),-1!==e.indexOf("-")&&n!==undefined&&L.set(this,e,t)})},null,t,arguments.length>1,null,!0)},removeData:function(e){return this.each(function(){L.remove(this,e)})}});function P(e,t,n){var r;if(n===undefined&&1===e.nodeType)if(r="data-"+t.replace(O,"-$1").toLowerCase(),n=e.getAttribute(r),"string"==typeof n){try{n="true"===n?!0:"false"===n?!1:"null"===n?null:+n+""===n?+n:H.test(n)?JSON.parse(n):n}catch(i){}L.set(e,t,n)}else n=undefined;return n}x.extend({queue:function(e,t,n){var r;return e?(t=(t||"fx")+"queue",r=q.get(e,t),n&&(!r||x.isArray(n)?r=q.access(e,t,x.makeArray(n)):r.push(n)),r||[]):undefined},dequeue:function(e,t){t=t||"fx";var n=x.queue(e,t),r=n.length,i=n.shift(),o=x._queueHooks(e,t),s=function(){x.dequeue(e,t) -};"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,s,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return q.get(e,n)||q.access(e,n,{empty:x.Callbacks("once memory").add(function(){q.remove(e,[t+"queue",n])})})}}),x.fn.extend({queue:function(e,t){var n=2;return"string"!=typeof e&&(t=e,e="fx",n--),n>arguments.length?x.queue(this[0],e):t===undefined?this:this.each(function(){var n=x.queue(this,e,t);x._queueHooks(this,e),"fx"===e&&"inprogress"!==n[0]&&x.dequeue(this,e)})},dequeue:function(e){return this.each(function(){x.dequeue(this,e)})},delay:function(e,t){return e=x.fx?x.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,t){var n,r=1,i=x.Deferred(),o=this,s=this.length,a=function(){--r||i.resolveWith(o,[o])};"string"!=typeof e&&(t=e,e=undefined),e=e||"fx";while(s--)n=q.get(o[s],e+"queueHooks"),n&&n.empty&&(r++,n.empty.add(a));return a(),i.promise(t)}});var R,M,W=/[\t\r\n\f]/g,$=/\r/g,B=/^(?:input|select|textarea|button)$/i;x.fn.extend({attr:function(e,t){return x.access(this,x.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){x.removeAttr(this,e)})},prop:function(e,t){return x.access(this,x.prop,e,t,arguments.length>1)},removeProp:function(e){return this.each(function(){delete this[x.propFix[e]||e]})},addClass:function(e){var t,n,r,i,o,s=0,a=this.length,u="string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).addClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];a>s;s++)if(n=this[s],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(W," "):" ")){o=0;while(i=t[o++])0>r.indexOf(" "+i+" ")&&(r+=i+" ");n.className=x.trim(r)}return this},removeClass:function(e){var t,n,r,i,o,s=0,a=this.length,u=0===arguments.length||"string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).removeClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];a>s;s++)if(n=this[s],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(W," "):"")){o=0;while(i=t[o++])while(r.indexOf(" "+i+" ")>=0)r=r.replace(" "+i+" "," ");n.className=e?x.trim(r):""}return this},toggleClass:function(e,t){var n=typeof e;return"boolean"==typeof t&&"string"===n?t?this.addClass(e):this.removeClass(e):x.isFunction(e)?this.each(function(n){x(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if("string"===n){var t,i=0,o=x(this),s=e.match(w)||[];while(t=s[i++])o.hasClass(t)?o.removeClass(t):o.addClass(t)}else(n===r||"boolean"===n)&&(this.className&&q.set(this,"__className__",this.className),this.className=this.className||e===!1?"":q.get(this,"__className__")||"")})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(W," ").indexOf(t)>=0)return!0;return!1},val:function(e){var t,n,r,i=this[0];{if(arguments.length)return r=x.isFunction(e),this.each(function(n){var i;1===this.nodeType&&(i=r?e.call(this,n,x(this).val()):e,null==i?i="":"number"==typeof i?i+="":x.isArray(i)&&(i=x.map(i,function(e){return null==e?"":e+""})),t=x.valHooks[this.type]||x.valHooks[this.nodeName.toLowerCase()],t&&"set"in t&&t.set(this,i,"value")!==undefined||(this.value=i))});if(i)return t=x.valHooks[i.type]||x.valHooks[i.nodeName.toLowerCase()],t&&"get"in t&&(n=t.get(i,"value"))!==undefined?n:(n=i.value,"string"==typeof n?n.replace($,""):null==n?"":n)}}}),x.extend({valHooks:{option:{get:function(e){var t=e.attributes.value;return!t||t.specified?e.value:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,s=o?null:[],a=o?i+1:r.length,u=0>i?a:o?i:0;for(;a>u;u++)if(n=r[u],!(!n.selected&&u!==i||(x.support.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&x.nodeName(n.parentNode,"optgroup"))){if(t=x(n).val(),o)return t;s.push(t)}return s},set:function(e,t){var n,r,i=e.options,o=x.makeArray(t),s=i.length;while(s--)r=i[s],(r.selected=x.inArray(x(r).val(),o)>=0)&&(n=!0);return n||(e.selectedIndex=-1),o}}},attr:function(e,t,n){var i,o,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return typeof e.getAttribute===r?x.prop(e,t,n):(1===s&&x.isXMLDoc(e)||(t=t.toLowerCase(),i=x.attrHooks[t]||(x.expr.match.bool.test(t)?M:R)),n===undefined?i&&"get"in i&&null!==(o=i.get(e,t))?o:(o=x.find.attr(e,t),null==o?undefined:o):null!==n?i&&"set"in i&&(o=i.set(e,n,t))!==undefined?o:(e.setAttribute(t,n+""),n):(x.removeAttr(e,t),undefined))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(w);if(o&&1===e.nodeType)while(n=o[i++])r=x.propFix[n]||n,x.expr.match.bool.test(n)&&(e[r]=!1),e.removeAttribute(n)},attrHooks:{type:{set:function(e,t){if(!x.support.radioValue&&"radio"===t&&x.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},propFix:{"for":"htmlFor","class":"className"},prop:function(e,t,n){var r,i,o,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return o=1!==s||!x.isXMLDoc(e),o&&(t=x.propFix[t]||t,i=x.propHooks[t]),n!==undefined?i&&"set"in i&&(r=i.set(e,n,t))!==undefined?r:e[t]=n:i&&"get"in i&&null!==(r=i.get(e,t))?r:e[t]},propHooks:{tabIndex:{get:function(e){return e.hasAttribute("tabindex")||B.test(e.nodeName)||e.href?e.tabIndex:-1}}}}),M={set:function(e,t,n){return t===!1?x.removeAttr(e,n):e.setAttribute(n,n),n}},x.each(x.expr.match.bool.source.match(/\w+/g),function(e,t){var n=x.expr.attrHandle[t]||x.find.attr;x.expr.attrHandle[t]=function(e,t,r){var i=x.expr.attrHandle[t],o=r?undefined:(x.expr.attrHandle[t]=undefined)!=n(e,t,r)?t.toLowerCase():null;return x.expr.attrHandle[t]=i,o}}),x.support.optSelected||(x.propHooks.selected={get:function(e){var t=e.parentNode;return t&&t.parentNode&&t.parentNode.selectedIndex,null}}),x.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){x.propFix[this.toLowerCase()]=this}),x.each(["radio","checkbox"],function(){x.valHooks[this]={set:function(e,t){return x.isArray(t)?e.checked=x.inArray(x(e).val(),t)>=0:undefined}},x.support.checkOn||(x.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})});var I=/^key/,z=/^(?:mouse|contextmenu)|click/,_=/^(?:focusinfocus|focusoutblur)$/,X=/^([^.]*)(?:\.(.+)|)$/;function U(){return!0}function Y(){return!1}function V(){try{return o.activeElement}catch(e){}}x.event={global:{},add:function(e,t,n,i,o){var s,a,u,l,c,p,f,h,d,g,m,y=q.get(e);if(y){n.handler&&(s=n,n=s.handler,o=s.selector),n.guid||(n.guid=x.guid++),(l=y.events)||(l=y.events={}),(a=y.handle)||(a=y.handle=function(e){return typeof x===r||e&&x.event.triggered===e.type?undefined:x.event.dispatch.apply(a.elem,arguments)},a.elem=e),t=(t||"").match(w)||[""],c=t.length;while(c--)u=X.exec(t[c])||[],d=m=u[1],g=(u[2]||"").split(".").sort(),d&&(f=x.event.special[d]||{},d=(o?f.delegateType:f.bindType)||d,f=x.event.special[d]||{},p=x.extend({type:d,origType:m,data:i,handler:n,guid:n.guid,selector:o,needsContext:o&&x.expr.match.needsContext.test(o),namespace:g.join(".")},s),(h=l[d])||(h=l[d]=[],h.delegateCount=0,f.setup&&f.setup.call(e,i,g,a)!==!1||e.addEventListener&&e.addEventListener(d,a,!1)),f.add&&(f.add.call(e,p),p.handler.guid||(p.handler.guid=n.guid)),o?h.splice(h.delegateCount++,0,p):h.push(p),x.event.global[d]=!0);e=null}},remove:function(e,t,n,r,i){var o,s,a,u,l,c,p,f,h,d,g,m=q.hasData(e)&&q.get(e);if(m&&(u=m.events)){t=(t||"").match(w)||[""],l=t.length;while(l--)if(a=X.exec(t[l])||[],h=g=a[1],d=(a[2]||"").split(".").sort(),h){p=x.event.special[h]||{},h=(r?p.delegateType:p.bindType)||h,f=u[h]||[],a=a[2]&&RegExp("(^|\\.)"+d.join("\\.(?:.*\\.|)")+"(\\.|$)"),s=o=f.length;while(o--)c=f[o],!i&&g!==c.origType||n&&n.guid!==c.guid||a&&!a.test(c.namespace)||r&&r!==c.selector&&("**"!==r||!c.selector)||(f.splice(o,1),c.selector&&f.delegateCount--,p.remove&&p.remove.call(e,c));s&&!f.length&&(p.teardown&&p.teardown.call(e,d,m.handle)!==!1||x.removeEvent(e,h,m.handle),delete u[h])}else for(h in u)x.event.remove(e,h+t[l],n,r,!0);x.isEmptyObject(u)&&(delete m.handle,q.remove(e,"events"))}},trigger:function(t,n,r,i){var s,a,u,l,c,p,f,h=[r||o],d=y.call(t,"type")?t.type:t,g=y.call(t,"namespace")?t.namespace.split("."):[];if(a=u=r=r||o,3!==r.nodeType&&8!==r.nodeType&&!_.test(d+x.event.triggered)&&(d.indexOf(".")>=0&&(g=d.split("."),d=g.shift(),g.sort()),c=0>d.indexOf(":")&&"on"+d,t=t[x.expando]?t:new x.Event(d,"object"==typeof t&&t),t.isTrigger=i?2:3,t.namespace=g.join("."),t.namespace_re=t.namespace?RegExp("(^|\\.)"+g.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,t.result=undefined,t.target||(t.target=r),n=null==n?[t]:x.makeArray(n,[t]),f=x.event.special[d]||{},i||!f.trigger||f.trigger.apply(r,n)!==!1)){if(!i&&!f.noBubble&&!x.isWindow(r)){for(l=f.delegateType||d,_.test(l+d)||(a=a.parentNode);a;a=a.parentNode)h.push(a),u=a;u===(r.ownerDocument||o)&&h.push(u.defaultView||u.parentWindow||e)}s=0;while((a=h[s++])&&!t.isPropagationStopped())t.type=s>1?l:f.bindType||d,p=(q.get(a,"events")||{})[t.type]&&q.get(a,"handle"),p&&p.apply(a,n),p=c&&a[c],p&&x.acceptData(a)&&p.apply&&p.apply(a,n)===!1&&t.preventDefault();return t.type=d,i||t.isDefaultPrevented()||f._default&&f._default.apply(h.pop(),n)!==!1||!x.acceptData(r)||c&&x.isFunction(r[d])&&!x.isWindow(r)&&(u=r[c],u&&(r[c]=null),x.event.triggered=d,r[d](),x.event.triggered=undefined,u&&(r[c]=u)),t.result}},dispatch:function(e){e=x.event.fix(e);var t,n,r,i,o,s=[],a=d.call(arguments),u=(q.get(this,"events")||{})[e.type]||[],l=x.event.special[e.type]||{};if(a[0]=e,e.delegateTarget=this,!l.preDispatch||l.preDispatch.call(this,e)!==!1){s=x.event.handlers.call(this,e,u),t=0;while((i=s[t++])&&!e.isPropagationStopped()){e.currentTarget=i.elem,n=0;while((o=i.handlers[n++])&&!e.isImmediatePropagationStopped())(!e.namespace_re||e.namespace_re.test(o.namespace))&&(e.handleObj=o,e.data=o.data,r=((x.event.special[o.origType]||{}).handle||o.handler).apply(i.elem,a),r!==undefined&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()))}return l.postDispatch&&l.postDispatch.call(this,e),e.result}},handlers:function(e,t){var n,r,i,o,s=[],a=t.delegateCount,u=e.target;if(a&&u.nodeType&&(!e.button||"click"!==e.type))for(;u!==this;u=u.parentNode||this)if(u.disabled!==!0||"click"!==e.type){for(r=[],n=0;a>n;n++)o=t[n],i=o.selector+" ",r[i]===undefined&&(r[i]=o.needsContext?x(i,this).index(u)>=0:x.find(i,this,null,[u]).length),r[i]&&r.push(o);r.length&&s.push({elem:u,handlers:r})}return t.length>a&&s.push({elem:this,handlers:t.slice(a)}),s},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,t){var n,r,i,s=t.button;return null==e.pageX&&null!=t.clientX&&(n=e.target.ownerDocument||o,r=n.documentElement,i=n.body,e.pageX=t.clientX+(r&&r.scrollLeft||i&&i.scrollLeft||0)-(r&&r.clientLeft||i&&i.clientLeft||0),e.pageY=t.clientY+(r&&r.scrollTop||i&&i.scrollTop||0)-(r&&r.clientTop||i&&i.clientTop||0)),e.which||s===undefined||(e.which=1&s?1:2&s?3:4&s?2:0),e}},fix:function(e){if(e[x.expando])return e;var t,n,r,i=e.type,s=e,a=this.fixHooks[i];a||(this.fixHooks[i]=a=z.test(i)?this.mouseHooks:I.test(i)?this.keyHooks:{}),r=a.props?this.props.concat(a.props):this.props,e=new x.Event(s),t=r.length;while(t--)n=r[t],e[n]=s[n];return e.target||(e.target=o),3===e.target.nodeType&&(e.target=e.target.parentNode),a.filter?a.filter(e,s):e},special:{load:{noBubble:!0},focus:{trigger:function(){return this!==V()&&this.focus?(this.focus(),!1):undefined},delegateType:"focusin"},blur:{trigger:function(){return this===V()&&this.blur?(this.blur(),!1):undefined},delegateType:"focusout"},click:{trigger:function(){return"checkbox"===this.type&&this.click&&x.nodeName(this,"input")?(this.click(),!1):undefined},_default:function(e){return x.nodeName(e.target,"a")}},beforeunload:{postDispatch:function(e){e.result!==undefined&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=x.extend(new x.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?x.event.trigger(i,null,t):x.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},x.removeEvent=function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)},x.Event=function(e,t){return this instanceof x.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.getPreventDefault&&e.getPreventDefault()?U:Y):this.type=e,t&&x.extend(this,t),this.timeStamp=e&&e.timeStamp||x.now(),this[x.expando]=!0,undefined):new x.Event(e,t)},x.Event.prototype={isDefaultPrevented:Y,isPropagationStopped:Y,isImmediatePropagationStopped:Y,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=U,e&&e.preventDefault&&e.preventDefault()},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=U,e&&e.stopPropagation&&e.stopPropagation()},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=U,this.stopPropagation()}},x.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){x.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj;return(!i||i!==r&&!x.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),x.support.focusinBubbles||x.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){x.event.simulate(t,e.target,x.event.fix(e),!0)};x.event.special[t]={setup:function(){0===n++&&o.addEventListener(e,r,!0)},teardown:function(){0===--n&&o.removeEventListener(e,r,!0)}}}),x.fn.extend({on:function(e,t,n,r,i){var o,s;if("object"==typeof e){"string"!=typeof t&&(n=n||t,t=undefined);for(s in e)this.on(s,t,n,e[s],i);return this}if(null==n&&null==r?(r=t,n=t=undefined):null==r&&("string"==typeof t?(r=n,n=undefined):(r=n,n=t,t=undefined)),r===!1)r=Y;else if(!r)return this;return 1===i&&(o=r,r=function(e){return x().off(e),o.apply(this,arguments)},r.guid=o.guid||(o.guid=x.guid++)),this.each(function(){x.event.add(this,e,r,n,t)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,t,n){var r,i;if(e&&e.preventDefault&&e.handleObj)return r=e.handleObj,x(e.delegateTarget).off(r.namespace?r.origType+"."+r.namespace:r.origType,r.selector,r.handler),this;if("object"==typeof e){for(i in e)this.off(i,t,e[i]);return this}return(t===!1||"function"==typeof t)&&(n=t,t=undefined),n===!1&&(n=Y),this.each(function(){x.event.remove(this,e,n,t)})},trigger:function(e,t){return this.each(function(){x.event.trigger(e,t,this)})},triggerHandler:function(e,t){var n=this[0];return n?x.event.trigger(e,t,n,!0):undefined}});var G=/^.[^:#\[\.,]*$/,J=/^(?:parents|prev(?:Until|All))/,Q=x.expr.match.needsContext,K={children:!0,contents:!0,next:!0,prev:!0};x.fn.extend({find:function(e){var t,n=[],r=this,i=r.length;if("string"!=typeof e)return this.pushStack(x(e).filter(function(){for(t=0;i>t;t++)if(x.contains(r[t],this))return!0}));for(t=0;i>t;t++)x.find(e,r[t],n);return n=this.pushStack(i>1?x.unique(n):n),n.selector=this.selector?this.selector+" "+e:e,n},has:function(e){var t=x(e,this),n=t.length;return this.filter(function(){var e=0;for(;n>e;e++)if(x.contains(this,t[e]))return!0})},not:function(e){return this.pushStack(et(this,e||[],!0))},filter:function(e){return this.pushStack(et(this,e||[],!1))},is:function(e){return!!et(this,"string"==typeof e&&Q.test(e)?x(e):e||[],!1).length},closest:function(e,t){var n,r=0,i=this.length,o=[],s=Q.test(e)||"string"!=typeof e?x(e,t||this.context):0;for(;i>r;r++)for(n=this[r];n&&n!==t;n=n.parentNode)if(11>n.nodeType&&(s?s.index(n)>-1:1===n.nodeType&&x.find.matchesSelector(n,e))){n=o.push(n);break}return this.pushStack(o.length>1?x.unique(o):o)},index:function(e){return e?"string"==typeof e?g.call(x(e),this[0]):g.call(this,e.jquery?e[0]:e):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){var n="string"==typeof e?x(e,t):x.makeArray(e&&e.nodeType?[e]:e),r=x.merge(this.get(),n);return this.pushStack(x.unique(r))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}});function Z(e,t){while((e=e[t])&&1!==e.nodeType);return e}x.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return x.dir(e,"parentNode")},parentsUntil:function(e,t,n){return x.dir(e,"parentNode",n)},next:function(e){return Z(e,"nextSibling")},prev:function(e){return Z(e,"previousSibling")},nextAll:function(e){return x.dir(e,"nextSibling")},prevAll:function(e){return x.dir(e,"previousSibling")},nextUntil:function(e,t,n){return x.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return x.dir(e,"previousSibling",n)},siblings:function(e){return x.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return x.sibling(e.firstChild)},contents:function(e){return e.contentDocument||x.merge([],e.childNodes)}},function(e,t){x.fn[e]=function(n,r){var i=x.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=x.filter(r,i)),this.length>1&&(K[e]||x.unique(i),J.test(e)&&i.reverse()),this.pushStack(i)}}),x.extend({filter:function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?x.find.matchesSelector(r,e)?[r]:[]:x.find.matches(e,x.grep(t,function(e){return 1===e.nodeType}))},dir:function(e,t,n){var r=[],i=n!==undefined;while((e=e[t])&&9!==e.nodeType)if(1===e.nodeType){if(i&&x(e).is(n))break;r.push(e)}return r},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}});function et(e,t,n){if(x.isFunction(t))return x.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return x.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(G.test(t))return x.filter(t,e,n);t=x.filter(t,e)}return x.grep(e,function(e){return g.call(t,e)>=0!==n})}var tt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,nt=/<([\w:]+)/,rt=/<|&#?\w+;/,it=/<(?:script|style|link)/i,ot=/^(?:checkbox|radio)$/i,st=/checked\s*(?:[^=]|=\s*.checked.)/i,at=/^$|\/(?:java|ecma)script/i,ut=/^true\/(.*)/,lt=/^\s*\s*$/g,ct={option:[1,""],thead:[1,"","
"],col:[2,"","
"],tr:[2,"","
"],td:[3,"","
"],_default:[0,"",""]};ct.optgroup=ct.option,ct.tbody=ct.tfoot=ct.colgroup=ct.caption=ct.thead,ct.th=ct.td,x.fn.extend({text:function(e){return x.access(this,function(e){return e===undefined?x.text(this):this.empty().append((this[0]&&this[0].ownerDocument||o).createTextNode(e))},null,e,arguments.length)},append:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=pt(this,e);t.appendChild(e)}})},prepend:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=pt(this,e);t.insertBefore(e,t.firstChild)}})},before:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},remove:function(e,t){var n,r=e?x.filter(e,this):this,i=0;for(;null!=(n=r[i]);i++)t||1!==n.nodeType||x.cleanData(mt(n)),n.parentNode&&(t&&x.contains(n.ownerDocument,n)&&dt(mt(n,"script")),n.parentNode.removeChild(n));return this},empty:function(){var e,t=0;for(;null!=(e=this[t]);t++)1===e.nodeType&&(x.cleanData(mt(e,!1)),e.textContent="");return this},clone:function(e,t){return e=null==e?!1:e,t=null==t?e:t,this.map(function(){return x.clone(this,e,t)})},html:function(e){return x.access(this,function(e){var t=this[0]||{},n=0,r=this.length;if(e===undefined&&1===t.nodeType)return t.innerHTML;if("string"==typeof e&&!it.test(e)&&!ct[(nt.exec(e)||["",""])[1].toLowerCase()]){e=e.replace(tt,"<$1>");try{for(;r>n;n++)t=this[n]||{},1===t.nodeType&&(x.cleanData(mt(t,!1)),t.innerHTML=e);t=0}catch(i){}}t&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(){var e=x.map(this,function(e){return[e.nextSibling,e.parentNode]}),t=0;return this.domManip(arguments,function(n){var r=e[t++],i=e[t++];i&&(r&&r.parentNode!==i&&(r=this.nextSibling),x(this).remove(),i.insertBefore(n,r))},!0),t?this:this.remove()},detach:function(e){return this.remove(e,!0)},domManip:function(e,t,n){e=f.apply([],e);var r,i,o,s,a,u,l=0,c=this.length,p=this,h=c-1,d=e[0],g=x.isFunction(d);if(g||!(1>=c||"string"!=typeof d||x.support.checkClone)&&st.test(d))return this.each(function(r){var i=p.eq(r);g&&(e[0]=d.call(this,r,i.html())),i.domManip(e,t,n)});if(c&&(r=x.buildFragment(e,this[0].ownerDocument,!1,!n&&this),i=r.firstChild,1===r.childNodes.length&&(r=i),i)){for(o=x.map(mt(r,"script"),ft),s=o.length;c>l;l++)a=r,l!==h&&(a=x.clone(a,!0,!0),s&&x.merge(o,mt(a,"script"))),t.call(this[l],a,l);if(s)for(u=o[o.length-1].ownerDocument,x.map(o,ht),l=0;s>l;l++)a=o[l],at.test(a.type||"")&&!q.access(a,"globalEval")&&x.contains(u,a)&&(a.src?x._evalUrl(a.src):x.globalEval(a.textContent.replace(lt,"")))}return this}}),x.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){x.fn[e]=function(e){var n,r=[],i=x(e),o=i.length-1,s=0;for(;o>=s;s++)n=s===o?this:this.clone(!0),x(i[s])[t](n),h.apply(r,n.get());return this.pushStack(r)}}),x.extend({clone:function(e,t,n){var r,i,o,s,a=e.cloneNode(!0),u=x.contains(e.ownerDocument,e);if(!(x.support.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||x.isXMLDoc(e)))for(s=mt(a),o=mt(e),r=0,i=o.length;i>r;r++)yt(o[r],s[r]);if(t)if(n)for(o=o||mt(e),s=s||mt(a),r=0,i=o.length;i>r;r++)gt(o[r],s[r]);else gt(e,a);return s=mt(a,"script"),s.length>0&&dt(s,!u&&mt(e,"script")),a},buildFragment:function(e,t,n,r){var i,o,s,a,u,l,c=0,p=e.length,f=t.createDocumentFragment(),h=[];for(;p>c;c++)if(i=e[c],i||0===i)if("object"===x.type(i))x.merge(h,i.nodeType?[i]:i);else if(rt.test(i)){o=o||f.appendChild(t.createElement("div")),s=(nt.exec(i)||["",""])[1].toLowerCase(),a=ct[s]||ct._default,o.innerHTML=a[1]+i.replace(tt,"<$1>")+a[2],l=a[0];while(l--)o=o.lastChild;x.merge(h,o.childNodes),o=f.firstChild,o.textContent=""}else h.push(t.createTextNode(i));f.textContent="",c=0;while(i=h[c++])if((!r||-1===x.inArray(i,r))&&(u=x.contains(i.ownerDocument,i),o=mt(f.appendChild(i),"script"),u&&dt(o),n)){l=0;while(i=o[l++])at.test(i.type||"")&&n.push(i)}return f},cleanData:function(e){var t,n,r,i,o,s,a=x.event.special,u=0;for(;(n=e[u])!==undefined;u++){if(F.accepts(n)&&(o=n[q.expando],o&&(t=q.cache[o]))){if(r=Object.keys(t.events||{}),r.length)for(s=0;(i=r[s])!==undefined;s++)a[i]?x.event.remove(n,i):x.removeEvent(n,i,t.handle);q.cache[o]&&delete q.cache[o]}delete L.cache[n[L.expando]]}},_evalUrl:function(e){return x.ajax({url:e,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})}});function pt(e,t){return x.nodeName(e,"table")&&x.nodeName(1===t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function ft(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function ht(e){var t=ut.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function dt(e,t){var n=e.length,r=0;for(;n>r;r++)q.set(e[r],"globalEval",!t||q.get(t[r],"globalEval"))}function gt(e,t){var n,r,i,o,s,a,u,l;if(1===t.nodeType){if(q.hasData(e)&&(o=q.access(e),s=q.set(t,o),l=o.events)){delete s.handle,s.events={};for(i in l)for(n=0,r=l[i].length;r>n;n++)x.event.add(t,i,l[i][n])}L.hasData(e)&&(a=L.access(e),u=x.extend({},a),L.set(t,u))}}function mt(e,t){var n=e.getElementsByTagName?e.getElementsByTagName(t||"*"):e.querySelectorAll?e.querySelectorAll(t||"*"):[];return t===undefined||t&&x.nodeName(e,t)?x.merge([e],n):n}function yt(e,t){var n=t.nodeName.toLowerCase();"input"===n&&ot.test(e.type)?t.checked=e.checked:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}x.fn.extend({wrapAll:function(e){var t;return x.isFunction(e)?this.each(function(t){x(this).wrapAll(e.call(this,t))}):(this[0]&&(t=x(e,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstElementChild)e=e.firstElementChild;return e}).append(this)),this)},wrapInner:function(e){return x.isFunction(e)?this.each(function(t){x(this).wrapInner(e.call(this,t))}):this.each(function(){var t=x(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=x.isFunction(e);return this.each(function(n){x(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){x.nodeName(this,"body")||x(this).replaceWith(this.childNodes)}).end()}});var vt,xt,bt=/^(none|table(?!-c[ea]).+)/,wt=/^margin/,Tt=RegExp("^("+b+")(.*)$","i"),Ct=RegExp("^("+b+")(?!px)[a-z%]+$","i"),kt=RegExp("^([+-])=("+b+")","i"),Nt={BODY:"block"},Et={position:"absolute",visibility:"hidden",display:"block"},St={letterSpacing:0,fontWeight:400},jt=["Top","Right","Bottom","Left"],Dt=["Webkit","O","Moz","ms"];function At(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=Dt.length;while(i--)if(t=Dt[i]+n,t in e)return t;return r}function Lt(e,t){return e=t||e,"none"===x.css(e,"display")||!x.contains(e.ownerDocument,e)}function qt(t){return e.getComputedStyle(t,null)}function Ht(e,t){var n,r,i,o=[],s=0,a=e.length;for(;a>s;s++)r=e[s],r.style&&(o[s]=q.get(r,"olddisplay"),n=r.style.display,t?(o[s]||"none"!==n||(r.style.display=""),""===r.style.display&&Lt(r)&&(o[s]=q.access(r,"olddisplay",Rt(r.nodeName)))):o[s]||(i=Lt(r),(n&&"none"!==n||!i)&&q.set(r,"olddisplay",i?n:x.css(r,"display"))));for(s=0;a>s;s++)r=e[s],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?o[s]||"":"none"));return e}x.fn.extend({css:function(e,t){return x.access(this,function(e,t,n){var r,i,o={},s=0;if(x.isArray(t)){for(r=qt(e),i=t.length;i>s;s++)o[t[s]]=x.css(e,t[s],!1,r);return o}return n!==undefined?x.style(e,t,n):x.css(e,t)},e,t,arguments.length>1)},show:function(){return Ht(this,!0)},hide:function(){return Ht(this)},toggle:function(e){return"boolean"==typeof e?e?this.show():this.hide():this.each(function(){Lt(this)?x(this).show():x(this).hide()})}}),x.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=vt(e,"opacity");return""===n?"1":n}}}},cssNumber:{columnCount:!0,fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":"cssFloat"},style:function(e,t,n,r){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var i,o,s,a=x.camelCase(t),u=e.style;return t=x.cssProps[a]||(x.cssProps[a]=At(u,a)),s=x.cssHooks[t]||x.cssHooks[a],n===undefined?s&&"get"in s&&(i=s.get(e,!1,r))!==undefined?i:u[t]:(o=typeof n,"string"===o&&(i=kt.exec(n))&&(n=(i[1]+1)*i[2]+parseFloat(x.css(e,t)),o="number"),null==n||"number"===o&&isNaN(n)||("number"!==o||x.cssNumber[a]||(n+="px"),x.support.clearCloneStyle||""!==n||0!==t.indexOf("background")||(u[t]="inherit"),s&&"set"in s&&(n=s.set(e,n,r))===undefined||(u[t]=n)),undefined)}},css:function(e,t,n,r){var i,o,s,a=x.camelCase(t);return t=x.cssProps[a]||(x.cssProps[a]=At(e.style,a)),s=x.cssHooks[t]||x.cssHooks[a],s&&"get"in s&&(i=s.get(e,!0,n)),i===undefined&&(i=vt(e,t,r)),"normal"===i&&t in St&&(i=St[t]),""===n||n?(o=parseFloat(i),n===!0||x.isNumeric(o)?o||0:i):i}}),vt=function(e,t,n){var r,i,o,s=n||qt(e),a=s?s.getPropertyValue(t)||s[t]:undefined,u=e.style;return s&&(""!==a||x.contains(e.ownerDocument,e)||(a=x.style(e,t)),Ct.test(a)&&wt.test(t)&&(r=u.width,i=u.minWidth,o=u.maxWidth,u.minWidth=u.maxWidth=u.width=a,a=s.width,u.width=r,u.minWidth=i,u.maxWidth=o)),a};function Ot(e,t,n){var r=Tt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function Ft(e,t,n,r,i){var o=n===(r?"border":"content")?4:"width"===t?1:0,s=0;for(;4>o;o+=2)"margin"===n&&(s+=x.css(e,n+jt[o],!0,i)),r?("content"===n&&(s-=x.css(e,"padding"+jt[o],!0,i)),"margin"!==n&&(s-=x.css(e,"border"+jt[o]+"Width",!0,i))):(s+=x.css(e,"padding"+jt[o],!0,i),"padding"!==n&&(s+=x.css(e,"border"+jt[o]+"Width",!0,i)));return s}function Pt(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=qt(e),s=x.support.boxSizing&&"border-box"===x.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=vt(e,t,o),(0>i||null==i)&&(i=e.style[t]),Ct.test(i))return i;r=s&&(x.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+Ft(e,t,n||(s?"border":"content"),r,o)+"px"}function Rt(e){var t=o,n=Nt[e];return n||(n=Mt(e,t),"none"!==n&&n||(xt=(xt||x(" + + + diff --git a/esp32_fw/data/www/index.html b/esp32_fw/data/www/index.html new file mode 100644 index 00000000..5f91685e --- /dev/null +++ b/esp32_fw/data/www/index.html @@ -0,0 +1,105 @@ + + + + + + + + Solum - alternative proto AP + + + + + +
+ +
+ +
+
+

00000000

+

+ + +

+

+ + +

+

+ + +

+
+

+ + +

+
+ +
+
+ +
+ +
+
+ + Currently active tags:
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+

+ logging + + +

+
    +
+
+
+ + +
+
+ + + + + + \ No newline at end of file diff --git a/esp32_fw/data/www/main.css b/esp32_fw/data/www/main.css new file mode 100644 index 00000000..1627b3dd --- /dev/null +++ b/esp32_fw/data/www/main.css @@ -0,0 +1,277 @@ +*{ + margin:0; + padding:0; + border:0; + list-style-type: none; + outline: none; + font-weight: 400; + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; + font-smooth: auto; + -webkit-font-smoothing: antialiased; +} + +html, body { + height: 100%; +} + +body { + font-size: 12px; + font-family: Helvetica, Arial, Verdana, sans-serif; + line-height: 1.5; + background-color: #e8f1f9; + background-color: #f1f1f1; + /*background-image: linear-gradient(315deg, #dde1ee 0%, #e8f1f9 100%);*/ +} + +header { + height: 50px; + background-color: #666; +} + +label { + width:100px; + display: inline-block; +} + +.logo { + margin: 0 auto; + height: 50px; + text-indent: 50px; + overflow:hidden; + background-size: 50px 50px; + font-size: 2.5em; + color: white; +} + +.window { + margin: 0 auto; + max-width: 94%; +} + +.actionbox>div:first-child { + padding: 10px; + background-color: white; + margin: 5px; +} + +.actionbox p { + padding: 5px; +} + +.actionbox .columns { + display:flex; + flex-wrap: wrap; +} + +.filebutton { + padding:2px 5px; + background-color: #cccccc; + text-decoration: none; + color: black; +} + +.editbtn { + float:right; +} + +.columns div { + flex: 1; +} + +input { + border: solid 1px #666666; + padding: 4px; +} + +input[type=button] { + border: 0px; + padding: 4px 10px; + cursor:pointer; +} +input[type=button]:hover { + background-color:#aaaaaa; +} +select { + padding: 4px; +} + +#configbox { + display: none; + position: fixed; + top: 80px; + left: 50px; + width: 500px; + padding: 15px; + background-color: #f0e6d3; + z-index: 999; + box-shadow: 7px 10px 52px -19px rgba(0, 0, 0, 0.63); +} + +#configbox p { + padding: 5px; +} + +#configbox h3 { + font-size: 1.5em; + font-weight: bold; +} + +#configbox input { + border: solid 1px #666666; + padding: 4px; +} + +#configbox label { + text-transform: capitalize; +} + +#cfgdelete { + position: absolute; + bottom: 15px; + right: 15px; + cursor:pointer; +} + +.closebtn { + border: 1px solid black; + float: right; + width: 19px; + height: 20px; + font-size: 1.1em; + text-align: center; + margin: 5px; + cursor: pointer; +} + +.logbox { + margin: 5px; +} + +.logbox p { + background-color: #ffffff; + padding: 5px 10px; +} + +.logbox img { + vertical-align: bottom; + cursor:pointer; +} + +.logbox #sysinfo { + float: right; +} + +.taglist { + display: flex; + flex-wrap: wrap; +} + +#tagtemplate { + display:none; +} + +.tagcard { + width: 225px; + position: relative; + height: 170px; + margin: 5px; + padding: 5px; + background-color: #dddddd; +} + +.tagcard .pending { + padding-bottom:15px; +} + +.currimg { + float: right; +} + +.currimg img { + max-width: 50px; +} + +.mac { + font-size: 0.9em; + cursor:pointer; +} + +.alias { + font-size: 1.4em; + font-weight: bold; +} + +.corner { + position: absolute; + right: 0px; + bottom: 0px; + padding: 5px; +} + +.configicon { + display: inline-block; + width: 20px; + height: 20px; + cursor:pointer; + background-image: url("data: image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAQAAAAngNWGAAABXklEQVQoz43SP2tUQRQF8N99ecFKFEVh0Y1ZbFQ2xEoIQkoLW0t7C/OVLGzyHay1EAQjRFGrLMkjKSwWsRGV3WvxZvc9XQtnivl35sydc048nfuvVkW0k8XYtT936pVja5jJv/Z7wPZo0wNzLzQSHWnVwTZtqY1su2to3bZhj7dewEYeu+iDawi7bhn7Yl9TWGsikrzksnNxr9zfsIErcaEAMysyZXrvE5mp6w7zc8rMzFJjGNlxFWHmWKMVd2DHsHuadQ+NkcKxZ2pPXC8FHHhu1v91X6ZcUZHYy8xwwyju5wAzJypDFdHka5OiaN1yHDl100BaMyq84cwrs1JjtTBu7E5xIpeebLndOZOlnK859d1bZ0JoHPiRU986ZxYZmdjP8/HRrkfSS2+MTTXlycyawhlHJBOH5k789A6x/H/sZQuMKKNatjGLvkoreUy/lsnsq1mXJOe/Ut6tM38DZpmDFxwTi8EAAAAASUVORK5CYII="); +} + +.warningicon { + display:none; + font-size: 1.3em; + background-color: yellow; + color: black; + height: 20px; + width: 20px; + vertical-align: top; + text-align: center; +} + +ul.messages { + padding: 5px; +} + +ul.messages li { + position: relative; +} + +ul.messages li.new { + animation-name: new; + animation-duration: 1400ms; + animation-iteration-count: 1; + animation-timing-function: ease-in-out; +} + +.error { + color: red; +} + + +@media(max-width: 460px) { + .messages li div, ul.messages li div.date, ul.messages li div.message { + display:block; + position:relative; + padding: 0; + left: auto; + } + .messages li div.message, li.pending { + margin-bottom: 8px; + } + ul.messages { + padding-bottom: 4px; + } +} + +@keyframes new { + 0% { + background-color: rgba(255, 255, 204, 1); + } + 50% { + background-color: rgba(255, 255, 204, .5); + } + 100% { + background-color: rgba(255, 255, 204, 0); + } +} \ No newline at end of file diff --git a/esp32_fw/data/www/main.js b/esp32_fw/data/www/main.js new file mode 100644 index 00000000..9d53493c --- /dev/null +++ b/esp32_fw/data/www/main.js @@ -0,0 +1,280 @@ +const $ = document.querySelector.bind(document); + +const contentModes = ["static image", "current date", "counting days", "counting hours", "current weather", "firmware update", "memo text", "image url"]; +const models = ["unknown type", "1.54\" 152x152px", "2.9\" 296x128px", "4.2\" 400x300px"]; +const contentModeOptions = []; +contentModeOptions[0] = ["filename","timetolive"]; +contentModeOptions[1] = []; +contentModeOptions[2] = ["counter", "thresholdred"]; +contentModeOptions[3] = ["counter", "thresholdred"]; +contentModeOptions[4] = ["location"]; +contentModeOptions[5] = ["filename"]; +contentModeOptions[6] = ["text"]; +contentModeOptions[7] = ["url","interval"]; + +const imageQueue = []; +let isProcessing = false; +let servertimediff = 0; + +let socket; +connect(); +setInterval(updatecards, 1000); +window.addEventListener("load", function () { loadTags(0) }); + +function loadTags(pos) { + fetch("/get_db?pos="+pos) + .then(response => response.json()) + .then(data => { + processTags(data.tags); + if (data.continu && data.continu>pos) loadTags(data.continu); + }) + //.catch(error => showMessage('loadTags error: ' + error)); +} + +function connect() { + socket = new WebSocket("ws://" + location.host + "/ws"); + + socket.addEventListener("open", (event) => { + showMessage("websocket connected"); + }); + + socket.addEventListener("message", (event) => { + console.log(event.data); + const msg = JSON.parse(event.data); + if (msg.logMsg) { + showMessage(msg.logMsg,false); + } + if (msg.errMsg) { + showMessage(msg.logMsg,true); + } + if (msg.tags) { + processTags(msg.tags); + } + if (msg.sys) { + $('#sysinfo').innerHTML = 'free heap: ' + msg.sys.heap + ' bytes ┇ db size: ' + msg.sys.dbsize + ' bytes ┇ db record count: ' + msg.sys.recordcount + ' ┇ littlefs free: ' + msg.sys.littlefsfree + ' bytes'; + servertimediff = (Date.now() / 1000) - msg.sys.currtime; + } + }); + + socket.addEventListener("close", (event) => { + showMessage(`websocket closed ${event.code}`); + setTimeout(connect, 5000); + }); +} + +function processTags(tagArray) { + for (const element of tagArray) { + tagmac = element.mac; + + var div = $('#tag' + tagmac); + if (div == null) { + + div = $('#tagtemplate').cloneNode(true); + div.setAttribute('id', 'tag'+tagmac); + div.dataset.mac = tagmac; + $('#taglist').appendChild(div); + + $('#tag' + tagmac + ' .mac').innerHTML = tagmac; + var img = $('#tag' + tagmac + ' .tagimg'); + img.addEventListener('error', function handleError() { + img.style.display = 'none'; + }); + } + + div.style.display = 'block'; + + let alias = element.alias; + if (!alias) alias = tagmac; + $('#tag' + tagmac + ' .alias').innerHTML = alias; + + if (div.dataset.hash != element.hash) loadImage(tagmac, '/current/' + tagmac + '.bmp?' + (new Date()).getTime()); + + $('#tag' + tagmac + ' .contentmode').innerHTML = contentModes[element.contentmode]; + $('#tag' + tagmac + ' .model').innerHTML = models[element.model]; + + if (element.nextupdate > 1672531200 && element.nextupdate!=3216153600) { + var date = new Date(element.nextupdate * 1000); + var options = { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false }; + $('#tag' + tagmac + ' .nextupdate').innerHTML = "next update: " + date.toLocaleString('nl-NL', options); + } else { + $('#tag' + tagmac + ' .nextupdate').innerHTML = ""; + } + + if (element.nextcheckin > 1672531200) { + div.dataset.nextcheckin = element.nextcheckin; + } else { + div.dataset.nextcheckin = element.lastseen + 1800; + } + + div.dataset.lastseen = element.lastseen; + div.dataset.hash = element.hash; + $('#tag' + tagmac + ' .warningicon').style.display = 'none'; + + if (element.pending) $('#tag' + tagmac + ' .pending').innerHTML = "pending update..."; else $('#tag' + tagmac + ' .pending').innerHTML = ""; + + } +} + +function updatecards() { + document.querySelectorAll('[data-mac]').forEach(item => { + let tagmac = item.dataset.mac; + + if (item.dataset.lastseen && item.dataset.lastseen > 1672531200) { + let idletime = (Date.now() / 1000) + servertimediff - item.dataset.lastseen; + $('#tag' + tagmac + ' .lastseen').innerHTML = "last seen: "+displayTime(Math.floor(idletime))+" ago"; + if ((Date.now() / 1000) + servertimediff > item.dataset.nextcheckin) $('#tag' + tagmac + ' .warningicon').style.display='inline-block'; + } else { + $('#tag' + tagmac + ' .lastseen').innerHTML = "" + } + + if (item.dataset.nextcheckin > 1672531200) { + let nextcheckin = item.dataset.nextcheckin - ((Date.now() / 1000) + servertimediff); + $('#tag' + tagmac + ' .nextcheckin').innerHTML = "expecting next checkin: " + displayTime(Math.floor(nextcheckin)); + } + }) +} + +$('#clearlog').onclick = function () { + $('#messages').innerHTML=''; +} + +$('.closebtn').onclick = function (event) { + event.target.parentNode.style.display='none'; +} + +$('#taglist').addEventListener("click", (event) => { + let currentElement = event.target; + while (currentElement !== $('#taglist')) { + if (currentElement.classList.contains("tagcard")) { + break; + } + currentElement = currentElement.parentNode; + } + if (!currentElement.classList.contains("tagcard")) { + return; + } + const mac = currentElement.dataset.mac; + if (event.target.classList.contains("mac")) { + $('#dstmac').value=mac; + } + if (event.target.classList.contains("configicon")) { + $('#cfgmac').innerHTML = mac; + $('#cfgmac').dataset.mac = mac; + fetch("/get_db?mac=" + mac) + .then(response => response.json()) + .then(data => { + console.log(data); + var tagdata = data.tags[0]; + $('#cfgalias').value = tagdata.alias; + $('#cfgcontent').value = tagdata.contentmode; + $('#cfgmodel').value = tagdata.model; + $('#cfgcontent').dataset.json = tagdata.modecfgjson; + contentselected(); + $('#configbox').style.display = 'block'; + }) + .catch(error => showMessage('Error: ' + error)); + } +}) + +$('#cfgsave').onclick = function () { + + let contentmode = $('#cfgcontent').value; + let extraoptions = contentModeOptions[contentmode]; + let obj={}; + extraoptions.forEach(element => { + obj[element] = $('#opt' + element).value; + }); + + let formData = new FormData(); + formData.append("mac", $('#cfgmac').dataset.mac); + formData.append("alias", $('#cfgalias').value); + formData.append("contentmode", contentmode); + formData.append("model", $('#cfgmodel').value); + formData.append("modecfgjson", JSON.stringify(obj)); + fetch("/save_cfg", { + method: "POST", + body: formData + }) + .then(response => response.text()) + .then(data => showMessage(data)) + .catch(error => showMessage('Error: ' + error)); + $('#configbox').style.display = 'none'; +} + +$('#cfgdelete').onclick = function () { + let mac = $('#cfgmac').dataset.mac; +} + +function contentselected() { + let contentmode=$('#cfgcontent').value; + let extraoptions = contentModeOptions[contentmode]; + $('#customoptions').innerHTML=""; + var obj = {}; + if ($('#cfgcontent').dataset.json && ($('#cfgcontent').dataset.json!="null")) { + obj = JSON.parse($('#cfgcontent').dataset.json); + } + console.log(obj); + extraoptions.forEach(element => { + var label = document.createElement("label"); + label.innerHTML = element; + label.setAttribute("for", 'opt' + element); + var input = document.createElement("input"); + input.type = "text"; + input.id = 'opt' + element; + if (obj[element]) input.value = obj[element]; + var p = document.createElement("p"); + p.appendChild(label); + p.appendChild(input); + $('#customoptions').appendChild(p); + }); +} + +function showMessage(message,iserr) { + const messages = $('#messages'); + var date = new Date(), + time = date.toLocaleTimeString('en-US', {hour12: false, hour: '2-digit', minute:'2-digit', second:'2-digit'}); + if (iserr) { + messages.insertAdjacentHTML("afterbegin", '
  • ' + htmlEncode(time + ' ' + message) + '
  • '); + } else { + messages.insertAdjacentHTML("afterbegin", '
  • '+htmlEncode(time+' '+message)+'
  • '); + } +} + +function htmlEncode(input) { + const textArea = document.createElement("textarea"); + textArea.innerText = input; + return textArea.innerHTML.split("
    ").join("\n"); +} + +function loadImage(id, imageSrc) { + imageQueue.push({ id, imageSrc }); + if (!isProcessing) { + processQueue(); + } +} + +function processQueue() { + if (imageQueue.length === 0) { + isProcessing = false; + return; + } + isProcessing = true; + const { id, imageSrc } = imageQueue.shift(); + const image = $('#tag' + id + ' .tagimg'); + image.onload = function () { + image.style.display = 'block'; + processQueue(); + } + image.onerror = function () { + image.style.display = 'none'; + processQueue(); + }; + image.src = imageSrc; +} + +function displayTime(seconds) { + let hours = Math.floor(Math.abs(seconds) / 3600); + let minutes = Math.floor((Math.abs(seconds) % 3600) / 60); + let remainingSeconds = Math.abs(seconds) % 60; + return (seconds < 0 ? '-' : '') + (hours > 0 ? `${hours}:${String(minutes).padStart(2, '0')}` : `${minutes}`) + `:${String(remainingSeconds).padStart(2, '0')}`; +} diff --git a/esp32_fw/include/commstructs.h b/esp32_fw/include/commstructs.h index bf1f2a24..ac93dba7 100644 --- a/esp32_fw/include/commstructs.h +++ b/esp32_fw/include/commstructs.h @@ -56,4 +56,6 @@ struct pendingData { } __packed; #define BLOCK_DATA_SIZE 4096 -#define BLOCK_XFER_BUFFER_SIZE BLOCK_DATA_SIZE + sizeof(struct blockData) \ No newline at end of file +#define BLOCK_XFER_BUFFER_SIZE BLOCK_DATA_SIZE + sizeof(struct blockData) + +#pragma pack(pop) \ No newline at end of file diff --git a/esp32_fw/include/contentmanager.h b/esp32_fw/include/contentmanager.h new file mode 100644 index 00000000..64fe7a25 --- /dev/null +++ b/esp32_fw/include/contentmanager.h @@ -0,0 +1,15 @@ +#include + +#include +#include "makeimage.h" +#include +#include "tag_db.h" +#include + +void contentRunner(); +void drawNew(uint8_t mac[8], bool buttonPressed, tagRecord *&taginfo); +bool updateTagImage(String &filename, uint8_t *dst, uint16_t nextCheckin); +void drawDate(String &filename); +void drawNumber(String &filename, int32_t count, int32_t thresholdred); +bool getImgURL(String &filename, String URL, time_t fetched); +char *formatHttpDate(time_t t); \ No newline at end of file diff --git a/esp32_fw/include/makeimage.h b/esp32_fw/include/makeimage.h new file mode 100644 index 00000000..8debd701 --- /dev/null +++ b/esp32_fw/include/makeimage.h @@ -0,0 +1,35 @@ +#include +#include + +#pragma once + +struct BitmapFileHeader { + uint8_t sig[2]; + uint32_t fileSz; + uint8_t rfu[4]; + uint32_t dataOfst; + uint32_t headerSz; //40 + int32_t width; + int32_t height; + uint16_t colorplanes; //must be one + uint16_t bpp; + uint32_t compression; + uint32_t dataLen; //may be 0 + uint32_t pixelsPerMeterX; + uint32_t pixelsPerMeterY; + uint32_t numColors; //if zero, assume 2^bpp + uint32_t numImportantColors; + +} __attribute__((packed)); + +enum EinkClut { + EinkClutTwoBlacks = 0, + EinkClutTwoBlacksAndRed, + EinkClutFourBlacks, + EinkClutThreeBlacksAndRed, +}; + +void spr2grays(TFT_eSprite &spr, long w, long h, String &fileout); +void jpg2grays(String filein, String fileout); +void bmp2grays(String filein, String fileout); + diff --git a/esp32_fw/include/pendingdata.h b/esp32_fw/include/pendingdata.h index b4116bfb..1bbc1e9f 100644 --- a/esp32_fw/include/pendingdata.h +++ b/esp32_fw/include/pendingdata.h @@ -21,3 +21,5 @@ class pendingdata { void garbageCollection(void* parameter); extern std::vector pendingfiles; + +#pragma pack(pop) \ No newline at end of file diff --git a/esp32_fw/include/tag_db.h b/esp32_fw/include/tag_db.h new file mode 100644 index 00000000..3c6a77c2 --- /dev/null +++ b/esp32_fw/include/tag_db.h @@ -0,0 +1,47 @@ +#include +#include + +#include + +#pragma pack(push, 1) +#pragma once + +enum contentModes { + Image, + Today, + CountDays, + CountHours, + Weather, + Firmware, + Memo, + ImageUrl, +}; + +class tagRecord { + public: + uint16_t nextCheckinpending; + tagRecord() : mac{0}, model(0), alias(""), lastseen(0), nextupdate(0), contentMode(Image), pending(false), button(false), md5{0}, md5pending{0}, CheckinInMinPending(0), expectedNextCheckin(0), modeConfigJson("") {} + + uint8_t mac[6]; + u_int8_t model; + String alias; + uint32_t lastseen; + uint32_t nextupdate; + contentModes contentMode; + bool pending; + bool button; + uint8_t md5[16]; + uint8_t md5pending[16]; + uint16_t CheckinInMinPending; + uint32_t expectedNextCheckin; + String modeConfigJson; + static tagRecord* findByMAC(uint8_t mac[6]); +}; + +extern std::vector tagDB; +String tagDBtoJson(uint8_t mac[6] = nullptr, uint8_t startPos = 0); +void fillNode(JsonObject &tag, tagRecord* &taginfo); +void saveDB(String filename); +void loadDB(String filename); + +#pragma pack(pop) \ No newline at end of file diff --git a/esp32_fw/include/web.h b/esp32_fw/include/web.h index e40b0795..524234df 100644 --- a/esp32_fw/include/web.h +++ b/esp32_fw/include/web.h @@ -1,13 +1,19 @@ -#include + +#include #include #include void init_web(); +void doImageUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final); extern void webSocketSendProcess(void *parameter); -extern void wsString(String text); +void wsLog(String text); +void wsErr(String text); +void wsSendTaginfo(uint8_t mac[6]); +void wsSendSysteminfo(); + extern uint64_t swap64(uint64_t x); -extern AsyncWebSocket ws;//("/ws"); +extern AsyncWebSocket ws; //("/ws"); extern SemaphoreHandle_t wsMutex; extern TaskHandle_t websocketUpdater; \ No newline at end of file diff --git a/esp32_fw/platformio.ini b/esp32_fw/platformio.ini index c22487e0..99d85fe2 100644 --- a/esp32_fw/platformio.ini +++ b/esp32_fw/platformio.ini @@ -22,5 +22,7 @@ lib_deps = https://github.com/me-no-dev/ESPAsyncWebServer https://github.com/tzapu/WiFiManager.git#feature_asyncwebserver bblanchon/ArduinoJson + bodmer/TFT_eSPI + https://github.com/Bodmer/TJpg_Decoder.git upload_port = COM5 monitor_port = COM5 diff --git a/esp32_fw/src/SPIFFSEditor.cpp b/esp32_fw/src/SPIFFSEditor.cpp index 42e8d375..e301ecbc 100644 --- a/esp32_fw/src/SPIFFSEditor.cpp +++ b/esp32_fw/src/SPIFFSEditor.cpp @@ -2,396 +2,9 @@ #include -// File: edit.htm.gz, Size: 4151 -#define edit_htm_gz_len 4151 -const uint8_t edit_htm_gz[] PROGMEM = { - 0x1F, 0x8B, 0x08, 0x08, 0xB8, 0x94, 0xB1, 0x59, 0x00, 0x03, 0x65, 0x64, 0x69, 0x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x54, 0x2E, 0x62, 0x62, 0x29, - 0xE6, 0xC9, 0x82, 0x91, 0x97, 0x7C, 0x16, 0x0D, 0x1A, 0x2B, 0x25, 0x55, 0x9E, 0x97, 0x7D, 0x95, - 0x43, 0x40, 0x59, 0x71, 0xE5, 0x35, 0x11, 0x06, 0x34, 0xE0, 0x63, 0x64, 0xF2, 0x41, 0xEB, 0xA7, - 0xD1, 0x94, 0x26, 0x87, 0x24, 0xA5, 0x06, 0x24, 0xCD, 0x65, 0xDC, 0x41, 0xA8, 0xE9, 0x04, 0xEB, - 0x76, 0x6D, 0x6E, 0x12, 0x05, 0xCE, 0x33, 0x77, 0xC4, 0xB1, 0x26, 0x03, 0xF9, 0xB2, 0xCA, 0x09, - 0xD4, 0xC6, 0xBE, 0x12, 0xA4, 0x3E, 0x52, 0x25, 0xA8, 0x61, 0x5A, 0xD0, 0x76, 0xC0, 0x35, 0x5F, - 0x26, 0x51, 0x4C, 0xC6, 0xB2, 0x07, 0x83, 0x35, 0x74, 0x0F, 0xA4, 0x66, 0x6D, 0x34, 0x91, 0x60, - 0xA9, 0x73, 0x29, 0xFC, 0x66, 0xD9, 0xC2, 0x70, 0x4B, 0x57, 0xC9, 0xB0, 0xBD, 0xF4, 0xA5, 0x35, - 0x59, 0x83, 0xE0, 0x0B, 0x6C, 0x62, 0xE0, 0x1E, 0x68, 0x64, 0xF2, 0x7B, 0x00, 0x77, 0x6B, 0xB6, - 0xA3, 0x3D, 0xD6, 0x8E, 0x6A, 0x35, 0x53, 0x55, 0xE9, 0xAE, 0x0B, 0x6D, 0x4E, 0x74, 0x23, 0x0B, - 0x4B, 0x10, 0xAA, 0x9A, 0x59, 0x0C, 0x38, 0x1B, 0x81, 0xAA, 0xBA, 0xC0, 0x11, 0xD6, 0x98, 0x66, - 0xA9, 0x23, 0xF1, 0x97, 0x1D, 0xC9, 0x13, 0xB5, 0x07, 0x95, 0xF5, 0x05, 0xD4, 0x31, 0xAB, 0x25, - 0x86, 0x30, 0xD3, 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 0x54, 0xA9, 0xD3, 0x68, 0x78, 0x3E, 0xFF, 0x9A, 0x42, 0x19, 0x1D, 0x65, 0xFE, 0x28, 0x20, - 0x09, 0xC5, 0x82, 0xA3, 0x41, 0xBE, 0x92, 0xFB, 0x46, 0xC0, 0x86, 0x69, 0x03, 0x93, 0x6D, 0xCB, - 0xDE, 0xB2, 0x77, 0x71, 0x64, 0x7F, 0x4D, 0xF7, 0x57, 0x4F, 0xD8, 0x5F, 0x34, 0x69, 0x58, 0x0B, - 0xE7, 0xB5, 0xAB, 0x8A, 0x4D, 0x6A, 0x83, 0xFB, 0xC4, 0xA7, 0x70, 0x3D, 0x6F, 0xB3, 0xCC, 0xB6, - 0x1A, 0xE4, 0x5F, 0x60, 0xD4, 0x31, 0xBA, 0x95, 0x2F, 0x92, 0xF4, 0x81, 0x7B, 0x18, 0x5B, 0x17, - 0x54, 0x26, 0x70, 0x49, 0xD5, 0x87, 0x34, 0xB9, 0xD3, 0x9C, 0x2F, 0x39, 0xC3, 0xB7, 0x3C, 0xA8, - 0x03, 0xE4, 0x37, 0x9C, 0x72, 0x39, 0xB0, 0xBF, 0x07, 0x5D, 0x33, 0x2A, 0x41, 0x79, 0xB1, 0x26, - 0x9B, 0xE6, 0x7C, 0x02, 0x82, 0x01, 0x70, 0xB1, 0xA3, 0x48, 0xCD, 0x2B, 0xCB, 0x98, 0x9B, 0x57, - 0x96, 0x54, 0xE2, 0x5F, 0x59, 0xCC, 0xDB, 0x9F, 0xFC, 0xDB, 0x4C, 0xF9, 0x7F, 0x5B, 0x28, 0x36, - 0x32, 0xF9, 0xE1, 0x09, 0xF7, 0x56, 0x3F, 0x45, 0xAD, 0x47, 0x51, 0xBB, 0xF7, 0xFF, 0x17, 0x53, - 0xE8, 0x9D, 0x36, 0x92, 0x29, 0x00, 0x00}; - #define SPIFFS_MAXLENGTH_FILEPATH 32 -const char *excludeListFile = "/.exclude.files"; -typedef struct ExcludeListS { - char *item; - ExcludeListS *next; -} ExcludeList; - -static ExcludeList *excludes = NULL; - -static bool matchWild(const char *pattern, const char *testee) { - const char *nxPat = NULL; - const char *nxTst = NULL; - - while (*testee) { - if ((*pattern == '?') || (*pattern == *testee)) { - ++pattern; - ++testee; - continue; - } - if (*pattern == '*') { - nxPat = pattern++; - nxTst = testee; - continue; - } - if (nxPat) { - pattern = nxPat + 1; - testee = ++nxTst; - continue; - } - return false; - } - while (*pattern == '*') { - ++pattern; - } - return (*pattern == 0); -} - -static bool addExclude(const char *item) { - size_t len = strlen(item); - if (!len) { - return false; - } - ExcludeList *e = (ExcludeList *)malloc(sizeof(ExcludeList)); - if (!e) { - return false; - } - e->item = (char *)malloc(len + 1); - if (!e->item) { - free(e); - return false; - } - memcpy(e->item, item, len + 1); - e->next = excludes; - excludes = e; - return true; -} - -static void loadExcludeList(fs::FS &_fs, const char *filename) { - static char linebuf[SPIFFS_MAXLENGTH_FILEPATH]; - fs::File excludeFile; - if (filename[0] != '/') { - excludeFile = _fs.open("/" + ((String)filename), "r"); - } else { - excludeFile = _fs.open(filename, "r"); - } - if (!excludeFile) { - // addExclude("/*.js.gz"); - return; - } -#ifdef ESP32 - if (excludeFile.isDirectory()) { - excludeFile.close(); - return; - } -#endif - if (excludeFile.size() > 0) { - uint8_t idx; - bool isOverflowed = false; - while (excludeFile.available()) { - linebuf[0] = '\0'; - idx = 0; - int lastChar; - do { - lastChar = excludeFile.read(); - if (lastChar != '\r') { - linebuf[idx++] = (char)lastChar; - } - } while ((lastChar >= 0) && (lastChar != '\n') && (idx < SPIFFS_MAXLENGTH_FILEPATH)); - - if (isOverflowed) { - isOverflowed = (lastChar != '\n'); - continue; - } - isOverflowed = (idx >= SPIFFS_MAXLENGTH_FILEPATH); - linebuf[idx - 1] = '\0'; - if (!addExclude(linebuf)) { - excludeFile.close(); - return; - } - } - } - excludeFile.close(); -} - -static bool isExcluded(fs::FS &_fs, const char *filename) { - if (excludes == NULL) { - loadExcludeList(_fs, excludeListFile); - } - ExcludeList *e = excludes; - while (e) { - if (matchWild(e->item, filename)) { - return true; - } - e = e->next; - } - return false; -} - -// WEB HANDLER IMPLEMENTATION - -#ifdef ESP32 SPIFFSEditor::SPIFFSEditor(const fs::FS &fs, const String &username, const String &password) -#else -SPIFFSEditor::SPIFFSEditor(const String &username, const String &password, const fs::FS &fs) -#endif : _fs(fs), _username(username), _password(password), _authenticated(false), _startTime(0) { } @@ -406,24 +19,20 @@ bool SPIFFSEditor::canHandle(AsyncWebServerRequest *request) { if (!request->_tempFile) { return false; } -#ifdef ESP32 if (request->_tempFile.isDirectory()) { request->_tempFile.close(); return false; } -#endif } if (request->hasParam("download")) { request->_tempFile = _fs.open("/" + request->arg("download"), "r"); if (!request->_tempFile) { return false; } -#ifdef ESP32 if (request->_tempFile.isDirectory()) { request->_tempFile.close(); return false; } -#endif } request->addInterestingHeader("If-Modified-Since"); return true; @@ -442,46 +51,22 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request) { if (request->method() == HTTP_GET) { if (request->hasParam("list")) { const String path = request->getParam("list")->value(); -#ifdef ESP32 + File dir = _fs.open(path); -#else - Dir dir = _fs.openDir(path); -#endif String output = "["; -#ifdef ESP32 File file = dir.openNextFile(); while (file) { -#else - while (dir.next()) { - fs::File entry = dir.openFile("r"); -#endif - if (isExcluded(_fs, file.name())) { -#ifdef ESP32 - file = dir.openNextFile(); -#endif - continue; - } if (output != "[") { output += ','; } - output += "{\"type\":\""; - output += "file"; - output += "\",\"name\":\""; - output += file.name(); - output += "\",\"size\":"; - output += file.size(); - output += ",\"ver\":"; - output += file.getLastWrite(); - output += "}"; -#ifdef ESP32 + if (file.isDirectory()) { + output += "{\"type\":\"dir\",\"name\":\"" + String(file.name()) + "\",\"size\":" + file.size() + "}"; + } else { + output += "{\"type\":\"file\",\"name\":\"" + String(file.name()) + "\",\"size\":" + file.size() + "}"; + } file = dir.openNextFile(); -#else - file.close(); -#endif } -#ifdef ESP32 dir.close(); -#endif output += "]"; request->send(200, "application/json", output); } else if (request->hasParam("edit") || request->hasParam("download")) { @@ -491,8 +76,7 @@ void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request) { if (request->header("If-Modified-Since").equals(buildTime)) { request->send(304); } else { - AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", edit_htm_gz, edit_htm_gz_len); - response->addHeader("Content-Encoding", "gzip"); + AsyncWebServerResponse *response = request->beginResponse(_fs, "/www/edit.html"); response->addHeader("Last-Modified", buildTime); request->send(response); } diff --git a/esp32_fw/src/contentmanager.cpp b/esp32_fw/src/contentmanager.cpp new file mode 100644 index 00000000..25bf46df --- /dev/null +++ b/esp32_fw/src/contentmanager.cpp @@ -0,0 +1,246 @@ +#include "contentmanager.h" + +#include +#include +#include +#include "newproto.h" +#include +#include +#include + +#include "commstructs.h" +#include "makeimage.h" +#include "web.h" + +void contentRunner() { + time_t now; + time(&now); + + for (int16_t c = 0; c < tagDB.size(); c++) { + tagRecord* taginfo = nullptr; + taginfo = tagDB.at(c); + + if (now >= taginfo->nextupdate || taginfo->button) { + uint8_t mac8[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + memcpy(mac8 + 2, taginfo->mac, 6); + uint8_t src[8]; + *((uint64_t *)src) = swap64(*((uint64_t *)mac8)); + + drawNew(src, taginfo->button, taginfo); + taginfo->button = false; + } + } +} + +void drawNew(uint8_t mac[8], bool buttonPressed, tagRecord *&taginfo) { + time_t now; + time(&now); + + char buffer[64]; + uint8_t src[8]; + *((uint64_t *)src) = swap64(*((uint64_t *)mac)); + sprintf(buffer, "%02X%02X%02X%02X%02X%02X\0", src[2], src[3], src[4], src[5], src[6], src[7]); + String dst = (String)buffer; + + String filename = "/" + dst + ".bmp"; + + struct tm time_info; + getLocalTime(&time_info); + time_info.tm_hour = 0; + time_info.tm_min = 0; + time_info.tm_sec = 0; + time_info.tm_mday++; + time_t midnight = mktime(&time_info); + + DynamicJsonDocument doc(500); + deserializeJson(doc, taginfo->modeConfigJson); + JsonObject cfgobj = doc.as(); + + wsLog("Updating " + dst + " mode " + String(taginfo->contentMode)); + taginfo->nextupdate = now + 600; + + switch (taginfo->contentMode) { + case Image: + + filename = cfgobj["filename"].as(); + if (filename && filename !="null" && !cfgobj["#fetched"].as()) { + if (prepareDataAvail(&filename, DATATYPE_IMGRAW, mac, cfgobj["timetolive"].as())) { + cfgobj["#fetched"] = true; + } else { + wsErr("Error accessing " + filename); + } + taginfo->nextupdate = 3216153600; + } + break; + + case Today: + + drawDate(filename); + // updateTagImage(filename, mac, (midnight - now) / 60 - 10); + updateTagImage(filename, mac, 60); + taginfo->nextupdate = midnight; + break; + + case CountDays: + + if (buttonPressed) cfgobj["counter"] = 0; + drawNumber(filename, (int32_t)cfgobj["counter"], (int32_t)cfgobj["thresholdred"]); + updateTagImage(filename, mac, (buttonPressed?0:60)); + cfgobj["counter"] = (int32_t)cfgobj["counter"] + 1; + taginfo->nextupdate = midnight; + break; + + case CountHours: + + if (buttonPressed) cfgobj["counter"] = 0; + drawNumber(filename, (int32_t)cfgobj["counter"], (int32_t)cfgobj["thresholdred"]); + // updateTagImage(&filename, mac, (3600 - now % 3600) / 60); + // taginfo->nextupdate = now + 3600 - (now % 3600); + updateTagImage(filename, mac, (buttonPressed?0:3)); + cfgobj["counter"] = (int32_t)cfgobj["counter"] + 1; + taginfo->nextupdate = now + 300; + break; + + case Weather: + + // https://open-meteo.com/ + break; + + case Firmware: + + filename = cfgobj["filename"].as(); + if (filename && filename != "null" && !cfgobj["#fetched"].as()) { + if (prepareDataAvail(&filename, DATATYPE_UPDATE, mac, cfgobj["timetolive"].as())) { + cfgobj["#fetched"] = true; + } else { + wsErr("Error accessing " + filename); + } + cfgobj["filename"]=""; + taginfo->nextupdate = 3216153600; + taginfo->contentMode = Image; + } else { + taginfo->nextupdate = now + 300; + } + break; + + case Memo: + break; + case ImageUrl: + + if (getImgURL(filename, cfgobj["url"], (time_t)cfgobj["#fetched"])) { + updateTagImage(filename, mac, cfgobj["interval"].as()); + cfgobj["#fetched"] = now; + } + taginfo->nextupdate = now + 60 * (cfgobj["interval"].as() < 5 ? 5 : cfgobj["interval"].as()) ; + break; + } + + taginfo->modeConfigJson = doc.as(); +} + +bool updateTagImage(String &filename, uint8_t *dst, uint16_t nextCheckin) { + prepareDataAvail(&filename, DATATYPE_IMGRAW, dst, nextCheckin); + return true; +} + +void drawDate(String &filename) { + + TFT_eSPI tft = TFT_eSPI(); + TFT_eSprite spr = TFT_eSprite(&tft); + time_t now; + time(&now); + struct tm timeinfo; + localtime_r(&now, &timeinfo); + String Dag[] = {"zondag","maandag","dinsdag", "woensdag", "donderdag", "vrijdag", "zaterdag"}; + String Maand[] = {"januari", "februari", "maart", "april", "mei", "juni","juli", "augustus", "september", "oktober", "november", "december"}; + int weekday_number = timeinfo.tm_wday; + int month_number = timeinfo.tm_mon; + + LittleFS.begin(); + long w = 296, h = 128; // mag staand of liggend + spr.createSprite(w, h); + if (spr.getPointer() == nullptr) { + wsErr("Failed to create sprite in drawDate"); + } + spr.setColorDepth(8); + spr.fillSprite(TFT_WHITE); + spr.setTextDatum(TC_DATUM); + spr.loadFont("fonts/calibrib62", LittleFS); + spr.setTextColor(TFT_RED, TFT_WHITE); + spr.drawString(Dag[timeinfo.tm_wday], w / 2, 10); + spr.loadFont("fonts/calibrib50", LittleFS); + spr.setTextColor(TFT_BLACK, TFT_WHITE); + spr.drawString(String(timeinfo.tm_mday) + " " + Maand[timeinfo.tm_mon], w / 2, 73); + spr.unloadFont(); + + spr2grays(spr, w, h, filename); + + spr.deleteSprite(); +} + +void drawNumber(String &filename, int32_t count, int32_t thresholdred) { + TFT_eSPI tft = TFT_eSPI(); + TFT_eSprite spr = TFT_eSprite(&tft); + + LittleFS.begin(); + long w = 296, h = 128; + spr.createSprite(w, h); + if (spr.getPointer() == nullptr) { + wsErr("Failed to create sprite in drawNumber"); + } + spr.setColorDepth(8); + spr.fillSprite(TFT_WHITE); + spr.setTextDatum(MC_DATUM); + if (count > thresholdred) { + spr.setTextColor(TFT_RED, TFT_WHITE); + } else { + spr.setTextColor(TFT_BLACK, TFT_WHITE); + } + String font = "fonts/numbers1-2"; + if (count > 999) font = "fonts/numbers2-2"; + if (count > 9999) font = "fonts/numbers3-2"; + spr.loadFont(font, LittleFS); + spr.drawString(String(count), w/2, h/2+10); + spr.unloadFont(); + + spr2grays(spr, w, h, filename); + + spr.deleteSprite(); +} + +bool getImgURL(String &filename, String URL, time_t fetched) { + // https://images.klari.net/kat-bw29.jpg + + LittleFS.begin(); + + Serial.println("get external " + URL); + HTTPClient http; + http.begin(URL); + http.addHeader("If-Modified-Since", formatHttpDate(fetched)); + http.setTimeout(5000); //timeout in ms + int httpCode = http.GET(); + if (httpCode == 200) { + File f = LittleFS.open(filename, "w"); + if (f) { + http.writeToStream(&f); + f.close(); + jpg2grays(filename, filename); + } + } else { + if (httpCode!=304) { + wsErr("http " + URL + " " + String(httpCode)); + } else { + wsLog("http " + URL + " " + String(httpCode)); + } + } + http.end(); + return (httpCode == 200); +} + +char *formatHttpDate(time_t t) { + static char buf[40]; + struct tm *timeinfo; + timeinfo = gmtime(&t); + strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", timeinfo); + return buf; +} diff --git a/esp32_fw/src/main.cpp b/esp32_fw/src/main.cpp index efe79a2d..f9552de1 100644 --- a/esp32_fw/src/main.cpp +++ b/esp32_fw/src/main.cpp @@ -3,50 +3,44 @@ #include #include +#include "contentmanager.h" #include "flasher.h" +#include "makeimage.h" #include "pendingdata.h" #include "serial.h" #include "soc/rtc_wdt.h" +#include "tag_db.h" #include "web.h" -void freeHeapTask(void* parameter) { +void timeTask(void* parameter) { while (1) { - //Serial.printf("Free heap=%d\n", ESP.getFreeHeap()); - vTaskDelay(30000 / portTICK_PERIOD_MS); + time_t now; + time(&now); + tm tm; + if (!getLocalTime(&tm)) { + Serial.println("Failed to obtain time"); + } else { + if (now % 10 == 0) wsSendSysteminfo(); + contentRunner(); + } + vTaskDelay(1000 / portTICK_PERIOD_MS); } } void setup() { Serial.begin(115200); Serial.print(">\n"); + + configTzTime("CET-1CEST,M3.5.0,M10.5.0/3", "europe.pool.ntp.org", "time.nist.gov"); + // https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv + init_web(); + loadDB("/current/tagDB.json"); - long timezone = 2; - byte daysavetime = 1; - configTime(0, 3600, "time.nist.gov", "0.pool.ntp.org", "1.pool.ntp.org"); - struct tm tmstruct; - delay(2000); - tmstruct.tm_year = 0; - getLocalTime(&tmstruct, 5000); - Serial.printf("\nNow is : %d-%02d-%02d %02d:%02d:%02d\n", (tmstruct.tm_year) + 1900, (tmstruct.tm_mon) + 1, tmstruct.tm_mday, tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec); - Serial.println(""); - - // WiFiManager wm; - xTaskCreate(freeHeapTask, "print free heap", 10000, NULL, 2, NULL); + xTaskCreate(timeTask, "timed tasks", 10000, NULL, 2, NULL); xTaskCreate(zbsRxTask, "zbsRX Process", 10000, NULL, 2, NULL); xTaskCreate(garbageCollection, "pending-data cleanup", 5000, NULL, 1, NULL); xTaskCreate(webSocketSendProcess, "ws", 5000, NULL,configMAX_PRIORITIES-10, NULL); - - /* - wm.setWiFiAutoReconnect(true); - wm.setConfigPortalTimeout(180); - bool res = wm.autoConnect("ESP32ZigbeeBase", "password"); // password protected ap - if (!res) { - Serial.println("Failed to connect"); - ESP.restart(); - } - wm.setWiFiAutoReconnect(true); - */ } void loop() { diff --git a/esp32_fw/src/makeimage.cpp b/esp32_fw/src/makeimage.cpp new file mode 100644 index 00000000..1d6762db --- /dev/null +++ b/esp32_fw/src/makeimage.cpp @@ -0,0 +1,430 @@ +#include +#include +#include +#include +#include +#include +#include + +TFT_eSPI tft = TFT_eSPI(); +TFT_eSprite spr = TFT_eSprite(&tft); + +bool spr_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap) { + spr.pushImage(x, y, w, h, bitmap); + return 1; +} + +void jpg2grays(String filein, String fileout) { + TJpgDec.setJpgScale(1); + TJpgDec.setCallback(spr_output); + uint16_t w = 0, h = 0; + TJpgDec.getFsJpgSize(&w, &h, filein); + Serial.println("jpeg conversion " + String(w) + "x" + String(h)); + + spr.createSprite(w, h); + if (spr.getPointer() == nullptr) { + wsErr("Failed to create sprite in jpg2grays"); + } + spr.setColorDepth(8); + spr.fillSprite(TFT_WHITE); + TJpgDec.drawFsJpg(0, 0, filein); + + spr2grays(spr, w, h, fileout); + spr.deleteSprite(); +} + +static uint32_t repackPackedVals(uint32_t val, uint32_t pixelsPerPackedUnit, uint32_t packedMultiplyVal) { + uint32_t ret = 0, i; + for (i = 0; i < pixelsPerPackedUnit; i++) { + ret = ret * packedMultiplyVal + val % packedMultiplyVal; + val /= packedMultiplyVal; + } + return ret; +} + +void spr2grays(TFT_eSprite &spr, long w, long h, String &fileout) { + // based on bmp2grays function by Dmitry.GR + + long t = millis(); + LittleFS.begin(); + + fs::File f_out = LittleFS.open(fileout, "w"); + + uint32_t c, rowBytesOut, rowBytesIn, outBpp, i, numRows, pixelsPerPackedUnit = 1, packedMultiplyVal = 0x01000000, packedOutBpp = 0; + uint32_t numGrays, extraColor = 0; + struct BitmapFileHeader hdr; + memset(&hdr, 0, sizeof(hdr)); + enum EinkClut clutType; + uint8_t clut[256][3]; + bool dither = false, rotated = false; + int skipBytes; + + clutType = EinkClutTwoBlacksAndRed; + + if (w > h) { + hdr.width = h; + hdr.height = w; + rotated = true; + } else { + hdr.width = w; + hdr.height = h; + } + hdr.bpp = 24; + hdr.sig[0] = 'B'; + hdr.sig[1] = 'M'; + hdr.colorplanes = 1; + + switch (clutType) { + case EinkClutTwoBlacks: + numGrays = 2; + outBpp = 1; + break; + + case EinkClutTwoBlacksAndRed: + extraColor = 0xff0000; + numGrays = 2; + outBpp = 2; + break; + + case EinkClutFourBlacks: + numGrays = 4; + outBpp = 2; + break; + + case EinkClutThreeBlacksAndRed: + numGrays = 3; + extraColor = 0xff0000; + outBpp = 2; + break; + } + + packedOutBpp = outBpp; + + rowBytesIn = (hdr.width * hdr.bpp + 31) / 32 * 4; + rowBytesOut = ((hdr.width + pixelsPerPackedUnit - 1) / pixelsPerPackedUnit) * packedOutBpp; + rowBytesOut = (rowBytesOut + 31) / 32 * 4; + + numRows = hdr.height < 0 ? -hdr.height : hdr.height; + hdr.bpp = outBpp; + hdr.numColors = 1 << outBpp; + hdr.numImportantColors = 1 << outBpp; + hdr.dataOfst = sizeof(struct BitmapFileHeader) + 4 * hdr.numColors; + hdr.dataLen = numRows * rowBytesOut; + hdr.fileSz = hdr.dataOfst + hdr.dataLen; + hdr.headerSz = 40; + hdr.compression = 0; + + f_out.write((uint8_t *)&hdr, sizeof(hdr)); + + // emit & record grey clut entries + for (i = 0; i < numGrays; i++) { + uint32_t val = 255 * i / (numGrays - 1); + + f_out.write(val); + f_out.write(val); + f_out.write(val); + f_out.write(val); + + clut[i][0] = val; + clut[i][1] = val; + clut[i][2] = val; + } + + if (extraColor) { + f_out.write((extraColor >> 0) & 0xff); // B + f_out.write((extraColor >> 8) & 0xff); // G + f_out.write((extraColor >> 16) & 0xff); // R + f_out.write(0x00); // A + + clut[i][0] = (extraColor >> 0) & 0xff; + clut[i][1] = (extraColor >> 8) & 0xff; + clut[i][2] = (extraColor >> 16) & 0xff; + } + + // pad clut to size + for (i = numGrays + (extraColor ? 1 : 0); i < hdr.numColors; i++) { + f_out.write(0x00); + f_out.write(0x00); + f_out.write(0x00); + f_out.write(0x00); + } + + while (numRows--) { + uint32_t pixelValsPackedSoFar = 0, numPixelsPackedSoFar = 0, valSoFar = 0, bytesIn = 0, bytesOut = 0, bitsSoFar = 0; + + for (c = 0; c < hdr.width; c++, bytesIn += 3) { + int64_t bestDist = 0x7fffffffffffffffll; + uint8_t bestIdx = 0; + int32_t ditherFudge = 0; + uint16_t color565; + if (rotated) { + color565 = spr.readPixel(hdr.height - 1 - numRows, c); + } else { + color565 = spr.readPixel(c, numRows); + } + + uint8_t red = ((color565 >> 11) & 0x1F) * 8; + uint8_t green = ((color565 >> 5) & 0x3F) * 4; + uint8_t blue = (color565 & 0x1F) * 8; + + if (dither) + ditherFudge = (rand() % 255 - 127) / (int)numGrays; + + for (i = 0; i < hdr.numColors; i++) { + int64_t dist = 0; + + dist += (blue - clut[i][0] + ditherFudge) * (blue - clut[i][0] + ditherFudge) * 4750ll; + dist += (green - clut[i][1] + ditherFudge) * (green - clut[i][1] + ditherFudge) * 47055ll; + dist += (red - clut[i][2] + ditherFudge) * (red - clut[i][2] + ditherFudge) * 13988ll; + + if (dist < bestDist) { + bestDist = dist; + bestIdx = i; + } + } + + // pack pixels as needed + pixelValsPackedSoFar = pixelValsPackedSoFar * packedMultiplyVal + bestIdx; + if (++numPixelsPackedSoFar != pixelsPerPackedUnit) + continue; + + numPixelsPackedSoFar = 0; + + // it is easier to display when low val is first pixel. currently last pixel is low - reverse this + pixelValsPackedSoFar = repackPackedVals(pixelValsPackedSoFar, pixelsPerPackedUnit, packedMultiplyVal); + + valSoFar = (valSoFar << packedOutBpp) | pixelValsPackedSoFar; + pixelValsPackedSoFar = 0; + bitsSoFar += packedOutBpp; + + if (bitsSoFar >= 8) { + f_out.write(valSoFar >> (bitsSoFar -= 8)); + valSoFar &= (1 << bitsSoFar) - 1; + bytesOut++; + } + } + + // see if we have unfinished pixel packages to write + if (numPixelsPackedSoFar) { + while (numPixelsPackedSoFar++ != pixelsPerPackedUnit) + pixelValsPackedSoFar *= packedMultiplyVal; + + // it is easier to display when low val is first pixel. currently last pixel is low - reverse this + pixelValsPackedSoFar = repackPackedVals(pixelValsPackedSoFar, pixelsPerPackedUnit, packedMultiplyVal); + + valSoFar = (valSoFar << packedOutBpp) | pixelValsPackedSoFar; + pixelValsPackedSoFar = 0; + bitsSoFar += packedOutBpp; + + if (bitsSoFar >= 8) { + f_out.write(valSoFar >> (bitsSoFar -= 8)); + valSoFar &= (1 << bitsSoFar) - 1; + bytesOut++; + } + } + + if (bitsSoFar) { + valSoFar <<= 8 - bitsSoFar; // left-align it as is expected + f_out.write(valSoFar); + bytesOut++; + } + + while (bytesOut++ < rowBytesOut) + f_out.write(0); + } + f_out.close(); + Serial.println(millis() - t); + Serial.println("finished writing BMP"); +} + +void bmp2grays(String filein, String fileout) { + // based on bmp2grays function by Dmitry.GR + + long t = millis(); + LittleFS.begin(); + + fs::File f_in = LittleFS.open(filein, "r"); + fs::File f_out = LittleFS.open(fileout, "w"); + + uint32_t c, rowBytesOut, rowBytesIn, outBpp, i, numRows, pixelsPerPackedUnit = 1, packedMultiplyVal = 0x01000000, packedOutBpp = 0; + uint32_t numGrays, extraColor = 0; + struct BitmapFileHeader hdr; + enum EinkClut clutType; + uint8_t clut[256][3]; + bool dither = false; + int skipBytes; + + clutType = EinkClutTwoBlacksAndRed; + + f_in.read((uint8_t *)&hdr, sizeof(hdr)); + + if (hdr.sig[0] != 'B' || hdr.sig[1] != 'M' || hdr.headerSz < 40 || hdr.colorplanes != 1 || hdr.bpp != 24 || hdr.compression) { + Serial.println("BITMAP HEADER INVALID, use uncompressed 24 bits RGB"); + return; + } + + switch (clutType) { + case EinkClutTwoBlacks: + numGrays = 2; + outBpp = 1; + break; + + case EinkClutTwoBlacksAndRed: + extraColor = 0xff0000; + numGrays = 2; + outBpp = 2; + break; + + case EinkClutFourBlacks: + numGrays = 4; + outBpp = 2; + break; + + case EinkClutThreeBlacksAndRed: + numGrays = 3; + extraColor = 0xff0000; + outBpp = 2; + break; + } + + packedOutBpp = outBpp; + + skipBytes = hdr.dataOfst - sizeof(hdr); + if (skipBytes < 0) { + fprintf(stderr, "file header was too short!\n"); + exit(-1); + } + f_in.read(NULL, skipBytes); + + rowBytesIn = (hdr.width * hdr.bpp + 31) / 32 * 4; + rowBytesOut = ((hdr.width + pixelsPerPackedUnit - 1) / pixelsPerPackedUnit) * packedOutBpp; + rowBytesOut = (rowBytesOut + 31) / 32 * 4; + + numRows = hdr.height < 0 ? -hdr.height : hdr.height; + hdr.bpp = outBpp; + hdr.numColors = 1 << outBpp; + hdr.numImportantColors = 1 << outBpp; + hdr.dataOfst = sizeof(struct BitmapFileHeader) + 4 * hdr.numColors; + hdr.dataLen = numRows * rowBytesOut; + hdr.fileSz = hdr.dataOfst + hdr.dataLen; + hdr.headerSz = 40; + hdr.compression = 0; + + f_out.write((uint8_t *)&hdr, sizeof(hdr)); + + // emit & record grey clut entries + for (i = 0; i < numGrays; i++) { + uint32_t val = 255 * i / (numGrays - 1); + + f_out.write(val); + f_out.write(val); + f_out.write(val); + f_out.write(val); + + clut[i][0] = val; + clut[i][1] = val; + clut[i][2] = val; + } + + // if there is a color CLUT entry, emit that + if (extraColor) { + f_out.write((extraColor >> 0) & 0xff); // B + f_out.write((extraColor >> 8) & 0xff); // G + f_out.write((extraColor >> 16) & 0xff); // R + f_out.write(0x00); // A + + clut[i][0] = (extraColor >> 0) & 0xff; + clut[i][1] = (extraColor >> 8) & 0xff; + clut[i][2] = (extraColor >> 16) & 0xff; + } + + // pad clut to size + for (i = numGrays + (extraColor ? 1 : 0); i < hdr.numColors; i++) { + f_out.write(0x00); + f_out.write(0x00); + f_out.write(0x00); + f_out.write(0x00); + } + + while (numRows--) { + uint32_t pixelValsPackedSoFar = 0, numPixelsPackedSoFar = 0, valSoFar = 0, bytesIn = 0, bytesOut = 0, bitsSoFar = 0; + + for (c = 0; c < hdr.width; c++, bytesIn += 3) { + int64_t bestDist = 0x7fffffffffffffffll; + uint8_t rgb[3], bestIdx = 0; + int32_t ditherFudge = 0; + + f_in.read(rgb, sizeof(rgb)); + + if (dither) + ditherFudge = (rand() % 255 - 127) / (int)numGrays; + + for (i = 0; i < hdr.numColors; i++) { + int64_t dist = 0; + + dist += (rgb[0] - clut[i][0] + ditherFudge) * (rgb[0] - clut[i][0] + ditherFudge) * 4750ll; + dist += (rgb[1] - clut[i][1] + ditherFudge) * (rgb[1] - clut[i][1] + ditherFudge) * 47055ll; + dist += (rgb[2] - clut[i][2] + ditherFudge) * (rgb[2] - clut[i][2] + ditherFudge) * 13988ll; + + if (dist < bestDist) { + bestDist = dist; + bestIdx = i; + } + } + + // pack pixels as needed + pixelValsPackedSoFar = pixelValsPackedSoFar * packedMultiplyVal + bestIdx; + if (++numPixelsPackedSoFar != pixelsPerPackedUnit) + continue; + + numPixelsPackedSoFar = 0; + + // it is easier to display when low val is first pixel. currently last pixel is low - reverse this + pixelValsPackedSoFar = repackPackedVals(pixelValsPackedSoFar, pixelsPerPackedUnit, packedMultiplyVal); + + valSoFar = (valSoFar << packedOutBpp) | pixelValsPackedSoFar; + pixelValsPackedSoFar = 0; + bitsSoFar += packedOutBpp; + + if (bitsSoFar >= 8) { + f_out.write(valSoFar >> (bitsSoFar -= 8)); + valSoFar &= (1 << bitsSoFar) - 1; + bytesOut++; + } + } + + // see if we have unfinished pixel packages to write + if (numPixelsPackedSoFar) { + while (numPixelsPackedSoFar++ != pixelsPerPackedUnit) + pixelValsPackedSoFar *= packedMultiplyVal; + + // it is easier to display when low val is first pixel. currently last pixel is low - reverse this + pixelValsPackedSoFar = repackPackedVals(pixelValsPackedSoFar, pixelsPerPackedUnit, packedMultiplyVal); + + valSoFar = (valSoFar << packedOutBpp) | pixelValsPackedSoFar; + pixelValsPackedSoFar = 0; + bitsSoFar += packedOutBpp; + + if (bitsSoFar >= 8) { + f_out.write(valSoFar >> (bitsSoFar -= 8)); + valSoFar &= (1 << bitsSoFar) - 1; + bytesOut++; + } + } + + if (bitsSoFar) { + valSoFar <<= 8 - bitsSoFar; // left-align it as is expected + f_out.write(valSoFar); + bytesOut++; + } + + while (bytesIn++ < rowBytesIn) + f_in.read(NULL, 1); + while (bytesOut++ < rowBytesOut) + f_out.write(0); + } + f_in.close(); + f_out.close(); + Serial.println(millis() - t); + Serial.println("finished writing BMP2"); +} \ No newline at end of file diff --git a/esp32_fw/src/newproto.cpp b/esp32_fw/src/newproto.cpp index a323b133..727fc0d2 100644 --- a/esp32_fw/src/newproto.cpp +++ b/esp32_fw/src/newproto.cpp @@ -1,14 +1,16 @@ -#pragma pack(push, 1) #include "newproto.h" #include #include +#include +#include #include "LittleFS.h" #include "commstructs.h" #include "pendingdata.h" #include "serial.h" #include "settings.h" +#include "tag_db.h" #include "web.h" extern void sendBlock(const void* data, const uint16_t len); @@ -29,7 +31,7 @@ bool checkCRC(void* p, uint8_t len) { return ((uint8_t*)p)[0] == total; } -uint8_t* getDataForFile(File* file) { +uint8_t* getDataForFile(fs::File* file) { uint8_t* ret = nullptr; ret = (uint8_t*)malloc(file->size()); if (ret) { @@ -48,15 +50,51 @@ void prepareCancelPending(uint64_t ver) { } bool prepareDataAvail(String* filename, uint8_t dataType, uint8_t* dst, uint16_t nextCheckin) { + + if (nextCheckin > 1440) { + //to prevent very long sleeps of the tag + nextCheckin = 0; + } + *filename = "/" + *filename; if (!LittleFS.exists(*filename)) return false; - File file = LittleFS.open(*filename); + fs::File file = LittleFS.open(*filename); if (file.size() == 0) { Serial.print("opened a file with size 0??\n"); return false; } + if (filename->endsWith(".bmp") || filename->endsWith(".BMP")) { + struct BitmapFileHeader hdr; + file.read((uint8_t*)&hdr, sizeof(hdr)); + if (hdr.width == 296 && hdr.height == 128) { + //sorry, can't rotate + Serial.println("when using BMP files, remember to only use 128px width and 296px height"); + wsErr("when using BMP files, remember to only use 128px width and 296px height"); + return false; + } + if (hdr.sig[0] == 'B' && hdr.sig[1] == 'M' && hdr.bpp == 24) { + Serial.println("converting 24bpp bmp to grays"); + char fileout[64]; + sprintf(fileout, "/temp/%02X%02X%02X%02X%02X%02X.bmp\0", dst[5], dst[4], dst[3], dst[2], dst[1], dst[0]); + bmp2grays(*filename,(String)fileout); + *filename = (String)fileout; + file.close(); + file = LittleFS.open(*filename); + } + } + + if (filename->endsWith(".jpg") || filename->endsWith(".JPG")) { + Serial.println("converting jpg to grays"); + char fileout[64]; + sprintf(fileout, "/temp/%02X%02X%02X%02X%02X%02X.bmp\0", dst[5], dst[4], dst[3], dst[2], dst[1], dst[0]); + jpg2grays(*filename, (String)fileout); + *filename = (String)fileout; + file.close(); + file = LittleFS.open(*filename); + } + uint8_t md5bytes[16]; { MD5Builder md5; @@ -66,6 +104,20 @@ bool prepareDataAvail(String* filename, uint8_t dataType, uint8_t* dst, uint16_t md5.getBytes(md5bytes); } + uint8_t src[8]; + *((uint64_t*)src) = swap64(*((uint64_t*)dst)); + uint8_t mac[6]; + memcpy(mac, src + 2, sizeof(mac)); + tagRecord* taginfo = nullptr; + taginfo = tagRecord::findByMAC(mac); + if (taginfo != nullptr) { + if (memcmp(md5bytes, taginfo->md5pending, 16) == 0) { + Serial.println("new image is the same as current image. not updating tag."); + wsSendTaginfo(mac); + return false; + } + } + // the message that will be sent to the AP to tell the tag there is data pending struct pendingData pending = {0}; memcpy(pending.targetMac, dst, 8); @@ -84,10 +136,38 @@ bool prepareDataAvail(String* filename, uint8_t dataType, uint8_t* dst, uint16_t pendinginfo->len = pending.availdatainfo.dataSize; pendinginfo->data = nullptr; pendinginfo->timeout = PENDING_TIMEOUT; - // pendinginfo->data = getDataForFile(&file); - file.close(); - pendinginfo->timeout = 1800; + //pendinginfo->data = getDataForFile(&file); + pendinginfo->timeout = 1800; // ***fixme... a tag can sleep for a long time when ttl is used. pendingfiles.push_back(pendinginfo); + + if (dataType != DATATYPE_UPDATE) { + char dst_path[64]; + sprintf(dst_path, "/current/%02X%02X%02X%02X%02X%02X.pending\0", dst[5], dst[4], dst[3], dst[2], dst[1], dst[0]); + fs::File dstfile = LittleFS.open(dst_path, "w"); + //int bytes_written = dstfile.write(pendinginfo->data, pendinginfo->len); + file.seek(0); + const int chunkSize = 512; + uint8_t buffer[chunkSize]; + size_t bytesRead = 0; + while ((bytesRead = file.read(buffer, chunkSize)) > 0) { + dstfile.write(buffer, bytesRead); + } + dstfile.close(); + + wsLog("new image pending: " + String(dst_path)); + if (taginfo != nullptr) { + taginfo->pending = true; + taginfo->CheckinInMinPending = nextCheckin + 1; + memcpy(taginfo->md5pending, md5bytes, sizeof(md5bytes)); + } + } + else { + wsLog("firmware upload pending"); + } + file.close(); + + wsSendTaginfo(mac); + return true; } @@ -105,7 +185,7 @@ void processBlockRequest(struct espBlockRequest* br) { } else { if (pd->data == nullptr) { // not cached. open file, cache the data - File file = LittleFS.open(pd->filename); + fs::File file = LittleFS.open(pd->filename); if (!file) { Serial.print("Dunno how this happened... File pending but deleted in the meantime?\n"); } @@ -129,7 +209,7 @@ void processBlockRequest(struct espBlockRequest* br) { sendBlock(pd->data + (br->blockId * BLOCK_DATA_SIZE), len); char buffer[64]; sprintf(buffer, "< Block Request received for MD5 %llu, block %d\n\0", br->ver, br->blockId); - wsString((String)buffer); + wsLog((String)buffer); Serial.printf("blockId); } @@ -138,14 +218,60 @@ void processXferComplete(struct espXferComplete* xfc) { uint8_t src[8]; *((uint64_t*)src) = swap64(*((uint64_t*)xfc->src)); sprintf(buffer, "< %02X%02X%02X%02X%02X%02X reports xfer complete\n\0", src[2], src[3], src[4], src[5], src[6], src[7]); - wsString((String)buffer); + wsLog((String)buffer); Serial.print(buffer); + uint8_t mac[6]; + memcpy(mac, src + 2, sizeof(mac)); + + char src_path[64]; + char dst_path[64]; + char tmp_path[64]; + sprintf(src_path, "/current/%02X%02X%02X%02X%02X%02X.pending\0", src[2], src[3], src[4], src[5], src[6], src[7]); + sprintf(dst_path, "/current/%02X%02X%02X%02X%02X%02X.bmp\0", src[2], src[3], src[4], src[5], src[6], src[7]); + sprintf(tmp_path, "/temp/%02X%02X%02X%02X%02X%02X.bmp\0", src[2], src[3], src[4], src[5], src[6], src[7]); + if (LittleFS.exists(dst_path)) { + LittleFS.remove(dst_path); + } + LittleFS.rename(src_path, dst_path); + if (LittleFS.exists(tmp_path)) { + LittleFS.remove(tmp_path); + } + + time_t now; + time(&now); + tagRecord* taginfo = nullptr; + taginfo = tagRecord::findByMAC(mac); + if (taginfo != nullptr) { + taginfo->pending = false; + taginfo->expectedNextCheckin = now + 60 * taginfo->CheckinInMinPending + 30; + memcpy(taginfo->md5, taginfo->md5pending, sizeof(taginfo->md5pending)); + } + wsSendTaginfo(mac); } void processDataReq(struct espAvailDataReq* eadr) { char buffer[64]; uint8_t src[8]; - sprintf(buffer, "src[7], eadr->src[6], eadr->src[5], eadr->src[4], eadr->src[3], eadr->src[2], eadr->src[1], eadr->src[0], eadr->adr.buttonState); - wsString((String)buffer); + *((uint64_t*)src) = swap64(*((uint64_t*)eadr->src)); + + tagRecord* taginfo = nullptr; + uint8_t mac[6]; + memcpy(mac, src + 2, sizeof(mac)); + + taginfo = tagRecord::findByMAC(mac); + if (taginfo == nullptr) { + taginfo = new tagRecord; + memcpy(taginfo->mac, src + 2, sizeof(taginfo->mac)); + taginfo->pending = false; + tagDB.push_back(taginfo); + } + time_t now; + time(&now); + taginfo->lastseen = now; + taginfo->expectedNextCheckin = now + 300; + taginfo->button = (eadr->adr.buttonState == 1); + + sprintf(buffer, " #include #include @@ -139,7 +138,6 @@ void SerialRXLoop() { } if (strncmp(cmdbuffer, "BST>", 4) == 0) { Serial.print(">SYNC BURST\n"); - wsString(">SYNC BURST"); RXState = ZBS_RX_WAIT_HEADER; } if (strncmp(cmdbuffer, "XFC>", 4) == 0) { diff --git a/esp32_fw/src/tag_db.cpp b/esp32_fw/src/tag_db.cpp new file mode 100644 index 00000000..794a0a8c --- /dev/null +++ b/esp32_fw/src/tag_db.cpp @@ -0,0 +1,167 @@ +#include "tag_db.h" + +#include +#include + +#include + +#include "LittleFS.h" + +std::vector tagDB; + +tagRecord* tagRecord::findByMAC(uint8_t mac[6]) { + for (int16_t c = 0; c < tagDB.size(); c++) { + tagRecord* tag = nullptr; + tag = tagDB.at(c); + if (memcmp(tag->mac, mac, 6) == 0) { + return tag; + } + } + return nullptr; +} + +String tagDBtoJson(uint8_t mac[6], uint8_t startPos) { + DynamicJsonDocument doc(2500); + JsonArray tags = doc.createNestedArray("tags"); + + for (int16_t c = startPos; c < tagDB.size(); c++) { + tagRecord* taginfo = nullptr; + taginfo = tagDB.at(c); + + bool select = false; + if (mac) { + if (memcmp(taginfo->mac, mac, 6) == 0) { + select = true; + } + } else { + select = true; + } + if (select) { + JsonObject tag = tags.createNestedObject(); + fillNode(tag, taginfo); + if (mac) { + break; + } + } + if (doc.capacity()-doc.memoryUsage() < doc.memoryUsage()/(c+1) + 100) { + doc["continu"] = c+1; + break; + } + } + return doc.as(); +} + +void fillNode(JsonObject &tag, tagRecord* &taginfo) { + char buffer[16]; + sprintf(buffer, "%02X%02X%02X%02X%02X%02X\0", taginfo->mac[0], taginfo->mac[1], taginfo->mac[2], taginfo->mac[3], taginfo->mac[4], taginfo->mac[5]); + tag["mac"] = (String)buffer; + char hex[7]; + sprintf(hex, "%02x%02x%02x\0", taginfo->md5[0], taginfo->md5[1], taginfo->md5[2]); + tag["hash"] = hex; + tag["lastseen"] = taginfo->lastseen; + tag["nextupdate"] = taginfo->nextupdate; + tag["nextcheckin"] = taginfo->expectedNextCheckin; + tag["model"] = taginfo->model; + tag["pending"] = taginfo->pending; + tag["button"] = taginfo->button; + tag["alias"] = taginfo->alias; + tag["contentmode"] = taginfo->contentMode; + tag["modecfgjson"] = taginfo->modeConfigJson; +} + +void saveDB(String filename) { + DynamicJsonDocument doc(2500); + + long t = millis(); + + LittleFS.begin(); + fs::File file = LittleFS.open(filename, "w"); + if (!file) { + Serial.println("saveDB: Failed to open file"); + return; + } + + file.write('['); + + for (int16_t c = 0; c < tagDB.size(); c++) { + doc.clear(); + tagRecord* taginfo = nullptr; + taginfo = tagDB.at(c); + + JsonObject tag = doc.createNestedObject(); + fillNode(tag, taginfo); + if (c > 0) { + file.write(','); + } + serializeJson(doc, file); + } + file.write(']'); + + file.close(); + Serial.println(millis() - t); + Serial.println("finished writing DB"); + + return; +} + +void loadDB(String filename) { + StaticJsonDocument<400> doc; + + Serial.println("start reading DB from file"); + long t = millis(); + + LittleFS.begin(); + fs::File readfile = LittleFS.open(filename, "r"); + if (!readfile) { + Serial.println("loadDB: Failed to open file"); + return; + } + + time_t now; + time(&now); + bool parsing = true; + + if (readfile.find("[")) { + while (parsing) { + DeserializationError err = deserializeJson(doc, readfile); + if (!err) { + JsonObject tag = doc[0]; + String dst = tag["mac"].as(); + uint8_t mac[12]; + if (sscanf(dst.c_str(), "%02X%02X%02X%02X%02X%02X", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) == 6) { + tagRecord* taginfo = nullptr; + taginfo = tagRecord::findByMAC(mac); + if (taginfo == nullptr) { + taginfo = new tagRecord; + memcpy(taginfo->mac, mac, sizeof(taginfo->mac)); + tagDB.push_back(taginfo); + } + //taginfo->lastseen = (uint32_t)tag["lastseen"]; + taginfo->lastseen = 0; + taginfo->nextupdate = (uint32_t)tag["nextupdate"]; + taginfo->expectedNextCheckin = (uint16_t)tag["nextcheckin"]; + if (taginfo->expectedNextCheckin < now - 1800) { + taginfo->expectedNextCheckin = now + 1800; + } + taginfo->model = (uint8_t)tag["model"]; + taginfo->pending = false; + taginfo->button = false; + taginfo->alias = tag["alias"].as(); + taginfo->contentMode = static_cast(tag["contentmode"]); + taginfo->modeConfigJson = tag["modecfgjson"].as(); + } + } else { + Serial.print(F("deserializeJson() failed: ")); + Serial.println(err.c_str()); + parsing = false; + } + parsing = parsing && readfile.find(","); + } + } + + readfile.close(); + Serial.println(millis() - t); + Serial.println("finished reading file"); + + return; +} diff --git a/esp32_fw/src/web.cpp b/esp32_fw/src/web.cpp index 35c5297a..1f4514d4 100644 --- a/esp32_fw/src/web.cpp +++ b/esp32_fw/src/web.cpp @@ -2,6 +2,7 @@ #include #include + #include #include #include @@ -14,6 +15,7 @@ #include "commstructs.h" #include "newproto.h" #include "settings.h" +#include "tag_db.h" extern uint8_t data_to_send[]; @@ -53,62 +55,15 @@ void webSocketSendProcess(void *parameter) { // sendStatus(STATUS_WIFI_ACTIVITY); DynamicJsonDocument doc(1500); if (ulNotificationValue & 2) { // WS_SEND_MODE_STATUS) { - /* doc["rxActive"] = status.rxActive; - doc["txActive"] = status.txActive; - doc["freq"] = status.freq; - doc["txMode"] = status.currentmode; - */ } /* JsonArray statusframes = doc.createNestedArray("frames"); - for (uint8_t c = 0; c < STATUSFRAMELISTSIZE; c++) { - if (statusframearr[c]) { - JsonObject statusframe = statusframes.createNestedObject(); - statusframe["frame"] = statusframearr[c]->frameno; - statusframe["isTX"] = statusframearr[c]->isTX; - statusframe["freq"] = statusframearr[c]->freq; - statusframe["txSkipped"] = statusframearr[c]->txCancelled; - switch (statusframearr[c]->rxtype) { - case flexsynctype::SYNC_FLEX_1600: - statusframe["rxType"] = "FLEX_1600"; - break; - case flexsynctype::SYNC_FLEX_3200_2: - statusframe["rxType"] = "FLEX_3200_2"; - break; - case flexsynctype::SYNC_FLEX_3200_4: - statusframe["rxType"] = "FLEX_3200_4"; - break; - case flexsynctype::SYNC_FLEX_6400: - statusframe["rxType"] = "FLEX_3200_4"; - break; - default: - break; - } - switch (statusframearr[c]->txformat) { - case txframe::FORMAT_FLEX: - statusframe["txType"] = "FLEX"; - break; - case txframe::FORMAT_POCSAG: - statusframe["txType"] = "POCSAG"; - break; - case txframe::FORMAT_IDLE: - statusframe["txType"] = "IDLE"; - break; - case txframe::FORMAT_BLOCKED: - statusframe["txType"] = "BLOCKED"; - break; - default: - break; - } - } - } }*/ size_t len = measureJson(doc); xSemaphoreTake(wsMutex, portMAX_DELAY); auto buffer = std::make_shared>(len); serializeJson(doc, buffer->data(), len); // ws.textAll((char*)buffer->data()); - ws.textAll("ohai"); xSemaphoreGive(wsMutex); } } @@ -188,16 +143,59 @@ void onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType } } -void doImageUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final); - -void wsString(String text) { +void wsLog(String text) { + DynamicJsonDocument doc(100); + doc["logMsg"] = text; xSemaphoreTake(wsMutex, portMAX_DELAY); - ws.textAll(text); + ws.textAll(doc.as()); xSemaphoreGive(wsMutex); } +void wsErr(String text) { + DynamicJsonDocument doc(100); + doc["errMsg"] = text; + xSemaphoreTake(wsMutex, portMAX_DELAY); + ws.textAll(doc.as()); + xSemaphoreGive(wsMutex); +} + +void wsSendSysteminfo() { + DynamicJsonDocument doc(250); + JsonObject sys = doc.createNestedObject("sys"); + time_t now; + time(&now); + sys["currtime"] = now; + sys["heap"] = ESP.getFreeHeap(); + sys["recordcount"] = tagDB.size(); + sys["dbsize"] = tagDB.size() * sizeof(tagRecord); + sys["littlefsfree"] = LittleFS.totalBytes() - LittleFS.usedBytes(); + + xSemaphoreTake(wsMutex, portMAX_DELAY); + ws.textAll(doc.as()); + xSemaphoreGive(wsMutex); +} + +void wsSendTaginfo(uint8_t mac[6]) { + + String json = ""; + json = tagDBtoJson(mac); + + xSemaphoreTake(wsMutex, portMAX_DELAY); + ws.textAll(json); + xSemaphoreGive(wsMutex); + +} + void init_web() { LittleFS.begin(true); + + if (!LittleFS.exists("/current")) { + LittleFS.mkdir("/current"); + } + if (!LittleFS.exists("/temp")) { + LittleFS.mkdir("/temp"); + } + WiFi.mode(WIFI_STA); WiFiManager wm; bool res; @@ -214,87 +212,20 @@ void init_web() { ws.onEvent(onEvent); server.addHandler(&ws); - server.on("/heap", HTTP_GET, [](AsyncWebServerRequest *request) { - request->send(200, "text/plain", String(ESP.getFreeHeap())); - }); - server.on("/reboot", HTTP_POST, [](AsyncWebServerRequest *request) { request->send(200, "text/plain", "OK Reboot"); ESP.restart(); }); - server.serveStatic("/", LittleFS, "/").setDefaultFile("index.htm"); - + server.serveStatic("/current", LittleFS, "/current/"); + server.serveStatic("/", LittleFS, "/www/").setDefaultFile("index.html"); + server.on( "/imgupload", HTTP_POST, [](AsyncWebServerRequest *request) { request->send(200); }, doImageUpload); - server.on("/send_image", HTTP_POST, [](AsyncWebServerRequest *request) { - String filename; - String dst; - uint16_t nextCheckin; - if (request->hasParam("filename", true) && request->hasParam("dst", true)) { - filename = request->getParam("filename", true)->value(); - dst = request->getParam("dst", true)->value(); - nextCheckin = request->getParam("ttl",true)->value().toInt(); - uint8_t mac_addr[12]; // I expected this to return like 8 values, but if I make the array 8 bytes long, things die. - mac_addr[0] = 0x00; - mac_addr[1] = 0x00; - if (sscanf(dst.c_str(), "%02X%02X%02X%02X%02X%02X", - &mac_addr[2], - &mac_addr[3], - &mac_addr[4], - &mac_addr[5], - &mac_addr[6], - &mac_addr[7]) != 6) { - request->send(200, "text/plain", "Something went wrong trying to parse the mac address"); - } else { - *((uint64_t *)mac_addr) = swap64(*((uint64_t *)mac_addr)); - if (prepareDataAvail(&filename, DATATYPE_IMGRAW, mac_addr, nextCheckin)) { - request->send(200, "text/plain", "Sending to " + dst); - } else { - request->send(200, "text/plain", "Couldn't find filename :("); - } - } - return; - } - request->send(200, "text/plain", "Didn't get the required filename + dst"); - return; - }); - - server.on("/send_fw", HTTP_POST, [](AsyncWebServerRequest *request) { - String filename; - String dst; - if (request->hasParam("filename", true) && request->hasParam("dst", true)) { - filename = request->getParam("filename", true)->value(); - dst = request->getParam("dst", true)->value(); - uint8_t mac_addr[12]; // I expected this to return like 8 values, but if I make the array 8 bytes long, things die. - mac_addr[0] = 0x00; - mac_addr[1] = 0x00; - if (sscanf(dst.c_str(), "%02X%02X%02X%02X%02X%02X", - &mac_addr[2], - &mac_addr[3], - &mac_addr[4], - &mac_addr[5], - &mac_addr[6], - &mac_addr[7]) != 6) { - request->send(200, "text/plain", "Something went wrong trying to parse the mac address"); - } else { - *((uint64_t *)mac_addr) = swap64(*((uint64_t *)mac_addr)); - if (prepareDataAvail(&filename, DATATYPE_UPDATE, mac_addr, 0)) { - request->send(200, "text/plain", "Sending FW to " + dst); - } else { - request->send(200, "text/plain", "Couldn't find filename :("); - } - } - return; - } - request->send(200, "text/plain", "Didn't get the required filename + dst"); - return; - }); - server.on("/req_checkin", HTTP_POST, [](AsyncWebServerRequest *request) { String filename; String dst; @@ -323,60 +254,53 @@ void init_web() { return; }); + server.on("/get_db", HTTP_GET, [](AsyncWebServerRequest *request) { + String json = ""; + if (request->hasParam("mac")) { + String dst = request->getParam("mac")->value(); + uint8_t mac[6]; + if (sscanf(dst.c_str(), "%02X%02X%02X%02X%02X%02X", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5])==6) { + json = tagDBtoJson(mac); + } + } else { + uint8_t startPos=0; + if (request->hasParam("pos")) { + startPos = atoi(request->getParam("pos")->value().c_str()); + } + json = tagDBtoJson(nullptr,startPos); + } + request->send(200, "application/json", json); + }); + + server.on("/save_cfg", HTTP_POST, [](AsyncWebServerRequest *request) { + if (request->hasParam("mac", true)) { + String dst = request->getParam("mac", true)->value(); + uint8_t mac[6]; + if (sscanf(dst.c_str(), "%02X%02X%02X%02X%02X%02X", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]) == 6) { + tagRecord *taginfo = nullptr; + taginfo = tagRecord::findByMAC(mac); + if (taginfo != nullptr) { + taginfo->alias = request->getParam("alias", true)->value(); + taginfo->modeConfigJson = request->getParam("modecfgjson", true)->value(); + taginfo->contentMode = (contentModes)atoi(request->getParam("contentmode", true)->value().c_str()); + taginfo->model = atoi(request->getParam("model", true)->value().c_str()); + taginfo->nextupdate = 0; + wsSendTaginfo(mac); + saveDB("/current/tagDB.json"); + request->send(200, "text/plain", "Ok, saved"); + } else { + request->send(200, "text/plain", "Error while saving: mac not found"); + } + } + } + request->send(200, "text/plain", "Ok, saved"); + }); + server.onNotFound([](AsyncWebServerRequest *request) { if (request->url() == "/" || request->url() == "index.htm") { request->send(200, "text/html", "-"); return; } - Serial.printf("NOT_FOUND: "); - - switch (request->method()) { - case HTTP_GET: - Serial.printf("GET"); - break; - case HTTP_POST: - Serial.printf("POST"); - break; - case HTTP_DELETE: - Serial.printf("DELETE"); - break; - case HTTP_PUT: - Serial.printf("PUT"); - break; - case HTTP_PATCH: - Serial.printf("PATCH"); - break; - case HTTP_HEAD: - Serial.printf("HEAD"); - break; - case HTTP_OPTIONS: - Serial.printf("OPTIONS"); - break; - - default: - Serial.printf("UNKNOWN"); - break; - } - Serial.printf(" http://%s%s\n", request->host().c_str(), request->url().c_str()); - - if (request->contentLength()) { - Serial.printf("_CONTENT_TYPE: %s\n", request->contentType().c_str()); - Serial.printf("_CONTENT_LENGTH: %u\n", request->contentLength()); - } - for (int i = 0; i < request->headers(); i++) { - AsyncWebHeader *h = request->getHeader(i); - Serial.printf("_HEADER[%s]: %s\n", h->name().c_str(), h->value().c_str()); - } - for (int i = 0; i < request->params(); i++) { - AsyncWebParameter *p = request->getParam(i); - if (p->isFile()) { - Serial.printf("_FILE[%s]: %s, size: %u\n", p->name().c_str(), p->value().c_str(), p->size()); - } else if (p->isPost()) { - Serial.printf("_POST[%s]: %s\n", p->name().c_str(), p->value().c_str()); - } else { - Serial.printf("_GET[%s]: %s\n", p->name().c_str(), p->value().c_str()); - } - } request->send(404); }); diff --git a/tag_fw/Makefile b/tag_fw/Makefile index 5dec4173..fae0f459 100644 --- a/tag_fw/Makefile +++ b/tag_fw/Makefile @@ -5,7 +5,7 @@ BUILD ?= zbs29v033 SOURCES += main.c eeprom.c drawing.c SOURCES += comms.c SOURCES += syncedproto.c epd.c userinterface.c - +SOURCES += powermgt.c barcode.c all: #make sure it is the first target diff --git a/tag_fw/barcode.c b/tag_fw/barcode.c new file mode 100644 index 00000000..c431d148 --- /dev/null +++ b/tag_fw/barcode.c @@ -0,0 +1,101 @@ +#include +#include "barcode.h" +#include "asmUtil.h" + +//code128 generator (c) 2021 Dmitry Grinberg https://dmitry.gr +//non-commercial use only, contact licensing@dmitry.gr for other options + +#pragma nogcse + +static const uint16_t __code mCode128[] = { + 0b00110011011, 0b00110110011, 0b01100110011, 0b00011001001, 0b00110001001, 0b00110010001, 0b00010011001, 0b00100011001, + 0b00100110001, 0b00010010011, 0b00100010011, 0b00100100011, 0b00111001101, 0b00111011001, 0b01110011001, 0b00110011101, + 0b00110111001, 0b01100111001, 0b01001110011, 0b00111010011, 0b01110010011, 0b00100111011, 0b00101110011, 0b01110110111, + 0b00110010111, 0b00110100111, 0b01100100111, 0b00100110111, 0b00101100111, 0b01001100111, 0b00011011011, 0b01100011011, + 0b01101100011, 0b00011000101, 0b00011010001, 0b01100010001, 0b00010001101, 0b00010110001, 0b01000110001, 0b00010001011, + 0b00010100011, 0b01000100011, 0b00011101101, 0b01110001101, 0b01110110001, 0b00011011101, 0b01100011101, 0b01101110001, + 0b01101110111, 0b01110001011, 0b01110100011, 0b00010111011, 0b01000111011, 0b01110111011, 0b00011010111, 0b01100010111, + 0b01101000111, 0b00010110111, 0b01000110111, 0b01011000111, 0b01011110111, 0b01000010011, 0b01010001111, 0b00001100101, + 0b00110000101, 0b00001101001, 0b01100001001, 0b00110100001, 0b01100100001, 0b00001001101, 0b00100001101, 0b00001011001, + 0b01000011001, 0b00101100001, 0b01001100001, 0b01001000011, 0b00001010011, 0b01011101111, 0b00101000011, 0b01011110001, + 0b00111100101, 0b00111101001, 0b01111001001, 0b00100111101, 0b00101111001, 0b01001111001, 0b00100101111, 0b00101001111, + 0b01001001111, 0b01111011011, 0b01101111011, 0b01101101111, 0b00011110101, 0b01111000101, 0b01111010001, 0b00010111101, + 0b01000111101, 0b00010101111, 0b01000101111, 0b01111011101, 0b01110111101, 0b01111010111, 0b01110101111 +}; + + +#define CODE128_START_B (0b00001001011) +#define CODE128_STOP (0b1101011100011) + +#define CODE128_IDX_START_A (103) +#define CODE128_IDX_START_B (104) +#define CODE128_IDX_START_C (105) +#define CODE128_IDX_CODE_STOP (106) + + +enum BarCodeState { + BarCodeInit, + BarCodeEmittingChar, + BarCodeEmittingChecksum, + BarCodeEmittingStop, + BarCodeDone, +}; + + + + +__bit barcodeIsDone(struct BarcodeInfo __xdata *bci) +{ + return bci->state == BarCodeDone; +} + +__bit barcodeNextBar(struct BarcodeInfo __xdata *bci) +{ + uint8_t t; + __bit ret; + + if (!bci->barsLeft) switch (bci->state) { + case BarCodeInit: + bci->curBars = CODE128_START_B; + bci->barsLeft = 11; + bci->state = BarCodeEmittingChar; + bci->csum = CODE128_IDX_START_B; + break; + + case BarCodeEmittingChar: + t = charsPrvDerefAndIncGenericPtr(&bci->str); + if (t) { + t -= 0x20; + if (t >= 0x60) + t = '?' - 0x20; + bci->csum = mathPrvMod16x8(mathPrvMul8x8(++bci->csumMul, t) + bci->csum, 103); + } + else { + + bci->state = BarCodeEmittingChecksum; + t = bci->csum; + } + bci->curBars = mCode128[t]; + bci->barsLeft = 11; + break; + + case BarCodeEmittingChecksum: + bci->state = BarCodeEmittingStop; + bci->curBars = CODE128_STOP; + bci->barsLeft = 13; + break; + + case BarCodeEmittingStop: + bci->state = BarCodeDone; + //fallthrough + + case BarCodeDone: + default: + return false; + } + + ret = bci->curBars & 1; + bci->curBars >>= 1; + bci->barsLeft--; + return ret; +} diff --git a/tag_fw/barcode.h b/tag_fw/barcode.h new file mode 100644 index 00000000..f6d784b9 --- /dev/null +++ b/tag_fw/barcode.h @@ -0,0 +1,29 @@ +#ifndef _BARCODE_H_ +#define _BARCODE_H_ + +#include + +//code128 generator (c) 2021 Dmitry Grinberg https://dmitry.gr +//non-commercial use only, contact licensing@dmitry.gr for other options + + +struct BarcodeInfo { //zero-init this except the string ptr + const char *str; + uint16_t curBars; + uint8_t barsLeft; + uint8_t state; + uint8_t csum; + uint8_t csumMul; +}; + +#define barcodeWidth(nChars) (11 * (nChars) + 11 /*start */+ 11 /*check sum */ + 13 /* stop */) + +#pragma callee_saves barcodeIsDone +__bit barcodeIsDone(struct BarcodeInfo __xdata *bci); + +#pragma callee_saves barcodeNextBar +__bit barcodeNextBar(struct BarcodeInfo __xdata *bci); + + + +#endif diff --git a/tag_fw/bitmaps.h b/tag_fw/bitmaps.h new file mode 100644 index 00000000..d16feecf --- /dev/null +++ b/tag_fw/bitmaps.h @@ -0,0 +1,210 @@ +#ifndef _BITMAPS_H_ +#define _BITMAPS_H_ + +// images generated by https://lvgl.io/tools/imageconverter, prepended with width, height. "CF_INDEXED_1_BIT"-mode, little-endian +#include + +static const uint8_t __code solum[] = { + 128, 26, + 0x00, 0x00, 0x07, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x1f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0xff, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x07, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x01, 0xfc, + 0x00, 0x0f, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x03, 0xfc, + 0x00, 0x1f, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0x07, 0xfc, + 0x00, 0x7f, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x00, 0x0f, 0xfc, + 0x00, 0xff, 0x80, 0x00, 0x00, 0x3f, 0xc0, 0x78, 0x03, 0x80, 0x1c, 0x01, 0xff, 0x80, 0x0f, 0xf8, + 0x00, 0xff, 0x00, 0x00, 0x01, 0xff, 0xf0, 0x78, 0x07, 0xc0, 0x3e, 0x01, 0xff, 0x80, 0x1f, 0xf8, + 0x01, 0xfe, 0x00, 0x00, 0x03, 0xff, 0xf8, 0xf8, 0x07, 0xc0, 0x3e, 0x01, 0xff, 0x80, 0x3e, 0xf8, + 0x01, 0xfe, 0x03, 0xfe, 0x0f, 0xe1, 0xfc, 0xf8, 0x0f, 0x80, 0x7c, 0x03, 0xef, 0x80, 0x7d, 0xf8, + 0x01, 0xfe, 0x00, 0x7f, 0x0f, 0x80, 0xfc, 0xf8, 0x0f, 0x80, 0x7c, 0x03, 0xef, 0x80, 0x7d, 0xf0, + 0x01, 0xff, 0x80, 0x3f, 0x9f, 0x00, 0x7c, 0xf0, 0x0f, 0x80, 0x7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0x1f, 0xff, 0xf0, 0x00, 0x0f, 0xfe, 0x07, 0xff, 0x8f, 0xfe, 0x00, 0x1f, 0x01, 0xf0, 0x1f, 0x80, +}; + +static const uint8_t __code hacked[] = { + 112, 56, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x03, 0xff, 0xc0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x87, 0xff, 0xe0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0x87, 0xc3, 0xf0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x87, 0x83, 0xf8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x81, 0xfb, 0x8f, 0x03, 0xfc, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x03, 0x81, 0xf3, 0x8f, 0x03, 0xfe, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x07, 0x81, 0xe7, 0x8f, 0x07, 0xbf, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x80, 0x07, 0x81, 0xc7, 0x8f, 0x07, 0x9f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, 0x07, 0x81, 0xc7, 0x87, 0x8f, 0x8f, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xe0, 0x07, 0x01, 0xcf, 0x07, 0x9f, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xf0, 0x0f, 0x01, 0xef, 0x07, 0xff, 0x00, + 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe1, 0xf8, 0x0f, 0x01, 0xff, 0x03, 0xfe, 0x00, + 0x38, 0x07, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xfc, 0x0f, 0x01, 0xfe, 0x03, 0xfc, 0x00, + 0x38, 0x07, 0x00, 0x00, 0x00, 0x01, 0xe0, 0x7c, 0x1e, 0x00, 0xff, 0xf0, 0x00, 0x00, + 0x3c, 0x07, 0x80, 0x00, 0x00, 0x01, 0xe0, 0x3e, 0x1e, 0x00, 0xff, 0xf0, 0x00, 0x00, + 0x3c, 0x07, 0x80, 0x00, 0x00, 0x03, 0xe0, 0x1f, 0x1e, 0x00, 0x3f, 0xf0, 0x00, 0x00, + 0x3e, 0x07, 0xc0, 0x00, 0x00, 0x03, 0xc0, 0x1f, 0x9f, 0xe0, 0x1f, 0xc0, 0x00, 0x00, + 0x1e, 0x03, 0xc0, 0x00, 0x00, 0x07, 0xc0, 0x0f, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x1f, 0x03, 0xc0, 0x00, 0x00, 0x07, 0x80, 0x07, 0xff, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x0f, 0x03, 0xe0, 0x03, 0xc0, 0x07, 0x80, 0x03, 0xfc, 0xff, 0xc0, 0x00, 0x00, 0x00, + 0x0f, 0x01, 0xe0, 0x07, 0xc0, 0x07, 0x00, 0x00, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0f, 0x81, 0xfc, 0x07, 0xf8, 0x07, 0x80, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x81, 0xfc, 0x0f, 0xf8, 0x07, 0x80, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x80, 0xfc, 0x0f, 0x7c, 0x07, 0xc0, 0x78, 0x3c, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0xc0, 0xfc, 0x0f, 0x7e, 0x03, 0xe0, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0xc3, 0xfc, 0x0e, 0x3e, 0x03, 0xf3, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0xdf, 0xfc, 0x0e, 0x3f, 0x01, 0xff, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0xff, 0xfe, 0x0e, 0x1f, 0x80, 0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0xff, 0x9e, 0x0f, 0x1f, 0x80, 0x7f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0xfc, 0x1e, 0x0f, 0x1f, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0xf0, 0x1f, 0x0f, 0xbf, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0xf0, 0x0f, 0x07, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xf8, 0x0f, 0x87, 0xfc, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x78, 0x07, 0x83, 0xf8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x78, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x03, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x38, 0x03, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x3c, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x3c, 0x01, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x3e, 0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1e, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0f, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + +static const uint8_t __code receive[] = { + 56, 56, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xc0, + 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xf0, + 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xf0, + 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xf0, + 0x00, 0x00, 0x00, 0x01, 0xff, 0xff, 0xf0, + 0x00, 0x00, 0x00, 0x07, 0xff, 0xff, 0xc0, + 0x00, 0x00, 0x00, 0x1f, 0xff, 0x80, 0x00, + 0x00, 0x00, 0x00, 0x7f, 0xf8, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xe0, 0x00, 0x00, + 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x07, 0xfe, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x0f, 0xf8, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x1f, 0xe0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x3f, 0xc0, 0x00, 0x03, 0xe0, + 0x00, 0x00, 0x7f, 0x80, 0x00, 0x7f, 0xf0, + 0x00, 0x00, 0xfe, 0x00, 0x03, 0xff, 0xf0, + 0x00, 0x01, 0xfc, 0x00, 0x0f, 0xff, 0xf0, + 0x00, 0x01, 0xf8, 0x00, 0x3f, 0xff, 0xf0, + 0x00, 0x03, 0xf8, 0x00, 0xff, 0xff, 0x80, + 0x00, 0x07, 0xf0, 0x01, 0xff, 0xe0, 0x00, + 0x00, 0x0f, 0xe0, 0x03, 0xff, 0x00, 0x00, + 0x00, 0x0f, 0xc0, 0x0f, 0xf8, 0x00, 0x00, + 0x00, 0x1f, 0x80, 0x1f, 0xf0, 0x00, 0x00, + 0x00, 0x1f, 0x80, 0x3f, 0xc0, 0x00, 0x00, + 0x00, 0x3f, 0x00, 0x3f, 0x80, 0x00, 0x00, + 0x00, 0x3f, 0x00, 0x7f, 0x00, 0x00, 0x00, + 0x00, 0x7e, 0x00, 0xfe, 0x00, 0x07, 0xe0, + 0x00, 0x7e, 0x01, 0xfc, 0x00, 0x1f, 0xf0, + 0x00, 0xfc, 0x01, 0xf8, 0x00, 0x7f, 0xf0, + 0x00, 0xfc, 0x03, 0xf0, 0x01, 0xff, 0xf0, + 0x00, 0xf8, 0x03, 0xf0, 0x03, 0xff, 0xf0, + 0x01, 0xf8, 0x07, 0xe0, 0x07, 0xff, 0x00, + 0x01, 0xf8, 0x07, 0xe0, 0x0f, 0xf0, 0x00, + 0x01, 0xf0, 0x0f, 0xc0, 0x1f, 0xe0, 0x00, + 0x01, 0xf0, 0x0f, 0xc0, 0x3f, 0x80, 0x00, + 0x03, 0xf0, 0x0f, 0x80, 0x3f, 0x00, 0x00, + 0x03, 0xf0, 0x1f, 0x80, 0x7e, 0x00, 0x00, + 0x03, 0xe0, 0x1f, 0x80, 0x7e, 0x00, 0x00, + 0x03, 0xe0, 0x1f, 0x00, 0xfc, 0x01, 0xe0, + 0x03, 0xe0, 0x1f, 0x00, 0xfc, 0x07, 0xf8, + 0x03, 0xe0, 0x1f, 0x00, 0xf8, 0x0f, 0xfc, + 0x03, 0xe0, 0x3f, 0x00, 0xf8, 0x0f, 0xfc, + 0x03, 0xe0, 0x3f, 0x01, 0xf8, 0x1f, 0xfe, + 0x03, 0xe0, 0x3f, 0x01, 0xf8, 0x1f, 0xfe, + 0x03, 0xe0, 0x3f, 0x01, 0xf8, 0x1f, 0xfe, + 0x03, 0xc0, 0x3e, 0x01, 0xf0, 0x1f, 0xfe, + 0x01, 0xc0, 0x1e, 0x00, 0xf0, 0x0f, 0xfc, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfc, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xf8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +}; + + +static const uint8_t __code failed[] = { + 48, 48, + 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x03, 0xff, 0xff, 0xe0, 0x00, + 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, + 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, + 0x00, 0x7f, 0xf0, 0x0f, 0xfe, 0x00, + 0x00, 0xff, 0x80, 0x01, 0xff, 0x00, + 0x01, 0xfe, 0x00, 0x00, 0x7f, 0x80, + 0x03, 0xf8, 0x00, 0x00, 0x1f, 0xc0, + 0x07, 0xf0, 0x00, 0x00, 0x3f, 0xe0, + 0x0f, 0xe0, 0x00, 0x00, 0x7f, 0xf0, + 0x0f, 0xc0, 0x00, 0x00, 0xff, 0xf0, + 0x1f, 0x80, 0x00, 0x01, 0xff, 0xf8, + 0x1f, 0x00, 0x00, 0x03, 0xff, 0xf8, + 0x3f, 0x00, 0x00, 0x07, 0xfe, 0xfc, + 0x3e, 0x00, 0x00, 0x0f, 0xfc, 0x7c, + 0x7e, 0x00, 0x00, 0x1f, 0xf8, 0x7e, + 0x7c, 0x00, 0x00, 0x3f, 0xf0, 0x3e, + 0x7c, 0x00, 0x00, 0x7f, 0xe0, 0x3e, + 0xfc, 0x00, 0x00, 0xff, 0xc0, 0x3f, + 0xf8, 0x00, 0x01, 0xff, 0x80, 0x1f, + 0xf8, 0x00, 0x03, 0xff, 0x00, 0x1f, + 0xf8, 0x00, 0x07, 0xfe, 0x00, 0x1f, + 0xf8, 0x00, 0x0f, 0xfc, 0x00, 0x1f, + 0xf8, 0x00, 0x1f, 0xf8, 0x00, 0x1f, + 0xf8, 0x00, 0x3f, 0xf0, 0x00, 0x1f, + 0xf8, 0x00, 0x7f, 0xe0, 0x00, 0x1f, + 0xf8, 0x00, 0xff, 0xc0, 0x00, 0x1f, + 0xfc, 0x01, 0xff, 0x80, 0x00, 0x3f, + 0x7c, 0x03, 0xff, 0x00, 0x00, 0x3e, + 0x7c, 0x07, 0xfe, 0x00, 0x00, 0x3e, + 0x7e, 0x0f, 0xfc, 0x00, 0x00, 0x7e, + 0x3e, 0x1f, 0xf8, 0x00, 0x00, 0x7c, + 0x3f, 0x3f, 0xf0, 0x00, 0x00, 0xfc, + 0x3f, 0x7f, 0xe0, 0x00, 0x00, 0xfc, + 0x1f, 0xff, 0xc0, 0x00, 0x01, 0xf8, + 0x0f, 0xff, 0x80, 0x00, 0x03, 0xf0, + 0x0f, 0xff, 0x00, 0x00, 0x07, 0xf0, + 0x07, 0xfe, 0x00, 0x00, 0x0f, 0xe0, + 0x03, 0xfc, 0x00, 0x00, 0x1f, 0xc0, + 0x01, 0xfe, 0x00, 0x00, 0x7f, 0x80, + 0x00, 0xff, 0x80, 0x01, 0xff, 0x00, + 0x00, 0x7f, 0xf0, 0x0f, 0xfe, 0x00, + 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, + 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, + 0x00, 0x03, 0xff, 0xff, 0xe0, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, + 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, +}; + +#endif \ No newline at end of file diff --git a/tag_fw/board/zbs154v033/board.h b/tag_fw/board/zbs154v033/board.h index 6e9a87ee..b5683d58 100644 --- a/tag_fw/board/zbs154v033/board.h +++ b/tag_fw/board/zbs154v033/board.h @@ -4,27 +4,11 @@ #include #include "spi.h" -#include "uart.h" - -//colors for ui messages -#define UI_MSG_MAGNIFY1 1 -#define UI_MSG_MAGNIFY2 1 -#define UI_MSG_MAGNIFY3 1 -#define UI_MSG_BACK_COLOR 4 -#define UI_MSG_FORE_COLOR_1 0 -#define UI_MSG_FORE_COLOR_2 5 -#define UI_MSG_FORE_COLOR_3 5 -#define UI_BARCODE_VERTICAL #define eepromByte spiByte #define eepromPrvSelect() do { __asm__("nop\nnop\nnop\n"); P1_1 = 0; __asm__("nop\nnop\nnop\n"); } while(0) #define eepromPrvDeselect() do { __asm__("nop\nnop\nnop\n"); P1_1 = 1; __asm__("nop\nnop\nnop\n"); } while(0) -//debug uart (enable only when needed, on some boards it inhibits eeprom access) -#define dbgUartOn() -#define dbgUartOff() -#define dbgUartByte uartTx - //eeprom map #define EEPROM_SETTINGS_AREA_START (0x01000UL) #define EEPROM_SETTINGS_AREA_LEN (0x03000UL) @@ -35,19 +19,10 @@ //till end of eeprom really. do not put anything after - it will be erased at pairing time!!! #define EEPROM_PROGRESS_BYTES (128) -//radio cfg -#define RADIO_FIRST_CHANNEL (11) //2.4-GHz channels start at 11 -#define RADIO_NUM_CHANNELS (1) - //hw types #define HW_TYPE_NORMAL HW_TYPE_154_INCH_ZBS_033 -#define HW_TYPE_CYCLING HW_TYPE_154_INCH_ZBS_033_FRAME_MODE - - - #include "../boardCommon.h" - -#endif +#endif \ No newline at end of file diff --git a/tag_fw/board/zbs154v033/screen.h b/tag_fw/board/zbs154v033/screen.h index 2dd805b3..6d1d4997 100644 --- a/tag_fw/board/zbs154v033/screen.h +++ b/tag_fw/board/zbs154v033/screen.h @@ -21,7 +21,7 @@ #define SCREEN_DATA_PASSES 2 - -#endif +#define SCREEN_LUT_LENGTH 10 +#endif \ No newline at end of file diff --git a/tag_fw/board/zbs29v033/board.h b/tag_fw/board/zbs29v033/board.h index 8951cd17..e63b5e11 100644 --- a/tag_fw/board/zbs29v033/board.h +++ b/tag_fw/board/zbs29v033/board.h @@ -4,27 +4,11 @@ #include #include "spi.h" -#include "uart.h" - -//colors for ui messages -#define UI_MSG_MAGNIFY1 1 -#define UI_MSG_MAGNIFY2 1 -#define UI_MSG_MAGNIFY3 1 -#define UI_MSG_BACK_COLOR 4 -#define UI_MSG_FORE_COLOR_1 0 -#define UI_MSG_FORE_COLOR_2 5 -#define UI_MSG_FORE_COLOR_3 5 -#define UI_BARCODE_VERTICAL #define eepromByte spiByte #define eepromPrvSelect() do { __asm__("nop\nnop\nnop\n"); P1_1 = 0; __asm__("nop\nnop\nnop\n"); } while(0) #define eepromPrvDeselect() do { __asm__("nop\nnop\nnop\n"); P1_1 = 1; __asm__("nop\nnop\nnop\n"); } while(0) -//debug uart (enable only when needed, on some boards it inhibits eeprom access) -#define dbgUartOn() -#define dbgUartOff() -#define dbgUartByte uartTx - //eeprom map #define EEPROM_SETTINGS_AREA_START (0x01000UL) #define EEPROM_SETTINGS_AREA_LEN (0x03000UL) @@ -35,19 +19,10 @@ //till end of eeprom really. do not put anything after - it will be erased at pairing time!!! #define EEPROM_PROGRESS_BYTES (128) -//radio cfg -#define RADIO_FIRST_CHANNEL (11) //2.4-GHz channels start at 11 -#define RADIO_NUM_CHANNELS (1) - //hw types #define HW_TYPE_NORMAL HW_TYPE_29_INCH_ZBS_026 -#define HW_TYPE_CYCLING HW_TYPE_29_INCH_ZBS_026_FRAME_MODE - - - #include "../boardCommon.h" - -#endif +#endif \ No newline at end of file diff --git a/tag_fw/board/zbs29v033/screen.h b/tag_fw/board/zbs29v033/screen.h index 576238d5..101e5339 100644 --- a/tag_fw/board/zbs29v033/screen.h +++ b/tag_fw/board/zbs29v033/screen.h @@ -4,12 +4,6 @@ #include #include - -//i hate globals, but for 8051 this makes life a lot easier, sorry :( -extern uint8_t __xdata mScreenVcom; -extern int8_t __xdata mCurTemperature; - - #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 296 @@ -27,22 +21,7 @@ extern int8_t __xdata mCurTemperature; #define SCREEN_DATA_PASSES 2 -void screenShutdown(void); - -void screenTest(void); - -__bit screenTxStart(__bit forPartial); - -void screenEndPass(void); //at end of each pass - -#pragma callee_saves screenByteTx -void screenByteTx(uint8_t byte); -void screenTxEnd(void); - -void screenSleep(void); - -extern uint8_t __xdata mScreenRow[]; //320 bytes used as temp by many on cc where memory is tight - -#endif +#define SCREEN_LUT_LENGTH 7 +#endif \ No newline at end of file diff --git a/tag_fw/board/zbs42v033/board.h b/tag_fw/board/zbs42v033/board.h index b23787ee..0cf71379 100644 --- a/tag_fw/board/zbs42v033/board.h +++ b/tag_fw/board/zbs42v033/board.h @@ -4,27 +4,11 @@ #include #include "spi.h" -#include "uart.h" - -//colors for ui messages -#define UI_MSG_MAGNIFY1 1 -#define UI_MSG_MAGNIFY2 1 -#define UI_MSG_MAGNIFY3 1 -#define UI_MSG_BACK_COLOR 4 -#define UI_MSG_FORE_COLOR_1 0 -#define UI_MSG_FORE_COLOR_2 5 -#define UI_MSG_FORE_COLOR_3 5 -#define UI_BARCODE_VERTICAL #define eepromByte spiByte #define eepromPrvSelect() do { __asm__("nop\nnop\nnop\n"); P1_1 = 0; __asm__("nop\nnop\nnop\n"); } while(0) #define eepromPrvDeselect() do { __asm__("nop\nnop\nnop\n"); P1_1 = 1; __asm__("nop\nnop\nnop\n"); } while(0) -//debug uart (enable only when needed, on some boards it inhibits eeprom access) -#define dbgUartOn() -#define dbgUartOff() -#define dbgUartByte uartTx - //eeprom map #define EEPROM_SETTINGS_AREA_START (0x01000UL) #define EEPROM_SETTINGS_AREA_LEN (0x03000UL) @@ -35,19 +19,10 @@ //till end of eeprom really. do not put anything after - it will be erased at pairing time!!! #define EEPROM_PROGRESS_BYTES (128) -//radio cfg -#define RADIO_FIRST_CHANNEL (11) //2.4-GHz channels start at 11 -#define RADIO_NUM_CHANNELS (1) - //hw types #define HW_TYPE_NORMAL HW_TYPE_42_INCH_ZBS_026 -#define HW_TYPE_CYCLING HW_TYPE_42_INCH_ZBS_026_FRAME_MODE - - - #include "../boardCommon.h" - -#endif +#endif \ No newline at end of file diff --git a/tag_fw/board/zbs42v033/screen.h b/tag_fw/board/zbs42v033/screen.h index e02a55d8..5f7891ff 100644 --- a/tag_fw/board/zbs42v033/screen.h +++ b/tag_fw/board/zbs42v033/screen.h @@ -4,12 +4,6 @@ #include #include - -//i hate globals, but for 8051 this makes life a lot easier, sorry :( -extern uint8_t __xdata mScreenVcom; -extern int8_t __xdata mCurTemperature; - - #define SCREEN_WIDTH 400 #define SCREEN_HEIGHT 300 @@ -27,24 +21,7 @@ extern int8_t __xdata mCurTemperature; #define SCREEN_DATA_PASSES 2 -void screenShutdown(void); - - -void screenTest(void); - -__bit screenTxStart(__bit forPartial); - -void screenEndPass(void); //at end of each pass - -#pragma callee_saves screenByteTx -void screenByteTx(uint8_t byte); -void screenTxEnd(void); - -void screenSleep(void); - - -extern uint8_t __xdata mScreenRow[]; //320 bytes used as temp by many on cc where memory is tight - -#endif +#define SCREEN_LUT_LENGTH 7 +#endif \ No newline at end of file diff --git a/tag_fw/comms.c b/tag_fw/comms.c index 273f81a2..10c6557c 100644 --- a/tag_fw/comms.c +++ b/tag_fw/comms.c @@ -21,34 +21,8 @@ static uint8_t __xdata mCommsBuf[127]; static uint8_t __xdata mSeq = 0; -static uint8_t __xdata mLastLqi = 0; -static int8_t __xdata mLastRSSI = 0; - - -struct MacFrameFromMaster { - struct MacFcs fcs; - uint8_t seq; - uint16_t pan; - uint8_t dst[8]; - uint16_t from; -}; - -struct MacFrameNormal { - struct MacFcs fcs; - uint8_t seq; - uint16_t pan; - uint8_t dst[8]; - uint8_t src[8]; -}; - -struct MacFrameBcast { - struct MacFcs fcs; - uint8_t seq; - uint16_t dstPan; - uint16_t dstAddr; - uint16_t srcPan; - uint8_t src[8]; -}; +uint8_t __xdata mLastLqi = 0; +int8_t __xdata mLastRSSI = 0; uint8_t commsGetLastPacketLQI(void) { diff --git a/tag_fw/comms.h b/tag_fw/comms.h index 7c1c67b9..c80f0113 100644 --- a/tag_fw/comms.h +++ b/tag_fw/comms.h @@ -3,21 +3,16 @@ #include -#define COMMS_MAX_RADIO_WAIT_MSEC 200 -#define COMMS_IV_SIZE (4) //zeroes except these 4 counter bytes +#define COMMS_MAX_RADIO_WAIT_MSEC 200 #define COMMS_RX_ERR_NO_PACKETS (-1) #define COMMS_RX_ERR_INVALID_PACKET (-2) -#define COMMS_RX_ERR_MIC_FAIL (-3) #define COMMS_MAX_PACKET_SZ (127) -#pragma callee_saves commsGetLastPacketLQI -uint8_t commsGetLastPacketLQI(void); - -#pragma callee_saves commsGetLastPacketRSSI -int8_t commsGetLastPacketRSSI(void); +extern uint8_t __xdata mLastLqi; +extern int8_t __xdata mLastRSSI; int8_t commsRxUnencrypted(void __xdata *data); bool commsTxUnencrypted(const void __xdata *packetP, uint8_t len); diff --git a/tag_fw/cpu/8051/printf.c b/tag_fw/cpu/8051/printf.c index 93246c9c..be6dc10c 100644 --- a/tag_fw/cpu/8051/printf.c +++ b/tag_fw/cpu/8051/printf.c @@ -1,795 +1,799 @@ -#include -#include -#include #include "printf.h" -#include "zbs243.h" + +#include +#include +#include + #include "board.h" +#include "epd.h" +#include "uart.h" +#include "zbs243.h" typedef void (*StrFormatOutputFunc)(uint32_t param /* low byte is data, bits 24..31 is char */) __reentrant; -static __idata __at (0x00) unsigned char R0; -static __idata __at (0x01) unsigned char R1; -static __idata __at (0x02) unsigned char R2; -static __idata __at (0x03) unsigned char R3; -static __idata __at (0x04) unsigned char R4; -static __idata __at (0x05) unsigned char R5; -static __idata __at (0x06) unsigned char R6; -static __idata __at (0x07) unsigned char R7; +static __idata __at(0x00) unsigned char R0; +static __idata __at(0x01) unsigned char R1; +static __idata __at(0x02) unsigned char R2; +static __idata __at(0x03) unsigned char R3; +static __idata __at(0x04) unsigned char R4; +static __idata __at(0x05) unsigned char R5; +static __idata __at(0x06) unsigned char R6; +static __idata __at(0x07) unsigned char R7; static uint8_t __xdata mCvtBuf[18]; - -//callback must be reentrant and callee_saves +// callback must be reentrant and callee_saves #pragma callee_saves prvPrintFormat -void prvPrintFormat(StrFormatOutputFunc formatF, uint16_t formatD, const char __code *fmt, va_list vl) __reentrant __naked -{ - //formatF is in DPTR - //sp[0..-1] is return addr - //sp[-2..-3] is formatD - //sp[-4..-5] is fmt - //sp[-6] is vl - - __asm__ ( - " push _R7 \n" - " push DPH \n" //push formatF - " push DPL \n" - " mov _R7, sp \n" //save place on stack where we stashed it so we can call it easily - " push _R4 \n" - " push _R3 \n" - " push _R2 \n" - " push _R1 \n" - " push _R0 \n" - - " mov A, #-12 \n" - " add A, sp \n" - " mov R0, A \n" - //R0 now points to pushed params, for large values, we see high bytes first - // to get next byte, we need to DECEREMENT R0 - - " mov DPH, @R0 \n" - " dec R0 \n" - " mov DPL, @R0 \n" - " dec R0 \n" - " mov _R0, @R0 \n" - " dec R0 \n" - - //now format string is in DPTR, and R0 points to the top byte of whatever was in the first param - - //main loop: get a byte of the format string - "00001$: \n" - " clr A \n" - " movc A, @A + DPTR \n" - " inc DPTR \n" - //if zero, we're done - " jz 00098$ \n" - //if not '%', print it - " cjne A, #'%', 00097$ \n" - - //we got a percent sign - init state for format processing - " mov R4, #0 \n" //bit flags: - // 0x01 = '*' = pointer provided instead of value (integers only) - // 0x02 = '0' = zero-pad (for numbers only) - // 0x04 = have pad-to length - // 0x08 = long - // 0x10 = long long - // 0x20 = signed print requested. also: need to print a negative (used to reuse hex printing for decimal once converted to bcd) - " mov R2, #0 \n" //padLen - - //loop for format string ingestion - "00002$: \n" - " clr A \n" - " movc A, @A + DPTR \n" - " inc DPTR \n" - //if zero, we're done - " jz 00098$ \n" - //check for percent sign - " cjne A, #'%', 00003$ \n" - //fallthrough to print it and go read next non-format byte - //print a char in A, go read next format byte - "00097$: \n" - " lcall 00060$ \n" - " sjmp 00001$ \n" - - //exit label - placed for easy jumping to - "00098$: \n" - " pop _R0 \n" - " pop _R1 \n" - " pop _R2 \n" - " pop _R3 \n" - " pop _R4 \n" - " pop DPL \n" - " pop DPH \n" - " pop _R7 \n" - " ret \n" - - //continue to process format string - handle %c - "00003$: \n" - " cjne A, #'c', 00004$ \n" - " dec R0 \n" //param is pushed as int (16 bits) - " mov A, @R0 \n" - " dec R0 \n" - " sjmp 00097$ \n" //print and go read next non-format byte - - //continue to process format string - handle %m - "00004$: \n" - " mov R3, A \n" - " orl A, #0x20 \n" - " cjne A, #'m', 00008$ \n" - - //sort out which hexch charset to use - " mov A, R3 \n" - " anl A, #0x20 \n" - " rr A \n" - " mov R1, A \n" - - //go, do - " push DPH \n" - " push DPL \n" - " lcall 00090$ \n" //read the short (__xdata) pointer - >DPTR - " mov R4, #8 \n" //byteSel - "00005$: \n" - " push DPH \n" - " push DPL \n" - " mov A, R4 \n" - " dec A \n" - " add A, DPL \n" - " mov DPL, A \n" - " mov A, DPH \n" - " addc A, #0 \n" - " mov DPH, A \n" - " movx A, @DPTR \n" - " mov R2, A \n" - " swap A \n" - " mov R3, #2 \n" - "00006$: \n" - " anl A, #0x0f \n" - " add A, R1 \n" - " mov DPTR, #00099$ \n" - " movc A, @A + DPTR \n" - " lcall 00060$ \n" - " mov A, R2 \n" - " djnz R3, 00006$ \n" - " pop DPL \n" - " pop DPH \n" - " djnz R4, 00007$ \n" - //done with mac addr - - "00055$: \n" - " pop DPL \n" - " pop DPH \n" - " sjmp 00001$ \n" - //print colon and contimue mac addr printing - "00007$: \n" - " mov A, #':' \n" - " lcall 00060$ \n" - " sjmp 00005$ \n" - - //continue to process format string - handle '*' - "00008$: \n" - " mov A, R3 \n" - " cjne A, #'*', 00009$ \n" - " cjne R2, #0, 00097$ \n" //only valid when no length/padding has been specified yet, else invalid specifier - " mov A, #0x01 \n" //"pointer mode" - "00010$: \n" - " orl A, R4 \n" - " mov R4, A \n" - " sjmp 00002$ \n" //get next format specifier now - - //continue to process format string - handle '0' - "00009$: \n" - " cjne A, #'0', 00011$ \n" - " cjne R2, #0, 00011$ \n" //setting "zero pad" is only valid when pad length is zero - " mov A, #0x06 \n" //"have pad length" | "zero-pad" - " sjmp 00010$ \n" //orr A into R4, get next format specifier now - - //continue to process format string - handle '1'...'9' - "00011$: \n" - " mov R3, A \n" - " add A, #-'0' \n" - " jnc 00012$ \n" //now 0..9 are valid - " add A, #-10 \n" - " jc 00012$ \n" - " add A, #10 \n" //get it back into 1..9 range - " mov R3, A \n" - " mov A, #10 \n" - " mov B, R2 \n" - " mul AB \n" - " add A, R3 \n" - " mov R2, A \n" - " mov A, #0x04 \n" //"have pad length" - " sjmp 00010$ \n" //orr A into R4, get next format specifier now - - //continue to process format string - handle 'l' - "00012$: \n" - " cjne R3, #'l', 00014$ \n" - " mov A, R4 \n" - " anl A, #0x08 \n" - " jz 00013$ \n" //no "long" yet? set that - //have long - set long log - " mov A, #0x10 \n" //"long long" - " sjmp 00010$ \n" //orr A into R4, get next format specifier now - //first 'l' - set long - "00013$: \n" - " mov A, #0x08 \n" //"long" - " sjmp 00010$ \n" //orr A into R4, get next format specifier now - - //continue to process format string - handle 's' - "00014$: \n" - " cjne R3, #'s', 00025$ \n" - " mov A, R4 \n" - " anl A, #0x08 \n" - " push DPH \n" - " push DPL \n" - " jnz 00015$ \n" - " lcall 00091$ \n" //get and resolve generic pointer into DPTR - " sjmp 00016$ \n" - "00015$: \n" //get short pointer into DPTR, record that it is to XRAM - " clr PSW.5 \n" - " clr PSW.1 \n" - " lcall 00090$ \n" - "00016$: \n" //pointer to string now in DPTR - //we have the string pointer in {DPTR,PSW}, let's see if we have padding to do - " mov A, R4 \n" - " anl A, #0x04 \n" - " jnz 00018$ \n" - //print string with no length restrictions - "00017$: \n" - " lcall 00095$ \n" - " jz 00055$ \n" - " lcall 00060$ \n" - " sjmp 00017$ \n" - - //print string with length restrictions and/or padding - "00018$: \n" - " cjne R2, #0, 00019$ \n" //verify reqested len was not zero - " sjmp 00055$ \n" - - "00019$: \n" - " lcall 00095$ \n" - " jz 00020$ \n" - " lcall 00060$ \n" - " djnz R2, 00019$ \n" - //we get here if we ran out of allowable bytes - we're done then - " ljmp 00055$ \n" - - //just a trampoline for range issues - "00035$: \n" - " ljmp 00036$ \n" - - //we need to pad with spaces - "00020$: \n" - " mov A, #' ' \n" - " lcall 00060$ \n" - " djnz R2, 00020$ \n" - " ljmp 00055$ \n" - - //continue to process format string - handle 'x'/'X' - "00025$: \n" - " mov A, R3 \n" - " orl A, #0x20 \n" - " cjne A, #'x', 00035$ \n" - " push DPH \n" - " push DPL \n" - " lcall 00080$ \n" //get pointer to the number in DPTR, length in bytes in B - //save it - - "00070$: \n" - " push DPH \n" - " push DPL \n" - - //sort out how long it would be if printed, first get a pointer to the highest - " mov A, B \n" - " rl A \n" - " mov R1, A \n" - " rr A \n" - " add A, #0xff \n" - " add A, DPL \n" - " mov DPL, A \n" - " mov A, DPH \n" - " addc A, #0x00 \n" - " mov DPH, A \n" - "00026$: \n" - " lcall 00079$ \n" - " anl A, #0xf0 \n" - " jnz 00028$ \n" - " dec R1 \n" - " lcall 00079$ \n" - " jnz 00028$ \n" - " dec R1 \n" - //dec DPTR - " dec DPL \n" - " mov A, DPL \n" - " cjne A, #0xff, 00027$ \n" - " dec DPH \n" - "00027$: \n" - " djnz B, 00026$ \n" - - //we now know how many digits the number is (in R1), except that it has "0" if the number if zero, we cannot have that - "00028$: \n" - " cjne R1, #0, 00029$ \n" - " inc R1 \n" - "00029$: \n" //we now finally have the full length of the digits - - //if the number is negative (happens when we're printing decimals) - // the length of it is one more, also in case of zero-padding, we need to print the minus sign here now - " mov A, R4 \n" - " anl A, #0x20 \n" - " jz 00051$ \n" - " inc R1 \n" //the length is one more - " mov A, R4 \n" - " anl A, #02 \n" //if zero-padding, the negative comes now - " jz 00051$ \n" - " mov A, #'-' \n" - " lcall 00060$ \n" - "00051$: \n" - - //sort out if we need padding at all and if there is space - " mov A, R4 \n" - " anl A, #0x04 \n" - " jz 00031$ \n" //no padding requested - //padding was requested len is in R2 - " mov A, R2 \n" - " clr C \n" - " subb A, R1 \n" - " jc 00031$ \n" //pad-to len < number_len -> no padding needed - " jz 00031$ \n" //pad-to len == number_len -> no padding needed - " mov R2, A \n" - - //sort out which character to use -> DPL - " mov A, R4 \n" //fancy way to create space/zero as needed - " anl A, #0x02 \n" - " swap A \n" - " rr A \n" - " add A, #0x20 \n" - " mov DPL, A \n" - - //pad! - "00030$: \n" - " mov A, DPL \n" - " lcall 00060$ \n" - " djnz R2, 00030$ \n" - "00031$: \n" - - //if the number is negative (happens when we're printing decimals) - // we made the length of it is one more, which we need to undo - // also in case of space-padding, we need to print the minus sign here now - " mov A, R4 \n" - " anl A, #0x20 \n" - " jz 00052$ \n" - " dec R1 \n" //the length is one less than we had increased it to - " mov A, R4 \n" - " anl A, #02 \n" //if space-padding, the negative comes now - " jnz 00052$ \n" - " mov A, #'-' \n" - " lcall 00060$ \n" - "00052$: \n" - - //time to print the number itself - //sort out which hexch charset to use -> R2 - " mov A, R3 \n" - " anl A, #0x20 \n" - " rr A \n" - " mov R2, A \n" - //re-get the number pointer - " pop DPL \n" - " pop DPH \n" - //currently DPTR points to the number low byte, R1 is now many digits we expect to print, R2 is the charset selection, R4 and R3 are free - //let's calculate how many bytes we expect to process -> R4 - " mov A, R1 \n" - " inc A \n" - " clr C \n" - " rrc A \n" - " mov R4, A \n" - //let's repoint DPTR to the first byte we'll print in (remember we print 2 digits per byte) - " dec A \n" - " add A, DPL \n" - " mov DPL, A \n" - " mov A, DPH \n" - " addc A, #0x00 \n" - " mov DPH, A \n" - - //decide if we need to print just a nibble of the high byte or the whole thing. Free up R1 - " mov A, R1 \n" - " anl A, #0x01 \n" - " jz 00032$ \n" - - //we're printing just the low nibble of the first byte - set up for it - " lcall 00079$ \n" - " mov R1, #1 \n" - " sjmp 00033$ \n" - - //print loop - "00032$: \n" - " lcall 00079$ \n" - " mov R1, #2 \n" - " mov R3, A \n" - " swap A \n" - "00033$: \n" - " anl A, #0x0f \n" - " add A, R2 \n" - " push DPH \n" - " push DPL \n" - " mov DPTR, #00099$ \n" - " movc A, @A + DPTR \n" - " pop DPL \n" - " pop DPH \n" - " lcall 00060$ \n" - " mov A, R3 \n" - " djnz R1, 00033$ \n" - - //dec DPTR - " dec DPL \n" - " mov A, DPL \n" - " cjne A, #0xff, 00034$ \n" - " dec DPH \n" - "00034$: \n" - " djnz R4, 00032$ \n" - - //done! - " ljmp 00055$ \n" - - //continue to process format string - handle 'd' - "00036$: \n" - " cjne R3, #'d', 00037$ \n" - " mov A, #0x20 \n" - " orl A, R4 \n" - " mov R4, A \n" - " sjmp 00040$ \n" - - //continue to process format string - handle 'u' - "00037$: \n" - " cjne R3, #'u', 00038$ \n" - " sjmp 00040$ \n" - - //no more format strings exist that we can handle - bail - "00038$: \n" - " ljmp 00001$ \n" - - //handle decimal printing - "00040$: \n" - " push DPH \n" - " push DPL \n" - " lcall 00080$ \n" //get pointer to the number in DPTR, length in bytes in B - " push B \n" - - //copy the number to the double-dabble storage at proper offset (0 for u64, 4 for u32, 6 for u16) - //we do this so that the dabble area always starts at the same place... - " mov A, #8 \n" - " clr C \n" - " subb A, B \n" - " add A, #_mCvtBuf \n" - " mov R1, A \n" - " clr A \n" - " addc A, #(_mCvtBuf >> 8) \n" - " mov R3, A \n" - "00041$: \n" - " lcall 00079$ \n" - " inc DPTR \n" - " lcall 00086$ \n" - " movx @DPTR, A \n" - " inc DPTR \n" - " lcall 00086$ \n" - " djnz B, 00041$ \n" - //leave DPTR pointing to dabble storage, past the number - " lcall 00086$ \n" - - //we now have the top byte of the number in A, good time to check for negatives, if needed - " mov B, A \n" - " mov A, R4 \n" - " anl A, #0x20 \n" - " jz 00050$ \n" //unsigned printing requested - " mov A, B \n" - " anl A, #0x80 \n" - " jnz 00043$ \n" //is negative - we need to invert, 0x20 bit in R1 stays - //positive - 0x20 bit in R1 needs to go - " mov A, R4 \n" - " anl A, #~0x20 \n" - " mov R4, A \n" - " sjmp 00050$ \n" - - //we need to negate the number - // but first we need a pointer to it, and its size - "00043$: \n" - " pop B \n" - " push B \n" - " mov A, #8 \n" - " clr C \n" - " subb A, B \n" - " add A, #_mCvtBuf \n" - " mov DPL, A \n" - " clr A \n" - " addc A, #(_mCvtBuf >> 8) \n" - " mov DPH, A \n" - - //ok, now we are ready to negate it - " clr C \n" - "00049$: \n" - " movx A, @DPTR \n" - " mov R1, A \n" - " clr A \n" - " subb A, R1 \n" - " movx @DPTR, A \n" - " inc DPTR \n" - " djnz B, 00049$ \n" - - //zero out the rest of the storage (10 bytes) - "00050$: \n" - " mov B, #10 \n" - " clr A \n" - "00042$: \n" - " movx @DPTR, A \n" - " inc DPTR \n" - " djnz B, 00042$ \n" - - //calculate number of dabble steps - " pop A \n" - " swap A \n" - " rr A \n" - " mov R3, A \n" - - //do the thing - "00044$: \n" - - //dabble (10 iters for simplicity) - " mov DPTR, #(_mCvtBuf + 8) \n" - " mov B, #10 \n" - "00046$: \n" - " movx A, @DPTR \n" - " mov R1, A \n" - " anl A, #0x0f \n" - " add A,#-0x05 \n" - " mov A, R1 \n" - " jnc 00047$ \n" - " add A, #0x03 \n" - "00047$: \n" - " mov R1, A \n" - " anl A, #0xf0 \n" - " add A,#-0x50 \n" - " mov A, R1 \n" - " jnc 00048$ \n" - " add A, #0x30 \n" - "00048$: \n" - " movx @DPTR, A \n" - " inc DPTR \n" - " djnz B, 00046$ \n" - - //double (18 iters for simplicity) - " mov DPTR, #_mCvtBuf \n" - " clr C \n" - " mov B, #18 \n" - "00045$: \n" - " movx A, @DPTR \n" - " rlc A \n" - " movx @DPTR, A \n" - " inc DPTR \n" - " djnz B, 00045$ \n" - - " djnz R3, 00044$ \n" - - //dabbling is done, print it now using hex routine - " mov DPTR, #(_mCvtBuf + 8) \n" - " mov B, #10 \n" - " clr PSW.5 \n" //it is now for sure in XRAM - " ljmp 00070$ \n" - - //read short pointer from param stack - "00090$: \n" - " mov DPH, @R0 \n" - "00093$: \n" - " dec R0 \n" - " mov DPL, @R0 \n" - " dec R0 \n" - " ret \n" - - //read and increment pointer of the type provided by 00091$ (in {DPTR,PSW}) into A. clobber nothing - "00095$: \n" - " jb PSW.5, 00066$ \n" - " jb PSW.1, 00067$ \n" - //XRAM - " movx A, @DPTR \n" - " inc DPTR \n" - " ret \n" - //CODE - "00066$: \n" - " clr A \n" - " movc A, @A+DPTR \n" - " inc DPTR \n" - " ret \n" - //IRAM - "00067$: \n" - " mov DPH, R0 \n" - " mov R0, DPL \n" - " mov A, @R0 \n" - " mov R0, DPH \n" - " inc DPL \n" - " ret \n" - - //resolve generic pointer on param stack to an pointer in DPTR and flags in PSW.5 and PSW.1 - //PSW.5 will be 0 and PSW.1 will be 0 for XRAM (PDATA goes here too) - //PSW.5 will be 1 and PSW.1 will be 0 for CODE - //PSW.5 will be 0 and PSW.1 will be 1 for IRAM - "00091$: \n" - " clr PSW.5 \n" - " clr PSW.1 \n" - " mov A, @R0 \n" - " dec R0 \n" - " jz 00090$ \n" //0x00: pointer type: xdata - " xrl A, #0x80 \n" - " jz 00094$ \n" //0x80: pointer type: code - " xrl A, #0xc0 \n" - " jz 00092$ \n" //0x40: pointer type: idata - //pdata - " mov DPH, _XPAGE \n" - " sjmp 00093$ \n" - //idata - "00092$: \n" - " setb PSW.1 \n" - " sjmp 00093$ \n" - //code - "00094$: \n" - " setb PSW.5 \n" - " sjmp 00090$ \n" - - //read the pointer of the type that 00080$ returns (in DPTR) into A. clobber nothing - "00079$: \n" - " jnb PSW.5, 00078$ \n" - " push _R0 \n" - " mov R0, DPL \n" - " mov A, @R0 \n" - " pop _R0 \n" - " ret \n" - "00078$: \n" - " movx A, @DPTR \n" - " ret \n" - - //get pointer to a number, might be pushed or might be pointed to, size might vary. return pointer to number's LOW byte in DPTR - "00080$: \n" - " mov A, R4 \n" - " anl A, #0x01 \n" - " jnz 00083$ \n" - //param is itself on stack - now we care about size, but either way, PSW.5 will be 1 - " setb PSW.5 \n" - " mov B, #0 \n" - " mov A, R4 \n" - " anl A, #0x18 \n" - " jz 00081$ \n" - " anl A, #0x10 \n" - " jz 00082$ \n" - //long long (8 bytes) \n" - " setb B.2 \n" - " dec R0 \n" - " dec R0 \n" - " dec R0 \n" - " dec R0 \n" - //long (4 bytes) - "00082$: \n" - " setb B.1 \n" - " dec R0 \n" - " dec R0 \n" - //int (2 bytes) \n" - "00081$: \n" - " setb B.0 \n" - " dec R0 \n" - " mov DPL, R0 \n" - " dec R0 \n" - " inc B \n" - " ret \n" - //pointer it on stack itself, number is in xram, but we still need to provide the length - "00083$: \n" - " clr PSW.5 \n" //mark as "in xram" - " mov A, R4 \n" - " anl A, #0x18 \n" - " jz 00084$ \n" - " anl A, #0x10 \n" - " jz 00085$ \n" - //long long - " mov B, #8 \n" - " ljmp 00090$ \n" - //long - "00085$: \n" - " mov B, #4 \n" - " ljmp 00090$ \n" - //int - "00084$: \n" - " mov B, #2 \n" - " ljmp 00090$ \n" +void prvPrintFormat(StrFormatOutputFunc formatF, uint16_t formatD, const char __code *fmt, va_list vl) __reentrant __naked { + // formatF is in DPTR + // sp[0..-1] is return addr + // sp[-2..-3] is formatD + // sp[-4..-5] is fmt + // sp[-6] is vl - //swap R3:R1 <-> DPH:DPL - "00086$: \n" - " xch A, DPH \n" - " xch A, R3 \n" - " xch A, DPH \n" - " xch A, DPL \n" - " xch A, R1 \n" - " xch A, DPL \n" - " ret \n" + __asm__( + " push _R7 \n" + " push DPH \n" // push formatF + " push DPL \n" + " mov _R7, sp \n" // save place on stack where we stashed it so we can call it easily + " push _R4 \n" + " push _R3 \n" + " push _R2 \n" + " push _R1 \n" + " push _R0 \n" - /* putchar func - called via call. char is in A, R7 has pointer to stack as needed - can clobber B, CANNOT clobber DPTR - a mess because...8051 - */ - "00060$: \n" - " push DPH \n" - " push DPL \n" - " push _R1 \n" - " push _R0 \n" - " mov _R0, R7 \n" - " mov DPL, @R0 \n" - " dec R0 \n" - " mov DPH, @R0 \n" //DPTR is now func ptr - " dec R0 \n" - " dec R0 \n" - " dec R0 \n" - " dec R0 \n" - " mov _R1, @R0 \n" - " dec R0 \n" - " mov _R0, @R0 \n" //R1:R0 is now "formatD" - " lcall 00061$ \n" //to set ret addr - " pop _R0 \n" - " pop _R1 \n" - " pop DPL \n" - " pop DPH \n" - " ret \n" - "00061$: \n" - " push DPL \n" - " push DPH \n" - " mov DPL, _R0 \n" - " mov DPH, _R1 \n" - " ret \n" - - "00099$: \n" - " .ascii \"01234567\" \n" - " .ascii \"89ABCDEF\" \n" - " .ascii \"01234567\" \n" - " .ascii \"89abcdef\" \n" - ); - (void)fmt; - (void)vl; - (void)formatF; - (void)formatD; + " mov A, #-12 \n" + " add A, sp \n" + " mov R0, A \n" + // R0 now points to pushed params, for large values, we see high bytes first + // to get next byte, we need to DECEREMENT R0 + + " mov DPH, @R0 \n" + " dec R0 \n" + " mov DPL, @R0 \n" + " dec R0 \n" + " mov _R0, @R0 \n" + " dec R0 \n" + + // now format string is in DPTR, and R0 points to the top byte of whatever was in the first param + + // main loop: get a byte of the format string + "00001$: \n" + " clr A \n" + " movc A, @A + DPTR \n" + " inc DPTR \n" + // if zero, we're done + " jz 00098$ \n" + // if not '%', print it + " cjne A, #'%', 00097$ \n" + + // we got a percent sign - init state for format processing + " mov R4, #0 \n" // bit flags: + // 0x01 = '*' = pointer provided instead of value (integers only) + // 0x02 = '0' = zero-pad (for numbers only) + // 0x04 = have pad-to length + // 0x08 = long + // 0x10 = long long + // 0x20 = signed print requested. also: need to print a negative (used to reuse hex printing for decimal once converted to bcd) + " mov R2, #0 \n" // padLen + + // loop for format string ingestion + "00002$: \n" + " clr A \n" + " movc A, @A + DPTR \n" + " inc DPTR \n" + // if zero, we're done + " jz 00098$ \n" + // check for percent sign + " cjne A, #'%', 00003$ \n" + // fallthrough to print it and go read next non-format byte + // print a char in A, go read next format byte + "00097$: \n" + " lcall 00060$ \n" + " sjmp 00001$ \n" + + // exit label - placed for easy jumping to + "00098$: \n" + " pop _R0 \n" + " pop _R1 \n" + " pop _R2 \n" + " pop _R3 \n" + " pop _R4 \n" + " pop DPL \n" + " pop DPH \n" + " pop _R7 \n" + " ret \n" + + // continue to process format string - handle %c + "00003$: \n" + " cjne A, #'c', 00004$ \n" + " dec R0 \n" // param is pushed as int (16 bits) + " mov A, @R0 \n" + " dec R0 \n" + " sjmp 00097$ \n" // print and go read next non-format byte + + // continue to process format string - handle %m + "00004$: \n" + " mov R3, A \n" + " orl A, #0x20 \n" + " cjne A, #'m', 00008$ \n" + + // sort out which hexch charset to use + " mov A, R3 \n" + " anl A, #0x20 \n" + " rr A \n" + " mov R1, A \n" + + // go, do + " push DPH \n" + " push DPL \n" + " lcall 00090$ \n" // read the short (__xdata) pointer - >DPTR + " mov R4, #8 \n" // byteSel + "00005$: \n" + " push DPH \n" + " push DPL \n" + " mov A, R4 \n" + " dec A \n" + " add A, DPL \n" + " mov DPL, A \n" + " mov A, DPH \n" + " addc A, #0 \n" + " mov DPH, A \n" + " movx A, @DPTR \n" + " mov R2, A \n" + " swap A \n" + " mov R3, #2 \n" + "00006$: \n" + " anl A, #0x0f \n" + " add A, R1 \n" + " mov DPTR, #00099$ \n" + " movc A, @A + DPTR \n" + " lcall 00060$ \n" + " mov A, R2 \n" + " djnz R3, 00006$ \n" + " pop DPL \n" + " pop DPH \n" + " djnz R4, 00007$ \n" + // done with mac addr + + "00055$: \n" + " pop DPL \n" + " pop DPH \n" + " sjmp 00001$ \n" + // print colon and contimue mac addr printing + "00007$: \n" + " mov A, #':' \n" + " lcall 00060$ \n" + " sjmp 00005$ \n" + + // continue to process format string - handle '*' + "00008$: \n" + " mov A, R3 \n" + " cjne A, #'*', 00009$ \n" + " cjne R2, #0, 00097$ \n" // only valid when no length/padding has been specified yet, else invalid specifier + " mov A, #0x01 \n" //"pointer mode" + "00010$: \n" + " orl A, R4 \n" + " mov R4, A \n" + " sjmp 00002$ \n" // get next format specifier now + + // continue to process format string - handle '0' + "00009$: \n" + " cjne A, #'0', 00011$ \n" + " cjne R2, #0, 00011$ \n" // setting "zero pad" is only valid when pad length is zero + " mov A, #0x06 \n" //"have pad length" | "zero-pad" + " sjmp 00010$ \n" // orr A into R4, get next format specifier now + + // continue to process format string - handle '1'...'9' + "00011$: \n" + " mov R3, A \n" + " add A, #-'0' \n" + " jnc 00012$ \n" // now 0..9 are valid + " add A, #-10 \n" + " jc 00012$ \n" + " add A, #10 \n" // get it back into 1..9 range + " mov R3, A \n" + " mov A, #10 \n" + " mov B, R2 \n" + " mul AB \n" + " add A, R3 \n" + " mov R2, A \n" + " mov A, #0x04 \n" //"have pad length" + " sjmp 00010$ \n" // orr A into R4, get next format specifier now + + // continue to process format string - handle 'l' + "00012$: \n" + " cjne R3, #'l', 00014$ \n" + " mov A, R4 \n" + " anl A, #0x08 \n" + " jz 00013$ \n" // no "long" yet? set that + // have long - set long log + " mov A, #0x10 \n" //"long long" + " sjmp 00010$ \n" // orr A into R4, get next format specifier now + // first 'l' - set long + "00013$: \n" + " mov A, #0x08 \n" //"long" + " sjmp 00010$ \n" // orr A into R4, get next format specifier now + + // continue to process format string - handle 's' + "00014$: \n" + " cjne R3, #'s', 00025$ \n" + " mov A, R4 \n" + " anl A, #0x08 \n" + " push DPH \n" + " push DPL \n" + " jnz 00015$ \n" + " lcall 00091$ \n" // get and resolve generic pointer into DPTR + " sjmp 00016$ \n" + "00015$: \n" // get short pointer into DPTR, record that it is to XRAM + " clr PSW.5 \n" + " clr PSW.1 \n" + " lcall 00090$ \n" + "00016$: \n" // pointer to string now in DPTR + // we have the string pointer in {DPTR,PSW}, let's see if we have padding to do + " mov A, R4 \n" + " anl A, #0x04 \n" + " jnz 00018$ \n" + // print string with no length restrictions + "00017$: \n" + " lcall 00095$ \n" + " jz 00055$ \n" + " lcall 00060$ \n" + " sjmp 00017$ \n" + + // print string with length restrictions and/or padding + "00018$: \n" + " cjne R2, #0, 00019$ \n" // verify reqested len was not zero + " sjmp 00055$ \n" + + "00019$: \n" + " lcall 00095$ \n" + " jz 00020$ \n" + " lcall 00060$ \n" + " djnz R2, 00019$ \n" + // we get here if we ran out of allowable bytes - we're done then + " ljmp 00055$ \n" + + // just a trampoline for range issues + "00035$: \n" + " ljmp 00036$ \n" + + // we need to pad with spaces + "00020$: \n" + " mov A, #' ' \n" + " lcall 00060$ \n" + " djnz R2, 00020$ \n" + " ljmp 00055$ \n" + + // continue to process format string - handle 'x'/'X' + "00025$: \n" + " mov A, R3 \n" + " orl A, #0x20 \n" + " cjne A, #'x', 00035$ \n" + " push DPH \n" + " push DPL \n" + " lcall 00080$ \n" // get pointer to the number in DPTR, length in bytes in B + // save it + + "00070$: \n" + " push DPH \n" + " push DPL \n" + + // sort out how long it would be if printed, first get a pointer to the highest + " mov A, B \n" + " rl A \n" + " mov R1, A \n" + " rr A \n" + " add A, #0xff \n" + " add A, DPL \n" + " mov DPL, A \n" + " mov A, DPH \n" + " addc A, #0x00 \n" + " mov DPH, A \n" + "00026$: \n" + " lcall 00079$ \n" + " anl A, #0xf0 \n" + " jnz 00028$ \n" + " dec R1 \n" + " lcall 00079$ \n" + " jnz 00028$ \n" + " dec R1 \n" + // dec DPTR + " dec DPL \n" + " mov A, DPL \n" + " cjne A, #0xff, 00027$ \n" + " dec DPH \n" + "00027$: \n" + " djnz B, 00026$ \n" + + // we now know how many digits the number is (in R1), except that it has "0" if the number if zero, we cannot have that + "00028$: \n" + " cjne R1, #0, 00029$ \n" + " inc R1 \n" + "00029$: \n" // we now finally have the full length of the digits + + // if the number is negative (happens when we're printing decimals) + // the length of it is one more, also in case of zero-padding, we need to print the minus sign here now + " mov A, R4 \n" + " anl A, #0x20 \n" + " jz 00051$ \n" + " inc R1 \n" // the length is one more + " mov A, R4 \n" + " anl A, #02 \n" // if zero-padding, the negative comes now + " jz 00051$ \n" + " mov A, #'-' \n" + " lcall 00060$ \n" + "00051$: \n" + + // sort out if we need padding at all and if there is space + " mov A, R4 \n" + " anl A, #0x04 \n" + " jz 00031$ \n" // no padding requested + // padding was requested len is in R2 + " mov A, R2 \n" + " clr C \n" + " subb A, R1 \n" + " jc 00031$ \n" // pad-to len < number_len -> no padding needed + " jz 00031$ \n" // pad-to len == number_len -> no padding needed + " mov R2, A \n" + + // sort out which character to use -> DPL + " mov A, R4 \n" // fancy way to create space/zero as needed + " anl A, #0x02 \n" + " swap A \n" + " rr A \n" + " add A, #0x20 \n" + " mov DPL, A \n" + + // pad! + "00030$: \n" + " mov A, DPL \n" + " lcall 00060$ \n" + " djnz R2, 00030$ \n" + "00031$: \n" + + // if the number is negative (happens when we're printing decimals) + // we made the length of it is one more, which we need to undo + // also in case of space-padding, we need to print the minus sign here now + " mov A, R4 \n" + " anl A, #0x20 \n" + " jz 00052$ \n" + " dec R1 \n" // the length is one less than we had increased it to + " mov A, R4 \n" + " anl A, #02 \n" // if space-padding, the negative comes now + " jnz 00052$ \n" + " mov A, #'-' \n" + " lcall 00060$ \n" + "00052$: \n" + + // time to print the number itself + // sort out which hexch charset to use -> R2 + " mov A, R3 \n" + " anl A, #0x20 \n" + " rr A \n" + " mov R2, A \n" + // re-get the number pointer + " pop DPL \n" + " pop DPH \n" + // currently DPTR points to the number low byte, R1 is now many digits we expect to print, R2 is the charset selection, R4 and R3 are free + // let's calculate how many bytes we expect to process -> R4 + " mov A, R1 \n" + " inc A \n" + " clr C \n" + " rrc A \n" + " mov R4, A \n" + // let's repoint DPTR to the first byte we'll print in (remember we print 2 digits per byte) + " dec A \n" + " add A, DPL \n" + " mov DPL, A \n" + " mov A, DPH \n" + " addc A, #0x00 \n" + " mov DPH, A \n" + + // decide if we need to print just a nibble of the high byte or the whole thing. Free up R1 + " mov A, R1 \n" + " anl A, #0x01 \n" + " jz 00032$ \n" + + // we're printing just the low nibble of the first byte - set up for it + " lcall 00079$ \n" + " mov R1, #1 \n" + " sjmp 00033$ \n" + + // print loop + "00032$: \n" + " lcall 00079$ \n" + " mov R1, #2 \n" + " mov R3, A \n" + " swap A \n" + "00033$: \n" + " anl A, #0x0f \n" + " add A, R2 \n" + " push DPH \n" + " push DPL \n" + " mov DPTR, #00099$ \n" + " movc A, @A + DPTR \n" + " pop DPL \n" + " pop DPH \n" + " lcall 00060$ \n" + " mov A, R3 \n" + " djnz R1, 00033$ \n" + + // dec DPTR + " dec DPL \n" + " mov A, DPL \n" + " cjne A, #0xff, 00034$ \n" + " dec DPH \n" + "00034$: \n" + " djnz R4, 00032$ \n" + + // done! + " ljmp 00055$ \n" + + // continue to process format string - handle 'd' + "00036$: \n" + " cjne R3, #'d', 00037$ \n" + " mov A, #0x20 \n" + " orl A, R4 \n" + " mov R4, A \n" + " sjmp 00040$ \n" + + // continue to process format string - handle 'u' + "00037$: \n" + " cjne R3, #'u', 00038$ \n" + " sjmp 00040$ \n" + + // no more format strings exist that we can handle - bail + "00038$: \n" + " ljmp 00001$ \n" + + // handle decimal printing + "00040$: \n" + " push DPH \n" + " push DPL \n" + " lcall 00080$ \n" // get pointer to the number in DPTR, length in bytes in B + " push B \n" + + // copy the number to the double-dabble storage at proper offset (0 for u64, 4 for u32, 6 for u16) + // we do this so that the dabble area always starts at the same place... + " mov A, #8 \n" + " clr C \n" + " subb A, B \n" + " add A, #_mCvtBuf \n" + " mov R1, A \n" + " clr A \n" + " addc A, #(_mCvtBuf >> 8) \n" + " mov R3, A \n" + "00041$: \n" + " lcall 00079$ \n" + " inc DPTR \n" + " lcall 00086$ \n" + " movx @DPTR, A \n" + " inc DPTR \n" + " lcall 00086$ \n" + " djnz B, 00041$ \n" + // leave DPTR pointing to dabble storage, past the number + " lcall 00086$ \n" + + // we now have the top byte of the number in A, good time to check for negatives, if needed + " mov B, A \n" + " mov A, R4 \n" + " anl A, #0x20 \n" + " jz 00050$ \n" // unsigned printing requested + " mov A, B \n" + " anl A, #0x80 \n" + " jnz 00043$ \n" // is negative - we need to invert, 0x20 bit in R1 stays + // positive - 0x20 bit in R1 needs to go + " mov A, R4 \n" + " anl A, #~0x20 \n" + " mov R4, A \n" + " sjmp 00050$ \n" + + // we need to negate the number + // but first we need a pointer to it, and its size + "00043$: \n" + " pop B \n" + " push B \n" + " mov A, #8 \n" + " clr C \n" + " subb A, B \n" + " add A, #_mCvtBuf \n" + " mov DPL, A \n" + " clr A \n" + " addc A, #(_mCvtBuf >> 8) \n" + " mov DPH, A \n" + + // ok, now we are ready to negate it + " clr C \n" + "00049$: \n" + " movx A, @DPTR \n" + " mov R1, A \n" + " clr A \n" + " subb A, R1 \n" + " movx @DPTR, A \n" + " inc DPTR \n" + " djnz B, 00049$ \n" + + // zero out the rest of the storage (10 bytes) + "00050$: \n" + " mov B, #10 \n" + " clr A \n" + "00042$: \n" + " movx @DPTR, A \n" + " inc DPTR \n" + " djnz B, 00042$ \n" + + // calculate number of dabble steps + " pop A \n" + " swap A \n" + " rr A \n" + " mov R3, A \n" + + // do the thing + "00044$: \n" + + // dabble (10 iters for simplicity) + " mov DPTR, #(_mCvtBuf + 8) \n" + " mov B, #10 \n" + "00046$: \n" + " movx A, @DPTR \n" + " mov R1, A \n" + " anl A, #0x0f \n" + " add A,#-0x05 \n" + " mov A, R1 \n" + " jnc 00047$ \n" + " add A, #0x03 \n" + "00047$: \n" + " mov R1, A \n" + " anl A, #0xf0 \n" + " add A,#-0x50 \n" + " mov A, R1 \n" + " jnc 00048$ \n" + " add A, #0x30 \n" + "00048$: \n" + " movx @DPTR, A \n" + " inc DPTR \n" + " djnz B, 00046$ \n" + + // double (18 iters for simplicity) + " mov DPTR, #_mCvtBuf \n" + " clr C \n" + " mov B, #18 \n" + "00045$: \n" + " movx A, @DPTR \n" + " rlc A \n" + " movx @DPTR, A \n" + " inc DPTR \n" + " djnz B, 00045$ \n" + + " djnz R3, 00044$ \n" + + // dabbling is done, print it now using hex routine + " mov DPTR, #(_mCvtBuf + 8) \n" + " mov B, #10 \n" + " clr PSW.5 \n" // it is now for sure in XRAM + " ljmp 00070$ \n" + + // read short pointer from param stack + "00090$: \n" + " mov DPH, @R0 \n" + "00093$: \n" + " dec R0 \n" + " mov DPL, @R0 \n" + " dec R0 \n" + " ret \n" + + // read and increment pointer of the type provided by 00091$ (in {DPTR,PSW}) into A. clobber nothing + "00095$: \n" + " jb PSW.5, 00066$ \n" + " jb PSW.1, 00067$ \n" + // XRAM + " movx A, @DPTR \n" + " inc DPTR \n" + " ret \n" + // CODE + "00066$: \n" + " clr A \n" + " movc A, @A+DPTR \n" + " inc DPTR \n" + " ret \n" + // IRAM + "00067$: \n" + " mov DPH, R0 \n" + " mov R0, DPL \n" + " mov A, @R0 \n" + " mov R0, DPH \n" + " inc DPL \n" + " ret \n" + + // resolve generic pointer on param stack to an pointer in DPTR and flags in PSW.5 and PSW.1 + // PSW.5 will be 0 and PSW.1 will be 0 for XRAM (PDATA goes here too) + // PSW.5 will be 1 and PSW.1 will be 0 for CODE + // PSW.5 will be 0 and PSW.1 will be 1 for IRAM + "00091$: \n" + " clr PSW.5 \n" + " clr PSW.1 \n" + " mov A, @R0 \n" + " dec R0 \n" + " jz 00090$ \n" // 0x00: pointer type: xdata + " xrl A, #0x80 \n" + " jz 00094$ \n" // 0x80: pointer type: code + " xrl A, #0xc0 \n" + " jz 00092$ \n" // 0x40: pointer type: idata + // pdata + " mov DPH, _XPAGE \n" + " sjmp 00093$ \n" + // idata + "00092$: \n" + " setb PSW.1 \n" + " sjmp 00093$ \n" + // code + "00094$: \n" + " setb PSW.5 \n" + " sjmp 00090$ \n" + + // read the pointer of the type that 00080$ returns (in DPTR) into A. clobber nothing + "00079$: \n" + " jnb PSW.5, 00078$ \n" + " push _R0 \n" + " mov R0, DPL \n" + " mov A, @R0 \n" + " pop _R0 \n" + " ret \n" + "00078$: \n" + " movx A, @DPTR \n" + " ret \n" + + // get pointer to a number, might be pushed or might be pointed to, size might vary. return pointer to number's LOW byte in DPTR + "00080$: \n" + " mov A, R4 \n" + " anl A, #0x01 \n" + " jnz 00083$ \n" + // param is itself on stack - now we care about size, but either way, PSW.5 will be 1 + " setb PSW.5 \n" + " mov B, #0 \n" + " mov A, R4 \n" + " anl A, #0x18 \n" + " jz 00081$ \n" + " anl A, #0x10 \n" + " jz 00082$ \n" + // long long (8 bytes) \n" + " setb B.2 \n" + " dec R0 \n" + " dec R0 \n" + " dec R0 \n" + " dec R0 \n" + // long (4 bytes) + "00082$: \n" + " setb B.1 \n" + " dec R0 \n" + " dec R0 \n" + // int (2 bytes) \n" + "00081$: \n" + " setb B.0 \n" + " dec R0 \n" + " mov DPL, R0 \n" + " dec R0 \n" + " inc B \n" + " ret \n" + // pointer it on stack itself, number is in xram, but we still need to provide the length + "00083$: \n" + " clr PSW.5 \n" // mark as "in xram" + " mov A, R4 \n" + " anl A, #0x18 \n" + " jz 00084$ \n" + " anl A, #0x10 \n" + " jz 00085$ \n" + // long long + " mov B, #8 \n" + " ljmp 00090$ \n" + // long + "00085$: \n" + " mov B, #4 \n" + " ljmp 00090$ \n" + // int + "00084$: \n" + " mov B, #2 \n" + " ljmp 00090$ \n" + + // swap R3:R1 <-> DPH:DPL + "00086$: \n" + " xch A, DPH \n" + " xch A, R3 \n" + " xch A, DPH \n" + " xch A, DPL \n" + " xch A, R1 \n" + " xch A, DPL \n" + " ret \n" + + /* putchar func + called via call. char is in A, R7 has pointer to stack as needed + can clobber B, CANNOT clobber DPTR + a mess because...8051 + */ + "00060$: \n" + " push DPH \n" + " push DPL \n" + " push _R1 \n" + " push _R0 \n" + " mov _R0, R7 \n" + " mov DPL, @R0 \n" + " dec R0 \n" + " mov DPH, @R0 \n" // DPTR is now func ptr + " dec R0 \n" + " dec R0 \n" + " dec R0 \n" + " dec R0 \n" + " mov _R1, @R0 \n" + " dec R0 \n" + " mov _R0, @R0 \n" // R1:R0 is now "formatD" + " lcall 00061$ \n" // to set ret addr + " pop _R0 \n" + " pop _R1 \n" + " pop DPL \n" + " pop DPH \n" + " ret \n" + "00061$: \n" + " push DPL \n" + " push DPH \n" + " mov DPL, _R0 \n" + " mov DPH, _R1 \n" + " ret \n" + + "00099$: \n" + " .ascii \"01234567\" \n" + " .ascii \"89ABCDEF\" \n" + " .ascii \"01234567\" \n" + " .ascii \"89abcdef\" \n"); + (void)fmt; + (void)vl; + (void)formatF; + (void)formatD; } #pragma callee_saves prPrvPutchar -static void prPrvPutchar(uint32_t data) __reentrant -{ - char ch = data >> 24; - - if (ch == '\n') - dbgUartByte('\r'); - dbgUartByte(ch); +static void prPrvPutchar(uint32_t data) __reentrant { + char ch = data >> 24; + if (ch == '\n') + uartTx('\r'); + uartTx(ch); +} +#pragma callee_saves epdPutchar +static void epdPutchar(uint32_t data) __reentrant { + char ch = data >> 24; + writeCharEPD(ch); } -void pr(const char __code *fmt, ...) __reentrant -{ - va_list vl; - - va_start(vl, fmt); - dbgUartOn(); - prvPrintFormat(prPrvPutchar, 0, fmt, vl); - dbgUartOff(); - va_end(vl); +void pr(const char __code *fmt, ...) __reentrant { + va_list vl; + va_start(vl, fmt); + prvPrintFormat(prPrvPutchar, 0, fmt, vl); + va_end(vl); +} + +void epdpr(const char __code *fmt, ...) __reentrant { + va_list vl; + va_start(vl, fmt); + prvPrintFormat(epdPutchar, 0, fmt, vl); + va_end(vl); } #pragma callee_saves prPrvPutS -static void prPrvPutS(uint32_t data) __reentrant -{ - char __xdata * __idata *strPP = (char __xdata * __idata *)data; - char ch = data >> 24; - - *(*strPP)++ = ch; +static void prPrvPutS(uint32_t data) __reentrant { + char __xdata *__idata *strPP = (char __xdata *__idata *)data; + char ch = data >> 24; + + *(*strPP)++ = ch; } -void spr(char __xdata* out, const char __code *fmt, ...) __reentrant -{ - char __xdata* outStart = out; - - va_list vl; - - va_start(vl, fmt); - prvPrintFormat(prPrvPutS, (uint16_t)&out, fmt, vl); - va_end(vl); - - *out = 0; -} +void spr(char __xdata *out, const char __code *fmt, ...) __reentrant { + char __xdata *outStart = out; + va_list vl; + + va_start(vl, fmt); + prvPrintFormat(prPrvPutS, (uint16_t)&out, fmt, vl); + va_end(vl); + + *out = 0; +} diff --git a/tag_fw/drawing.c b/tag_fw/drawing.c index 1c91b4bc..e752395a 100644 --- a/tag_fw/drawing.c +++ b/tag_fw/drawing.c @@ -1,8 +1,10 @@ +#include "drawing.h" + #include + #include "asmUtil.h" #include "board.h" #include "cpu.h" -#include "drawing.h" #include "eeprom.h" #include "epd.h" #include "printf.h" @@ -318,10 +320,9 @@ static void drawPrvDecodeImageOnce(void) { } } -extern uint8_t blockXferBuffer[]; +static uint8_t __xdata prev, step = 0; void ByteDecode(uint8_t byte) { - static uint8_t __xdata prev, step = 0; prev <<= 2; prev |= (mColorMap[mPassNo][byte >> 4] << 1) | mColorMap[mPassNo][byte & 0x0f]; if (++step == 4) { @@ -341,15 +342,19 @@ void drawImageAtAddress(uint32_t addr) { return; drawPrvLoadAndMapClut(clutAddr); - //screenTxStart(false); epdSetup(); mPassNo = 0; beginFullscreenImage(); beginWriteFramebuffer(EPD_COLOR_BLACK); + prev = 0; + step = 0; drawPrvDecodeImageOnce(); endWriteFramebuffer(); mPassNo++; + beginFullscreenImage(); beginWriteFramebuffer(EPD_COLOR_RED); + prev = 0; + step = 0; drawPrvDecodeImageOnce(); endWriteFramebuffer(); diff --git a/tag_fw/epd.c b/tag_fw/epd.c index 79d08ab1..1aa05b94 100644 --- a/tag_fw/epd.c +++ b/tag_fw/epd.c @@ -4,6 +4,7 @@ #include #include "asmUtil.h" +#include "barcode.h" #include "board.h" #include "cpu.h" #include "font.h" @@ -64,16 +65,24 @@ P2_2 = 1; \ } while (0) -static uint8_t __xdata currentLUT = 0x00; // Current selected LUT -static bool __idata epdPr = false; // wheter or not we copy the pr("") output to the EPD -static uint8_t __xdata epdCharSize = 1; // character size, 1 or 2 (doubled) -static bool __xdata directionY = true; // print direction, X or Y (true) -static uint8_t __xdata rbuffer[32]; // used to rotate bits around -static uint16_t __xdata fontCurXpos = 0; // current X value we're working with -static uint16_t __xdata fontCurYpos = 0; // current Y value we're working with +extern void dump(uint8_t* __xdata a, uint16_t __xdata l); // remove me when done + +static uint8_t __xdata epdCharSize = 1; // character size, 1 or 2 (doubled) +static bool __xdata directionY = true; // print direction, X or Y (true) +static uint8_t __xdata rbuffer[32]; // used to rotate bits around +static uint16_t __xdata fontCurXpos = 0; // current X value we're working with +static uint16_t __xdata fontCurYpos = 0; // current Y value we're working with +static uint8_t __xdata currentLut = 0; static bool __xdata isInited = false; -struct waveform __xdata waveform; + +uint8_t waveformbuffer[120]; +#if (SCREEN_LUT_LENGTH == 10) +struct waveform10* __xdata waveform = (struct waveform10*)waveformbuffer; // holds the LUT/waveform +#endif +#if (SCREEN_LUT_LENGTH == 7) +struct waveform* __xdata waveform = (struct waveform*)waveformbuffer; // holds the LUT/waveform +#endif #pragma callee_saves epdBusySleep #pragma callee_saves epdBusyWait @@ -189,13 +198,12 @@ void epdEnterSleep() { P2_0 = 1; timerDelay(50); shortCommand(CMD_SOFT_RESET2); - epdBusyWait(133300); + epdBusyWait(TIMER_TICKS_PER_MS * 10); shortCommand1(CMD_ENTER_SLEEP, 0x03); isInited = false; } void epdSetup() { epdReset(); - currentLUT = 0; shortCommand1(CMD_ANALOG_BLK_CTRL, 0x54); shortCommand1(CMD_DIGITAL_BLK_CTRL, 0x3B); shortCommand2(CMD_UNKNOWN_1, 0x04, 0x63); @@ -219,8 +227,9 @@ void epdSetup() { shortCommand1(CMD_DISP_UPDATE_CTRL2, 0xB1); // mode 1 (i2C) // shortCommand1(CMD_DISP_UPDATE_CTRL2, 0xB9); // mode 2? shortCommand(CMD_ACTIVATION); - epdBusyWait(1333000UL); + epdBusyWait(TIMER_TICKS_PER_SECOND); isInited = true; + currentLut = EPD_LUT_DEFAULT; } static uint8_t epdGetStatus() { uint8_t sta; @@ -238,11 +247,11 @@ uint16_t epdGetBattery(void) { shortCommand1(CMD_DISP_UPDATE_CTRL2, SCREEN_CMD_CLOCK_ON | SCREEN_CMD_ANALOG_ON); shortCommand(CMD_ACTIVATION); - epdBusyWait(133300); + epdBusyWait(TIMER_TICKS_PER_MS * 100); for (val = 3; val < 8; val++) { shortCommand1(CMD_SETUP_VOLT_DETECT, val); - epdBusyWait(133300); + epdBusyWait(TIMER_TICKS_PER_MS * 100); if (epdGetStatus() & 0x10) { // set if voltage is less than threshold ( == 1.9 + val / 10) voltage = 1850 + mathPrvMul8x8(val, 100); break; @@ -251,30 +260,109 @@ uint16_t epdGetBattery(void) { shortCommand1(CMD_DISP_UPDATE_CTRL2, 0xB1); shortCommand(CMD_ACTIVATION); - epdBusyWait(133300); + epdBusyWait(TIMER_TICKS_PER_MS * 100); if (!isInited) epdEnterSleep(); return voltage; } +void loadFixedTempOTPLUT() { + shortCommand1(0x18, 0x48); // external temp sensor + shortCommand2(0x1A, 0x05, 0x00); // < temp register + shortCommand1(CMD_DISP_UPDATE_CTRL2, 0xB1); // mode 1 (i2C) + shortCommand(CMD_ACTIVATION); + epdBusyWait(TIMER_TICKS_PER_SECOND); +} +static void writeLut() { + commandBegin(CMD_WRITE_LUT); + for (uint8_t i = 0; i < (SCREEN_LUT_LENGTH * 10); i++) + epdSend(waveformbuffer[i]); + commandEnd(); +} +static void readLut() { + commandReadBegin(0x33); + uint16_t checksum = 0; + uint16_t ident = 0; + uint16_t shortl = 0; + for (uint16_t c = 0; c < ((SCREEN_LUT_LENGTH * 10) + 6); c++) { + waveformbuffer[c] = epdReadByte(); + } + commandReadEnd(); +} +static void lutGroupDisable(uint8_t group) { + memset(&(waveform->group[group]), 0x00, 5); +} +static void lutGroupSpeedup(uint8_t group, uint8_t speed) { + for (uint8_t i = 0; i < 4; i++) { + waveform->group[group].phaselength[i] = 1 + (waveform->group[group].phaselength[i] / speed); + } +} +static void lutGroupRepeat(uint8_t group, uint8_t repeat) { + waveform->group[group].repeat = repeat; +} +static void lutGroupRepeatReduce(uint8_t group, uint8_t factor) { + waveform->group[group].repeat = waveform->group[group].repeat / factor; +} void selectLUT(uint8_t lut) { - if (lut == currentLUT) return; - // lut = 1; + if (currentLut == lut) { + return; + } + + if (currentLut != EPD_LUT_DEFAULT) { + // load the 'default' LUT for the current temperature in the EPD lut register + shortCommand1(CMD_DISP_UPDATE_CTRL2, 0xB1); // mode 1? + shortCommand(CMD_ACTIVATION); + epdBusyWait(TIMER_TICKS_PER_SECOND); + } + + currentLut = lut; + + // if we're going to be using the default LUT, we're done here. + if (lut == EPD_LUT_DEFAULT) { + return; + } + + // download the current LUT from the waveform buffer + readLut(); + switch (lut) { - case 0: - shortCommand1(CMD_DISP_UPDATE_CTRL2, 0xB1); // mode 1? - shortCommand(CMD_ACTIVATION); - epdBusyWait(1333000UL); + case EPD_LUT_NO_REPEATS: + lutGroupDisable(LUTGROUP_NEGATIVE); + lutGroupDisable(LUTGROUP_FASTBLINK); + lutGroupRepeat(LUTGROUP_SLOWBLINK, 0); + lutGroupSpeedup(LUTGROUP_SET, 2); + lutGroupSpeedup(LUTGROUP_IMPROVE_SHARPNESS, 2); + lutGroupRepeatReduce(LUTGROUP_IMPROVE_SHARPNESS, 2); + lutGroupSpeedup(LUTGROUP_IMPROVE_REDS, 2); + lutGroupRepeatReduce(LUTGROUP_IMPROVE_REDS, 2); break; - case 1: - commandBegin(CMD_WRITE_LUT); - for (uint8_t i = 0; i < 70; i++) - epdSend(lutorig[i]); - commandEnd(); + case EPD_LUT_FAST_NO_REDS: + lutGroupDisable(LUTGROUP_NEGATIVE); + lutGroupDisable(LUTGROUP_FASTBLINK); + lutGroupDisable(LUTGROUP_SLOWBLINK); + //lutGroupSpeedup(LUTGROUP_SET, 2); + lutGroupDisable(LUTGROUP_IMPROVE_REDS); + lutGroupDisable(LUTGROUP_IMPROVE_SHARPNESS); + break; + case EPD_LUT_FAST: + lutGroupDisable(LUTGROUP_NEGATIVE); + lutGroupDisable(LUTGROUP_FASTBLINK); + lutGroupDisable(LUTGROUP_SLOWBLINK); + lutGroupRepeat(LUTGROUP_SET, 0); + //lutGroupSpeedup(LUTGROUP_SET, 2); + lutGroupDisable(LUTGROUP_IMPROVE_REDS); + lutGroupDisable(LUTGROUP_IMPROVE_SHARPNESS); break; } - currentLUT = lut; + +#if (SCREEN_LUT_LENGTH == 10) + lutGroupDisable(LUTGROUP_UNUSED); + lutGroupDisable(LUTGROUP_UNKNOWN); + lutGroupDisable(LUTGROUP_UNUSED3); + lutGroupDisable(LUTGROUP_UNUSED4); +#endif + writeLut(); } void setWindowX(uint16_t start, uint16_t end) { @@ -284,8 +372,8 @@ void setWindowY(uint16_t start, uint16_t end) { commandBegin(CMD_WINDOW_Y_SIZE); epdSend((start)&0xff); epdSend((start) >> 8); - epdSend((end)&0xff); // was end-1 - epdSend((end) >> 8); // was end-1 + epdSend((end - 1) & 0xff); + epdSend((end - 1) >> 8); commandEnd(); } void setPosXY(uint16_t x, uint16_t y) { @@ -316,10 +404,11 @@ void clearScreen() { setWindowX(0, SCREEN_WIDTH); setWindowY(0, SCREEN_HEIGHT); setPosXY(0, 0); + shortCommand1(CMD_DATA_ENTRY_MODE, 3); // was 3 shortCommand1(CMD_WRITE_PATTERN_BW, 0x66); - epdBusyWait(133300UL); + epdBusyWait(TIMER_TICKS_PER_MS * 100); shortCommand1(CMD_WRITE_PATTERN_RED, 0x66); - epdBusyWait(133300UL); + epdBusyWait(TIMER_TICKS_PER_MS * 100); } void draw() { shortCommand1(0x22, 0xCF); @@ -332,6 +421,9 @@ void drawNoWait() { // shortCommand1(0x22, SCREEN_CMD_REFRESH); shortCommand(0x20); } +void epdWaitRdy() { + epdBusyWait(TIMER_TICKS_PER_SECOND * 120); +} void drawLineHorizontal(bool color, uint16_t x1, uint16_t x2, uint16_t y) { setWindowX(x1, x2); setWindowY(y, y + 1); @@ -340,9 +432,8 @@ void drawLineHorizontal(bool color, uint16_t x1, uint16_t x2, uint16_t y) { } else { shortCommand1(CMD_WRITE_PATTERN_BW, 0xE6); } - epdBusyWait(133300UL); + epdBusyWait(TIMER_TICKS_PER_MS * 100); } - void drawLineVertical(bool color, uint16_t x, uint16_t y1, uint16_t y2) { setWindowY(y1, y2); setWindowX(x, x + 8); @@ -354,7 +445,7 @@ void drawLineVertical(bool color, uint16_t x, uint16_t y1, uint16_t y2) { commandBegin(CMD_WRITE_FB_BW); } uint8_t __xdata c = 0x80; - c>>=(x%8); + c >>= (x % 8); for (; y1 < y2; y1++) { epdSend(c); } @@ -378,7 +469,43 @@ void beginWriteFramebuffer(bool color) { void endWriteFramebuffer() { commandEnd(); } - +void loadRawBitmap(uint8_t* bmp, uint16_t x, uint16_t y, bool color) { + uint16_t xsize = bmp[0] / 8; + if (bmp[0] % 8) xsize++; + uint16_t size = xsize * bmp[1]; + setWindowX(x, x + (xsize * 8)); + setWindowY(y, bmp[1] + y); + setPosXY(x, y); + shortCommand1(CMD_DATA_ENTRY_MODE, 3); + if (color) { + commandBegin(CMD_WRITE_FB_RED); + } else { + commandBegin(CMD_WRITE_FB_BW); + } + bmp += 2; + while (size--) { + epdSend(*(bmp++)); + } + commandEnd(); +} +void printBarcode(const uint8_t* string, uint16_t x, uint16_t y) { + setWindowY(y, 1); + setWindowX(x, x + 8); + setPosXY(x, y); + shortCommand1(CMD_DATA_ENTRY_MODE, 1); + commandBegin(CMD_WRITE_FB_BW); + struct BarcodeInfo __xdata bci = { + .str = string, + }; + while (!barcodeIsDone(&bci)) { + if (barcodeNextBar(&bci)) { + epdSend(0xFF); + } else { + epdSend(0x00); + } + } + commandEnd(); +} // stuff for printing text static void pushXFontBytesToEPD(uint8_t byte1, uint8_t byte2) { if (epdCharSize == 1) { @@ -464,9 +591,6 @@ static void pushYFontBytesToEPD(uint8_t byte1, uint8_t byte2) { } } void writeCharEPD(uint8_t c) { - if (!epdPr) { - return; - } // Writes a single character to the framebuffer bool empty = true; for (uint8_t i = 0; i < 20; i++) { @@ -508,6 +632,7 @@ void writeCharEPD(uint8_t c) { pushXFontBytesToEPD(0x00, 0x00); } } + // Print text to the EPD. Origin is top-left void epdPrintBegin(uint16_t x, uint16_t y, bool direction, bool fontsize, bool color) { directionY = direction; @@ -526,7 +651,7 @@ void epdPrintBegin(uint16_t x, uint16_t y, bool direction, bool fontsize, bool c rbuffer[1] = 0; } - setWindowY(y, 0); + setWindowY(y, 1); if (epdCharSize == 2) { setWindowX(x, x + 32 + extra); setPosXY(x, y); @@ -550,7 +675,6 @@ void epdPrintBegin(uint16_t x, uint16_t y, bool direction, bool fontsize, bool c memset(rbuffer, 0, 32); } - epdPr = true; if (color) { commandBegin(CMD_WRITE_FB_RED); } else { @@ -564,29 +688,8 @@ void epdPrintEnd() { } } commandEnd(); - epdPr = false; } -void loadFixedTempLUT() { - shortCommand1(0x18, 0x48); - shortCommand2(0x1A, 0x05, 0x00); // < temp register - shortCommand1(CMD_DISP_UPDATE_CTRL2, 0xB1); // mode 1 (i2C) - shortCommand(CMD_ACTIVATION); - epdBusyWait(1333000UL); -} -static void readLut() { - commandReadBegin(0x33); - uint16_t checksum = 0; - uint16_t ident = 0; - uint16_t shortl = 0; - for (uint16_t c = 0; c < 76; c++) { - ((uint8_t*)&waveform)[c] = epdReadByte(); - } - commandReadEnd(); -} - -extern void dump(uint8_t* __xdata a, uint16_t __xdata l); // remove me when done - extern uint8_t __xdata blockXferBuffer[]; void readRam() { @@ -612,4 +715,4 @@ void readRam() { void lutTest() { readLut(); dump((uint8_t*)&waveform, 96); -} \ No newline at end of file +} diff --git a/tag_fw/epd.h b/tag_fw/epd.h index e9eefd7c..b7cfc94b 100644 --- a/tag_fw/epd.h +++ b/tag_fw/epd.h @@ -11,11 +11,18 @@ #define EPD_SIZE_DOUBLE true #define EPD_COLOR_RED true #define EPD_COLOR_BLACK false - +#define EPD_LOAD_CUSTOM_LUT true +#define EPD_LOAD_OTP_LUT false #define EPD_MODE_NORMAL 0x00 #define EPD_MODE_INVERT 0x08 #define EPD_MODE_IGNORE 0x04 +#define EPD_LUT_DEFAULT 0 +#define EPD_LUT_NO_REPEATS 1 +#define EPD_LUT_FAST_NO_REDS 2 +#define EPD_LUT_FAST 3 + + #define epdSelect() \ do { \ P1_7 = 0; \ @@ -38,12 +45,15 @@ void clearWindow(bool color); void clearScreen(); void draw(); void drawNoWait(); +void epdWaitRdy(); void drawLineHorizontal(bool color, uint16_t x1, uint16_t x2, uint16_t y); void drawLineVertical(bool color, uint16_t x, uint16_t y1, uint16_t y2); void beginFullscreenImage(); void beginWriteFramebuffer(bool color); void endWriteFramebuffer(); +void loadRawBitmap(uint8_t* bmp, uint16_t x, uint16_t y, bool color); +void printBarcode(const uint8_t* string, uint16_t x, uint16_t y); void selectLUT(uint8_t lut); @@ -52,10 +62,12 @@ void ByteDecode(uint8_t byte); void epdPrintBegin(uint16_t x, uint16_t y, bool direction, bool fontsize, bool red); void epdPrintEnd(); - void beginFullscreenImage(); void beginWriteFramebuffer(bool color); void lutTest(); +// for printf.c +void writeCharEPD(uint8_t c); + #endif \ No newline at end of file diff --git a/tag_fw/lut.h b/tag_fw/lut.h index 7e0f8a34..9a09d3ca 100644 --- a/tag_fw/lut.h +++ b/tag_fw/lut.h @@ -1,5 +1,21 @@ #define __packed +#include "screen.h" + +#define LUTGROUP_NEGATIVE 0 +#define LUTGROUP_FASTBLINK 1 +#define LUTGROUP_SLOWBLINK 2 +#define LUTGROUP_SET 3 +#define LUTGROUP_IMPROVE_SHARPNESS 4 +#define LUTGROUP_IMPROVE_REDS 5 +#define LUTGROUP_UNUSED 6 + +#if (SCREEN_LUT_LENGTH == 10) +#define LUTGROUP_UNKNOWN 7 +#define LUTGROUP_UNUSED3 8 +#define LUTGROUP_UNUSED4 9 +#endif + struct vgroup { uint8_t A : 2; uint8_t B : 2; @@ -11,143 +27,29 @@ struct lut { struct vgroup group[7]; } __packed; +struct lut10 { + struct vgroup group[10]; +} __packed; + struct group { uint8_t phaselength[4]; uint8_t repeat; } __packed; struct waveform { - struct lut elut[5]; - struct group egroup[7]; + struct lut lut[5]; + struct group group[7]; uint8_t gatelevel; uint8_t sourcelevel[3]; uint8_t dummyline; uint8_t gatewidth; } __packed; -static const uint8_t __code lut154[] = { - // lut0 (KEEP) voltages - 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // lut1 (W2B) voltages - 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // lut2 (B2W) voltages - 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // lut3 (unused) voltages - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // lut4 (vcom) voltages - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // group0 phase lengths and repeat count - 0x40, 0x0, 0x00, 0x00, 0x00, - // group1 not used - 0x00, 0x00, 0x00, 0x00, 0x00, - // group2 not used - 0x00, 0x00, 0x00, 0x00, 0x00, - // group3 phase lengths and repeat count - 0x00, 0x00, 0x00, 0x00, 0x00, - // group4 phase lengths and repeat count - 0x00, 0x00, 0x00, 0x00, 0x00, - // group5 phase lengths and repeat count - 0x00, 0x00, 0x00, 0x00, 0x00, - // group6 phase lengths and repeat count - 0x00, 0x00, 0x00, 0x00, 0x00, -}; - - -static const uint8_t __code lut29[] = { - // lut0 (KEEP) voltages - 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // lut1 (W2B) voltages - 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // lut2 (B2W) voltages - 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // lut3 (unused) voltages - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // lut4 (vcom) voltages - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - // group0 phase lengths and repeat count -// 0x10, 0x02, 0x00, 0x00, 0x03 - 1, - 0x05, 0x02, 0x00, 0x00, 0x00, - -// 0x40, 0x00, 0x00, 0x00, 0x00, - - // group1 not used - 0x00, 0x00, 0x00, 0x00, 0x00, - // group2 not used - 0x00, 0x00, 0x00, 0x00, 0x00, - // group3 phase lengths and repeat count - 0x00, 0x00, 0x00, 0x00, 0x00, - // group4 phase lengths and repeat count - 0x00, 0x00, 0x00, 0x00, 0x00, - // group5 phase lengths and repeat count - 0x00, 0x00, 0x00, 0x00, 0x00, - // group6 phase lengths and repeat count - 0x00, 0x00, 0x00, 0x00, 0x00, -}; - -static const uint8_t __code lutSHA[] = { - // Voltages and other settings? Timing? - 0xA0, 0x90, 0x50, 0x0, 0x0, 0x0, 0x0, - 0x50, 0x90, 0xA0, 0x0, 0x0, 0x0, 0x0, - 0xA0, 0x90, 0x50, 0x0, 0x0, 0x0, 0x0, - 0x50, 0x90, 0xA0, 0x0, 0x0, 0x0, 0x0, - 0x00, 0x00, 0x00, 0x0, 0x0, 0x0, 0x0, - - // Update program - // - // Top three lines are the main program (bottom 4 have unknown function) - // Line 1: Negative image - // Line 2: White/Black flashing - // Line 3: Positive image - // - // Line construction - // First two bytes denote Intensity (range 0x00 to 0x0F) - // Second two bytes denote lenght of each 'pulse' (range 0x00 to 0xFF) - // Last byte denotes number of repeats (0 = line runs 1 time, range 0x00 to 0xFF) - // If you don't want a line to do anything, set all bytes to 0x0. - // This way you can make a quick update cycle between two screens. - // Maybe not as pretty/crisp but nice and fast is also awesome! - - // Negative image - // first two bytes negative image, length white pulse (0-FF), length black pulse (0-FF), last byte repeats - - 0x0, 0x0, 0x0, 0x0, 0x0, - - //0xF, 0xF, 0x0, 0x0, 0x0, - - // White or black flash - // white flash intensity, black flash intensity, length white pulse (0-FF), length black pulse (0-FF), repeats - - //0x0, 0x0, 0x0, 0x0, 0x00, - 0xF, 0xF, 0x1, 0x1, 0x00, - //0xF, 0xF, 0x0, 0x0, 0x02, - - - // Positive image - // first byte or second byte positive image (don't know why you need both), rest same as above - - 0xF, 0xF, 0x0, 0x0, 0x0, - - // Unknown what lines below actually do. - // They seem to be programs to, but have no visible effect on dislay. - 0x0F, 0x0F, 0x0, 0x0, 0x0, - 0x0F, 0x0F, 0x0, 0x0, 0x0, - 0x0F, 0x0F, 0x0, 0x0, 0x0, - 0x0F, 0x0F, 0x0, 0x0, 0x0, -}; - - -static const uint8_t __code lutorig[] = { - 0x00, 0x66, 0x21, 0x45, 0x40, 0x00, 0x00, - 0x15, 0x66, 0x21, 0xA8, 0x20, 0xA0, 0x00, - 0xA0, 0x66, 0x21, 0x85, 0x2B, 0x2F, 0x00, - 0xA0, 0x66, 0x21, 0x85, 0x2B, 0x2F, 0x00, - 0x00, 0x00, 0x12, 0x48, 0x00, 0x00, 0x00, - //0x04, 0x49, 0x2F, 0x2A, 0x00, - 0x0, 0x0, 0x0, 0x0, 0x0, - 0x02, 0x04, 0x01, 0x03, 0x00, // was 11 repeat - 0x01, 0x14, 0x01, 0x14, 0x00, // was 3 repeat - 0x02, 0x0A, 0x03, 0x0A, 0x00, // was 2 repeat - 0x06, 0x04, 0x04, 0x20, 0x00, // was 3 rpeat - 0x04, 0x04, 0x02, 0x26, 0x00, // was 3 repeat - 0x00, 0x00, 0x00, 0x00, 0x0, -}; \ No newline at end of file +struct waveform10 { + struct lut10 lut[5]; + struct group group[10]; + uint8_t gatelevel; + uint8_t sourcelevel[3]; + uint8_t dummyline; + uint8_t gatewidth; +} __packed; \ No newline at end of file diff --git a/tag_fw/main.c b/tag_fw/main.c index 997b765a..920d94d6 100644 --- a/tag_fw/main.c +++ b/tag_fw/main.c @@ -4,22 +4,140 @@ #include #include #include + #include "asmUtil.h" -#include "board.h" -#include "comms.h" -#include "cpu.h" -#include "drawing.h" +#include "comms.h" // for mLastLqi and mLastRSSI #include "eeprom.h" +#include "epd.h" +#include "powermgt.h" #include "printf.h" #include "proto.h" #include "radio.h" -#include "screen.h" -#include "sleep.h" -#include "timer.h" -#include "wdt.h" #include "syncedproto.h" +#include "timer.h" +#include "userinterface.h" +#include "wdt.h" +//#define DEBUG_MODE -void main(void){ +uint8_t showChannelSelect() { + uint8_t __xdata result[16]; + memset(result, 0, sizeof(result)); + showScanningWindow(); + for (uint8_t i = 0; i < 8; i++) { + for (uint8_t c = 11; c < 27; c++) { + if (probeChannel(c)) { + if (mLastLqi > result[c - 11]) result[c - 11] = mLastLqi; + pr("Channel: %d - LQI: %d RSSI %d\n", c, mLastLqi, mLastRSSI); + } + } + epdWaitRdy(); + for (uint8_t c = 0; c < 16; c++) { + addScanResult(11 + c, result[c]); + } + drawNoWait(); + } + uint8_t __xdata highestLqi = 0; + uint8_t __xdata highestSlot = 0; + for (uint8_t c = 0; c < sizeof(result); c++) { + if (result[c] > highestLqi) { + highestSlot = c + 11; + highestLqi = result[c]; + } + } + epdWaitRdy(); + mLastLqi = highestLqi; + return highestSlot; +} + +void mainProtocolLoop(void) { + clockingAndIntsInit(); + timerInit(); + boardInit(); + + if (!boardGetOwnMac(mSelfMac)) { + pr("failed to get MAC. Aborting\n"); + while (1) + ; + } else { + pr("MAC>%02X%02X", mSelfMac[0], mSelfMac[1]); + pr("%02X%02X", mSelfMac[2], mSelfMac[3]); + pr("%02X%02X", mSelfMac[4], mSelfMac[5]); + pr("%02X%02X\n", mSelfMac[6], mSelfMac[7]); + } + + irqsOn(); + boardInitStage2(); + + pr("BOOTED> (UI 0.03-1)\n\n"); + + if (!eepromInit()) { + pr("failed to init eeprom\n"); + while (1) + ; + } else { + initializeProto(); + } + eepromDeepPowerDown(); + // initialize Powers-saving-attempt-array with the default value; + initPowerSaving(); +#ifndef DEBUG_MODE + // show the splashscreen + showSplashScreen(); + + eepromDeepPowerDown(); + initRadio(); + + currentChannel = showChannelSelect(); + if (currentChannel == 0) { + // couldn't find an AP :() + showNoAP(); + } else { + radioSetChannel(currentChannel); + // Found an AP. + showAPFound(); + } +#endif +#ifdef DEBUG_MODE + initRadio(); + currentChannel = 11; +#endif + epdEnterSleep(); + + P1CHSTA &= ~(1 << 0); + + while (1) { + radioRxEnable(true, true); + + struct AvailDataInfo *__xdata avail = getAvailDataInfo(); + if (avail == NULL) { + // no data :( + nextCheckInFromAP = 0; // let the power-saving algorithm determine the next sleep period + } else { + nextCheckInFromAP = avail->nextCheckIn; + // got some data from the AP! + if (avail->dataType != DATATYPE_NOUPDATE) { + // data transfer + if (doDataDownload(avail)) { + // succesful transfer, next wake time is determined by the NextCheckin; + } else { + // failed transfer, let the algorithm determine next sleep interval (not the AP) + nextCheckInFromAP = 0; + } + } else { + // no data transfer, just sleep. + } + } + + // if the AP told us to sleep for a specific period, do so. + if (nextCheckInFromAP) { + doSleep(nextCheckInFromAP * 60000UL); + } else { + doSleep(getNextSleep() * 1000UL); + } + } +} + +void main(void) { mainProtocolLoop(); } diff --git a/tag_fw/make.bat b/tag_fw/make.bat index 8f656d19..500df1a7 100644 --- a/tag_fw/make.bat +++ b/tag_fw/make.bat @@ -1,6 +1,20 @@ @echo off +del fs154.bin +del fw29.bin +del fw42.bin makeit clean -makeit +makeit BUILD=zbs154v033 CPU=8051 SOC=zbs243 +pause +ren main.bin fw154.bin +makeit clean +makeit BUILD=zbs29v033 CPU=8051 SOC=zbs243 +pause +ren main.bin fw29.bin +makeit clean +makeit BUILD=zbs42v033 CPU=8051 SOC=zbs243 +pause +ren main.bin fw42.bin + del /s *.asm del /s *.lst del /s *.rst diff --git a/tag_fw/powermgt.c b/tag_fw/powermgt.c new file mode 100644 index 00000000..df441448 --- /dev/null +++ b/tag_fw/powermgt.c @@ -0,0 +1,92 @@ +#include "powermgt.h" + +#include +#include +#include +#include +#include + +#include "asmUtil.h" +#include "board.h" +#include "comms.h" +#include "cpu.h" +#include "drawing.h" +#include "eeprom.h" +#include "epd.h" +#include "i2c.h" +#include "printf.h" +#include "proto.h" +#include "radio.h" +#include "sleep.h" +#include "syncedproto.h" +#include "timer.h" +#include "userinterface.h" +#include "wdt.h" +#include "settings.h" + + +uint16_t __xdata dataReqAttemptArr[POWER_SAVING_SMOOTHING] = {0}; // Holds the amount of attempts required per data_req/check-in +uint8_t __xdata dataReqAttemptArrayIndex = 0; +uint8_t __xdata dataReqLastAttempt = 0; +uint16_t __xdata nextCheckInFromAP = 0; + +void initPowerSaving() { + for (uint8_t c = 0; c < POWER_SAVING_SMOOTHING; c++) { + dataReqAttemptArr[c] = INTERVAL_BASE; + } +} + +// init/sleep +void initAfterWake() { + clockingAndIntsInit(); + timerInit(); + // partialInit(); + boardInit(); + epdEnterSleep(); + irqsOn(); + boardInitStage2(); + initRadio(); +} +void doSleep(uint32_t __xdata t) { + if (t > 1000) pr("s=%lu\n ", t / 1000); + powerPortsDownForSleep(); + +#ifdef HAS_BUTTON + // Button setup on TEST pin 1.0 (input pullup) + P1FUNC &= ~(1 << 0); + P1DIR |= (1 << 0); + P1PULL |= (1 << 0); + P1LVLSEL |= (1 << 0); + P1INTEN = (1 << 0); + P1CHSTA &= ~(1 << 0); +#endif + + // sleepy + sleepForMsec(t); + +#ifdef HAS_BUTTON + P1INTEN = 0; +#endif + + initAfterWake(); +} +uint16_t getNextSleep() { + uint16_t __xdata curval = INTERVAL_AT_MAX_ATTEMPTS - INTERVAL_BASE; + curval *= dataReqLastAttempt; + curval /= DATA_REQ_MAX_ATTEMPTS; + curval += INTERVAL_BASE; + dataReqAttemptArr[dataReqAttemptArrayIndex % POWER_SAVING_SMOOTHING] = curval; + dataReqAttemptArrayIndex++; + + uint16_t avg = 0; + bool noNetwork = true; + for (uint8_t c = 0; c < POWER_SAVING_SMOOTHING; c++) { + avg += dataReqAttemptArr[c]; + if (dataReqAttemptArr[c] != INTERVAL_AT_MAX_ATTEMPTS) { + noNetwork = false; + } + } + if (noNetwork == true) return INTERVAL_NO_SIGNAL; + avg /= POWER_SAVING_SMOOTHING; + return avg; +} \ No newline at end of file diff --git a/tag_fw/powermgt.h b/tag_fw/powermgt.h new file mode 100644 index 00000000..7f641671 --- /dev/null +++ b/tag_fw/powermgt.h @@ -0,0 +1,24 @@ +#ifndef _POWERMGT_H_ +#define _POWERMGT_H_ +#include + +// power saving algorithm +#define INTERVAL_BASE 40 // interval (in seconds) (when 1 packet is sent/received) for target current (7.2µA) +#define INTERVAL_AT_MAX_ATTEMPTS 600 // interval (in seconds) (at max attempts) for target average current +#define INTERVAL_NO_SIGNAL 1800 // interval (in seconds) when no answer for POWER_SAVING_SMOOTHING attempts, + // (INTERVAL_AT_MAX_ATTEMPTS * POWER_SAVING_SMOOTHING) seconds +#define DATA_REQ_RX_WINDOW_SIZE 5UL // How many milliseconds we should wait for a packet during the data_request. + // If the AP holds a long list of data for tags, it may need a little more time to lookup the mac address +#define DATA_REQ_MAX_ATTEMPTS 14 // How many attempts (at most) we should do to get something back from the AP +#define POWER_SAVING_SMOOTHING 8 // How many samples we should use to smooth the data request interval +#define MINIMUM_INTERVAL 45 // IMPORTANT: Minimum interval for check-in; this determines overal battery life! + +extern void initAfterWake(); +extern void doSleep(uint32_t __xdata t); +extern uint16_t getNextSleep(); +extern void initPowerSaving(); + +extern uint16_t __xdata nextCheckInFromAP; +extern uint8_t __xdata dataReqLastAttempt; + +#endif \ No newline at end of file diff --git a/tag_fw/printf.h b/tag_fw/printf.h index b04e0590..8ca2eea5 100644 --- a/tag_fw/printf.h +++ b/tag_fw/printf.h @@ -19,6 +19,9 @@ #pragma callee_saves pr void pr(const char __code *fmt, ...) __reentrant; +#pragma callee_saves epdpr +void epdpr(const char __code *fmt, ...) __reentrant; + #pragma callee_saves spr void spr(char __xdata* out, const char __code *fmt, ...) __reentrant; diff --git a/tag_fw/proto.h b/tag_fw/proto.h index 2dd14159..e71224fe 100644 --- a/tag_fw/proto.h +++ b/tag_fw/proto.h @@ -1,47 +1,8 @@ #ifndef _PROTO_H_ #define _PROTO_H_ - +#define __packed #include -/* - All communications are direct from tag to station, EXCEPT association (tag will broadcast). - All comms shall be encrypted and authenticated with AES-CCM. Shared key shall be burned into the firmware. - Master shall provision new key at association. All non-bcast packets shall have pan id compression. - Master may skip "from" field. Tag checking in confirms it got the master's provisioning reply. - - Sadly filtering on MZ100 fails for long addr with no src addr. so short addr for src is used - - T = tag, S = station - - PACKET TYPE USE PAYLOAD STRUCT NOTES - ASSOC_REQ T2bcast TagInfo tag's info and assoc request (encrypted with shared key) - ASSOC_RESP S2T AssocInfo tag's association info (encrypted with shared key) - CHECKIN T2S CheckinInfo tag checking in occasionally - CHECKOUT S2T PendingInfo station's checkin reply telling tag what we have for it - CHUNK_REQ T2S ChunkReqInfo tag requesting a piece of data - CHUNK_RESP S2T ChunkInfo station provides chunk - -*/ - -#define PROTO_PRESHARED_KEY {0x34D906D3, 0xE3E5298E, 0x3429BF58, 0xC1022081} - -#define PROTO_PAN_ID (0x4447) //PAN ID compression shall be used - -#define PKT_ASSOC_REQ (0xF0) -#define PKT_ASSOC_RESP (0xF1) -#define PKT_CHECKIN (0xF2) -#define PKT_CHECKOUT (0xF3) -#define PKT_CHUNK_REQ (0xF4) -#define PKT_CHUNK_RESP (0xF5) - -#define PROTO_VER_0 (0) -#define PROTO_VER_CURRENT (PROTO_VER_0) - -#define PROTO_COMPR_TYPE_LZ (0x0001) -#define PROTO_COMPR_TYPE_BITPACK (0x0002) - -#define PROTO_MAX_DL_LEN (88) - enum TagScreenType { TagScreenEink_BW_1bpp, TagScreenEink_BW_2bpp, @@ -72,111 +33,135 @@ enum TagScreenType { #define __packed __attribute__((packed)) #endif -struct TagState { - uint64_t swVer; - uint16_t hwType; - uint16_t batteryMv; +#define PROTO_PAN_ID (0x4447) //PAN ID compression shall be used + + +#define RADIO_MAX_PACKET_LEN (125) //useful payload, not including the crc + +#define ADDR_MODE_NONE (0) +#define ADDR_MODE_SHORT (2) +#define ADDR_MODE_LONG (3) + +#define FRAME_TYPE_BEACON (0) +#define FRAME_TYPE_DATA (1) +#define FRAME_TYPE_ACK (2) +#define FRAME_TYPE_MAC_CMD (3) + +#define SHORT_MAC_UNUSED (0x10000000UL) //for radioRxFilterCfg's myShortMac + + + +struct MacFcs { + uint8_t frameType : 3; + uint8_t secure : 1; + uint8_t framePending : 1; + uint8_t ackReqd : 1; + uint8_t panIdCompressed : 1; + uint8_t rfu1 : 1; + uint8_t rfu2 : 2; + uint8_t destAddrType : 2; + uint8_t frameVer : 2; + uint8_t srcAddrType : 2; +} __packed ; + +struct MacFrameFromMaster { + struct MacFcs fcs; + uint8_t seq; + uint16_t pan; + uint8_t dst[8]; + uint16_t from; } __packed; -struct TagInfo { - uint8_t protoVer; //PROTO_VER_* - struct TagState state; - uint8_t rfu1[1]; //shall be ignored for now - uint16_t screenPixWidth; - uint16_t screenPixHeight; - uint16_t screenMmWidth; - uint16_t screenMmHeight; - uint16_t compressionsSupported; //COMPR_TYPE_* bitfield - uint16_t maxWaitMsec; //how long tag will wait for packets before going to sleep - uint8_t screenType; //enum TagScreenType - uint8_t rfu[11]; //shall be zero for now +struct MacFrameNormal { + struct MacFcs fcs; + uint8_t seq; + uint16_t pan; + uint8_t dst[8]; + uint8_t src[8]; } __packed; -struct AssocInfo { - uint32_t checkinDelay; //space between checkins, in msec - uint32_t retryDelay; //if download fails mid-way wait thi smany msec to retry (IFF progress was made) - uint16_t failedCheckinsTillBlank; //how many fails till we go blank - uint16_t failedCheckinsTillDissoc; //how many fails till we dissociate - uint32_t newKey[4]; - uint8_t rfu[8]; //shall be zero for now +struct MacFrameBcast { + struct MacFcs fcs; + uint8_t seq; + uint16_t dstPan; + uint16_t dstAddr; + uint16_t srcPan; + uint8_t src[8]; } __packed; -#define CHECKIN_TEMP_OFFSET 0x7f +#define PKT_AVAIL_DATA_REQ 0xE5 +#define PKT_AVAIL_DATA_INFO 0xE6 +#define PKT_BLOCK_PARTIAL_REQUEST 0xE7 +#define PKT_BLOCK_REQUEST_ACK 0xE9 +#define PKT_BLOCK_REQUEST 0xE4 +#define PKT_BLOCK_PART 0xE8 +#define PKT_XFER_COMPLETE 0xEA +#define PKT_XFER_COMPLETE_ACK 0xEB +#define PKT_CANCEL_XFER 0xEC -struct CheckinInfo { - struct TagState state; - uint8_t lastPacketLQI; //zero if not reported/not supported to be reported - int8_t lastPacketRSSI; //zero if not reported/not supported to be reported - uint8_t temperature; //zero if not reported/not supported to be reported. else, this minus CHECKIN_TEMP_OFFSET is temp in degrees C - uint8_t rfu[6]; //shall be zero for now +struct AvailDataReq { + uint8_t checksum; + uint8_t lastPacketLQI; // zero if not reported/not supported to be reported + int8_t lastPacketRSSI; // zero if not reported/not supported to be reported + uint8_t temperature; // zero if not reported/not supported to be reported. else, this minus CHECKIN_TEMP_OFFSET is temp in degrees C + uint16_t batteryMv; + uint8_t softVer; + uint8_t hwType; + uint8_t protoVer; + uint8_t buttonState; } __packed; -struct PendingInfo { - uint64_t imgUpdateVer; - uint32_t imgUpdateSize; - uint64_t osUpdateVer; //version of OS update avail - uint32_t osUpdateSize; - uint8_t rfu[8]; //shall be zero for now +#define DATATYPE_NOUPDATE 0 +#define DATATYPE_IMG 1 +#define DATATYPE_IMGRAW 2 +#define DATATYPE_UPDATE 3 + +struct AvailDataInfo { + uint8_t checksum; + uint64_t dataVer; + uint32_t dataSize; + uint8_t dataType; + uint16_t nextCheckIn; } __packed; -struct ChunkReqInfo { - uint64_t versionRequested; - uint32_t offset; - uint8_t len; - uint8_t osUpdatePlz : 1; - uint8_t rfu[6]; //shall be zero for now +struct blockPart { + uint8_t checksum; + uint8_t blockId; + uint8_t blockPart; + uint8_t data[]; } __packed; -struct ChunkInfo { - uint32_t offset; - uint8_t osUpdatePlz : 1; - uint8_t rfu; //shall be zero for now - uint8_t data[]; //no data means request is out of bounds of this version no longer exists +struct blockData { + uint16_t size; + uint16_t checksum; + uint8_t data[]; } __packed; +struct burstMacData { + uint16_t offset; + uint8_t targetMac[8]; +} __packed; +#define BLOCK_PART_DATA_SIZE 99 +#define BLOCK_MAX_PARTS 42 +#define BLOCK_DATA_SIZE 4096UL +#define BLOCK_XFER_BUFFER_SIZE BLOCK_DATA_SIZE + sizeof(struct blockData) +#define BLOCK_REQ_PARTS_BYTES 6 + +struct blockRequest { + uint8_t checksum; + uint64_t ver; + uint8_t blockId; + uint8_t type; + uint8_t requestedParts[BLOCK_REQ_PARTS_BYTES]; +} __packed; + +struct blockRequestAck { + uint8_t checksum; + uint16_t pleaseWaitMs; +} __packed; #define MACFMT "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" #define MACCVT(x) ((const uint8_t*)(x))[7], ((const uint8_t*)(x))[6], ((const uint8_t*)(x))[5], ((const uint8_t*)(x))[4], ((const uint8_t*)(x))[3], ((const uint8_t*)(x))[2], ((const uint8_t*)(x))[1], ((const uint8_t*)(x))[0] - -#define VERSION_SIGNIFICANT_MASK (0x0000ffffffffffffull) - -#define HW_TYPE_42_INCH_SAMSUNG (1) -#define HW_TYPE_42_INCH_SAMSUNG_ROM_VER_OFST (0xEFF8) - -#define HW_TYPE_74_INCH_DISPDATA (2) -#define HW_TYPE_74_INCH_DISPDATA_FRAME_MODE (3) -#define HW_TYPE_74_INCH_DISPDATA_ROM_VER_OFST (0x008b) - -#define HW_TYPE_ZBD_EPOP50 (4) -#define HW_TYPE_ZBD_EPOP50_ROM_VER_OFST (0x008b) - -#define HW_TYPE_ZBD_EPOP900 (5) -#define HW_TYPE_ZBD_EPOP900_ROM_VER_OFST (0x008b) - -#define HW_TYPE_29_INCH_DISPDATA (6) -#define HW_TYPE_29_INCH_DISPDATA_FRAME_MODE (7) -#define HW_TYPE_29_INCH_DISPDATA_ROM_VER_OFST (0x008b) - -#define HW_TYPE_29_INCH_ZBS_026 (8) -#define HW_TYPE_29_INCH_ZBS_026_FRAME_MODE (9) - -#define HW_TYPE_154_INCH_ZBS_033 (18) -#define HW_TYPE_154_INCH_ZBS_033_FRAME_MODE (19) - -#define HW_TYPE_42_INCH_ZBS_026 (28) -#define HW_TYPE_42_INCH_ZBS_026_FRAME_MODE (29) - -#define HW_TYPE_29_INCH_ZBS_025 (10) -#define HW_TYPE_29_INCH_ZBS_025_FRAME_MODE (11) - -#define HW_TYPE_29_INCH_ZBS_ROM_VER_OFST (0x008b) - - - -#endif - - - - +#endif \ No newline at end of file diff --git a/tag_fw/settings.h b/tag_fw/settings.h new file mode 100644 index 00000000..763a26ef --- /dev/null +++ b/tag_fw/settings.h @@ -0,0 +1,12 @@ +#ifndef SYNCED_H +#define SYNCED_H + +#include + +#define FW_VERSION 012 // version number (max 2.5.5 :) ) +#define FW_VERSION_SUFFIX "-rf15" // suffix, like -RC1 or whatever. +#define HAS_BUTTON // uncomment to enable reading a push button (connect between 'TEST' en 'GND' on the tag, along with a 100nF capacitor in parallel). +// #define DEBUGBLOCKS // uncomment to enable extra debug information on the block transfers + + +#endif \ No newline at end of file diff --git a/tag_fw/soc/radioCommon.h b/tag_fw/soc/radioCommon.h index 61c4f8f5..99937234 100644 --- a/tag_fw/soc/radioCommon.h +++ b/tag_fw/soc/radioCommon.h @@ -5,6 +5,10 @@ #include +//radio cfg +#define RADIO_FIRST_CHANNEL (11) //2.4-GHz channels start at 11 +#define RADIO_NUM_CHANNELS (15) + #define RADIO_MAX_PACKET_LEN (125) //useful payload, not including the crc @@ -20,22 +24,6 @@ #define SHORT_MAC_UNUSED (0x10000000UL) //for radioRxFilterCfg's myShortMac - -struct MacFcs { - - uint8_t frameType : 3; - uint8_t secure : 1; - uint8_t framePending : 1; - uint8_t ackReqd : 1; - uint8_t panIdCompressed : 1; - uint8_t rfu1 : 1; - uint8_t rfu2 : 2; - uint8_t destAddrType : 2; - uint8_t frameVer : 2; - uint8_t srcAddrType : 2; -}; - - void radioInit(void); bool radioTx(const void __xdata* packet); //waits for tx end diff --git a/tag_fw/soc/zbs243/timer.h b/tag_fw/soc/zbs243/timer.h index bce2b700..26aa216b 100644 --- a/tag_fw/soc/zbs243/timer.h +++ b/tag_fw/soc/zbs243/timer.h @@ -4,7 +4,7 @@ #include #define TIMER_TICKS_PER_SECOND (16000000 / 12) //overflows every 53 minutes - +#define TIMER_TICKS_PER_MS 1333UL //this is a requirement by SDCC. is this prototype is missing when compiling main(), we get no irq handler void T0_ISR(void) __interrupt (1); diff --git a/tag_fw/soc/zbs243/uart.c b/tag_fw/soc/zbs243/uart.c index c41514c5..5b0c8199 100644 --- a/tag_fw/soc/zbs243/uart.c +++ b/tag_fw/soc/zbs243/uart.c @@ -12,10 +12,7 @@ void uartInit(void) { UARTSTA = 0x12; // also set the "empty" bit else we wait forever for it to go up } -extern void writeCharEPD(uint8_t c); - void uartTx(uint8_t val) { - writeCharEPD(val); while (!(UARTSTA & (1 << 1))) ; UARTSTA &= ~(1 << 1); diff --git a/tag_fw/syncedproto.c b/tag_fw/syncedproto.c index 5be1e4a2..f0aa3d85 100644 --- a/tag_fw/syncedproto.c +++ b/tag_fw/syncedproto.c @@ -6,122 +6,23 @@ #include #include #include + #include "asmUtil.h" -#include "board.h" #include "comms.h" #include "cpu.h" #include "drawing.h" #include "eeprom.h" #include "i2c.h" +#include "powermgt.h" #include "printf.h" #include "proto.h" #include "radio.h" -#include "epd.h" -#include "userinterface.h" +#include "settings.h" #include "sleep.h" #include "timer.h" +#include "userinterface.h" #include "wdt.h" -struct MacFrameFromMaster { - struct MacFcs fcs; - uint8_t seq; - uint16_t pan; - uint8_t dst[8]; - uint16_t from; -} __packed; - -struct MacFrameNormal { - struct MacFcs fcs; - uint8_t seq; - uint16_t pan; - uint8_t dst[8]; - uint8_t src[8]; -} __packed; - -struct MacFrameBcast { - struct MacFcs fcs; - uint8_t seq; - uint16_t dstPan; - uint16_t dstAddr; - uint16_t srcPan; - uint8_t src[8]; -} __packed; - -#define PKT_AVAIL_DATA_REQ 0xE5 -#define PKT_AVAIL_DATA_INFO 0xE6 -#define PKT_BLOCK_PARTIAL_REQUEST 0xE7 -#define PKT_BLOCK_REQUEST_ACK 0xE9 -#define PKT_BLOCK_REQUEST 0xE4 -#define PKT_BLOCK_PART 0xE8 -#define PKT_XFER_COMPLETE 0xEA -#define PKT_XFER_COMPLETE_ACK 0xEB -#define PKT_CANCEL_XFER 0xEC - -struct AvailDataReq { - uint8_t checksum; - uint8_t lastPacketLQI; // zero if not reported/not supported to be reported - int8_t lastPacketRSSI; // zero if not reported/not supported to be reported - uint8_t temperature; // zero if not reported/not supported to be reported. else, this minus CHECKIN_TEMP_OFFSET is temp in degrees C - uint16_t batteryMv; - uint8_t softVer; - uint8_t hwType; - uint8_t protoVer; - uint8_t buttonState; -} __packed; - -#define DATATYPE_NOUPDATE 0 -#define DATATYPE_IMG 1 -#define DATATYPE_IMGRAW 2 -#define DATATYPE_UPDATE 3 - -struct AvailDataInfo { - uint8_t checksum; - uint64_t dataVer; - uint32_t dataSize; - uint8_t dataType; - uint16_t nextCheckIn; -} __packed; - -struct blockPart { - uint8_t checksum; - uint8_t blockId; - uint8_t blockPart; - uint8_t data[]; -} __packed; - -struct blockData { - uint16_t size; - uint16_t checksum; - uint8_t data[]; -} __packed; - -struct burstMacData { - uint16_t offset; - uint8_t targetMac[8]; -} __packed; - -#define BLOCK_PART_DATA_SIZE 99 -#define BLOCK_MAX_PARTS 42 -#define BLOCK_DATA_SIZE 4096UL -#define BLOCK_XFER_BUFFER_SIZE BLOCK_DATA_SIZE + sizeof(struct blockData) -#define BLOCK_REQ_PARTS_BYTES 6 - -struct blockRequest { - uint8_t checksum; - uint64_t ver; - uint8_t blockId; - uint8_t type; - uint8_t requestedParts[BLOCK_REQ_PARTS_BYTES]; -} __packed; - -struct blockRequestAck { - uint8_t checksum; - uint16_t pleaseWaitMs; -} __packed; - -#define TIMER_TICKS_PER_MS 1333UL -// #define DEBUGBLOCKS - // download-stuff bool __xdata dataPending = true; uint8_t __xdata blockXferBuffer[BLOCK_XFER_BUFFER_SIZE] = {0}; @@ -131,7 +32,7 @@ uint16_t __xdata dataRemaining = 0; bool __xdata curXferComplete = false; bool __xdata requestPartialBlock = false; -//uint8_t __xdata *tempBuffer = blockXferBuffer; +// uint8_t __xdata *tempBuffer = blockXferBuffer; uint8_t __xdata curImgSlot = 0; uint32_t __xdata curHighSlotId = 0; uint8_t __xdata nextImgSlot = 0; @@ -148,24 +49,7 @@ uint8_t __xdata APmac[8] = {0}; uint16_t __xdata APsrcPan = 0; uint8_t __xdata mSelfMac[8] = {0}; uint8_t __xdata seq = 0; - -// power saving algorithm -#define INTERVAL_BASE 40 // interval (in seconds) (when 1 packet is sent/received) for target current (7.2µA) -#define INTERVAL_AT_MAX_ATTEMPTS 600 // interval (in seconds) (at max attempts) for target average current -#define INTERVAL_NO_SIGNAL 1800 // interval (in seconds) when no answer for POWER_SAVING_SMOOTHING attempts, - // (INTERVAL_AT_MAX_ATTEMPTS * POWER_SAVING_SMOOTHING) seconds -#define DATA_REQ_RX_WINDOW_SIZE 5UL // How many milliseconds we should wait for a packet during the data_request. - // If the AP holds a long list of data for tags, it may need a little more time to lookup the mac address -#define DATA_REQ_MAX_ATTEMPTS 14 // How many attempts (at most) we should do to get something back from the AP -#define POWER_SAVING_SMOOTHING 8 // How many samples we should use to smooth the data request interval -#define MINIMUM_INTERVAL 45 // IMPORTANT: Minimum interval for check-in; this determines overal battery life! - -#define HAS_BUTTON // uncomment to enable reading a push button (connect between 'TEST' en 'GND' on the tag, along with a 100nF capacitor in parallel). - -uint16_t __xdata dataReqAttemptArr[POWER_SAVING_SMOOTHING] = {0}; // Holds the amount of attempts required per data_req/check-in -uint8_t __xdata dataReqAttemptArrayIndex = 0; -uint8_t __xdata dataReqLastAttempt = 0; -uint16_t __xdata nextCheckInFromAP = 0; +uint8_t __xdata currentChannel = 0; // buffer we use to prepare/read packets // static uint8_t __xdata mRxBuf[130]; @@ -224,11 +108,15 @@ void addCRC(void *p, uint8_t len) { ((uint8_t *)p)[0] = total; } -// init/sleep +// radio stuff void initRadio() { radioInit(); radioRxFilterCfg(mSelfMac, 0x10000, PROTO_PAN_ID); - radioSetChannel(RADIO_FIRST_CHANNEL); + if (currentChannel >= 11 && currentChannel <= 25) { + radioSetChannel(currentChannel); + } else { + radioSetChannel(RADIO_FIRST_CHANNEL); + } radioSetTxPower(10); } void killRadio() { @@ -242,58 +130,14 @@ void killRadio() { RADIO_command = 0xC5; CFGPAGE = cfgPg; } -void initAfterWake() { - clockingAndIntsInit(); - timerInit(); - // partialInit(); - boardInit(); - epdEnterSleep(); - irqsOn(); - boardInitStage2(); - initRadio(); -} -void doSleep(uint32_t __xdata t) { - if (t > 1000) pr("s=%lu\n ", t / 1000); - powerPortsDownForSleep(); +bool probeChannel(uint8_t channel) { + radioRxEnable(false, true); + radioRxFlush(); + radioSetChannel(channel); + radioRxEnable(true, true); + getAvailDataInfo(); + return(dataReqLastAttempt != DATA_REQ_MAX_ATTEMPTS); -#ifdef HAS_BUTTON - // Button setup on TEST pin 1.0 (input pullup) - P1FUNC &= ~(1 << 0); - P1DIR |= (1 << 0); - P1PULL |= (1 << 0); - P1LVLSEL |= (1 << 0); - P1INTEN = (1 << 0); - P1CHSTA &= ~(1 << 0); -#endif - - // sleepy - sleepForMsec(t); - -#ifdef HAS_BUTTON - P1INTEN = 0; -#endif - - initAfterWake(); -} -uint16_t getNextSleep() { - uint16_t __xdata curval = INTERVAL_AT_MAX_ATTEMPTS - INTERVAL_BASE; - curval *= dataReqLastAttempt; - curval /= DATA_REQ_MAX_ATTEMPTS; - curval += INTERVAL_BASE; - dataReqAttemptArr[dataReqAttemptArrayIndex % POWER_SAVING_SMOOTHING] = curval; - dataReqAttemptArrayIndex++; - - uint16_t avg = 0; - bool noNetwork = true; - for (uint8_t c = 0; c < POWER_SAVING_SMOOTHING; c++) { - avg += dataReqAttemptArr[c]; - if (dataReqAttemptArr[c] != INTERVAL_AT_MAX_ATTEMPTS) { - noNetwork = false; - } - } - if (noNetwork == true) return INTERVAL_NO_SIGNAL; - avg /= POWER_SAVING_SMOOTHING; - return avg; } // data xfer stuff @@ -311,7 +155,7 @@ void sendAvailDataReq() { txframe->seq = seq++; txframe->dstPan = 0xFFFF; txframe->dstAddr = 0xFFFF; - txframe->srcPan = 0x4447; + txframe->srcPan = PROTO_PAN_ID; // TODO: send some meaningful data availreq->softVer = 1; if (P1CHSTA && (1 << 0)) { @@ -573,7 +417,6 @@ uint32_t getHighSlotId() { return temp; } -// #define DEBUGBLOCKS // Main download function bool doDataDownload(struct AvailDataInfo *__xdata avail) { // this is the main function for the download process @@ -835,86 +678,7 @@ bool doDataDownload(struct AvailDataInfo *__xdata avail) { return true; } -// main loop; -void mainProtocolLoop(void) { - clockingAndIntsInit(); - timerInit(); - boardInit(); - - if (!boardGetOwnMac(mSelfMac)) { - pr("failed to get MAC. Aborting\n"); - while (1) - ; - } else { - /* - for (uint8_t c = 0; c < 8; c++) { - mSelfMac[c] = c + 5; - } - */ - // really... if I do the call below, it'll cost me 8 bytes IRAM. Not the kind of 'optimization' I ever dreamed of doing - // pr("MAC>%02X%02X%02X%02X%02X%02X%02X%02X\n", mSelfMac[0], mSelfMac[1], mSelfMac[2], mSelfMac[3], mSelfMac[4], mSelfMac[5], mSelfMac[6], mSelfMac[7]); - pr("MAC>%02X%02X", mSelfMac[0], mSelfMac[1]); - pr("%02X%02X", mSelfMac[2], mSelfMac[3]); - pr("%02X%02X", mSelfMac[4], mSelfMac[5]); - pr("%02X%02X\n", mSelfMac[6], mSelfMac[7]); - } - - irqsOn(); - boardInitStage2(); - - pr("BOOTED> (UI 0.03-1)\n\n"); - - if (!eepromInit()) { - pr("failed to init eeprom\n"); - while (1) - ; - } else { - getNumSlots(); - curHighSlotId = getHighSlotId(); - } - - // initialize attempt-array with the default value; - for (uint8_t c = 0; c < POWER_SAVING_SMOOTHING; c++) { - dataReqAttemptArr[c] = INTERVAL_BASE; - } - - // show the splashscreen - showSplashScreen(); - - epdEnterSleep(); - eepromDeepPowerDown(); - initRadio(); - - P1CHSTA &= ~(1 << 0); - - while (1) { - radioRxEnable(true, true); - - struct AvailDataInfo *__xdata avail = getAvailDataInfo(); - if (avail == NULL) { - // no data :( - nextCheckInFromAP = 0; // let the power-saving algorithm determine the next sleep period - } else { - nextCheckInFromAP = avail->nextCheckIn; - // got some data from the AP! - if (avail->dataType != DATATYPE_NOUPDATE) { - // data transfer - if (doDataDownload(avail)) { - // succesful transfer, next wake time is determined by the NextCheckin; - } else { - // failed transfer, let the algorithm determine next sleep interval (not the AP) - nextCheckInFromAP = 0; - } - } else { - // no data transfer, just sleep. - } - } - - // if the AP told us to sleep for a specific period, do so. - if (nextCheckInFromAP) { - doSleep(nextCheckInFromAP * 60000UL); - } else { - doSleep(getNextSleep() * 1000UL); - } - } +void initializeProto() { + getNumSlots(); + curHighSlotId = getHighSlotId(); } \ No newline at end of file diff --git a/tag_fw/syncedproto.h b/tag_fw/syncedproto.h index 718babfb..583296dc 100644 --- a/tag_fw/syncedproto.h +++ b/tag_fw/syncedproto.h @@ -3,8 +3,18 @@ #include -void mainProtocolLoop(void); -extern uint8_t __xdata mSelfMac[]; + +extern uint8_t __xdata mSelfMac[8]; +extern uint8_t __xdata currentChannel; +extern uint8_t __xdata APmac[]; + +extern void initRadio(); +extern void killRadio(); +extern struct AvailDataInfo *__xdata getAvailDataInfo(); +extern bool doDataDownload(struct AvailDataInfo *__xdata avail); +extern void initializeProto(); +extern struct AvailDataInfo *__xdata getAvailDataInfo(); +bool probeChannel(uint8_t channel); #endif \ No newline at end of file diff --git a/tag_fw/userinterface.c b/tag_fw/userinterface.c index c9eb1129..b005d802 100644 --- a/tag_fw/userinterface.c +++ b/tag_fw/userinterface.c @@ -1,109 +1,285 @@ + + #include "userinterface.h" #include #include #include "asmUtil.h" +#include "bitmaps.h" #include "board.h" +#include "comms.h" #include "cpu.h" #include "epd.h" #include "font.h" #include "lut.h" #include "printf.h" #include "screen.h" +#include "settings.h" #include "sleep.h" #include "spi.h" +#include "syncedproto.h" // for APmac / Channel #include "timer.h" -extern uint8_t mSelfMac[]; +extern uint8_t __xdata mSelfMac[8]; +extern uint8_t __xdata currentChannel; +extern uint8_t __xdata APmac[]; + +static const uint8_t __code fwVersion = FW_VERSION; +static const char __code fwVersionSuffix[] = FW_VERSION_SUFFIX; void showSplashScreen() { epdSetup(); - lutTest(); + #if (SCREEN_WIDTH == 152) // 1.54" - selectLUT(1); clearScreen(); setColorMode(EPD_MODE_NORMAL, EPD_MODE_INVERT); - drawLineHorizontal(EPD_COLOR_BLACK, 33, 1); - epdPrintBegin(0, 0, EPD_DIRECTION_X, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); - pr("Booting!"); + selectLUT(1); + epdPrintBegin(12, 2, EPD_DIRECTION_X, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); + epdpr("Starting!"); + epdPrintEnd(); + + loadRawBitmap(solum, 8, 34, EPD_COLOR_BLACK); + loadRawBitmap(hacked, 32, 46, EPD_COLOR_RED); + + epdPrintBegin(5, 136, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_RED); + epdpr("%02X%02X", mSelfMac[7], mSelfMac[6]); + epdpr("%02X%02X", mSelfMac[5], mSelfMac[4]); + epdpr("%02X%02X", mSelfMac[3], mSelfMac[2]); + epdpr("%02X%02X", mSelfMac[1], mSelfMac[0]); + epdPrintEnd(); + + epdPrintBegin(2, 120, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("zbs154v033 %d.%d.%d%s", fwVersion / 100, (fwVersion % 100) / 10, (fwVersion % 10), fwVersionSuffix); epdPrintEnd(); draw(); - timerDelay(1333000); #endif + #if (SCREEN_WIDTH == 128) // 2.9" - selectLUT(1); + selectLUT(EPD_LUT_NO_REPEATS); clearScreen(); setColorMode(EPD_MODE_NORMAL, EPD_MODE_INVERT); - epdPrintBegin(0, 200, EPD_DIRECTION_Y, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); - pr("Booting!"); + epdPrintBegin(0, 295, EPD_DIRECTION_Y, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); + epdpr("Starting!"); epdPrintEnd(); - epdPrintBegin(0, 294, EPD_DIRECTION_Y, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); - pr("="); + epdPrintBegin(80, 295, EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("zbs29v033 %d.%d.%d%s", fwVersion / 100, (fwVersion % 100) / 10, (fwVersion % 10), fwVersionSuffix); epdPrintEnd(); - epdPrintBegin(32, 150, EPD_DIRECTION_Y, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); - pr("-TESTING-"); + epdPrintBegin(105, 270, EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_RED); + epdpr("MAC: %02X:%02X", mSelfMac[7], mSelfMac[6]); + epdpr(":%02X:%02X", mSelfMac[5], mSelfMac[4]); + epdpr(":%02X:%02X", mSelfMac[3], mSelfMac[2]); + epdpr(":%02X:%02X", mSelfMac[1], mSelfMac[0]); epdPrintEnd(); - epdPrintBegin(115, 295, EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_RED); - pr("MAC: %02X:%02X", mSelfMac[7], mSelfMac[6]); - pr(":%02X:%02X", mSelfMac[5], mSelfMac[4]); - pr(":%02X:%02X", mSelfMac[3], mSelfMac[2]); - pr(":%02X:%02X", mSelfMac[1], mSelfMac[0]); - epdPrintEnd(); + uint8_t __xdata buffer[17]; + spr(buffer, "%02X%02X", mSelfMac[7], mSelfMac[6]); + spr(buffer + 4, "%02X%02X", mSelfMac[5], mSelfMac[4]); + spr(buffer + 8, "%02X%02X", mSelfMac[3], mSelfMac[2]); + spr(buffer + 12, "%02X%02X", mSelfMac[1], mSelfMac[0]); + printBarcode(buffer, 120, 284); - epdPrintBegin(68, 294, EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); - pr("MAC64: %02X:%02X", mSelfMac[7], mSelfMac[6]); - pr(":%02X:%02X", mSelfMac[5], mSelfMac[4]); - pr(":%02X:%02X", mSelfMac[3], mSelfMac[2]); - pr(":%02X:%02X", mSelfMac[1], mSelfMac[0]); - epdPrintEnd(); - - drawLineVertical(EPD_COLOR_RED, 64, 10, 286); - drawLineVertical(EPD_COLOR_BLACK, 65, 10, 286); + loadRawBitmap(solum, 0, 0, EPD_COLOR_BLACK); + loadRawBitmap(hacked, 16, 12, EPD_COLOR_RED); + // lutTest(); + // drawLineVertical(EPD_COLOR_RED, 64, 10, 286); + // drawLineVertical(EPD_COLOR_BLACK, 65, 10, 286); draw(); - timerDelay(1333000); + // timerDelay(TIMER_TICKS_PER_SECOND * 4); #endif #if (SCREEN_WIDTH == 400) // 2.9" selectLUT(1); clearScreen(); setColorMode(EPD_MODE_NORMAL, EPD_MODE_INVERT); - epdPrintBegin(64, 150, EPD_DIRECTION_X, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); - pr("TEST"); - epdPrintEnd(); - epdPrintBegin(300, 296, EPD_DIRECTION_Y, EPD_SIZE_DOUBLE, EPD_COLOR_RED); - pr("Booting!Y"); - epdPrintEnd(); + epdpr("Booting!Y"); + epdpr(); epdPrintBegin(0, 0, EPD_DIRECTION_X, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); - pr("BootingX!"); + epdpr("Starting!"); epdPrintEnd(); - epdPrintBegin(16, 284, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_RED); - pr("MAC: %02X:%02X", mSelfMac[7], mSelfMac[6]); - pr(":%02X:%02X", mSelfMac[5], mSelfMac[4]); - pr(":%02X:%02X", mSelfMac[3], mSelfMac[2]); - pr(":%02X:%02X", mSelfMac[1], mSelfMac[0]); + epdPrintBegin(16, 252, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("zbs42v033 %d.%d.%d%s", fwVersion / 100, (fwVersion % 100) / 10, (fwVersion % 10), fwVersionSuffix); epdPrintEnd(); + epdPrintBegin(16, 284, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_RED); + epdpr("MAC: %02X:%02X", mSelfMac[7], mSelfMac[6]); + epdpr(":%02X:%02X", mSelfMac[5], mSelfMac[4]); + epdpr(":%02X:%02X", mSelfMac[3], mSelfMac[2]); + epdpr(":%02X:%02X", mSelfMac[1], mSelfMac[0]); + epdPrintEnd(); + + loadRawBitmap(solum, 256, 10, EPD_COLOR_BLACK); + loadRawBitmap(hacked, 264, 22, EPD_COLOR_RED); + + loadRawBitmap(solum, 253, 72, EPD_COLOR_BLACK); + loadRawBitmap(hacked, 261, 82, EPD_COLOR_RED); draw(); - timerDelay(1333000); #endif } void showApplyUpdate() { epdSetup(); + setColorMode(EPD_MODE_NORMAL, EPD_MODE_INVERT); + selectLUT(1); clearScreen(); setColorMode(EPD_MODE_IGNORE, EPD_MODE_NORMAL); epdPrintBegin(8, 60, EPD_DIRECTION_X, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); - pr("Updating!"); + epdpr("Updating!"); epdPrintEnd(); drawNoWait(); -} \ No newline at end of file +} + +uint8_t __xdata resultcounter = 0; + +void showScanningWindow() { + epdSetup(); + setColorMode(EPD_MODE_NORMAL, EPD_MODE_INVERT); + selectLUT(EPD_LUT_FAST_NO_REDS); + clearScreen(); +#if (SCREEN_WIDTH == 128) // 2.9" + epdPrintBegin(2, 275, EPD_DIRECTION_Y, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); + epdpr("Scanning for APs"); + epdPrintEnd(); + epdPrintBegin(40, 262, EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_RED); + epdpr("Channel - Quality"); + epdPrintEnd(); + loadRawBitmap(receive, 36, 24, EPD_COLOR_BLACK); +#endif +#if (SCREEN_WIDTH == 152) // 1.54" + loadRawBitmap(receive, 96, 28, EPD_COLOR_BLACK); + epdPrintBegin(3, 0, EPD_DIRECTION_X, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); + epdpr("Scanning..."); + epdPrintEnd(); +#endif + draw(); + selectLUT(EPD_LUT_FAST); + resultcounter = 0; +} + +void addScanResult(uint8_t channel, uint8_t lqi) { + if (channel == 11) resultcounter = 0; +#if (SCREEN_WIDTH == 128) + epdPrintBegin(56 + ((resultcounter % 4) * 16), 282 - (47 * (resultcounter / 4)), EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("%d-%d", channel, lqi); + epdPrintEnd(); +#endif +#if (SCREEN_WIDTH == 152) // 1.54" + epdPrintBegin(4 + (47 * (resultcounter / 8)), 31 + (15 * (resultcounter % 8)), EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("%d-%d", channel, lqi); + epdPrintEnd(); +#endif + resultcounter++; +} + +void showAPFound() { + selectLUT(EPD_LUT_FAST_NO_REDS); + clearScreen(); +#if (SCREEN_WIDTH == 128) + epdPrintBegin(0, 285, EPD_DIRECTION_Y, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); + epdpr("Waiting for data..."); + epdPrintEnd(); + epdPrintBegin(48, 278, EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("Found the following AP:"); + epdPrintEnd(); + epdPrintBegin(64, 293, EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("AP MAC: %02X:%02X", APmac[7], APmac[6]); + epdpr(":%02X:%02X", APmac[5], APmac[4]); + epdpr(":%02X:%02X", APmac[3], APmac[2]); + epdpr(":%02X:%02X", APmac[1], APmac[0]); + epdPrintEnd(); + epdPrintBegin(80, 293, EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("Ch: %d RSSI: %d LQI: %d", currentChannel, mLastRSSI, mLastLqi); + epdPrintEnd(); + + epdPrintBegin(103, 258, EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("Tag MAC: %02X:%02X", mSelfMac[7], mSelfMac[6]); + epdpr(":%02X:%02X", mSelfMac[5], mSelfMac[4]); + epdpr(":%02X:%02X", mSelfMac[3], mSelfMac[2]); + epdpr(":%02X:%02X", mSelfMac[1], mSelfMac[0]); + epdPrintEnd(); + + uint8_t __xdata buffer[17]; + spr(buffer, "%02X%02X", mSelfMac[7], mSelfMac[6]); + spr(buffer + 4, "%02X%02X", mSelfMac[5], mSelfMac[4]); + spr(buffer + 8, "%02X%02X", mSelfMac[3], mSelfMac[2]); + spr(buffer + 12, "%02X%02X", mSelfMac[1], mSelfMac[0]); + printBarcode(buffer, 120, 253); + loadRawBitmap(receive, 36, 14, EPD_COLOR_BLACK); +#endif +#if (SCREEN_WIDTH == 152) // 1.54" + epdPrintBegin(25, 0, EPD_DIRECTION_X, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); + epdpr("Waiting"); + epdPrintEnd(); + epdPrintBegin(3, 32, EPD_DIRECTION_X, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); + epdpr("for data..."); + epdPrintEnd(); + + epdPrintBegin(5, 64, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("AP MAC:"); + epdPrintEnd(); + epdPrintBegin(5, 80, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("%02X%02X", APmac[7], APmac[6]); + epdpr("%02X%02X", APmac[5], APmac[4]); + epdpr("%02X%02X", APmac[3], APmac[2]); + epdpr("%02X%02X", APmac[1], APmac[0]); + epdPrintEnd(); + + epdPrintBegin(5, 96, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("Ch:%d rssi:%d lqi:%d", currentChannel, mLastRSSI, mLastLqi); + epdPrintEnd(); + + epdPrintBegin(5, 120, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("Tag MAC:"); + epdPrintEnd(); + + epdPrintBegin(5, 136, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_RED); + epdpr("%02X%02X", mSelfMac[7], mSelfMac[6]); + epdpr("%02X%02X", mSelfMac[5], mSelfMac[4]); + epdpr("%02X%02X", mSelfMac[3], mSelfMac[2]); + epdpr("%02X%02X", mSelfMac[1], mSelfMac[0]); + epdPrintEnd(); +#endif + draw(); +} + +void showNoAP() { + selectLUT(EPD_LUT_NO_REPEATS); + clearScreen(); +#if (SCREEN_WIDTH == 128) // 1.54" + epdPrintBegin(0, 285, EPD_DIRECTION_Y, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); + epdpr("No AP found :("); + epdPrintEnd(); + epdPrintBegin(48, 285, EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("We'll try again in a"); + epdPrintEnd(); + epdPrintBegin(64, 285, EPD_DIRECTION_Y, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("little while..."); + epdPrintEnd(); + loadRawBitmap(receive, 36, 24, EPD_COLOR_BLACK); + loadRawBitmap(failed, 42, 26, EPD_COLOR_RED); +#endif +#if (SCREEN_WIDTH == 152) // 1.54" + epdPrintBegin(40, 0, EPD_DIRECTION_X, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); + epdpr("No AP"); + epdPrintEnd(); + epdPrintBegin(22, 32, EPD_DIRECTION_X, EPD_SIZE_DOUBLE, EPD_COLOR_BLACK); + epdpr("found :("); + epdPrintEnd(); + + epdPrintBegin(8, 76, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("We'll try again in"); + epdPrintEnd(); + epdPrintBegin(25, 92, EPD_DIRECTION_X, EPD_SIZE_SINGLE, EPD_COLOR_BLACK); + epdpr("a little while"); + epdPrintEnd(); +#endif + draw(); +} diff --git a/tag_fw/userinterface.h b/tag_fw/userinterface.h index 548affd7..7b697e72 100644 --- a/tag_fw/userinterface.h +++ b/tag_fw/userinterface.h @@ -1,9 +1,11 @@ - #ifndef _UI_H_ #define _UI_H_ +#include void showSplashScreen(); void showApplyUpdate(); - - +void showScanningWindow(); +void addScanResult(uint8_t channel, uint8_t lqi); +void showAPFound(); +void showNoAP(); #endif \ No newline at end of file