File tree Expand file tree Collapse file tree 3 files changed +88
-1
lines changed Expand file tree Collapse file tree 3 files changed +88
-1
lines changed Original file line number Diff line number Diff line change 1+ < html >
2+
3+ < head >
4+ < script src ="../dist/webduino-all.js "> </ script >
5+ < script >
6+
7+ ( async function ( ) {
8+ var board , led , vv ;
9+ var tt = 0 ;
10+
11+ window . sboard = board = new webduino . WebArduino ( 'O9Qq' ) ;
12+
13+ board . on ( 'ready' , async ( ) => {
14+ board . systemReset ( ) ;
15+ board . samplingInterval = 250 ;
16+ board . sendingInterval = 50 ;
17+ led = new webduino . module . Led ( board , board . getDigitalPin ( 13 ) ) ;
18+ vv = 0 ;
19+
20+ for ( var count = 0 ; count < 100 ; count ++ ) {
21+ if ( vv == 0 ) {
22+ vv = 1 ;
23+ led . on ( ( ) => msg ( `${ tt ++ } _light` ) ) ;
24+ } else {
25+ vv = 0 ;
26+ led . off ( ( ) => msg ( `${ tt ++ } _dark` ) ) ;
27+ }
28+ await delay ( 0.02 ) ;
29+ }
30+ await delay ( 0.5 ) ;
31+ msg ( `end, ${ tt } ` ) ;
32+ console . log ( 'end' ) ;
33+ } ) ;
34+
35+ function delay ( t ) {
36+ return new Promise ( function ( resolve , reject ) {
37+ setTimeout ( function ( ) {
38+ resolve ( ) ;
39+ } , 1000 * t ) ;
40+ } ) ;
41+ }
42+
43+ function msg ( val ) {
44+ console . log ( 'TCL: msg -> val' , val ) ;
45+ document . getElementById ( "demo-area-01-show" ) . innerHTML = val ;
46+ }
47+
48+ } ) ( ) ;
49+ </ script >
50+ </ head >
51+
52+ < body >
53+ < div > start</ div >
54+ < div id ='demo-area-01-show '> </ div >
55+ </ body >
56+
57+ </ html >
Original file line number Diff line number Diff line change 1212 "license" : " MIT" ,
1313 "scripts" : {
1414 "lint" : " eslint src/**/*.js" ,
15+ "dev" : " gulp watch" ,
1516 "build" : " ./node_modules/.bin/gulp"
1617 },
1718 "devDependencies" : {
Original file line number Diff line number Diff line change 9696 this . _transport = null ;
9797 this . _pinStateEventCenter = new EventEmitter ( ) ;
9898 this . _logger = new Logger ( 'Board' ) ;
99+ this . _sendingInterval = 0 ;
100+ this . _sendingRec = [ ] ;
99101
100102 this . _initialVersionResultHandler = onInitialVersionResult . bind ( this ) ;
101103 this . _openHandler = onOpen . bind ( this ) ;
211213 }
212214 } ,
213215
216+ sendingInterval : {
217+ get : function ( ) {
218+ return this . _sendingInterval ;
219+ } ,
220+ set : function ( interval ) {
221+ if ( typeof interval !== 'number' ) return ;
222+ this . _sendingInterval = interval < 0 ? 0 : interval ;
223+ }
224+ } ,
225+
214226 isReady : {
215227 get : function ( ) {
216228 return this . _isReady ;
865877 } ;
866878
867879 proto . send = function ( data ) {
868- this . isConnected && this . _transport . send ( data ) ;
880+ if ( ! this . isConnected ) return ;
881+ if ( this . sendingInterval === 0 ) {
882+ this . _transport . send ( data ) ;
883+ return ;
884+ }
885+
886+ var idx = this . _sendingRec . findIndex ( function ( val ) {
887+ return val . value . toString ( ) === data . toString ( ) ;
888+ } ) ;
889+ if ( idx !== - 1 ) {
890+ if ( Date . now ( ) - this . _sendingRec [ idx ] . timestamp < this . sendingInterval ) return ;
891+ this . _sendingRec . splice ( idx , 1 ) ;
892+ }
893+ this . _sendingRec . push ( {
894+ value : data . slice ( ) ,
895+ timestamp : Date . now ( )
896+ } ) ;
897+ this . _transport . send ( data ) ;
869898 } ;
870899
871900 proto . close = function ( callback ) {
You can’t perform that action at this time.
0 commit comments