{"id":271,"date":"2009-03-23T22:38:11","date_gmt":"2009-03-23T11:38:11","guid":{"rendered":"http:\/\/www.madox.net\/blog\/?p=271"},"modified":"2009-03-23T22:38:11","modified_gmt":"2009-03-23T11:38:11","slug":"mchumby-mazdamadox-chumby","status":"publish","type":"post","link":"http:\/\/www.madox.net\/blog\/2009\/03\/23\/mchumby-mazdamadox-chumby\/","title":{"rendered":"mChumby &#8211; Mazda\/Madox Chumby"},"content":{"rendered":"<p>It&#8217;s taken me a while to officially start this project.\u00a0 When I first bought my Mazda 3 I had envisaged making my own speedometer based off the Mazda CAN Bus but somehow never quite got around to it.<\/p>\n<p>I even ended up buying 2 <a href=\"http:\/\/www.chumby.com\/\" target=\"_blank\">Chumbies<\/a> for the purpose of hacking one and developing the same speedo (The chumby is such a great alarm clock I couldn&#8217;t live without one&#8230;).<\/p>\n<p>There has been quite a bit of interest in the comments for source code\/information etc etc.\u00a0 So now I&#8217;m officially starting the mChumby project!\u00a0 This first post is basically a brainstorming session write-up or a mini requirements specification on myself.\u00a0 Feel free to comment on any ideas\/improvements you think I can make.<\/p>\n<p>(This post seems too wordy without a photo but I&#8217;m just too lazy)<\/p>\n<h1><!--more-->The concept<\/h1>\n<p>A Chumby will connect via CAN Bus to the Mazda to offer an alternative &#8216;GUI&#8217; to the car.\u00a0 Information such as fuel consumption that has been removed from the Australian Mazda&#8217;s will be displayed.<\/p>\n<p>Since a chumby doesn&#8217;t have native CAN Bus connections, a custom daughter board with dual CAN controllers and transceivers will be built to replace the native Chumby power board.<\/p>\n<h1>The hardware<\/h1>\n<p>In addition to the Chumby mainboard, there will be a custom daughter board to be made to handle the car interface.\u00a0 The Chumby has multiple SPI interfaces brought out through the &#8216;Chumbilical&#8217;, as well as on-board voltage regulators that will take up to 15V.\u00a0 So a quick brainstorm on the daughter-board components leads me to :-<\/p>\n<p>CAN Controller : MCP2515 &#8211; Has SPI interface, great for Chumby.<br \/>\nCAN Transceiver : TJA1041 or whatever it is I have in my box of electronics &#8211; Because I have them already<br \/>\nUSB Connectors + Associated electronics&#8230;<br \/>\nAutomotive Voltage Suppressor : Vishay had a few good ones<\/p>\n<p>Luxuries like accelerometers are too much of a pain to hand solder \ud83d\ude42<\/p>\n<h1>The software<\/h1>\n<p>I&#8217;m going to try use completely open source software in the development.\u00a0 This will be discounting the Flash Lite 3 player that ships with the Chumby.\u00a0 I debated much about developing a QT app or a flash widget, what I decided was undecided and I switched back and forth.\u00a0 In the end, I&#8217;m sticking with Flash (for now).<\/p>\n<p>There are two main pieces of software required, the GUI and the CAN Bus drivers.<\/p>\n<p>The GUI as decided before will be Flash targetting the Flash Lite 3 on the Chumby.\u00a0 For this I decided to use <a href=\"http:\/\/www.haxe.org\/\" target=\"_blank\">HaXe<\/a>, which will happily compile to Flash 8 bytecode.\u00a0 It is not as popular in open source flash developement as say ActionScript 2 with <a href=\"http:\/\/tech.motion-twin.com\/mtasc.html\" target=\"_blank\">mtasc<\/a> but I figured I&#8217;ll use the newer language.\u00a0 Unfortunately there is a severe lack of HaXe examples on the net and when you find them, you&#8217;ll find that its based on Flash 9 API&#8230; GAH.\u00a0 However a little bit of experimentation and googling around made me see how easy it is to actually use HaXe.\u00a0 More on this later.<\/p>\n<p>The driver&#8217;s for the MCP2515&#8217;s I haven&#8217;t really looked at yet but I hope that it&#8217;ll be a simple matter of adapting MCP2515 code from elsewhere and merging it with hopefully some SPI driver&#8217;s in the Chumby kernel source (did I mention how great the Chumby is? Source code is made available!).<\/p>\n<p>There is a bit of other software that&#8217;ll be used to create this project.\u00a0 I&#8217;m planning on learning how to use <a href=\"http:\/\/http:\/\/iut-tice.ujf-grenoble.fr\/kicad\/\" target=\"_blank\">KiCAD<\/a> to generate the PCB where as I&#8217;ve only previously used<a href=\"http:\/\/cadsoftusa.com\/\" target=\"_blank\"> Eagle<\/a> on my hobby projects.\u00a0 While I&#8217;m sure Eagle will get the job done, I really want to give a try in learning how to use the open source KiCAD.\u00a0 Let me know if you have any hints.<\/p>\n<p><a href=\"http:\/\/www.geany.org\/\" target=\"_blank\">Geany<\/a> will be my lightweight editor\/IDE of choice, its so simple to use and amazing.\u00a0 (I like <a href=\"http:\/\/notepad-plus.sourceforge.net\/\" target=\"_blank\">Notepad++<\/a> in Windows but I haven&#8217;t booted Windows at home for a while&#8230;)<\/p>\n<h1>The HMI<\/h1>\n<p>I like easy to use and simple user interfaces.\u00a0 This is especially true when I&#8217;m driving, I definitely do not want this thing distracting me.\u00a0 My initial idea was to organise it such that all the &#8216;buttons&#8217; are on the corners of the screen but on second thought even trying to touch that while driving may be a bit difficult.<\/p>\n<p>Current idea is to use some simple swipe gestures to control the screen.\u00a0 The idea is to have minimal interaction with my mChumby as possible while driving.\u00a0 I intend to have 2 screens, one to display a large speedo and the main displays and a second screen to display a smaller speed with alot of additional potentially useless information (I haven&#8217;t figured out what yet).\u00a0 I will also need brightness control to avoid getting a super bright screen at night.\u00a0 So simply, swipe left-right will allow me to change screens and wipe up-down will allow me to adjust backlight brightness.<\/p>\n<h2>Below is just an embarassing sample of the HaXe code I was experimenting with&#8230;<\/h2>\n<h3><\/h3>\n<h3>Mchumby.hx<\/h3>\n<blockquote>\n<pre>\/\/MChumby GUI - HaXe code targetting Flash 8\r\n\r\nclass Mchumby{\r\n  \/\/Gesture Variables\r\n  static var fGestureStartX:Float;\r\n  static var fGestureStartY:Float;\r\n  static var fGestureEndX:Float;\r\n  static var fGestureEndY:Float;\r\n  static var fGestureDeltaX:Float;\r\n  static var fGestureDeltaY:Float;\r\n\r\n  \/\/MovieClips (Screens)\r\n  static var mcMain : flash.MovieClip;\r\n\r\n  static var mcD100 : flash.MovieClip;\r\n  static var mcD101 : flash.MovieClip;\r\n  \/\/MovieClips (Buttons\/Other Elements)\r\n\r\n  \/\/Text Fields\r\n  static var tfText : flash.TextField;\r\n\r\n  static var tfSpeedo : flash.TextField;\r\n  static var tfAccelX : flash.TextField;\r\n  static var tfAccelY : flash.TextField;\r\n  static var tfAccelZ : flash.TextField;  \r\n\r\n  \/\/Text Format\/Styles\r\n  static var ts = new flash.TextFormat();\r\n  static var tsCenter = new flash.TextFormat();\r\n\r\n  public function new(){\r\n    \/\/Constructor - Most items are moved to main();\r\n    fGestureStartX=0;\r\n    fGestureStartY=0;\r\n  }\r\n\r\n  static function main(){\r\n    \/\/Setup main MovieClip\r\n    mcMain = flash.Lib.current;\r\n\r\n    \/\/Set up some font styles\r\n    ts.font = \"Arial\";\r\n    ts.size = 24;\r\n    ts.color = 0x00FFFF;\r\n\r\n    tsCenter.font = \"Arial\";\r\n    tsCenter.size = 24;\r\n    tsCenter.color = 0xFF0000;\r\n    tsCenter.align = 'center';\r\n\r\n    \/\/Set up screens the new way\r\n    \/\/var m100 = new M100(mcMain);\r\n    \/\/var m101 = new M101(mcMain);\r\n\r\n    \/\/Set up screens\r\n    mcD100 = mcMain.createEmptyMovieClip(\"D100\", mcMain.getNextHighestDepth());\r\n    mcD101 = mcMain.createEmptyMovieClip(\"D101\", mcMain.getNextHighestDepth());\r\n\r\n    \/\/Set up text fields\r\n    tfText = mcMain.createTextField(\"tfText\", mcMain.getNextHighestDepth(), 20, 20, 280, 100);\r\n    tfText.setNewTextFormat(tsCenter);\r\n\r\n    \/\/Set up text fields (D100)\r\n    tfSpeedo = mcD100.createTextField(\"speedotext\", mcD100.getNextHighestDepth(), 20,50,280,100);\r\n    tfSpeedo.setNewTextFormat(ts);\r\n    tfAccelX = mcD100.createTextField(\"accelx\", mcD100.getNextHighestDepth(), 20,80,280,100);\r\n    tfAccelX.setNewTextFormat(ts);\r\n    tfAccelY = mcD100.createTextField(\"accely\", mcD100.getNextHighestDepth(), 20,110,280,100);\r\n    tfAccelY.setNewTextFormat(ts);\r\n    tfAccelZ = mcD100.createTextField(\"accelz\", mcD100.getNextHighestDepth(), 20,140,280,100);\r\n    tfAccelZ.setNewTextFormat(ts);\r\n\r\n    \/\/Set up text fields (D101)\r\n\r\n    \/\/Initialise text\r\n    tfText.text = 'Hello World!';\r\n\r\n    tfSpeedo.text = 'Accelerometer Values...';\r\n\r\n    \/\/Set up event handlers\r\n    mcMain.onMouseDown = startGesture;\r\n    mcMain.onMouseUp = endGesture;\r\n    mcMain.onEnterFrame = update;\r\n  }\r\n\r\n  static function update(){\r\n    tfAccelX.text = Std.string(ChumbyNative.getAccelerometer(5));\r\n    tfAccelY.text = Std.string(ChumbyNative.getAccelerometer(6));\r\n    tfAccelZ.text = Std.string(ChumbyNative.getAccelerometer(7));\r\n  }\r\n  static function startGesture () {\r\n    fGestureStartX = flash.Lib.current._xmouse;\r\n    fGestureStartY = flash.Lib.current._ymouse;\r\n  }\r\n\r\n  static function endGesture () {\r\n    fGestureEndX = flash.Lib.current._xmouse;\r\n    fGestureEndY = flash.Lib.current._ymouse;\r\n    fGestureDeltaX = Math.round(fGestureEndX - fGestureStartX);\r\n    fGestureDeltaY = Math.round(fGestureEndY - fGestureStartY);\r\n\r\n\t\t\/\/Rather than else-if, the following if's are deliberately done to allow compound gestures\r\n\t\t\/\/e.g. Up &amp; Left, Down &amp; Right etc.\r\n    if (!Math.isNaN(fGestureDeltaY) &amp;&amp; (fGestureDeltaY &gt; 100)) {\r\n      gestureDown();\r\n    }\r\n\r\n    if (!Math.isNaN(fGestureDeltaY) &amp;&amp; (fGestureDeltaY &lt; -100)) {\r\n      gestureUp();\r\n    } \r\n\r\n    if (!Math.isNaN(fGestureDeltaX) &amp;&amp; (fGestureDeltaX &lt; -200)) {\r\n      gestureLeft();\r\n    }\r\n\r\n    if (!Math.isNaN(fGestureDeltaX) &amp;&amp; (fGestureDeltaX &gt; 200)) {\r\n      gestureRight();\r\n    }\r\n  }\r\n  static function gestureRight () {\r\n    tfText.text = \"To the right!\";\r\n    mcD100._alpha = 0;\r\n    \/\/tfText.setTextFormat(ts);\r\n  }\r\n  static function gestureLeft () {\r\n    tfText.text = \"To the left!\";\r\n    mcD100._alpha = 100;\r\n  }\r\n  static function gestureUp () {\r\n    tfText.text = \"Bright!\";\r\n    ChumbyNative.setLCDMute(0);\r\n  }\r\n  static function gestureDown () {\r\n    tfText.text = \"Dim!\";\r\n    ChumbyNative.setLCDMute(1);\r\n  }\r\n}<\/pre>\n<\/blockquote>\n<h3>ChumbyNative.hx<\/h3>\n<blockquote>\n<pre>class ChumbyNative{\r\n  public static function getLCDMute():Int{\r\n    return flash.Lib._global.ASnative(5,19);\r\n  }\r\n  public static function setLCDMute(x:Int):Void{\r\n    flash.Lib._global.ASnative(5,20)(x);\r\n  }\r\n  public static function getAccelerometer(x:Int):Float{\r\n    return flash.Lib._global.ASnative(5,60)(x);\r\n  }\r\n}<\/pre>\n<\/blockquote>\n<h3>Mchumby.hxml<\/h3>\n<blockquote><p>-swf mchumby.swf<br \/>\n-main Mchumby<br \/>\n-swf-header 320:240:12:000033<br \/>\n-swf-version 8<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s taken me a while to officially start this project.\u00a0 When I first bought my Mazda 3 I had envisaged making my own speedometer based off the Mazda CAN Bus but somehow never quite got around to it. I even ended up buying 2 Chumbies for the purpose of hacking one and developing the same &hellip; <a href=\"http:\/\/www.madox.net\/blog\/2009\/03\/23\/mchumby-mazdamadox-chumby\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;mChumby &#8211; Mazda\/Madox Chumby&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[24,12,8,11,55],"class_list":["post-271","post","type-post","status-publish","format-standard","hentry","category-engineering","tag-arm","tag-can-bus","tag-free-software","tag-mazda","tag-microcontrollers"],"_links":{"self":[{"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/posts\/271","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/comments?post=271"}],"version-history":[{"count":4,"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/posts\/271\/revisions"}],"predecessor-version":[{"id":275,"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/posts\/271\/revisions\/275"}],"wp:attachment":[{"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/media?parent=271"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/categories?post=271"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/tags?post=271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}