7 years ago.

What is a repository? What is a project?

And there's a "program". I can see what that "program" means. Do "repository" and "project" have precise meanings within the MBED environment?

The "publishing" article I'm looking at shows how to publish "code". Is "code" different from a "program"? Maybe "code" includes libraries as well as code collections with a main.cpp.

Regarding publishing, I think too much emphasis is placed on sharing with others. Right now to me, publishing seems the way to package something so I can include it in various programs of mine. I don't seek secrecy here, but at this stage something I published would be too rough to share.

2 Answers

6 years, 10 months ago.

"repository" could have various meanings, but generally it would be a referring to the location of the files that are being version managed. In mbed, when you commit and publish, you are taking your working copy, and committing it into the repository (version control system). From there, you have a managed history you can see if you activate the "revisions" feature.

"project" would generally refer to a set of source code and library files that perform a function (like "blinky" is a complete set of source code and library files to produce the blinking LED program).

in the mbed online environment, you can have many projects (in the tree view on the left side) but only those projects where you actually issued a commit would be more formally described as "in the repository".

"code" would generally refer to the source files (.h, .cpp), but in conversation it may also refer to libs you may have in your project.

"program" would usually refer to the product of that code, once compiled/linked/located and ready to run in the mbed.

For your own needs, you should learn about the commit and revision process. This is not visible to others. In this way, when you come to the point where you think, "I wish I still had yesterday's version - it worked a lot better than this", you will be able to use the revision tools to compare yesterday's code and hopefully find and fix the defect.

committing is also a necessary step on the way to publishing, but even as you publish, you can publish it visibly, or you can publish it in a way that you have to explicitly share it for others to see it.

Accepted Answer

I am extremely mechanically minded. What is in a library (not counting the mbed library)? .cpp and .h files? libraries? When a library is included, is the inclusion process simply copying in the code contained in the library, as though it were an include file?

Thanks for giving my earlier question your attention!

posted by Alfred Hume 20 Jun 2017

Sorry the delay - "what is in a library?" Typically, you would find a collection of functions that are reusable. For example, if you had a temp sensor that produces a voltage, you would create code to read the analog input, and perhaps linearize the voltage reading to a temperature and scale it to degrees C (or F). You could put this in "main", but you might also create a function "ReadTemperator()". If you put this function into a separate file and compile it as a library, you can reuse this [presumably tested and trusted] library in many different programs. You don't need to worry about how it works anymore, you just have defined a standardized way to get the temperature. So, to put it into a [possibly poor] analogy, the library is composed of components - like a transmission, which is pretty useless as a component until you attach it to a power source (engine), and in turn deliver the power (to the axle to turn the wheels). The transmission (aka library) could be quite a complex component, but the interface is defined, so again, you don't have to deal too much with the internals.

How to use a library? If we go back to the simple example, the code might be one .cpp file and the declaration for how to use the library would be exposed in a single .h file. The .h could have a very simple line like:

float ReadTemperature(void);

If you put that .cpp and the .h into a new folder, then you can convert that folder into a library.

To make the library more useful, you might put some additional documentation into the .h file.

/// Read the temperature sensor and return the value in degrees C.
///
/// This reads the temperature sensor (using part # AB12345) which is wired to 
/// Analog Input channel 2. It then takes the non-linear output of that sensor and
/// linearizes it to within 0.5 degrees over the range of -10 to +50 C.
/// It will function over a wider range of -40 to +85C to within 2 degrees C.
/// 
/// @returns single precision floating point value representing the temperature
///               in degrees C.
///
float ReadTemperature(void);

The subtle formatting shown here is "doxygen" formatting, so building the documentation creates an easier to read aid to this library.

Finally, to use this library, your program would have something like this:

#include "TempSensorAB12345.h"

...

float tempC = ReadTemperature();

if (tempC > 95.0f) 
    printf("Alert: Temperature (%3.1f) exceeded alert level (95.0)\r\n", tempC);

One last pass - back to the "transmission" example, the library can be quite complex and do a lot. It would be a good practice not to put unrelated functions into a single library, but to create additionally libraries. So, if I want to display the temperature, I could create some functions to control a display, and I could put those functions into the temperature sensor library, but that would not be a best-practice. Instead, Create a separate library for the display.

posted by David Smart 26 Jun 2017
6 years, 10 months ago.

You can set the access level of published library / program.

  1. Private: You can reuse your code in your other projects.
  2. Team: Your team can reuse your code. You can create any number of teams and you can invite other developers.
  3. Public: Everyone can reuse your code.