Typica is a free program for professional coffee roasters. https://typica.us
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

productionroaster.xml 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  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. var device;
  229. if(driverReference.autoSelect == "true") {
  230. device = new DataqSdkDevice(driverReference.deviceNumber);
  231. }
  232. else {
  233. device = new DataqSdkDevice(driverReference.port);
  234. }
  235. var sampleRate = 6;
  236. if(configModel.hasChildren(driverIndex)) {
  237. for(var j = 0; j < configModel.rowCount(driverIndex); j++) {
  238. var channelIndex = configModel.index(j, 0, driverIndex);
  239. var channelReference = configModel.referenceElement(configModel.data(channelIndex, 32));
  240. var unit;
  241. if(channelReference.type == "Temperature") {
  242. unit = Units.Fahrenheit;
  243. }
  244. else {
  245. unit = Units.Unitless;
  246. }
  247. var channel = device.newChannel(unit);
  248. var calibrator = new LinearCalibrator;
  249. calibrator.measuredLower = channelReference.calibrationMeasuredLower;
  250. calibrator.measuredUpper = channelReference.calibrationMeasuredUpper;
  251. calibrator.mappedLower = channelReference.calibrationMappedLower;
  252. calibrator.mappedUpper = channelReference.calibrationMappedUpper;
  253. calibrator.sensitivity = channelReference.calibrationSensitivity;
  254. calibrator.closedRange = channelReference.calibrationClosedInterval;
  255. // device.setSmoothingEnabled(j) = channelReference.smoothing;
  256. channel.newData.connect(calibrator.newMeasurement)
  257. channels.push(calibrator);
  258. columnNames.push(channelReference.column);
  259. var indicator = new TemperatureDisplay;
  260. temperatureDisplays.push(indicator);
  261. var decorator = new WidgetDecorator(indicator, configModel.data(channelIndex, 0), 2);
  262. calibrator.newData.connect(indicator.setValue);
  263. indicatorPanel.addWidget(decorator);
  264. }
  265. sampleRate /= configModel.rowCount(driverIndex);
  266. }
  267. device.setClockRate(sampleRate);
  268. device.start();
  269. dataqsdkdevices.push(device);
  270. }
  271. else if(driverReference.driver == "modbusrtu")
  272. {
  273. var device = new ModbusRTUDevice(configModel, driverIndex);
  274. modbusdevices.push(device);
  275. var pvchannel = device.pVChannel();
  276. channels.push(pvchannel);
  277. columnNames.push(driverReference.pvcolname);
  278. var indicator = new TemperatureDisplay;
  279. temperatureDisplays.push(indicator);
  280. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0) + " PV", 2);
  281. pvchannel.newData.connect(indicator.setValue);
  282. indicatorPanel.addWidget(decorator);
  283. if(driverReference.sVEnabled == "true")
  284. {
  285. var svchannel = device.sVChannel();
  286. channels.push(svchannel);
  287. columnNames.push(driverReference.svcolname);
  288. var indicator = new TemperatureDisplay;
  289. temperatureDisplays.push(indicator);
  290. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0) + " SV", 2);
  291. svchannel.newData.connect(indicator.setValue);
  292. indicatorPanel.addWidget(decorator);
  293. }
  294. if(driverReference.sVWritable == "true")
  295. {
  296. var outputControl = new AnnotationSpinBox;
  297. device.SVLowerChanged.connect(function(min) {
  298. outputControl.minimum = min;
  299. });
  300. outputControl.minimum = device.SVLower();
  301. device.SVUpperChanged.connect(function(max) {
  302. outputControl.maximum = max;
  303. });
  304. outputControl.maximum = device.SVUpper();
  305. device.SVDecimalChanged.connect(function(prec) {
  306. outputControl.decimals = prec;
  307. });
  308. outputControl.decimals = device.decimals();
  309. outputControl.editingFinished.connect(function() {
  310. device.outputSV(outputControl.value);
  311. });
  312. var layout = new QBoxLayout;
  313. var label = new QLabel("Change SV");
  314. layout.addWidget(label, 0, 2);
  315. layout.addWidget(outputControl, 0, 1);
  316. annotationPanel.addLayout(layout);
  317. tabControls.push(outputControl);
  318. }
  319. }
  320. else if(driverReference.driver == "annotationbutton")
  321. {
  322. var button = new AnnotationButton(driverReference.buttontext);
  323. button.setAnnotation(driverReference.annotationtext);
  324. annotationButtons.push(button);
  325. annotationPanel.addWidget(button);
  326. tabControls.push(button);
  327. }
  328. else if(driverReference.driver == "reconfigurablebutton")
  329. {
  330. var button = new AnnotationButton(driverReference.buttontext);
  331. button.setAnnotation(driverReference.annotationtext);
  332. annotationButtons.push(button);
  333. annotationPanel.addWidget(button);
  334. tabControls.push(button);
  335. nsparam.enabled = true;
  336. nsparam.triggered.connect(function() {
  337. var setParam = createWindow("sampleParameters");
  338. setParam.windowTitle = "Typica - Set Sample Parameters";
  339. setParam.button = button;
  340. });
  341. }
  342. else if(driverReference.driver == "annotationspinbox")
  343. {
  344. var layout = new QBoxLayout;
  345. var label = new QLabel(driverReference.label);
  346. layout.addWidget(label, 0, 2);
  347. var spinbox = new AnnotationSpinBox;
  348. spinbox.setPretext(driverReference.pretext);
  349. spinbox.setPosttext(driverReference.posttext);
  350. spinbox.minimum = driverReference.minimum;
  351. spinbox.maximum = driverReference.maximum;
  352. spinbox.decimals = driverReference.precision;
  353. layout.addWidget(spinbox, 0, 1);
  354. annotationPanel.addLayout(layout);
  355. annotationButtons.push(spinbox);
  356. tabControls.push(spinbox);
  357. }
  358. else if(driverReference.driver == "freeannotation")
  359. {
  360. var layout = new QBoxLayout;
  361. var label = new QLabel(driverReference.labeltext);
  362. var control = new QLineEdit;
  363. layout.addWidget(label, 0, 2);
  364. layout.addWidget(control, 0, 1);
  365. annotationPanel.addLayout(layout);
  366. tabControls.push(control);
  367. control.returnPressed.connect(function() {
  368. for(var i = window.firstTempColumn; i < window.annotationColumn; i++) {
  369. log.newAnnotation(control.text, i, window.annotationColumn);
  370. }
  371. });
  372. }
  373. else if(driverReference.driver == "linearspline")
  374. {
  375. var colname = driverReference.source;
  376. for(var j = 0; j < columnNames.length; j++)
  377. {
  378. if(columnNames[j] == colname)
  379. {
  380. var calibrator = new LinearSplineInterpolator;
  381. var sv = driverReference.sourcevalues;
  382. var dv = driverReference.destinationvalues;
  383. var sourcevalues = sv.slice(2, sv.length-2).split(",");
  384. var destvalues = dv.slice(2, dv.length-2).split(",");
  385. if(sourcevalues.length > 1 && destvalues.length == sourcevalues.length)
  386. {
  387. for(var k = 0; k < sourcevalues.length; k++)
  388. {
  389. calibrator.add_pair(Number(sourcevalues[k]),Number(destvalues[k]));
  390. }
  391. var indicator = new TemperatureDisplay;
  392. temperatureDisplays.push(indicator);
  393. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  394. channels[j].newData.connect(calibrator.newMeasurement);
  395. calibrator.newData.connect(indicator.setValue);
  396. channels.push(calibrator);
  397. columnNames.push(driverReference.destination);
  398. indicatorPanel.addWidget(decorator);
  399. }
  400. break;
  401. }
  402. }
  403. }
  404. else if(driverReference.driver == "translation")
  405. {
  406. var colname = driverReference.column;
  407. window.targetcolumnname = colname;
  408. for(var j = 0; j < columnNames.length; j++)
  409. {
  410. if(columnNames[j] == colname)
  411. {
  412. translationChannel = j;
  413. var indicator = new TemperatureDisplay;
  414. indicator.digitCount = 4;
  415. externtrans = indicator;
  416. indicator.display(0);
  417. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  418. indicatorPanel.addWidget(decorator);
  419. currentDetector.timeForValue.connect(function(value) {
  420. if(!hasTranslated)
  421. {
  422. var currentOffset = value;
  423. if(targetOffset != 0)
  424. {
  425. var translation = currentOffset - targetOffset;
  426. externtrans.display(translation);
  427. gtrans = translation;
  428. if(translation > 0)
  429. {
  430. window.translateLoadedSeries(translation);
  431. }
  432. else
  433. {
  434. window.translateCurrentSeries(-translation);
  435. }
  436. }
  437. }
  438. hasTranslated = true;
  439. });
  440. var resetTranslation = findChildObject(this, 'unshift');
  441. resetTranslation.triggered.connect(function() {
  442. if(gtrans > 0) {
  443. window.translateLoadedSeries(-gtrans);
  444. }
  445. else {
  446. window.translateCurrentSeries(gtrans);
  447. }
  448. gtrans = 0;
  449. indicator.display(0);
  450. });
  451. }
  452. }
  453. targetDetector.setThreshold(driverReference.FValue);
  454. currentDetector.setThreshold(driverReference.FValue);
  455. }
  456. else if(driverReference.driver == "rate")
  457. {
  458. var primaryColumn = driverReference.column;
  459. for(var j = 0; j < columnNames.length; j++)
  460. {
  461. if(columnNames[j] == primaryColumn)
  462. {
  463. var rate = new RateOfChange(driverReference.cache, driverReference.scale);
  464. channels[j].newData.connect(rate.newMeasurement);
  465. var indicator = new TemperatureDisplay;
  466. indicator.setRelativeMode(true);
  467. indicator.display(0);
  468. indicator.digitCount = 9;
  469. var decorator = new WidgetDecorator(indicator, configModel.data(driverIndex, 0), 2);
  470. indicatorPanel.addWidget(decorator);
  471. rate.newData.connect(indicator.setValue);
  472. temperatureDisplays.push(indicator);
  473. channels.push(rate);
  474. columnNames.push(configModel.data(driverIndex, 0));
  475. }
  476. }
  477. }
  478. }
  479. }
  480. for(var i = 1; i < tabControls.length; i++)
  481. {
  482. setTabOrder(tabControls[i-1], tabControls[i]);
  483. }
  484. log.setHeaderData(0, "Time");
  485. for(var i = 0; i < columnNames.length; i++) {
  486. log.setHeaderData(i + 1, columnNames[i]);
  487. }
  488. log.setHeaderData(columnNames.length + 1, "Note");
  489. for(var i = 0; i < channels.length; i++) {
  490. log.addToCurrentColumnSet(i + 1);
  491. }
  492. var timer = new TimerDisplay;
  493. timer.displayFormat = "mm:ss";
  494. timer.autoReset = true;
  495. var btdecorator = new WidgetDecorator(timer, "Batch Timer", 2);
  496. indicatorPanel.addWidget(btdecorator);
  497. var vsplit = findChildObject(this, 'main');
  498. var isplit = findChildObject(this, 'indicators');
  499. var lsplit = findChildObject(this, 'logsplit');
  500. window.aboutToClose.connect(function() {
  501. for(var i = 0; i < nidevices.length; i++)
  502. {
  503. nidevices[i].stop();
  504. nidevices[i].deleteLater();
  505. }
  506. for(var i = 0; i < modbusdevices.length; i++)
  507. {
  508. modbusdevices[i].deleteLater();
  509. }
  510. for(var i = 0; i < dataqsdkdevices.length; i++)
  511. {
  512. dataqsdkdevices[i].deleteLater();
  513. }
  514. delete nidevices;
  515. delete modbusdevices;
  516. delete dataqsdkdevices;
  517. window.saveSizeAndPosition("window");
  518. vsplit.saveState("script/mainSplitter");
  519. isplit.saveState("script/instrumentSplitter");
  520. lsplit.saveState("script/logSplitter");
  521. log.saveState("script/log", 7);
  522. window.navigationWindow.loggingWindow = undefined;
  523. });
  524. this.restoreSizeAndPosition('window');
  525. vsplit.restoreState("script/mainSplitter");
  526. isplit.restoreState("script/instrumentSplitter");
  527. lsplit.restoreState("script/logSplitter");
  528. log.restoreState("script/log", 7);
  529. var offsets = new Array();
  530. var zeroemitters = new Array();
  531. var adapters = new Array();
  532. for(var i = 0; i < channels.length; i++) {
  533. var offset = new MeasurementTimeOffset(epoch);
  534. offsets.push(offset);
  535. channels[i].newData.connect(offset.newMeasurement);
  536. var adapter = new MeasurementAdapter(i + 1);
  537. adapters.push(adapter);
  538. offset.measurement.connect(adapter.newMeasurement);
  539. var emitter = new ZeroEmitter(i + 1);
  540. zeroemitters.push(emitter);
  541. channels[i].newData.connect(emitter.newMeasurement);
  542. emitter.measurement.connect(log.newMeasurement);
  543. emitter.measurement.connect(graph.newMeasurement);
  544. }
  545. start.clicked.connect(function() {
  546. start.enabled = false;
  547. hasTranslated = false;
  548. var epoch = new QTime();
  549. epoch = epoch.currentTime();
  550. for(var i = 0; i < offsets.length; i++)
  551. {
  552. offsets[i].setZeroTime(epoch);
  553. zeroemitters[i].emitZero();
  554. adapters[i].measurement.connect(log.newMeasurement);
  555. adapters[i].measurement.connect(graph.newMeasurement);
  556. }
  557. for(var i = 0; i < rateadapters.length; i++)
  558. {
  559. rateoffsets[i].setZeroTime(epoch);
  560. ratezeros[i].emitZero();
  561. rateadapters[i].measurement.connect(graph.newMeasurement);
  562. }
  563. timer.startTimer();
  564. if(typeof(currentBatchInfo) == 'undefined') { } else {
  565. query = new QSqlQuery();
  566. query.exec("SELECT now()::timestamp without time zone");
  567. query.next();
  568. var result = query.value(0);
  569. query = query.invalidate();
  570. var timefield = findChildObject(currentBatchInfo, 'time');
  571. timefield.text = result.replace('T', ' ');
  572. }
  573. if(translationChannel >= 0)
  574. {
  575. offsets[translationChannel].measurement.connect(currentDetector.newMeasurement);
  576. }
  577. if(typeof(externtrans) != 'undefined') {
  578. externtrans.display(0);
  579. }
  580. stop.enabled = true;
  581. window.windowModified = true;
  582. });
  583. for(var i = 0; i < annotationButtons.length; i++) {
  584. if(channels.length > 0)
  585. {
  586. annotationButtons[i].annotation.connect(log.newAnnotation);
  587. annotationButtons[i].setTemperatureColumn(1);
  588. annotationButtons[i].setAnnotationColumn(channels.length + 1);
  589. annotationButtons[i].annotation.connect(function(note, tcol, ncol) {
  590. for(var i = tcol; i < ncol; i++) {
  591. log.newAnnotation(note, i, ncol);
  592. }
  593. });
  594. }
  595. }
  596. start.setFocus();
  597. stop.annotation.connect(log.newAnnotation);
  598. stop.clicked.connect(timer.stopTimer);
  599. stop.setTemperatureColumn(1);
  600. stop.setAnnotationColumn(channels.length + 1);
  601. QSettings.setValue("liveColumn", 1);
  602. var lc = 1;
  603. stop.clicked.connect(function() {
  604. stop.enabled = false;
  605. for(var i = 0; i < adapters.length; i++)
  606. {
  607. adapters[i].measurement.disconnect(log.newMeasurement);
  608. adapters[i].measurement.disconnect(graph.newMeasurement);
  609. }
  610. for(var i = 0; i < rateadapters.length; i++)
  611. {
  612. rateadapters[i].measurement.disconnect(graph.newMeasurement);
  613. }
  614. if(typeof(currentBatchInfo) == 'undefined') { } else {
  615. lc = Number(QSettings.value("liveColumn"));
  616. var duration = log.lastTime(lc);
  617. var durfield = findChildObject(currentBatchInfo, 'duration');
  618. durfield.text = duration;
  619. log.clearOutputColumns();
  620. for(var i = 0; i < channels.length; i++)
  621. {
  622. log.addOutputTemperatureColumn(lc + i);
  623. }
  624. log.addOutputAnnotationColumn(lc + channels.length);
  625. var filename = log.saveTemporary();
  626. currentBatchInfo.tempData = filename;
  627. currentBatchInfo.raise();
  628. currentBatchInfo.activateWindow();
  629. }
  630. if(translationChannel >= 0)
  631. {
  632. offsets[translationChannel].measurement.disconnect(currentDetector.newMeasurement);
  633. }
  634. start.enabled = true;
  635. window.windowModified = false;
  636. });
  637. stop.annotation.connect(function(note, tcol, ncol) {
  638. for(var i = tcol; i < ncol; i++) {
  639. log.newAnnotation(note, i, ncol);
  640. }
  641. });
  642. var quitMenu = findChildObject(this, 'quit');
  643. quitMenu.triggered.connect(function() {
  644. window.close();
  645. Application.quit();
  646. });
  647. var v1 = findChildObject(this, 'ms');
  648. v1.triggered.connect(log.LOD_ms);
  649. var v2 = findChildObject(this, '1s');
  650. v2.triggered.connect(log.LOD_1s);
  651. var v3 = findChildObject(this, '5s');
  652. v3.triggered.connect(log.LOD_5s);
  653. var v4 = findChildObject(this, '10s');
  654. v4.triggered.connect(log.LOD_10s);
  655. var v5 = findChildObject(this, '15s');
  656. v5.triggered.connect(log.LOD_15s);
  657. var v6 = findChildObject(this, '30s');
  658. v6.triggered.connect(log.LOD_30s);
  659. var v7 = findChildObject(this, '1m');
  660. v7.triggered.connect(log.LOD_1m);
  661. var showC = findChildObject(this, 'showC');
  662. showC.triggered.connect(function() {
  663. for(var i = 0; i < temperatureDisplays.length; i++)
  664. {
  665. temperatureDisplays[i].setDisplayUnits(Units.Celsius);
  666. }
  667. log.setDisplayUnits(Units.Celsius);
  668. graph.showC();
  669. });
  670. var showF = findChildObject(this, 'showF');
  671. showF.triggered.connect(function() {
  672. for(var i = 0; i < temperatureDisplays.length; i++)
  673. {
  674. temperatureDisplays[i].setDisplayUnits(Units.Fahrenheit);
  675. }
  676. log.setDisplayUnits(Units.Fahrenheit);
  677. graph.showF();
  678. });
  679. var clear = findChildObject(this, 'clear');
  680. clear.triggered.connect(log.clear);
  681. clear.triggered.connect(graph.clear);
  682. clear.triggered.connect(function() {
  683. window.windowTitle = "Typica";
  684. log.setHeaderData(0, "Time");
  685. QSettings.setValue("liveColumn", 1);
  686. window.postLoadColumnSetup(0);
  687. if(typeof(externtrans) != 'undefined') {
  688. externtrans.display(0);
  689. }
  690. });
  691. var openMenu = findChildObject(this, 'open');
  692. var compareMenu = findChildObject(this, 'compare');
  693. compareMenu.triggered.connect(function() {
  694. QSettings.setValue('cseries', lc+1);
  695. var history = createWindow("history");
  696. history.windowTitle = 'Typica - Roasting Log';
  697. });
  698. var printMenu = findChildObject(this, 'print');
  699. printMenu.triggered.connect(function() {
  700. var exportWindow = createWindow("print");
  701. exportWindow.windowTitle = "Typica - Print";
  702. exportWindow.log = log;
  703. });
  704. var svgExportMenu = findChildObject(this, 'svgexport');
  705. svgExportMenu.triggered.connect(function() {
  706. var exportWindow = createWindow("exportWindow");
  707. exportWindow.windowTitle = "Typica - Export XHTML+SVG";
  708. exportWindow.log = log;
  709. });
  710. openMenu.triggered.connect(function() {
  711. var filename = QFileDialog.getOpenFileName(window, 'Open Log…', QSettings.value('script/lastDir', '') + '/');
  712. if(filename != '') {
  713. var file = new QFile(filename);
  714. var input = new XMLInput(file, 1);
  715. targetseries = -1;
  716. input.newTemperatureColumn.connect(log.setHeaderData);
  717. input.newTemperatureColumn.connect(function(col, text) {
  718. if(text == window.targetcolumnname) {
  719. targetseries = col;
  720. }
  721. });
  722. input.newAnnotationColumn.connect(log.setHeaderData);
  723. input.measure.connect(graph.newMeasurement);
  724. input.measure.connect(log.newMeasurement);
  725. input.measure.connect(function(data, series) {
  726. if(series == targetseries) {
  727. targetDetector.newMeasurement(data);
  728. }
  729. });
  730. input.annotation.connect(log.newAnnotation);
  731. input.annotation.connect(function(note, tcol, ncol) {
  732. for(var i = tcol; i < ncol; i++) {
  733. log.newAnnotation(note, i, ncol);
  734. }
  735. });
  736. var lc;
  737. input.lastColumn.connect(function(c) {
  738. lc = c;
  739. QSettings.setValue("liveColumn", c + 1);
  740. window.postLoadColumnSetup(c);
  741. });
  742. input.input();
  743. window.windowTitle = 'Typica - ' + baseName(filename);
  744. QSettings.setValue("script/lastDir", dir(filename));
  745. log.newAnnotation("End", 1, lc);
  746. }
  747. });
  748. window.postLoadColumnSetup = function(c) {
  749. for(var i = 0; i < adapters.length; i++)
  750. {
  751. adapters[i].setColumn(c + i + 1);
  752. zeroemitters[i].setColumn(c + i + 1);
  753. log.setHeaderData(c + i + 1, columnNames[i]);
  754. }
  755. log.setHeaderData(c + columnNames.length + 1, "Note");
  756. stop.setTemperatureColumn(c + 1);
  757. stop.setAnnotationColumn(c + columnNames.length + 1);
  758. for(var i = 0; i < annotationButtons.length; i++)
  759. {
  760. annotationButtons[i].setTemperatureColumn(c + 1);
  761. annotationButtons[i].setAnnotationColumn(c + columnNames.length + 1);
  762. }
  763. log.clearCurrentColumnSet();
  764. for(var i = 0; i < channels.length; i++) {
  765. log.addToCurrentColumnSet(c + i + 1);
  766. }
  767. window.firstTempColumn = c + 1;
  768. window.annotationColumn = c + columnNames.length + 1;
  769. }
  770. var saveMenu = findChildObject(this, 'save');
  771. saveMenu.triggered.connect(function() {
  772. var filename = QFileDialog.getSaveFileName(window, "Save Log As…", QSettings.value("script/lastDir", "") + "/");
  773. if(filename != "") {
  774. var lc = Number(QSettings.value("liveColumn"));
  775. var file = new QFile(filename);
  776. log.clearOutputColumns();
  777. for(var i = 0; i < columnNames.length; i++)
  778. {
  779. log.addOutputTemperatureColumn(lc + i);
  780. }
  781. log.addOutputAnnotationColumn(lc + columnNames.length);
  782. log.saveXML(file);
  783. QSettings.setValue("script/lastDir", dir(filename));
  784. }
  785. });
  786. var exportMenu = findChildObject(this, 'export');
  787. exportMenu.triggered.connect(function() {
  788. var filename = QFileDialog.getSaveFileName(window, "Export CSV As…", QSettings.value("script/lastDir", "") + "/");
  789. if(filename != "") {
  790. var lc = Number(QSettings.value("liveColumn"));
  791. var file = new QFile(filename);
  792. log.clearOutputColumns();
  793. for(var i = 0; i < columnNames.length; i++)
  794. {
  795. log.addOutputTemperatureColumn(lc + i);
  796. }
  797. log.addOutputAnnotationColumn(lc + columnNames.length);
  798. log.saveCSV(file);
  799. QSettings.setValue("script/lastDir", dir(filename));
  800. }
  801. });
  802. var manual = findChildObject(this, 'manual');
  803. manual.triggered.connect(function() {
  804. var entry = new LogEditWindow();
  805. entry.show();
  806. });
  807. var newMenu = findChildObject(this, 'new');
  808. newMenu.triggered.connect(function() {
  809. var bwindow = createWindow("batchWindow");
  810. bwindow.windowTitle = "Typica - New Batch";
  811. });
  812. window.postLoadColumnSetup(0);
  813. ]]>
  814. </program>
  815. </window>