Skip to content

This is the template for all ChiliPeppr widgets to use so they follow a consistent style.

Notifications You must be signed in to change notification settings

jarretluft/widget-smoothie

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

com-chilipeppr-widget-Smoothie

This widget shows smoothie specific controls and current status information.

alt text

ChiliPeppr Widget / Smoothieboard

All ChiliPeppr widgets/elements are defined using cpdefine() which is a method that mimics require.js. Each defined object must have a unique ID so it does not conflict with other ChiliPeppr widgets.

Item Value
ID com-chilipeppr-widget-Smoothie
Name Widget / Smoothieboard
Description This widget shows smoothie specific controls and current status information.
chilipeppr.load() URL http://raw.githubusercontent.com/https://master/auto-generated-widget.html
Edit URL http://ide.c9.io/jarretluft/widget-smoothie
Github URL http://github.com/https:/
Test URL https://preview.c9users.io/jarretluft/widget-smoothie/widget.html

Example Code for chilipeppr.load() Statement

You can use the code below as a starting point for instantiating this widget inside a workspace or from another widget. The key is that you need to load your widget inlined into a div so the DOM can parse your HTML, CSS, and Javascript. Then you use cprequire() to find your widget's Javascript and get back the instance of it.

// Inject new div to contain widget or use an existing div with an ID
$("body").append('<' + 'div id="myDivWidgetSmoothie"><' + '/div>');

chilipeppr.load(
  "#myDivWidgetSmoothie",
  "http://raw.githubusercontent.com/https://master/auto-generated-widget.html",
  function() {
    // Callback after widget loaded into #myDivWidgetSmoothie
    // Now use require.js to get reference to instantiated widget
    cprequire(
      ["inline:com-chilipeppr-widget-Smoothie"], // the id you gave your widget
      function(myObjWidgetSmoothie) {
        // Callback that is passed reference to the newly loaded widget
        console.log("Widget / Smoothieboard just got loaded.", myObjWidgetSmoothie);
        myObjWidgetSmoothie.init();
      }
    );
  }
);

Publish

This widget/element publishes the following signals. These signals are owned by this widget/element and are published to all objects inside the ChiliPeppr environment that listen to them via the chilipeppr.subscribe(signal, callback) method. To better understand how ChiliPeppr's subscribe() method works see amplify.js's documentation at http://amplifyjs.com/api/pubsub/

Signal Description
/com-chilipeppr-widget-Smoothie/com-chilipeppr-interface-cnccontroller/feedholdFeedhold (Emergency Stop). This signal is published when user hits the Feedhold button for an emergency stop of the Smoothie. Other widgets should see this and stop sending all commands such that even when the plannerresume signal is received when the user clears the queue or cycle starts again, they have to manually start sending code again. So, for example, a Gcode sender widget should place a pause on the sending but allow user to unpause.
/com-chilipeppr-widget-Smoothie/com-chilipeppr-interface-cnccontroller/plannerpauseThis widget will publish this signal when it determines that the planner buffer is too full on the Smoothie and all other elements/widgets need to stop sending data. You will be sent a /plannerresume when this widget determines you can start sending again. The Smoothie has a buffer of 28 slots for data. You want to fill it up with around 12 commands to give the planner enough data to work on for optimizing velocities of movement. However, you can't overfill the Smoothie or it will go nuts with buffer overflows. This signal helps you fire off your data and not worry about it, but simply pause the sending of the data when you see this signal. This signal does rely on the Smoothie being in {qv:2} mode which means it will auto-send us a report on the planner every time it changes. This widget watches for those changes to generate the signal. The default setting is when we hit 12 remaining planner buffer slots we will publish this signal.
/com-chilipeppr-widget-Smoothie/com-chilipeppr-interface-cnccontroller/plannerresumeThis widget will send this signal when it is ok to send data to the Smoothie again. This widget watches the {qr:[val]} status report from the Smoothie to determine when the planner buffer has enough room in it to send more data. You may not always get a 1 to 1 /plannerresume for every /plannerpause sent because we will keep sending /plannerpause signals if we're below threshold, but once back above threshold we'll only send you one /plannerresume. The default setting is to send this signal when we get back to 16 available planner buffer slots.
/com-chilipeppr-widget-Smoothie/com-chilipeppr-interface-cnccontroller/axesThis widget will normalize the Smoothie status report of axis coordinates to send off to other widgets like the XYZ widget. The axes publish payload contains {x:float, y:float, z:float, a:float} If a different CNC controller is implemented, it should normalize the coordinate status reports like this model. The goal of this is to abstract away the specific controller implementation from generic CNC widgets.
/com-chilipeppr-widget-Smoothie/com-chilipeppr-interface-cnccontroller/unitsThis widget will normalize the Smoothie units to the interface object of units {units: "mm"} or {units: "inch"}. This signal will be published on load or when this widget detects a change in units so other widgets like the XYZ widget can display the units for the coordinates it is displaying.
/com-chilipeppr-widget-Smoothie/com-chilipeppr-interface-cnccontroller/proberesponsePublish a probe response with the coordinates triggered during probing, or an alarm state if the probe does not contact a surface
/com-chilipeppr-widget-Smoothie/com-chilipeppr-interface-cnccontroller/statusPublish a signal each time the Smoothie status changes

Subscribe

This widget/element subscribes to the following signals. These signals are owned by this widget/element. Other objects inside the ChiliPeppr environment can publish to these signals via the chilipeppr.publish(signal, data) method. To better understand how ChiliPeppr's publish() method works see amplify.js's documentation at http://amplifyjs.com/api/pubsub/

Signal Description
/com-chilipeppr-widget-Smoothie/com-chilipeppr-interface-cnccontroller/jogdoneWe subscribe to a jogdone event so that we can fire off an exclamation point (!) to the Smoothie to force it to drop all planner buffer items to stop the jog immediately.
/com-chilipeppr-widget-Smoothie/com-chilipeppr-interface-cnccontroller/recvgcodeSubscribe to receive gcode from other widgets for processing and passing on to serial port

Foreign Publish

This widget/element publishes to the following signals that are owned by other objects. To better understand how ChiliPeppr's subscribe() method works see amplify.js's documentation at http://amplifyjs.com/api/pubsub/

Signal Description
/com-chilipeppr-widget-Smoothie/com-chilipeppr-widget-serialport/sendWe send to the serial port certain commands like the initial configuration commands for the Smoothie to be in the correct mode and to get initial statuses like planner buffers and XYZ coords. We also send the Emergency Stop and Resume of ! and ~

Foreign Subscribe

This widget/element publishes to the following signals that are owned by other objects. To better understand how ChiliPeppr's publish() method works see amplify.js's documentation at http://amplifyjs.com/api/pubsub/

Signal Description
/com-chilipeppr-widget-Smoothie/com-chilipeppr-widget-serialport/ws/onconnectWhen we see a new connect, query for status.
/com-chilipeppr-widget-Smoothie/com-chilipeppr-widget-serialport/recvlineWhen we get a dataline from serialport, process it and fire off generic CNC controller signals to the /com-chilipeppr-interface-cnccontroller channel.
/com-chilipeppr-widget-Smoothie/com-chilipeppr-widget-serialport/sendSubscribe to serial send and override so no other subscriptions receive command.

Methods / Properties

The table below shows, in order, the methods and properties inside the widget/element.

Method / Property Type Description
idstring"com-chilipeppr-widget-Smoothie"

The ID of the widget. You must define this and make it unique.
namestring"Widget / Smoothieboard"
descstring"This widget shows smoothie specific controls and current status information."
urlstring"http://raw.githubusercontent.com/https://master/auto-generated-widget.html"
fiddleurlstring"http://ide.c9.io/jarretluft/widget-smoothie"
githuburlstring"http://github.com/https:/"
testurlstring"http://widget-smoothie-jarretluft.c9users.io/widget.html"
publishobjectPlease see docs above.

Define the publish signals that this widget/element owns or defines so that other widgets know how to subscribe to them and what they do.
subscribeobjectPlease see docs above.

Define the subscribe signals that this widget/element owns or defines so that other widgets know how to subscribe to them and what they do.
foreignPublishobjectPlease see docs above.

Document the foreign publish signals, i.e. signals owned by other widgets or elements, that this widget/element publishes to.
foreignSubscribeobjectPlease see docs above.

Document the foreign subscribe signals, i.e. signals owned by other widgets or elements, that this widget/element subscribes to.
configobjectAll widgets should have an init method. It should be run by the instantiating code like a workspace or a different widget.
err_logobject
buffer_namestring
report_modenumber
work_modenumber
controller_unitsobject
statusstring"Offline"
versionstring
q_countnumber
alarmboolean
offsetsobject
last_workobject
last_machineobject
g_status_reportsobject
gcode_lookupobject
initfunctionfunction ()
btnSetupfunctionfunction ()

Call this method from init to setup all the buttons when this widget is first loaded. This basically attaches click events to your buttons. It also turns on all the bootstrap popovers by scanning the entire DOM of the widget.
updateWorkUnitsfunctionfunction (units)
updateReportUnitsfunctionfunction ()
openControllerfunctionfunction (isWithDelay)
closeControllerfunctionfunction (isWithDelay)
getControllerInfofunctionfunction ()
trackGcodeLinesfunctionfunction ()
restartStatusIntervalfunctionfunction ()
SmoothieResponsefunctionfunction (recvline)
sendCodefunctionfunction (sendline)
clearBufferfunctionfunction ()
publishAxisStatusfunctionfunction (axes)
plannerLastEventstring"resume"
publishPlannerPausefunctionfunction ()
publishPlannerResumefunctionfunction ()
toInchfunctionfunction (mm)
toMMfunctionfunction (inch)
addErrorfunctionfunction (line, msg)
optionsobjectUser options are available in this property for reference by your methods. If any change is made on these options, please call saveOptionsLocalStorage()
setupUiFromLocalStoragefunctionfunction ()

Call this method on init to setup the UI by reading the user's stored settings from localStorage and then adjust the UI to reflect what the user wants.
saveOptionsLocalStoragefunctionfunction ()

When a user changes a value that is stored as an option setting, you should call this method immediately so that on next load the value is correctly set.
showBodyfunctionfunction (evt)

Show the body of the panel.

evt ({jquery_event}) - If you pass the event parameter in, we know it was clicked by the user and thus we store it for the next load so we can reset the user's preference. If you don't pass this value in we don't store the preference because it was likely code that sent in the param.
hideBodyfunctionfunction (evt)

Hide the body of the panel.

evt ({jquery_event}) - If you pass the event parameter in, we know it was clicked by the user and thus we store it for the next load so we can reset the user's preference. If you don't pass this value in we don't store the preference because it was likely code that sent in the param.
forkSetupfunctionfunction ()

This method loads the pubsubviewer widget which attaches to our upper right corner triangle menu and generates 3 menu items like Pubsub Viewer, View Standalone, and Fork Widget. It also enables the modal dialog that shows the documentation for this widget.

By using chilipeppr.load() we can ensure that the pubsubviewer widget is only loaded and inlined once into the final ChiliPeppr workspace. We are given back a reference to the instantiated singleton so its not instantiated more than once. Then we call it's attachTo method which creates the full pulldown menu for us and attaches the click events.
uiHoverfunctionfunction ()

About ChiliPeppr

ChiliPeppr is a hardware fiddle, meaning it is a website that lets you easily create a workspace to fiddle with your hardware from software. ChiliPeppr provides a Serial Port JSON Server that you run locally on your computer, or remotely on another computer, to connect to the serial port of your hardware like an Arduino or other microcontroller.

You then create a workspace at ChiliPeppr.com that connects to your hardware by starting from scratch or forking somebody else's workspace that is close to what you are after. Then you write widgets in Javascript that interact with your hardware by forking the base template widget or forking another widget that is similar to what you are trying to build.

ChiliPeppr is massively capable such that the workspaces for TinyG and Grbl CNC controllers have become full-fledged CNC machine management software used by tens of thousands.

ChiliPeppr has inspired many people in the hardware/software world to use the browser and Javascript as the foundation for interacting with hardware. The Arduino team in Italy caught wind of ChiliPeppr and now ChiliPeppr's Serial Port JSON Server is the basis for the Arduino's new web IDE. If the Arduino team is excited about building on top of ChiliPeppr, what will you build on top of it?

About

This is the template for all ChiliPeppr widgets to use so they follow a consistent style.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 58.7%
  • HTML 40.9%
  • CSS 0.4%