Typica is a free program for professional coffee roasters. https://typica.us
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

productionroaster.xml 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. <window id="basicWindow">
  2. <layout type="vertical">
  3. <splitter type = "vertical" id = "main">
  4. <splitter type = "horizontal" id = "indicators" />
  5. <widget id="widget">
  6. <layout type="horizontal" id="controlpanel">
  7. <button name="Start Batch" type="push" id="startbutton" />
  8. <button name="Stop Batch" type="annotation" id="stopbutton" annotation="End" />
  9. </layout>
  10. </widget>
  11. <splitter type="horizontal" id="logsplit">
  12. <measurementtable id="log" />
  13. <graph id="graph" />
  14. </splitter>
  15. </splitter>
  16. </layout>
  17. <menu name="File">
  18. <item id="open" shortcut="Ctrl+O">Open…</item>
  19. <item id="save" shortcut="Ctrl+S">Save…</item>
  20. <item id="print" shortcut="Ctrl+P">Print…</item>
  21. <item id="export">Export CSV…</item>
  22. <item id="svgexport">Export XHTML+SVG…</item>
  23. <item id="quit" shortcut="Ctrl+Q">Quit</item>
  24. </menu>
  25. <menu name="Batch">
  26. <item id="new" shortcut="Ctrl+N">New Batch…</item>
  27. <item id="compare">Load Additional Profiles...</item>
  28. </menu>
  29. <menu name="Log">
  30. <item id="showC">Display Celsius</item>
  31. <item id="showF">Display Fahrenheit</item>
  32. <item id="setSample">New Sample Parameters</item>
  33. <separator />
  34. <item id="clear" shortcut="Ctrl+L">Clear Log</item>
  35. <separator />
  36. <item id="ms">Millisecond View</item>
  37. <item id="1s">1 Second View</item>
  38. <item id="5s">5 Second View</item>
  39. <item id="10s">10 Second View</item>
  40. <item id="15s">15 Second View</item>
  41. <item id="30s">30 Second View</item>
  42. <item id="1m">1 Minute View</item>
  43. <separator />
  44. <item id="manual" shortcut="Ctrl+E">Manual Entry</item>
  45. </menu>
  46. <menu name="Graph">
  47. <item id="unshift">Reset Translation</item>
  48. </menu>
  49. <program>
  50. <![CDATA[
  51. var window = this;
  52. var targetOffset = 0;
  53. var gtrans = 0;
  54. var targetDetector = new ThresholdDetector;
  55. window.targetcolumnname = "";
  56. var currentDetector = new ThresholdDetector;
  57. var translationChannel = -1;
  58. targetDetector.timeForValue.connect(function(value) {
  59. targetOffset = value;
  60. });
  61. var epoch = new QTime;
  62. epoch = epoch.currentTime;
  63. var translationCurrentColumn = -1;
  64. var configModel = new DeviceTreeModel;
  65. var rootIndex = configModel.index(roasterlist.currentIndex, 0);
  66. var channels = new Array();
  67. var annotationButtons = new Array();
  68. var nidevices = new Array();
  69. var dataqsdkdevices = new Array();
  70. var temperatureDisplays = new Array();
  71. var columnNames = new Array();
  72. var modbusdevices = new Array();
  73. var rateCalculators = new Array();
  74. var rateadapters = new Array();
  75. var rateoffsets = new Array();
  76. var ratezeros = new Array();
  77. var indicatorPanel = findChildObject(this, 'indicators');
  78. var annotationPanel = findChildObject(this, 'controlpanel');
  79. var log = findChildObject(this, 'log');
  80. var tabControls = new Array();
  81. var start = findChildObject(this, 'startbutton');
  82. var stop = findChildObject(this, 'stopbutton');
  83. stop.enabled = false;
  84. tabControls.push(start);
  85. tabControls.push(stop);
  86. var nsparam = findChildObject(this, 'setSample');
  87. nsparam.enabled = false;
  88. var graph = findChildObject(this, 'graph');
  89. var hasTranslated = false;
  90. var externtrans = undefined;
  91. window.translateLoadedSeries = function(translation) {
  92. var lc = Number(QSettings.value("liveColumn"));
  93. for(var i = 1; i < lc - 1; i++)
  94. {
  95. graph.setSeriesTranslation(i, translation);
  96. }
  97. };
  98. window.translateCurrentSeries = function(translation) {
  99. var lc = Number(QSettings.value("liveColumn"));
  100. for(var i = 0; i < columnNames.length; i++)
  101. {
  102. graph.setSeriesTranslation(lc + i, translation);
  103. }
  104. };
  105. var selectedRoasterName = configModel.data(rootIndex, 0);
  106. var machineReference = configModel.referenceElement(configModel.data(rootIndex, 32));
  107. var selectedRoasterID = machineReference.databaseid;
  108. if(configModel.hasChildren(rootIndex)) {
  109. for(var i = 0; i < configModel.rowCount(rootIndex); i++) {
  110. var driverIndex = configModel.index(i, 0, rootIndex);
  111. var driverReference = configModel.referenceElement(configModel.data(driverIndex, 32));
  112. if(driverReference.driver == "nidaqmxbase" || driverReference.driver == "nidaqmx") {
  113. if(configModel.hasChildren(driverIndex)) {
  114. for(var j = 0; j < configModel.rowCount(driverIndex); j++) {
  115. var deviceIndex = configModel.index(j, 0, driverIndex);
  116. var deviceReference = configModel.referenceElement(configModel.data(deviceIndex, 32));
  117. if(deviceReference.driver == "nidaqmxbase9211series" || deviceReference.driver == "nidaqmx9211series") {
  118. var device = new DAQ(deviceReference.deviceID, driverReference.driver);
  119. nidevices.push(device);
  120. var DAQChannels = 0;
  121. if(configModel.hasChildren(deviceIndex)) {
  122. for(var k = 0; k < configModel.rowCount(deviceIndex); k++) {
  123. var channelIndex = configModel.index(k, 0, deviceIndex);
  124. var channelReference = configModel.referenceElement(configModel.data(channelIndex, 32));
  125. if(channelReference.driver == "ni9211seriestc") {
  126. var channel;
  127. if(channelReference.type == "J") {
  128. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeJ);
  129. }
  130. else if(channelReference.type == "K") {
  131. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeK);
  132. }
  133. else if(channelReference.type == "T") {
  134. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeT);
  135. }
  136. else if(channelReference.type == "B") {
  137. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeB);
  138. }
  139. else if(channelReference.type == "E") {
  140. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeE);
  141. }
  142. else if(channelReference.type == "N") {
  143. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeN);
  144. }
  145. else if(channelReference.type == "R") {
  146. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeR);
  147. }
  148. else if(channelReference.type == "S") {
  149. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeS);
  150. }
  151. channels.push(channel);
  152. columnNames.push(channelReference.columnname);
  153. DAQChannels++;
  154. var indicator = new TemperatureDisplay;
  155. temperatureDisplays.push(indicator);
  156. var decorator = new WidgetDecorator(indicator, configModel.data(channelIndex, 0), 2);
  157. channel.newData.connect(indicator.setValue);
  158. indicatorPanel.addWidget(decorator);
  159. }
  160. }
  161. switch(DAQChannels) {
  162. case 1:
  163. device.setClockRate(4);
  164. break;
  165. case 2:
  166. device.setClockRate(2);
  167. break;
  168. case 3:
  169. device.setClockRate(1.5);
  170. break;
  171. case 4:
  172. device.setClockRate(1);
  173. break;
  174. }
  175. device.start();
  176. }
  177. }
  178. else if(deviceReference.driver == "nidaqmxtc01")
  179. {
  180. var device = new DAQ(deviceReference.deviceID, "nidaqmx");
  181. var channel;
  182. if(deviceReference.type == "J")
  183. {
  184. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeJ);
  185. }
  186. else if(deviceReference.type == "K")
  187. {
  188. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeK);
  189. }
  190. else if(deviceReference.type == "T")
  191. {
  192. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeT);
  193. }
  194. else if(deviceReference.type == "B")
  195. {
  196. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeB);
  197. }
  198. else if(deviceReference.type == "E")
  199. {
  200. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeE);
  201. }
  202. else if(deviceReference.type == "N")
  203. {
  204. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeN);
  205. }
  206. else if(deviceReference.type == "R")
  207. {
  208. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeR);
  209. }
  210. else if(deviceReference.type == "S")
  211. {
  212. channel = device.newChannel(DAQ.Fahrenheit, DAQ.TypeS);
  213. }
  214. channels.push(channel);
  215. columnNames.push(deviceReference.columnname);
  216. var indicator = new TemperatureDisplay;
  217. temperatureDisplays.push(indicator);
  218. var decorator = new WidgetDecorator(indicator, configModel.data(deviceIndex, 0), 2);
  219. channel.newData.connect(indicator.setValue);
  220. indicatorPanel.addWidget(decorator);
  221. device.start();
  222. nidevices.push(device);
  223. }
  224. }
  225. }
  226. }
  227. else if(driverReference.driver == "dataqsdk")
  228. {
  229. var device = new DataqSdkDevice(driverReference.autoSelect ? driverReference.deviceNumber : driverReference.port);
  230. var sampleRate = 6;
  231. if(configModel.hasChildren(driverIndex)
  232. {
  233. for(var j = 0; j < configModel.rowCount(driverIndex); j++)
  234. {
  235. var channelIndex = configModel.index(j, 0, driverIndex);
  236. var channelReference = configModel.referenceElement(configModel.data(channelIndex, 32));
  237. var unit;
  238. if(channelReference.type == "Temperature") {
  239. unit = Units.Fahrenheit;
  240. }
  241. else {
  242. unit = Units.Unitless;
  243. }
  244. var channel = device.newChannel(unit);
  245. var calibrator = new LinearCalibrator;
  246. calibrator.measuredLower = channelReference.calibrationMeasuredLower;
  247. calibrator.measuredUpper = channelReference.calibrationMeasuredUpper;
  248. calibrator.mappedLower = channelReference.calibrationMappedLower;
  249. calibrator.mappedUpper = channelReference.calibrationMappedUpper;
  250. calibrator.sensitivity = channelReference.calibrationSensitivity;
  251. calibrator.closedRange = channelReference.calibrationClosedInterval;
  252. // device.setSmoothingEnabled(j) = channelReference.smoothing;
  253. channel.newData.connect(calibrator.newMeasurement)
  254. channels.push(calibrator);
  255. columnNames.push(channelReference.column);
  256. var indicator = new TemperatureDisplay;
  257. temperatureDisplays.push(indicator);
  258. var decorator = new WidgetDecorator(indicator, configModel.data(channelIndex, 0), 2);
  259. calibrator.newData.connect(indicator.setValue);
  260. indicatorPanel.addWidget(decorator);
  261. }
  262. sampleRate /= configModel.rowCount(driverIndex);
  263. }
  264. device.setSampleRate(sampleRate);
  265. device.start();
  266. dataqsdkdevices.push(device);
  267. }
  268. else if(driverReference.driver == "modbusrtu")
  269. {
  270. var device = new ModbusRTUDevice(configModel, driverIndex);
  271. modbusdevices.push(device);
  272. var pvchannel = device.pVChannel();
  273. channels.push(pvchannel);
  274. columnNames.push(driverReference.pvcolname);
  275. var indicator = new TemperatureDisplay;
  276. temperatureDisplays.push(indicator);
  277. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0) + " PV", 2);
  278. pvchannel.newData.connect(indicator.setValue);
  279. indicatorPanel.addWidget(decorator);
  280. if(driverReference.sVEnabled == "true")
  281. {
  282. var svchannel = device.sVChannel();
  283. channels.push(svchannel);
  284. columnNames.push(driverReference.svcolname);
  285. var indicator = new TemperatureDisplay;
  286. temperatureDisplays.push(indicator);
  287. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0) + " SV", 2);
  288. svchannel.newData.connect(indicator.setValue);
  289. indicatorPanel.addWidget(decorator);
  290. }
  291. if(driverReference.sVWritable == "true")
  292. {
  293. var outputControl = new AnnotationSpinBox;
  294. device.SVLowerChanged.connect(function(min) {
  295. outputControl.minimum = min;
  296. });
  297. outputControl.minimum = device.SVLower();
  298. device.SVUpperChanged.connect(function(max) {
  299. outputControl.maximum = max;
  300. });
  301. outputControl.maximum = device.SVUpper();
  302. device.SVDecimalChanged.connect(function(prec) {
  303. outputControl.decimals = prec;
  304. });
  305. outputControl.decimals = device.decimals();
  306. outputControl.editingFinished.connect(function() {
  307. device.outputSV(outputControl.value);
  308. });
  309. var layout = new QBoxLayout;
  310. var label = new QLabel("Change SV");
  311. layout.addWidget(label, 0, 2);
  312. layout.addWidget(outputControl, 0, 1);
  313. annotationPanel.addLayout(layout);
  314. tabControls.push(outputControl);
  315. }
  316. }
  317. else if(driverReference.driver == "annotationbutton")
  318. {
  319. var button = new AnnotationButton(driverReference.buttontext);
  320. button.setAnnotation(driverReference.annotationtext);
  321. annotationButtons.push(button);
  322. annotationPanel.addWidget(button);
  323. tabControls.push(button);
  324. }
  325. else if(driverReference.driver == "reconfigurablebutton")
  326. {
  327. var button = new AnnotationButton(driverReference.buttontext);
  328. button.setAnnotation(driverReference.annotationtext);
  329. annotationButtons.push(button);
  330. annotationPanel.addWidget(button);
  331. tabControls.push(button);
  332. nsparam.enabled = true;
  333. nsparam.triggered.connect(function() {
  334. var setParam = createWindow("sampleParameters");
  335. setParam.windowTitle = "Typica - Set Sample Parameters";
  336. setParam.button = button;
  337. });
  338. }
  339. else if(driverReference.driver == "annotationspinbox")
  340. {
  341. var layout = new QBoxLayout;
  342. var label = new QLabel(driverReference.label);
  343. layout.addWidget(label, 0, 2);
  344. var spinbox = new AnnotationSpinBox;
  345. spinbox.setPretext(driverReference.pretext);
  346. spinbox.setPosttext(driverReference.posttext);
  347. spinbox.minimum = driverReference.minimum;
  348. spinbox.maximum = driverReference.maximum;
  349. spinbox.decimals = driverReference.precision;
  350. layout.addWidget(spinbox, 0, 1);
  351. annotationPanel.addLayout(layout);
  352. annotationButtons.push(spinbox);
  353. tabControls.push(spinbox);
  354. }
  355. else if(driverReference.driver == "freeannotation")
  356. {
  357. var layout = new QBoxLayout;
  358. var label = new QLabel(driverReference.labeltext);
  359. var control = new QLineEdit;
  360. layout.addWidget(label, 0, 2);
  361. layout.addWidget(control, 0, 1);
  362. annotationPanel.addLayout(layout);
  363. tabControls.push(control);
  364. control.returnPressed.connect(function() {
  365. for(var i = window.firstTempColumn; i < window.annotationColumn; i++) {
  366. log.newAnnotation(control.text, i, window.annotationColumn);
  367. }
  368. });
  369. }
  370. else if(driverReference.driver == "linearspline")
  371. {
  372. var colname = driverReference.source;
  373. for(var j = 0; j < columnNames.length; j++)
  374. {
  375. if(columnNames[j] == colname)
  376. {
  377. var calibrator = new LinearSplineInterpolator;
  378. var sv = driverReference.sourcevalues;
  379. var dv = driverReference.destinationvalues;
  380. var sourcevalues = sv.slice(2, sv.length-2).split(",");
  381. var destvalues = dv.slice(2, dv.length-2).split(",");
  382. if(sourcevalues.length > 1 && destvalues.length == sourcevalues.length)
  383. {
  384. for(var k = 0; k < sourcevalues.length; k++)
  385. {
  386. calibrator.add_pair(Number(sourcevalues[k]),Number(destvalues[k]));
  387. }
  388. var indicator = new TemperatureDisplay;
  389. temperatureDisplays.push(indicator);
  390. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  391. channels[j].newData.connect(calibrator.newMeasurement);
  392. calibrator.newData.connect(indicator.setValue);
  393. channels.push(calibrator);
  394. columnNames.push(driverReference.destination);
  395. indicatorPanel.addWidget(decorator);
  396. }
  397. break;
  398. }
  399. }
  400. }
  401. else if(driverReference.driver == "translation")
  402. {
  403. var colname = driverReference.column;
  404. window.targetcolumnname = colname;
  405. for(var j = 0; j < columnNames.length; j++)
  406. {
  407. if(columnNames[j] == colname)
  408. {
  409. translationChannel = j;
  410. var indicator = new TemperatureDisplay;
  411. indicator.digitCount = 4;
  412. externtrans = indicator;
  413. indicator.display(0);
  414. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  415. indicatorPanel.addWidget(decorator);
  416. currentDetector.timeForValue.connect(function(value) {
  417. if(!hasTranslated)
  418. {
  419. var currentOffset = value;
  420. if(targetOffset != 0)
  421. {
  422. var translation = currentOffset - targetOffset;
  423. externtrans.display(translation);
  424. gtrans = translation;
  425. if(translation > 0)
  426. {
  427. window.translateLoadedSeries(translation);
  428. }
  429. else
  430. {
  431. window.translateCurrentSeries(-translation);
  432. }
  433. }
  434. }
  435. hasTranslated = true;
  436. });
  437. var resetTranslation = findChildObject(this, 'unshift');
  438. resetTranslation.triggered.connect(function() {
  439. if(gtrans > 0) {
  440. window.translateLoadedSeries(-gtrans);
  441. }
  442. else {
  443. window.translateCurrentSeries(gtrans);
  444. }
  445. gtrans = 0;
  446. indicator.display(0);
  447. });
  448. }
  449. }
  450. targetDetector.setThreshold(driverReference.FValue);
  451. currentDetector.setThreshold(driverReference.FValue);
  452. }
  453. else if(driverReference.driver == "rate")
  454. {
  455. var primaryColumn = driverReference.column;
  456. for(var j = 0; j < columnNames.length; j++)
  457. {
  458. if(columnNames[j] == primaryColumn)
  459. {
  460. var rate = new RateOfChange(driverReference.cache, driverReference.scale);
  461. channels[j].newData.connect(rate.newMeasurement);
  462. var indicator = new TemperatureDisplay;
  463. indicator.setRelativeMode(true);
  464. indicator.display(0);
  465. indicator.digitCount = 9;
  466. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  467. indicatorPanel.addWidget(decorator);
  468. rate.newData.connect(indicator.setValue);
  469. temperatureDisplays.push(indicator);
  470. channels.push(rate);
  471. columnNames.push(configModel.data(driverIndex, 0));
  472. }
  473. }
  474. }
  475. }
  476. }
  477. for(var i = 1; i < tabControls.length; i++)
  478. {
  479. setTabOrder(tabControls[i-1], tabControls[i]);
  480. }
  481. log.setHeaderData(0, "Time");
  482. for(var i = 0; i < columnNames.length; i++) {
  483. log.setHeaderData(i + 1, columnNames[i]);
  484. }
  485. log.setHeaderData(columnNames.length + 1, "Note");
  486. for(var i = 0; i < channels.length; i++) {
  487. log.addToCurrentColumnSet(i + 1);
  488. }
  489. var timer = new TimerDisplay;
  490. timer.displayFormat = "mm:ss";
  491. timer.autoReset = true;
  492. var btdecorator = new WidgetDecorator(timer, "Batch Timer", 2);
  493. indicatorPanel.addWidget(btdecorator);
  494. var vsplit = findChildObject(this, 'main');
  495. var isplit = findChildObject(this, 'indicators');
  496. var lsplit = findChildObject(this, 'logsplit');
  497. window.aboutToClose.connect(function() {
  498. for(var i = 0; i < nidevices.length; i++)
  499. {
  500. nidevices[i].stop();
  501. nidevices[i].deleteLater();
  502. }
  503. for(var i = 0; i < modbusdevices.length; i++)
  504. {
  505. modbusdevices[i].deleteLater();
  506. }
  507. for(var i = 0; i < dataqsdkdevices.length; i++)
  508. {
  509. dataqsdkdevices[i].deleteLater();
  510. }
  511. delete nidevices;
  512. delete modbusdevices;
  513. delete dataqsdkdevices;
  514. window.saveSizeAndPosition("window");
  515. vsplit.saveState("script/mainSplitter");
  516. isplit.saveState("script/instrumentSplitter");
  517. lsplit.saveState("script/logSplitter");
  518. log.saveState("script/log", 7);
  519. window.navigationWindow.loggingWindow = undefined;
  520. });
  521. this.restoreSizeAndPosition('window');
  522. vsplit.restoreState("script/mainSplitter");
  523. isplit.restoreState("script/instrumentSplitter");
  524. lsplit.restoreState("script/logSplitter");
  525. log.restoreState("script/log", 7);
  526. var offsets = new Array();
  527. var zeroemitters = new Array();
  528. var adapters = new Array();
  529. for(var i = 0; i < channels.length; i++) {
  530. var offset = new MeasurementTimeOffset(epoch);
  531. offsets.push(offset);
  532. channels[i].newData.connect(offset.newMeasurement);
  533. var adapter = new MeasurementAdapter(i + 1);
  534. adapters.push(adapter);
  535. offset.measurement.connect(adapter.newMeasurement);
  536. var emitter = new ZeroEmitter(i + 1);
  537. zeroemitters.push(emitter);
  538. channels[i].newData.connect(emitter.newMeasurement);
  539. emitter.measurement.connect(log.newMeasurement);
  540. emitter.measurement.connect(graph.newMeasurement);
  541. }
  542. start.clicked.connect(function() {
  543. start.enabled = false;
  544. hasTranslated = false;
  545. var epoch = new QTime();
  546. epoch = epoch.currentTime();
  547. for(var i = 0; i < offsets.length; i++)
  548. {
  549. offsets[i].setZeroTime(epoch);
  550. zeroemitters[i].emitZero();
  551. adapters[i].measurement.connect(log.newMeasurement);
  552. adapters[i].measurement.connect(graph.newMeasurement);
  553. }
  554. for(var i = 0; i < rateadapters.length; i++)
  555. {
  556. rateoffsets[i].setZeroTime(epoch);
  557. ratezeros[i].emitZero();
  558. rateadapters[i].measurement.connect(graph.newMeasurement);
  559. }
  560. timer.startTimer();
  561. if(typeof(currentBatchInfo) == 'undefined') { } else {
  562. query = new QSqlQuery();
  563. query.exec("SELECT now()::timestamp without time zone");
  564. query.next();
  565. var result = query.value(0);
  566. query = query.invalidate();
  567. var timefield = findChildObject(currentBatchInfo, 'time');
  568. timefield.text = result.replace('T', ' ');
  569. }
  570. if(translationChannel >= 0)
  571. {
  572. offsets[translationChannel].measurement.connect(currentDetector.newMeasurement);
  573. }
  574. if(typeof(externtrans) != 'undefined') {
  575. externtrans.display(0);
  576. }
  577. stop.enabled = true;
  578. window.windowModified = true;
  579. });
  580. for(var i = 0; i < annotationButtons.length; i++) {
  581. if(channels.length > 0)
  582. {
  583. annotationButtons[i].annotation.connect(log.newAnnotation);
  584. annotationButtons[i].setTemperatureColumn(1);
  585. annotationButtons[i].setAnnotationColumn(channels.length + 1);
  586. annotationButtons[i].annotation.connect(function(note, tcol, ncol) {
  587. for(var i = tcol; i < ncol; i++) {
  588. log.newAnnotation(note, i, ncol);
  589. }
  590. });
  591. }
  592. }
  593. start.setFocus();
  594. stop.annotation.connect(log.newAnnotation);
  595. stop.clicked.connect(timer.stopTimer);
  596. stop.setTemperatureColumn(1);
  597. stop.setAnnotationColumn(channels.length + 1);
  598. QSettings.setValue("liveColumn", 1);
  599. var lc = 1;
  600. stop.clicked.connect(function() {
  601. stop.enabled = false;
  602. for(var i = 0; i < adapters.length; i++)
  603. {
  604. adapters[i].measurement.disconnect(log.newMeasurement);
  605. adapters[i].measurement.disconnect(graph.newMeasurement);
  606. }
  607. for(var i = 0; i < rateadapters.length; i++)
  608. {
  609. rateadapters[i].measurement.disconnect(graph.newMeasurement);
  610. }
  611. if(typeof(currentBatchInfo) == 'undefined') { } else {
  612. lc = Number(QSettings.value("liveColumn"));
  613. var duration = log.lastTime(lc);
  614. var durfield = findChildObject(currentBatchInfo, 'duration');
  615. durfield.text = duration;
  616. log.clearOutputColumns();
  617. for(var i = 0; i < channels.length; i++)
  618. {
  619. log.addOutputTemperatureColumn(lc + i);
  620. }
  621. log.addOutputAnnotationColumn(lc + channels.length);
  622. var filename = log.saveTemporary();
  623. currentBatchInfo.tempData = filename;
  624. currentBatchInfo.raise();
  625. currentBatchInfo.activateWindow();
  626. }
  627. if(translationChannel >= 0)
  628. {
  629. offsets[translationChannel].measurement.disconnect(currentDetector.newMeasurement);
  630. }
  631. start.enabled = true;
  632. window.windowModified = false;
  633. });
  634. stop.annotation.connect(function(note, tcol, ncol) {
  635. for(var i = tcol; i < ncol; i++) {
  636. log.newAnnotation(note, i, ncol);
  637. }
  638. });
  639. var quitMenu = findChildObject(this, 'quit');
  640. quitMenu.triggered.connect(function() {
  641. window.close();
  642. Application.quit();
  643. });
  644. var v1 = findChildObject(this, 'ms');
  645. v1.triggered.connect(log.LOD_ms);
  646. var v2 = findChildObject(this, '1s');
  647. v2.triggered.connect(log.LOD_1s);
  648. var v3 = findChildObject(this, '5s');
  649. v3.triggered.connect(log.LOD_5s);
  650. var v4 = findChildObject(this, '10s');
  651. v4.triggered.connect(log.LOD_10s);
  652. var v5 = findChildObject(this, '15s');
  653. v5.triggered.connect(log.LOD_15s);
  654. var v6 = findChildObject(this, '30s');
  655. v6.triggered.connect(log.LOD_30s);
  656. var v7 = findChildObject(this, '1m');
  657. v7.triggered.connect(log.LOD_1m);
  658. var showC = findChildObject(this, 'showC');
  659. showC.triggered.connect(function() {
  660. for(var i = 0; i < temperatureDisplays.length; i++)
  661. {
  662. temperatureDisplays[i].setDisplayUnits(Units.Celsius);
  663. }
  664. log.setDisplayUnits(Units.Celsius);
  665. graph.showC();
  666. });
  667. var showF = findChildObject(this, 'showF');
  668. showF.triggered.connect(function() {
  669. for(var i = 0; i < temperatureDisplays.length; i++)
  670. {
  671. temperatureDisplays[i].setDisplayUnits(Units.Fahrenheit);
  672. }
  673. log.setDisplayUnits(Units.Fahrenheit);
  674. graph.showF();
  675. });
  676. var clear = findChildObject(this, 'clear');
  677. clear.triggered.connect(log.clear);
  678. clear.triggered.connect(graph.clear);
  679. clear.triggered.connect(function() {
  680. window.windowTitle = "Typica";
  681. log.setHeaderData(0, "Time");
  682. QSettings.setValue("liveColumn", 1);
  683. window.postLoadColumnSetup(0);
  684. if(typeof(externtrans) != 'undefined') {
  685. externtrans.display(0);
  686. }
  687. });
  688. var openMenu = findChildObject(this, 'open');
  689. var compareMenu = findChildObject(this, 'compare');
  690. compareMenu.triggered.connect(function() {
  691. QSettings.setValue('cseries', lc+1);
  692. var history = createWindow("history");
  693. history.windowTitle = 'Typica - Roasting Log';
  694. });
  695. var printMenu = findChildObject(this, 'print');
  696. printMenu.triggered.connect(function() {
  697. var exportWindow = createWindow("print");
  698. exportWindow.windowTitle = "Typica - Print";
  699. exportWindow.log = log;
  700. });
  701. var svgExportMenu = findChildObject(this, 'svgexport');
  702. svgExportMenu.triggered.connect(function() {
  703. var exportWindow = createWindow("exportWindow");
  704. exportWindow.windowTitle = "Typica - Export XHTML+SVG";
  705. exportWindow.log = log;
  706. });
  707. openMenu.triggered.connect(function() {
  708. var filename = QFileDialog.getOpenFileName(window, 'Open Log…', QSettings.value('script/lastDir', '') + '/');
  709. if(filename != '') {
  710. var file = new QFile(filename);
  711. var input = new XMLInput(file, 1);
  712. targetseries = -1;
  713. input.newTemperatureColumn.connect(log.setHeaderData);
  714. input.newTemperatureColumn.connect(function(col, text) {
  715. if(text == window.targetcolumnname) {
  716. targetseries = col;
  717. }
  718. });
  719. input.newAnnotationColumn.connect(log.setHeaderData);
  720. input.measure.connect(graph.newMeasurement);
  721. input.measure.connect(log.newMeasurement);
  722. input.measure.connect(function(data, series) {
  723. if(series == targetseries) {
  724. targetDetector.newMeasurement(data);
  725. }
  726. });
  727. input.annotation.connect(log.newAnnotation);
  728. input.annotation.connect(function(note, tcol, ncol) {
  729. for(var i = tcol; i < ncol; i++) {
  730. log.newAnnotation(note, i, ncol);
  731. }
  732. });
  733. var lc;
  734. input.lastColumn.connect(function(c) {
  735. lc = c;
  736. QSettings.setValue("liveColumn", c + 1);
  737. window.postLoadColumnSetup(c);
  738. });
  739. input.input();
  740. window.windowTitle = 'Typica - ' + baseName(filename);
  741. QSettings.setValue("script/lastDir", dir(filename));
  742. log.newAnnotation("End", 1, lc);
  743. }
  744. });
  745. window.postLoadColumnSetup = function(c) {
  746. for(var i = 0; i < adapters.length; i++)
  747. {
  748. adapters[i].setColumn(c + i + 1);
  749. zeroemitters[i].setColumn(c + i + 1);
  750. log.setHeaderData(c + i + 1, columnNames[i]);
  751. }
  752. log.setHeaderData(c + columnNames.length + 1, "Note");
  753. stop.setTemperatureColumn(c + 1);
  754. stop.setAnnotationColumn(c + columnNames.length + 1);
  755. for(var i = 0; i < annotationButtons.length; i++)
  756. {
  757. annotationButtons[i].setTemperatureColumn(c + 1);
  758. annotationButtons[i].setAnnotationColumn(c + columnNames.length + 1);
  759. }
  760. log.clearCurrentColumnSet();
  761. for(var i = 0; i < channels.length; i++) {
  762. log.addToCurrentColumnSet(c + i + 1);
  763. }
  764. window.firstTempColumn = c + 1;
  765. window.annotationColumn = c + columnNames.length + 1;
  766. }
  767. var saveMenu = findChildObject(this, 'save');
  768. saveMenu.triggered.connect(function() {
  769. var filename = QFileDialog.getSaveFileName(window, "Save Log As…", QSettings.value("script/lastDir", "") + "/");
  770. if(filename != "") {
  771. var lc = Number(QSettings.value("liveColumn"));
  772. var file = new QFile(filename);
  773. log.clearOutputColumns();
  774. for(var i = 0; i < columnNames.length; i++)
  775. {
  776. log.addOutputTemperatureColumn(lc + i);
  777. }
  778. log.addOutputAnnotationColumn(lc + columnNames.length);
  779. log.saveXML(file);
  780. QSettings.setValue("script/lastDir", dir(filename));
  781. }
  782. });
  783. var exportMenu = findChildObject(this, 'export');
  784. exportMenu.triggered.connect(function() {
  785. var filename = QFileDialog.getSaveFileName(window, "Export CSV As…", QSettings.value("script/lastDir", "") + "/");
  786. if(filename != "") {
  787. var lc = Number(QSettings.value("liveColumn"));
  788. var file = new QFile(filename);
  789. log.clearOutputColumns();
  790. for(var i = 0; i < columnNames.length; i++)
  791. {
  792. log.addOutputTemperatureColumn(lc + i);
  793. }
  794. log.addOutputAnnotationColumn(lc + columnNames.length);
  795. log.saveCSV(file);
  796. QSettings.setValue("script/lastDir", dir(filename));
  797. }
  798. });
  799. var manual = findChildObject(this, 'manual');
  800. manual.triggered.connect(function() {
  801. var entry = new LogEditWindow();
  802. entry.show();
  803. });
  804. var newMenu = findChildObject(this, 'new');
  805. newMenu.triggered.connect(function() {
  806. var bwindow = createWindow("batchWindow");
  807. bwindow.windowTitle = "Typica - New Batch";
  808. });
  809. window.postLoadColumnSetup(0);
  810. ]]>
  811. </program>
  812. </window>