From a4a9a5a2c680462d85bb8394e62476b33fcd3602 Mon Sep 17 00:00:00 2001 From: Derek K Date: Sat, 30 Jan 2016 22:21:58 -0500 Subject: [PATCH 1/3] README update --- README.md | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 25318f2..5ae5ba6 100644 --- a/README.md +++ b/README.md @@ -5,25 +5,57 @@ Android / iOS App for controlling your CANBus Triple via USB or Bluetooth - [CANBus Triple](http://canb.us) -This software is in an alpha state. Test builds will be available soon. +This software is in an beta state. Builds are available at [https://canb.us](https://canb.us) # Building for Desktop +You'll need NodeJS and NPM installed to build. Get them here: [NodeJS.org](https://nodejs.org/) + +## Mac OS / Linux + ``` +npm install -g bower gulp +export npm_config_disturl=https://atom.io/download/atom-shell +export npm_config_target=0.36.7 +export npm_config_arch=x64 +export npm_config_runtime=electron npm install bower install -npm install -g node-pre-gyp -cd node_modules/serialport -node-pre-gyp rebuild --runtime=node-webkit --target=0.12.0-alpha3 +cd node_modules/serialport/build/Release +mv electron-v0.36-darwin-x64 node-v47-darwin-x64 +cd ../../../../ gulp build ``` -After a successful build you will find the binaries in ./build +If everything goes according to plan you will find the build in the 'release' folder. + + +## Windows +You'll need Microsoft Visual Studio Express (2015) community edition [from here.](https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx) and 7zip [from here](http://sourceforge.net/projects/sevenzip/files/7-Zip/). +``` +npm install -g bower gulp +set npm_config_disturl=https://atom.io/download/atom-shell +set npm_config_target=0.36.7 +set npm_config_arch=x64 +set npm_config_runtime=electron +GYP_MSVS_VERSION=2015 +npm install +cd node_modules/serialport/build/Release +mv electron-v0.36-win32-x64 node-v47-win32-x64 +cd ../../../../ +bower install +gulp build +``` + + + # Building for Mobile +**Mobile has been abandon in favor of the upcoming Android app.** + Install android sdks and correctly set your PATH env var. `` From fd95ea11dab715279ba5875e88cf5876f991cd6a Mon Sep 17 00:00:00 2001 From: Derek K Date: Sun, 31 Jan 2016 16:01:15 -0500 Subject: [PATCH 2/3] Move to chip.avr.avr109 module for flashing 32u4 MCU --- gulpfile.js | 22 +++- main.js | 60 ++++++++++- package.json | 4 + www/css/base.min.css | 2 +- www/js/app/app.js | 29 +++++- www/js/app/services/FirmwareService.js | 93 +++++++++++++++-- www/js/app/services/HardwareService.js | 1 - www/js/app/services/SerialService.js | 10 +- www/js/scripts.js | 133 ++++++++++++++++++++++--- www/templates/hardware/firmware.html | 2 +- 10 files changed, 317 insertions(+), 39 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 0e42de1..a992efe 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,13 +9,12 @@ var sh = require('shelljs'); var browserSync = require('browser-sync'); var reload = browserSync.reload; var del = require('del'); - var gulp = require('gulp'); var electron = require('gulp-electron'); var elecRebuild = require('electron-rebuild'); var packageJson = require('./package.json'); var install = require("gulp-install"); - +var createInstaller = require('electron-installer-squirrel-windows'); @@ -129,7 +128,10 @@ gulp.task('electron-copy', ['sass', 'scripts', /*'electron-rebuild', 'electron-c 'node_modules/serialport/build/**/*', 'node_modules/serialport/serialport*.*', 'node_modules/serialport/*.js', - 'node_modules/serialport/*.json' + 'node_modules/serialport/*.json', + 'node_modules/intel-hex/**/*', + 'node_modules/electron-squirrel-startup/**/*', + 'node_modules/chip.avr.avr109/**/*', ]; @@ -163,7 +165,17 @@ gulp.task('electron-copy', ['sass', 'scripts', /*'electron-rebuild', 'electron-c }); - +gulp.task('electron-installer', [], function(){ + var opts = { + "path": "release/v0.36.7/win32-x64/", + "name": "CANBus Triple", + "description": "CANBus Triple Desktop app http://canb.us" + } + createInstaller(opts, function done (err){ + if(err) + gutil.log('electron-installer', gutil.colors.red(err), err); + }) +}); gulp.task('electron-install', ['electron-copy'], function() { gulp.src(['./electron-src/package.json']) @@ -181,7 +193,7 @@ gulp.task('electron-build', ['electron-copy'], function() { asar: true, version: 'v0.36.7', packaging: true, - platforms: [/*'win32-ia32', 'win32-x64', */'darwin-x64', /*'linux-x64'*/], + platforms: [/*'win32-ia32',*/ 'win32-x64', 'darwin-x64', /*'linux-x64'*/], platformResources: { darwin: { CFBundleDisplayName: packageJson.name, diff --git a/main.js b/main.js index 20aaca9..11cda5a 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,57 @@ -var app = require('app'); // Module to control application life. + +const app = require('electron').app; // Module to control application life. var BrowserWindow = require('browser-window'); // Module to create native browser window. +var autoUpdater = require('auto-updater'); + +if(require('electron-squirrel-startup')) return; + +var handleStartupEvent = function() { + if (process.platform !== 'win32') { + return false; + } + + var squirrelCommand = process.argv[1]; + switch (squirrelCommand) { + case '--squirrel-install': + case '--squirrel-updated': + + // Optionally do things such as: + // + // - Install desktop and start menu shortcuts + // - Add your .exe to the PATH + // - Write to the registry for things like file associations and + // explorer context menus + + // Always quit when done + app.quit(); + + return true; + case '--squirrel-uninstall': + // Undo anything you did in the --squirrel-install and + // --squirrel-updated handlers + + // Always quit when done + app.quit(); + + return true; + case '--squirrel-obsolete': + // This is called on the outgoing version of your app before + // we update to the new version - it's the opposite of + // --squirrel-updated + app.quit(); + return true; + } +}; + +if (handleStartupEvent()) { + return; +} + +// autoUpdater.setFeedUrl('http://files.canb.us/app/latest?version=' + app.getVersion()); +// autoUpdater.on('update-downloaded', function(event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate){ +// console.info('Quit and update'); +// quitAndUpdate(); +// }); // Report crashes to our server. require('crash-reporter').start(); @@ -20,11 +72,12 @@ app.on('window-all-closed', function() { // This method will be called when Electron has finished // initialization and is ready to create browser windows. app.on('ready', function() { + // Create the browser window. mainWindow = new BrowserWindow({width: 1280, height: 768, frame: false}); // and load the index.html of the app. - mainWindow.loadUrl('file://' + __dirname + '/www/index.html'); + mainWindow.loadURL('file://' + __dirname + '/www/index.html'); // Open the devtools. //mainWindow.openDevTools(); @@ -36,4 +89,7 @@ app.on('ready', function() { // when you should delete the corresponding element. mainWindow = null; }); + + autoUpdater.checkForUpdates(); + }); diff --git a/package.json b/package.json index a8036e2..193b859 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "browser-sync": "^2.9.1", "connect": "*", "del": "^2.0.2", + "electron-installer-squirrel-windows": "^1.2.2", "electron-prebuilt": "^0.36.7", "electron-rebuild": "^1.1.2", "gulp": "^3.9.0", @@ -32,6 +33,9 @@ }, "dependencies": { "cbt-wireshark": "^0.1.1", + "chip.avr.avr109": "^1.0.5", + "electron-squirrel-startup": "^0.1.4", + "intel-hex": "^0.1.1", "noble": "^1.1.0", "serialport": "^2.0.6" } diff --git a/www/css/base.min.css b/www/css/base.min.css index 245ef4a..67fd6df 100644 --- a/www/css/base.min.css +++ b/www/css/base.min.css @@ -1 +1 @@ -.card,ion-nav-bar{-webkit-transform:translate3d(0,0,0)}.color-assertive{background-color:#ef4e3a}.type-white{color:#fff}.type-energized{color:#f0b840}body,html{height:100%;-webkit-user-select:text!important}.scroll{-webkit-user-select:text}ion-nav-bar{display:block;height:3em;-webkit-app-region:drag;position:relative;z-index:9999;cursor:move}ion-nav-bar button{-webkit-app-region:no-drag;cursor:pointer}p{white-space:pre-line}body,h1,h2,h3,h4,h5{font-family:Roboto,"Helvetica Neue",Helvetica,Arial,"Lucida Grande"}h1{font-weight:700}.italic{font-style:italic}.center{text-align:center}#left-menu #logo,.element-center{display:block;margin:0 auto}form input[type=number]::-webkit-inner-spin-button,form input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.cbt-white-box{background:url(../img/cbt-outline-white.svg) center center no-repeat;background-size:contain}.card{margin-left:0;margin-right:0;-webkit-backface-visibility:hidden;-webkit-perspective:1000}.side-menu .icon{font-size:1.6em}ion-nav-bar.nav-showing .left-buttons{margin-left:-4px}ion-nav-bar .left-buttons{margin-left:0;transition:margin-left .33s ease-out}#connection-icon{max-width:100%}.cbt-icon{margin-top:.2em;height:2em;width:2.2em;background:url(../img/cbt-outline-white.svg) no-repeat!important;background-size:contain!important}.height-animation{-webkit-transition:1.5s linear max-height;transition:1.5s linear max-height;max-height:1200px}.height-animation.ng-hide{max-height:0}.height-animation.ng-hide-remove{display:block!important}.scale-up.ng-hide-add,.scale-up.ng-hide-remove{transition:all .6s cubic-bezier(.68,-.55,.265,1.55);opacity:1;-webkit-transform:scale(1) rotate(0);transform:scale(1) rotate(0)}.scale-up.ng-hide{opacity:0;-webkit-transform:scale(.333) rotate(-24deg);transform:scale(.333) rotate(-24deg)}.scale-up.ng-show{opacity:1;-webkit-transform:scale(1);transform:scale(1)}md-grid-tile{background-color:#fff}md-grid-tile-header h3{font-weight:900;font-style:italic;font-size:200%;color:#282828}table.pid-table{width:100%;background-color:#f8f8f8;text-align:left}table.pid-table th{font-size:1.5em;font-weight:light;padding:.3em;color:#b1b1b1;border-bottom:solid 1px #efefef}table.pid-table td{padding:.5em;border-bottom:solid 1px #efefef;color:#5a6065}.pill,flag-view{background-color:#555;border:1px solid #444;border-radius:5em;color:#fff;display:block;padding:.5em 1em;margin:.2em;font-size:75%;text-align:right;position:relative}.pill.bottom,flag-view.bottom{position:absolute;bottom:12px}.md-grid-text{padding-bottom:5px}flag-view .led{transition:all 50ms;display:inline-block;background-color:#666;border-radius:100%;height:.8em;width:.8em;margin-left:.3em}.side-menu,.side-menu #panel{position:absolute;left:0;height:100%}flag-view .led.active{background-color:red}.user-info{display:table}.user-info img.avatar{border-radius:9999px;border:3px solid #f5f5f5;max-height:64px;max-width:64px;margin:8px;display:table-cell}.user-info p{display:table-cell;vertical-align:middle;margin:0;padding:0}.side-menu{top:44px;display:block;min-height:100%;z-index:9900}.side-menu .has-header{top:0}.side-menu #panel{display:block;width:80%;max-width:380px;z-index:9901;box-shadow:2px 4px 5px rgba(50,50,50,.4);-webkit-transform:translate3d(-300px,0,0)}img#logo{display:block;margin:0 auto;max-width:100%;width:8em;height:8em}.bevel-shadow{box-shadow:0 1px 0 #CCC,0 2px 0 #C9C9C9,0 3px 0 #BBB,0 4px 0 #B9B9B9,0 5px 0 #AAA,0 6px 1px rgba(0,0,0,.1),0 0 5px rgba(0,0,0,.1),0 1px 3px rgba(0,0,0,.3),0 3px 5px rgba(0,0,0,.2),0 5px 10px rgba(0,0,0,.25),0 10px 10px rgba(0,0,0,.2),0 20px 20px rgba(0,0,0,.15)}.pids{margin:22px -1% 0;width:100%;-webkit-transition:.6s ease-out all}.pid-object{border-radius:4px;min-height:3em;width:18em;display:block;margin:0 1% 2%;padding:.8em;background:#f2f2f2;float:left}.pids h3{background-color:#aaa;color:#fff;margin-top:0}.pid-form{margin:0 auto}.pid-form input{border:none;border-bottom:1px solid #ccc;padding:3px;width:78%}.pid-form input,.pid-form label{display:inline-block;vertical-align:baseline}.pid-form label{width:20%;margin-right:2%}.pid-form form,.pid-form input{box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box} \ No newline at end of file +.card,ion-nav-bar{-webkit-transform:translate3d(0,0,0)}#loading,ion-nav-bar{-webkit-app-region:drag}#loading:after,.center{text-align:center}.color-assertive{background-color:#ef4e3a}.type-white{color:#fff}.type-energized{color:#f0b840}body,html{height:100%;-webkit-user-select:text!important}.scroll{-webkit-user-select:text}ion-nav-bar{display:block;height:3em;position:relative;z-index:9999;cursor:move}ion-nav-bar button{-webkit-app-region:no-drag;cursor:pointer}p{white-space:pre-line}body,h1,h2,h3,h4,h5{font-family:Roboto,"Helvetica Neue",Helvetica,Arial,"Lucida Grande"}h1{font-weight:700}.italic{font-style:italic}#left-menu #logo,.element-center{display:block;margin:0 auto}form input[type=number]::-webkit-inner-spin-button,form input[type=number]::-webkit-outer-spin-button{-webkit-appearance:none;margin:0}.cbt-white-box{background:url(../img/cbt-outline-white.svg) center center no-repeat;background-size:contain}.card{margin-left:0;margin-right:0;-webkit-backface-visibility:hidden;-webkit-perspective:1000}.side-menu .icon{font-size:1.6em}ion-nav-bar.nav-showing .left-buttons{margin-left:-4px}ion-nav-bar .left-buttons{margin-left:0;transition:margin-left .33s ease-out}#connection-icon{max-width:100%}.cbt-icon{margin-top:.2em;height:2em;width:2.2em;background:url(../img/cbt-outline-white.svg) no-repeat!important;background-size:contain!important}#loading:before,md-grid-tile{background-color:#fff}.height-animation{-webkit-transition:1.5s linear max-height;transition:1.5s linear max-height;max-height:1200px}.height-animation.ng-hide{max-height:0}.height-animation.ng-hide-remove{display:block!important}.scale-up.ng-hide-add,.scale-up.ng-hide-remove{transition:all .6s cubic-bezier(.68,-.55,.265,1.55);opacity:1;-webkit-transform:scale(1) rotate(0);transform:scale(1) rotate(0)}.scale-up.ng-hide{opacity:0;-webkit-transform:scale(.333) rotate(-24deg);transform:scale(.333) rotate(-24deg)}.scale-up.ng-show{opacity:1;-webkit-transform:scale(1);transform:scale(1)}md-grid-tile-header h3{font-weight:900;font-style:italic;font-size:200%;color:#282828}#loading{position:absolute;top:0;left:0;bottom:0;right:0;z-index:9999999;background-color:#ef4e3a;opacity:1;filter:blur(0);transition:all .2s ease-out}#loading:after{content:'LOADING';color:#fff;display:inline-block;width:100%;position:absolute;top:49%}#loading:before{content:'';height:22px;width:22px;display:block;position:absolute;top:40%;left:33%;margin-top:0;border-radius:2px 0 2px 2px;animation:cbt-bounce 1s infinite;animation-direction:alternate-reverse;animation-timing-function:ease-in-out}@keyframes cbt-bounce{0%{left:40%;height:32px;width:10px;margin-top:-5px}20%,80%{height:22px;width:22px;margin-top:0}100%{left:60%;height:32px;width:10px;margin-top:-5px}}#loading.fade{opacity:0;filter:blur(32)}#loading.hide{display:none;visibility:hidden}table.pid-table{width:100%;background-color:#f8f8f8;text-align:left}table.pid-table th{font-size:1.5em;font-weight:light;padding:.3em;color:#b1b1b1;border-bottom:solid 1px #efefef}table.pid-table td{padding:.5em;border-bottom:solid 1px #efefef;color:#5a6065}.pill,flag-view{background-color:#555;border:1px solid #444;border-radius:5em;color:#fff;display:block;padding:.5em 1em;margin:.2em;font-size:75%;text-align:right;position:relative}.pill.bottom,flag-view.bottom{position:absolute;bottom:12px}.md-grid-text{padding-bottom:5px}flag-view .led{transition:all 50ms;display:inline-block;background-color:#666;border-radius:100%;height:.8em;width:.8em;margin-left:.3em}.side-menu,.side-menu #panel{position:absolute;left:0;height:100%}flag-view .led.active{background-color:red}.user-info{display:table}.user-info img.avatar{border-radius:9999px;border:3px solid #f5f5f5;max-height:64px;max-width:64px;margin:8px;display:table-cell}.user-info p{display:table-cell;vertical-align:middle;margin:0;padding:0}.side-menu{top:44px;display:block;min-height:100%;z-index:9900}.side-menu .has-header{top:0}.side-menu #panel{display:block;width:80%;max-width:380px;z-index:9901;box-shadow:2px 4px 5px rgba(50,50,50,.4);-webkit-transform:translate3d(-300px,0,0)}img#logo{display:block;margin:0 auto;max-width:100%;width:8em;height:8em}.bevel-shadow{box-shadow:0 1px 0 #CCC,0 2px 0 #C9C9C9,0 3px 0 #BBB,0 4px 0 #B9B9B9,0 5px 0 #AAA,0 6px 1px rgba(0,0,0,.1),0 0 5px rgba(0,0,0,.1),0 1px 3px rgba(0,0,0,.3),0 3px 5px rgba(0,0,0,.2),0 5px 10px rgba(0,0,0,.25),0 10px 10px rgba(0,0,0,.2),0 20px 20px rgba(0,0,0,.15)}.pids{margin:22px -1% 0;width:100%;-webkit-transition:.6s ease-out all}.pid-object{border-radius:4px;min-height:3em;width:18em;display:block;margin:0 1% 2%;padding:.8em;background:#f2f2f2;float:left}.pids h3{background-color:#aaa;color:#fff;margin-top:0}.pid-form{margin:0 auto}.pid-form input{border:none;border-bottom:1px solid #ccc;padding:3px;width:78%}.pid-form input,.pid-form label{display:inline-block;vertical-align:baseline}.pid-form label{width:20%;margin-right:2%}.pid-form form,.pid-form input{box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box} \ No newline at end of file diff --git a/www/js/app/app.js b/www/js/app/app.js index 8229644..cb4159f 100644 --- a/www/js/app/app.js +++ b/www/js/app/app.js @@ -8,7 +8,30 @@ // window.cbtAppDebug = true; var remote = require('remote'); -var app = remote.require('app'); +var app = remote.require('electron').app; +var autoUpdater = remote.require('auto-updater'); + +autoUpdater.setFeedUrl('http://files.canb.us/app/latest?version=' + app.getVersion()); +autoUpdater.on('update-downloaded', function(event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate){ + console.info(arguments); + quitAndUpdate(); +}); + +autoUpdater.on('checking-for-update', function(){ + console.info('checking-for-update'); +}); +autoUpdater.on('update-available', function(){ + console.info('update-available'); +}); +autoUpdater.on('update-not-available', function(){ + console.info('update-not-available'); +}); +autoUpdater.on('update-downloaded', function(){ + console.info('update-downloaded'); +}); + +console.info('CBT App version: '+app.getVersion(), autoUpdater); + /* @@ -16,7 +39,7 @@ var app = remote.require('app'); */ window.onerror = function(message, url, lineNumber) { console.error(message, url, lineNumber); - return true; + return false; }; @@ -67,7 +90,7 @@ angular.module('cbt', ['ngAnimate', 'ionic', 'ngMaterial', 'LocalStorageModule'] }; }]) - .constant('appVersion', '0.2.8-alpha3') // Set app version + .constant('appVersion', app.getVersion()) // Set app version .config(function($stateProvider, $urlRouterProvider, localStorageServiceProvider) { diff --git a/www/js/app/services/FirmwareService.js b/www/js/app/services/FirmwareService.js index 7a7d1f4..4b233b8 100644 --- a/www/js/app/services/FirmwareService.js +++ b/www/js/app/services/FirmwareService.js @@ -4,8 +4,15 @@ * A FSM for uploading firmware to the CBT via the HardwareService */ +var avr109 = require('chip.avr.avr109'), + Serialport = require('serialport'), + tempSerialPort; + + + + angular.module('cbt') - .factory('FirmwareService', function($rootScope, $q, $http, $timeout, HardwareService, UtilsService){ + .factory('FirmwareService', function($rootScope, $q, $http, $timeout, HardwareService, SerialService, UtilsService){ var pageSize = 128, sendMaxBytes = 16, @@ -321,8 +328,8 @@ angular.module('cbt') fetchFirmware(s) .then( function(d){ HardwareService.registerRawHandler( readHandler ); - hex = new IntelHex( d ); - startMachine(); + // hex = new IntelHex( d ); + // startMachine(); }) .catch(function (error){ $rootScope.$broadcast('FirmwareService.HEX_ERROR', error); @@ -339,7 +346,8 @@ angular.module('cbt') fetchFirmware(s) .then( function(d){ - hex = new IntelHex( d ); + // hex = new IntelHex( d ); + hex = d; }) .catch(function (error){ $rootScope.$broadcast('FirmwareService.HEX_ERROR', error); @@ -351,14 +359,87 @@ angular.module('cbt') function sendLoaded(){ if( hex != null ){ - HardwareService.registerRawHandler( readHandler ); - startMachine(); + // HardwareService.registerRawHandler( readHandler ); + // startMachine(); + + if( SerialService.getSerialPort() == undefined ){ + $rootScope.$broadcast('FirmwareService.SERIAL_PORT_FAIL'); + return; + } + + var oldPort = SerialService.getSerialPort(); + + HardwareService.command('bootloader'); + + $timeout(function () { + tempSerialPort = new Serialport.SerialPort(oldPort.path, { + baudRate: 115200, + }, false); + tempSerialPort.open(doFlash); + }, 1000); + }else $rootScope.$broadcast('FirmwareService.HEX_UNAVAILABLE', error); } + function doFlash(err){ + + if(err) + $rootScope.$broadcast('FirmwareService.FLASH_ERROR', err); + + avr109.init(tempSerialPort, { signature: 'CANBusT', timeout:500 }, function (err, flasher) { + + $timeout(function(){ + if(err) + $rootScope.$broadcast('FirmwareService.FLASH_ERROR', err); + else { + $rootScope.$broadcast('FirmwareService.FLASH_PROGRESS', 0.555 ); + } + }); + + console.info('flasher start'); + flasher.erase(function() { + console.log('initialized'); + $timeout(function(){ + $rootScope.$broadcast('FirmwareService.FLASH_PROGRESS', 0.555 ); + }); + + flasher.program(hex.toString(), function(err) { + $timeout(function(){ + if (err){ + $rootScope.$broadcast('FirmwareService.FLASH_ERROR', err); + }else{ + console.log('programmed!'); + $rootScope.$broadcast('FirmwareService.FLASH_PROGRESS', 0.555 ); + } + }); + + flasher.verify(function(err) { + $timeout(function(){ + $rootScope.$broadcast('FirmwareService.FLASH_PROGRESS', 0.666 ); + if(err) $rootScope.$broadcast('FirmwareService.FLASH_ERROR', err); + }); + + flasher.fuseCheck(function(err) { + $timeout(function(){ + $rootScope.$broadcast('FirmwareService.FLASH_PROGRESS', 0.888 ); + if(err){ + $rootScope.$broadcast('FirmwareService.FLASH_ERROR', err); + }else{ + console.log('Flash OK!'); + $rootScope.$broadcast('FirmwareService.FLASH_PROGRESS', 1 ); + $rootScope.$broadcast('FirmwareService.FLASH_SUCCESS'); + } + }); + }); + }); + }); + }); + }); + } + diff --git a/www/js/app/services/HardwareService.js b/www/js/app/services/HardwareService.js index dfb1f50..64cb442 100644 --- a/www/js/app/services/HardwareService.js +++ b/www/js/app/services/HardwareService.js @@ -324,7 +324,6 @@ angular.module('cbt') function setHardwareInfo(obj){ - console.info( 'HW INFO: ', obj ); hardwareInfo = obj; } diff --git a/www/js/app/services/SerialService.js b/www/js/app/services/SerialService.js index bc60330..c45ab5f 100644 --- a/www/js/app/services/SerialService.js +++ b/www/js/app/services/SerialService.js @@ -9,8 +9,8 @@ if( typeof process != "undefined" && process.platform ) angular.module('cbt') .factory('SerialService', function( $q, $rootScope, $interval, $timeout, UtilsService ) { - var serialport = require("serialport"), - SerialPort = serialport.SerialPort, + var sp = require("serialport"), + SerialPort = sp.SerialPort, serialPort; var serialOpened = false, @@ -42,7 +42,7 @@ angular.module('cbt') serialPort = new SerialPort(serialPath, { // encoding: 'ascii', //Buffer utf8 utf16le ucs2 ascii hex. - baudrate: baudRate, + baudrate: baudRate, databits: 8, stopbits: 1, parity: 'none', @@ -69,6 +69,7 @@ angular.module('cbt') serialPort.on('close', function(){ console.info("Serial Port Closed"); + $rootScope.$broadcast('SerialService.CLOSE'); }); return deferred.promise; @@ -80,7 +81,7 @@ angular.module('cbt') * Serial Data callback */ - var readline = serialport.parsers.readline("\r\n", "binary"); + var readline = sp.parsers.readline("\r\n", "binary"); function parser(obj, data){ @@ -163,7 +164,6 @@ angular.module('cbt') * @return null */ function registerReadCallback(callback){ - serialPort.on('data', function(data){ // TODO Write a new parser for SerialPort that converts directly to ArrayBuffer. Take note of the realline wrapper function above. callback( UtilsService.str2ab(data) ); diff --git a/www/js/scripts.js b/www/js/scripts.js index af4562f..e951ea1 100644 --- a/www/js/scripts.js +++ b/www/js/scripts.js @@ -8,7 +8,30 @@ // window.cbtAppDebug = true; var remote = require('remote'); -var app = remote.require('app'); +var app = remote.require('electron').app; +var autoUpdater = remote.require('auto-updater'); + +autoUpdater.setFeedUrl('http://files.canb.us/app/latest?version=' + app.getVersion()); +autoUpdater.on('update-downloaded', function(event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate){ + console.info(arguments); + quitAndUpdate(); +}); + +autoUpdater.on('checking-for-update', function(){ + console.info('checking-for-update'); +}); +autoUpdater.on('update-available', function(){ + console.info('update-available'); +}); +autoUpdater.on('update-not-available', function(){ + console.info('update-not-available'); +}); +autoUpdater.on('update-downloaded', function(){ + console.info('update-downloaded'); +}); + +console.info('CBT App version: '+app.getVersion(), autoUpdater); + /* @@ -16,7 +39,7 @@ var app = remote.require('app'); */ window.onerror = function(message, url, lineNumber) { console.error(message, url, lineNumber); - return true; + return false; }; @@ -67,7 +90,7 @@ angular.module('cbt', ['ngAnimate', 'ionic', 'ngMaterial', 'LocalStorageModule'] }; }]) - .constant('appVersion', '0.2.8-alpha3') // Set app version + .constant('appVersion', app.getVersion()) // Set app version .config(function($stateProvider, $urlRouterProvider, localStorageServiceProvider) { @@ -3027,8 +3050,15 @@ angular.module('cbt') * A FSM for uploading firmware to the CBT via the HardwareService */ +var avr109 = require('chip.avr.avr109'), + Serialport = require('serialport'), + tempSerialPort; + + + + angular.module('cbt') - .factory('FirmwareService', function($rootScope, $q, $http, $timeout, HardwareService, UtilsService){ + .factory('FirmwareService', function($rootScope, $q, $http, $timeout, HardwareService, SerialService, UtilsService){ var pageSize = 128, sendMaxBytes = 16, @@ -3344,8 +3374,8 @@ angular.module('cbt') fetchFirmware(s) .then( function(d){ HardwareService.registerRawHandler( readHandler ); - hex = new IntelHex( d ); - startMachine(); + // hex = new IntelHex( d ); + // startMachine(); }) .catch(function (error){ $rootScope.$broadcast('FirmwareService.HEX_ERROR', error); @@ -3362,7 +3392,8 @@ angular.module('cbt') fetchFirmware(s) .then( function(d){ - hex = new IntelHex( d ); + // hex = new IntelHex( d ); + hex = d; }) .catch(function (error){ $rootScope.$broadcast('FirmwareService.HEX_ERROR', error); @@ -3374,14 +3405,87 @@ angular.module('cbt') function sendLoaded(){ if( hex != null ){ - HardwareService.registerRawHandler( readHandler ); - startMachine(); + // HardwareService.registerRawHandler( readHandler ); + // startMachine(); + + if( SerialService.getSerialPort() == undefined ){ + $rootScope.$broadcast('FirmwareService.SERIAL_PORT_FAIL'); + return; + } + + var oldPort = SerialService.getSerialPort(); + + HardwareService.command('bootloader'); + + $timeout(function () { + tempSerialPort = new Serialport.SerialPort(oldPort.path, { + baudRate: 115200, + }, false); + tempSerialPort.open(doFlash); + }, 1000); + }else $rootScope.$broadcast('FirmwareService.HEX_UNAVAILABLE', error); } + function doFlash(err){ + + if(err) + $rootScope.$broadcast('FirmwareService.FLASH_ERROR', err); + + avr109.init(tempSerialPort, { signature: 'CANBusT', timeout:500 }, function (err, flasher) { + + $timeout(function(){ + if(err) + $rootScope.$broadcast('FirmwareService.FLASH_ERROR', err); + else { + $rootScope.$broadcast('FirmwareService.FLASH_PROGRESS', 0.555 ); + } + }); + + console.info('flasher start'); + flasher.erase(function() { + console.log('initialized'); + $timeout(function(){ + $rootScope.$broadcast('FirmwareService.FLASH_PROGRESS', 0.555 ); + }); + + flasher.program(hex.toString(), function(err) { + $timeout(function(){ + if (err){ + $rootScope.$broadcast('FirmwareService.FLASH_ERROR', err); + }else{ + console.log('programmed!'); + $rootScope.$broadcast('FirmwareService.FLASH_PROGRESS', 0.555 ); + } + }); + + flasher.verify(function(err) { + $timeout(function(){ + $rootScope.$broadcast('FirmwareService.FLASH_PROGRESS', 0.666 ); + if(err) $rootScope.$broadcast('FirmwareService.FLASH_ERROR', err); + }); + + flasher.fuseCheck(function(err) { + $timeout(function(){ + $rootScope.$broadcast('FirmwareService.FLASH_PROGRESS', 0.888 ); + if(err){ + $rootScope.$broadcast('FirmwareService.FLASH_ERROR', err); + }else{ + console.log('Flash OK!'); + $rootScope.$broadcast('FirmwareService.FLASH_PROGRESS', 1 ); + $rootScope.$broadcast('FirmwareService.FLASH_SUCCESS'); + } + }); + }); + }); + }); + }); + }); + } + @@ -3719,7 +3823,6 @@ angular.module('cbt') function setHardwareInfo(obj){ - console.info( 'HW INFO: ', obj ); hardwareInfo = obj; } @@ -3877,8 +3980,8 @@ if( typeof process != "undefined" && process.platform ) angular.module('cbt') .factory('SerialService', function( $q, $rootScope, $interval, $timeout, UtilsService ) { - var serialport = require("serialport"), - SerialPort = serialport.SerialPort, + var sp = require("serialport"), + SerialPort = sp.SerialPort, serialPort; var serialOpened = false, @@ -3910,7 +4013,7 @@ angular.module('cbt') serialPort = new SerialPort(serialPath, { // encoding: 'ascii', //Buffer utf8 utf16le ucs2 ascii hex. - baudrate: baudRate, + baudrate: baudRate, databits: 8, stopbits: 1, parity: 'none', @@ -3937,6 +4040,7 @@ angular.module('cbt') serialPort.on('close', function(){ console.info("Serial Port Closed"); + $rootScope.$broadcast('SerialService.CLOSE'); }); return deferred.promise; @@ -3948,7 +4052,7 @@ angular.module('cbt') * Serial Data callback */ - var readline = serialport.parsers.readline("\r\n", "binary"); + var readline = sp.parsers.readline("\r\n", "binary"); function parser(obj, data){ @@ -4031,7 +4135,6 @@ angular.module('cbt') * @return null */ function registerReadCallback(callback){ - serialPort.on('data', function(data){ // TODO Write a new parser for SerialPort that converts directly to ArrayBuffer. Take note of the realline wrapper function above. callback( UtilsService.str2ab(data) ); diff --git a/www/templates/hardware/firmware.html b/www/templates/hardware/firmware.html index 3bd618c..9b318f5 100644 --- a/www/templates/hardware/firmware.html +++ b/www/templates/hardware/firmware.html @@ -19,7 +19,7 @@

Available Firmware Builds

Flash Now + ng-click="flash(selectedBuildVersion)">Load Firmware From f500a73d25a0c3b6b8ab8f4b6c295414bfbdb206 Mon Sep 17 00:00:00 2001 From: Derek K Date: Sun, 31 Jan 2016 17:02:02 -0500 Subject: [PATCH 3/3] Auto updater setup --- main.js | 24 +++++++++++++++++++----- www/js/app/app.js | 23 ----------------------- www/js/scripts.js | 23 ----------------------- 3 files changed, 19 insertions(+), 51 deletions(-) diff --git a/main.js b/main.js index 11cda5a..b68b8ca 100644 --- a/main.js +++ b/main.js @@ -47,11 +47,25 @@ if (handleStartupEvent()) { return; } -// autoUpdater.setFeedUrl('http://files.canb.us/app/latest?version=' + app.getVersion()); -// autoUpdater.on('update-downloaded', function(event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate){ -// console.info('Quit and update'); -// quitAndUpdate(); -// }); +var autoUpdater = require('auto-updater'); + +autoUpdater.setFeedUrl('http://files.canb.us/app/latest-'+process.platform+'?version=' + app.getVersion()); +autoUpdater.on('update-downloaded', function(event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate){ + console.info(arguments); + new Notification("CANBus Triple", {"body":"An update has been downloaded for the CANBus Triple App", "icon":__dirname+"/www/img/cbt-128.png"}); + quitAndUpdate(); +}); + +autoUpdater.on('checking-for-update', function(){ + console.info('checking-for-update'); +}); +autoUpdater.on('update-available', function(){ + console.info('update-available'); +}); +autoUpdater.on('update-not-available', function(){ + console.info('update-not-available'); +}); + // Report crashes to our server. require('crash-reporter').start(); diff --git a/www/js/app/app.js b/www/js/app/app.js index cb4159f..55be3bf 100644 --- a/www/js/app/app.js +++ b/www/js/app/app.js @@ -9,29 +9,6 @@ var remote = require('remote'); var app = remote.require('electron').app; -var autoUpdater = remote.require('auto-updater'); - -autoUpdater.setFeedUrl('http://files.canb.us/app/latest?version=' + app.getVersion()); -autoUpdater.on('update-downloaded', function(event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate){ - console.info(arguments); - quitAndUpdate(); -}); - -autoUpdater.on('checking-for-update', function(){ - console.info('checking-for-update'); -}); -autoUpdater.on('update-available', function(){ - console.info('update-available'); -}); -autoUpdater.on('update-not-available', function(){ - console.info('update-not-available'); -}); -autoUpdater.on('update-downloaded', function(){ - console.info('update-downloaded'); -}); - -console.info('CBT App version: '+app.getVersion(), autoUpdater); - /* diff --git a/www/js/scripts.js b/www/js/scripts.js index e951ea1..4472c9f 100644 --- a/www/js/scripts.js +++ b/www/js/scripts.js @@ -9,29 +9,6 @@ var remote = require('remote'); var app = remote.require('electron').app; -var autoUpdater = remote.require('auto-updater'); - -autoUpdater.setFeedUrl('http://files.canb.us/app/latest?version=' + app.getVersion()); -autoUpdater.on('update-downloaded', function(event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate){ - console.info(arguments); - quitAndUpdate(); -}); - -autoUpdater.on('checking-for-update', function(){ - console.info('checking-for-update'); -}); -autoUpdater.on('update-available', function(){ - console.info('update-available'); -}); -autoUpdater.on('update-not-available', function(){ - console.info('update-not-available'); -}); -autoUpdater.on('update-downloaded', function(){ - console.info('update-downloaded'); -}); - -console.info('CBT App version: '+app.getVersion(), autoUpdater); - /*