@@ -394,11 +394,23 @@ function showNotification(text) {
394394
395395var pinPresets = {
396396 // array: reset, isp, conn, ser, swap, rxpup
397- "esp-01" : [ 0 , - 1 , 2 , - 1 , 0 , 1 ] ,
398- "esp-12" : [ 12 , 14 , 0 , 2 , 0 , 1 ] ,
399- "esp-12 swap" : [ 1 , 3 , 0 , 2 , 1 , 1 ] ,
400- "esp-bridge" : [ 12 , 13 , 0 , 14 , 0 , 0 ] ,
401- "wifi-link-12" : [ 1 , 3 , 0 , 2 , 1 , 0 ] ,
397+ "esp-01" : [ 0 , - 1 , 2 , - 1 , 0 , 1 , 0 ] ,
398+ "esp-01-inv" : [ 0 , - 1 , 2 , - 1 , 0 , 1 , 63 ] ,
399+ "esp-12" : [ 12 , 14 , 0 , 2 , 0 , 1 , 0 ] ,
400+ "esp-12 swap" : [ 1 , 3 , 0 , 2 , 1 , 1 , 0 ] ,
401+ "esp-12-inv" : [ 12 , 14 , 0 , 2 , 0 , 1 , 63 ] ,
402+ "esp-12 swap-inv" : [ 1 , 3 , 0 , 2 , 1 , 1 , 63 ] ,
403+ "esp-bridge" : [ 12 , 13 , 0 , 14 , 0 , 0 , 0 ] ,
404+ "wifi-link-12" : [ 1 , 3 , 0 , 2 , 1 , 0 , 0 ] ,
405+ } ;
406+
407+ var invertPins = {
408+ "rxd" : 1 ,
409+ "cts" : 2 ,
410+ "dsr" : 4 ,
411+ "txd" : 8 ,
412+ "rts" : 16 ,
413+ "dtr" : 32
402414} ;
403415
404416function createPresets ( sel ) {
@@ -418,6 +430,16 @@ function createPresets(sel) {
418430 setPP ( "ser" , pp [ 3 ] ) ;
419431 setPP ( "swap" , pp [ 4 ] ) ;
420432 $ ( "#pin-rxpup" ) . checked = ! ! pp [ 5 ] ;
433+ $ ( "#pin-invert" ) . checked = ! ! pp [ 6 ] ;
434+ if ( $ ( "#pin-invert" ) . checked )
435+ {
436+ $ ( "#pins-invert-group" ) . style . display = "block" ;
437+ }
438+ else
439+ {
440+ $ ( "#pins-invert-group" ) . style . display = "none" ;
441+ }
442+ pinsInvertApplyConfig ( pp [ 6 ] ) ;
421443 sel . value = 0 ;
422444 } ;
423445
@@ -453,6 +475,12 @@ function displayPins(resp) {
453475 createSelectForPin ( "ser" , resp [ "ser" ] ) ;
454476 $ ( "#pin-swap" ) . value = resp [ "swap" ] ;
455477 $ ( "#pin-rxpup" ) . checked = ! ! resp [ "rxpup" ] ;
478+ $ ( "#pin-invert" ) . checked = ! ! resp [ "pinvert" ] ;
479+ pinsInvertApplyConfig ( resp [ "pinvert" ] ) ;
480+ if ( $ ( "#pin-invert" ) . checked )
481+ {
482+ $ ( "#pins-invert-group" ) . style . display = "block" ;
483+ }
456484 createPresets ( $ ( "#pin-preset" ) ) ;
457485
458486 $ ( "#pin-spinner" ) . setAttribute ( "hidden" , "" ) ;
@@ -465,15 +493,81 @@ function fetchPins() {
465493 } ) ;
466494}
467495
496+ function pinsInvertApplyConfig ( v )
497+ {
498+ for ( var p in invertPins )
499+ {
500+ if ( invertPins [ p ] & v )
501+ {
502+ $ ( "#pin-" + p + "-invert" ) . checked = true ;
503+ }
504+ else
505+ {
506+ $ ( "#pin-" + p + "-invert" ) . checked = false ;
507+ }
508+ }
509+
510+ }
511+
512+ function pinInvertChanged ( )
513+ {
514+ var any = false ;
515+ for ( var p in invertPins )
516+ {
517+ if ( $ ( "#pin-" + p + "-invert" ) . checked )
518+ {
519+ any = true ;
520+ }
521+ }
522+ if ( ! any )
523+ {
524+ $ ( "#pin-invert" ) . checked = false ;
525+ pinsInvertChanged ( ) ;
526+ }
527+ }
528+
529+ function pinsInvertChanged ( )
530+ {
531+ if ( $ ( "#pin-invert" ) . checked )
532+ {
533+ pinsInvertApplyConfig ( 63 ) ;
534+ $ ( "#pins-invert-group" ) . style . display = "block" ;
535+ }
536+ else
537+ {
538+ pinsInvertApplyConfig ( 0 ) ;
539+ $ ( "#pins-invert-group" ) . style . display = "none" ;
540+ }
541+ }
542+
543+ function setInvertBindings ( )
544+ {
545+ bnd ( $ ( "#pin-invert" ) , "click" , pinsInvertChanged ) ;
546+ for ( var p in invertPins )
547+ {
548+ bnd ( $ ( "#pin-" + p + "-invert" ) , "click" , pinInvertChanged ) ;
549+ }
550+ }
551+
468552function setPins ( ev ) {
469553 ev . preventDefault ( ) ;
554+ setEditToClick ( )
470555 var url = "/pins" ;
471556 var sep = "?" ;
472557 [ "reset" , "isp" , "conn" , "ser" , "swap" ] . forEach ( function ( p ) {
473558 url += sep + p + "=" + $ ( "#pin-" + p ) . value ;
474559 sep = "&" ;
475560 } ) ;
476561 url += "&rxpup=" + ( $ ( "#pin-rxpup" ) . checked ? "1" : "0" ) ;
562+ var invert = 0 ;
563+ for ( var p in invertPins )
564+ {
565+ if ( $ ( "#pin-" + p + "-invert" ) . checked )
566+ {
567+ invert += invertPins [ p ] ;
568+ }
569+ }
570+ url += "&pinvert=" + invert ;
477571// console.log("set pins: " + url);
478572 ajaxSpin ( "POST" , url , function ( ) {
479573 showNotification ( "Pin assignment changed" ) ;
0 commit comments