1
1
import CancellationToken from 'cancellationtoken' ;
2
+ import Log from './Log' ;
2
3
import IndiManager from './IndiManager' ;
3
4
4
- function debug ( ...args :any [ ] ) {
5
- console . log ( 'IndiAutoConnect: ' + args . map ( ( e ) => '' + e ) . join ( ' ' ) ) ;
6
- }
7
-
5
+ const logger = Log . logger ( __filename ) ;
8
6
9
7
// Evaluate f function, but if fail, return def
10
8
function noErr < T > ( f :( ) => T , def : T )
@@ -54,7 +52,7 @@ export default class IndiAutoGphotoSensorSize {
54
52
// - busy, set the memory to done
55
53
// - idle disconnected, connect
56
54
// Remove the unknown devices from the memory
57
- debug ( 'Recheck' ) ;
55
+ logger . debug ( 'Recheck' ) ;
58
56
const configDevices = noErr ( ( ) => this . indiManager . currentStatus . configuration . indiServer . devices , undefined ) || { } ;
59
57
60
58
const configuredDevices :{ [ id :string ] :boolean } = { } ;
@@ -65,7 +63,7 @@ export default class IndiAutoGphotoSensorSize {
65
63
if ( ! noErr ( ( ) => dev . options . autoGphotoSensorSize , undefined ) ) {
66
64
continue ;
67
65
}
68
- debug ( 'Configured device: ' , devId ) ;
66
+ logger . debug ( 'Configured device' , { devId} ) ;
69
67
configuredDevices [ devId ] = true ;
70
68
}
71
69
@@ -76,28 +74,23 @@ export default class IndiAutoGphotoSensorSize {
76
74
77
75
const deviceIds = c . getAvailableDeviceIdsWith ( [ targetVector ] ) ;
78
76
79
- debug ( 'valid devices = ' , JSON . stringify ( deviceIds ) ) ;
77
+ logger . debug ( 'valid devices' , { deviceIds} ) ;
80
78
for ( let devId of deviceIds ) {
81
- debug ( 'What about' , devId ) ;
82
79
if ( ! Object . prototype . hasOwnProperty . call ( configuredDevices , devId ) ) {
83
- debug ( 'Not configured' ) ;
84
80
continue ;
85
81
}
86
82
87
83
// Check the connection state
88
84
const connVector = c . getDevice ( devId ) . getVector ( 'CONNECTION' ) ;
89
85
if ( ! connVector . exists ( ) ) {
90
- debug ( 'CONNECTION does not exists' ) ;
91
86
continue ;
92
87
}
93
88
94
89
if ( connVector . getState ( ) === 'Busy' ) {
95
- debug ( 'CONNECTION is busy' ) ;
96
90
continue ;
97
91
}
98
92
99
93
if ( connVector . getPropertyValueIfExists ( 'CONNECT' ) !== 'On' ) {
100
- debug ( 'CONNECTION NOT On' ) ;
101
94
continue ;
102
95
}
103
96
@@ -106,25 +99,23 @@ export default class IndiAutoGphotoSensorSize {
106
99
107
100
const vector = c . getDevice ( devId ) . getVector ( targetVector ) ;
108
101
if ( vector . getState ( ) === 'Busy' ) {
109
- debug ( targetVector , 'is busy' ) ;
110
102
continue ;
111
103
}
112
104
113
105
const values = Object . keys ( defaultValues ) . sort ( ) . map ( k => {
114
106
const strValue = vector . getPropertyValueIfExists ( k ) ;
115
107
return strValue === null ? null : parseFloat ( strValue ) ;
116
108
} ) ;
117
- debug ( 'Current values: ' , JSON . stringify ( values ) ) ;
109
+ logger . debug ( 'Current values' , { devId , values} ) ;
118
110
119
111
if ( values . filter ( e => ( e !== 0 && e !== null ) ) . length === 0 ) {
120
- debug ( 'Values are fine' ) ;
121
112
continue ;
122
113
}
123
114
124
115
// Check the connection state of the device
125
116
// Take memory state from the state of the connection vector
126
117
const memoryState = Object . prototype . hasOwnProperty . call ( this . memory , devId ) ? this . memory [ devId ] : null ;
127
- debug ( 'Memory state is ' , memoryState ) ;
118
+ logger . debug ( 'Memory state ' , { devId , memoryState} ) ;
128
119
if ( memoryState === true ) {
129
120
continue ;
130
121
}
@@ -133,17 +124,17 @@ export default class IndiAutoGphotoSensorSize {
133
124
134
125
( async ( ) => {
135
126
try {
136
- debug ( 'Starting...' ) ;
127
+ logger . info ( 'Starting' , { devId , defaultValues } ) ;
137
128
await this . indiManager . setParam ( CancellationToken . CONTINUE , devId , targetVector , defaultValues , true ) ;
138
129
} catch ( e ) {
139
- debug ( 'Ignoring set size error' , e ) ;
130
+ logger . warn ( 'Ignoring set size error' , { devId , defaultValues } , e ) ;
140
131
}
141
132
} ) ( ) ;
142
133
}
143
134
}
144
135
145
136
for ( let devId of Object . keys ( unseenDevices ) ) {
146
- debug ( 'Forget about ' , devId ) ;
137
+ logger . debug ( 'Forget' , { devId} ) ;
147
138
delete this . memory [ devId ] ;
148
139
}
149
140
}
0 commit comments