Commit 70af792b authored by Philippe Kalaf's avatar Philippe Kalaf

Nasty commit converting dos to unix files

parent df053f32
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
/* mbed GraphicsDisplay Display Library Base Class
* Copyright (c) 2007-2009 sford
* Released under the MIT License: http://mbed.org/license/mit
*
* A library for providing a common base class for Graphics displays
* To port a new display, derive from this class and implement
* the constructor (setup the display), pixel (put a pixel
* at a location), width and height functions. Everything else
* (locate, printf, putc, cls, window, putp, fill, blit, blitbit)
* will come for free. You can also provide a specialised implementation
* of window and putp to speed up the results
*/
#ifndef MBED_GRAPHICSDISPLAY_H
#define MBED_GRAPHICSDISPLAY_H
#include "TextDisplay.h"
class GraphicsDisplay : public TextDisplay {
public:
GraphicsDisplay(const char* name);
virtual void pixel(int x, int y, int colour) = 0;
virtual int width() = 0;
virtual int height() = 0;
virtual void window(int x, int y, int w, int h);
virtual void putp(int colour);
virtual void cls();
virtual void fill(int x, int y, int w, int h, int colour);
virtual void blit(int x, int y, int w, int h, const int *colour);
virtual void blitbit(int x, int y, int w, int h, const char* colour);
virtual void character(int column, int row, int value);
virtual int columns();
virtual int rows();
protected:
// pixel location
short _x;
short _y;
// window location
short _x1;
short _x2;
short _y1;
short _y2;
};
#endif
/* mbed GraphicsDisplay Display Library Base Class
* Copyright (c) 2007-2009 sford
* Released under the MIT License: http://mbed.org/license/mit
*
* A library for providing a common base class for Graphics displays
* To port a new display, derive from this class and implement
* the constructor (setup the display), pixel (put a pixel
* at a location), width and height functions. Everything else
* (locate, printf, putc, cls, window, putp, fill, blit, blitbit)
* will come for free. You can also provide a specialised implementation
* of window and putp to speed up the results
*/
#ifndef MBED_GRAPHICSDISPLAY_H
#define MBED_GRAPHICSDISPLAY_H
#include "TextDisplay.h"
class GraphicsDisplay : public TextDisplay {
public:
GraphicsDisplay(const char* name);
virtual void pixel(int x, int y, int colour) = 0;
virtual int width() = 0;
virtual int height() = 0;
virtual void window(int x, int y, int w, int h);
virtual void putp(int colour);
virtual void cls();
virtual void fill(int x, int y, int w, int h, int colour);
virtual void blit(int x, int y, int w, int h, const int *colour);
virtual void blitbit(int x, int y, int w, int h, const char* colour);
virtual void character(int column, int row, int value);
virtual int columns();
virtual int rows();
protected:
// pixel location
short _x;
short _y;
// window location
short _x1;
short _x2;
short _y1;
short _y2;
};
#endif
/* mbed TextDisplay Display Library Base Class
* Copyright (c) 2007-2009 sford
* Released under the MIT License: http://mbed.org/license/mit
*/
#include "TextDisplay.h"
TextDisplay::TextDisplay(const char *name) : Stream(name){
_row = 0;
_column = 0;
if (name == NULL) {
_path = NULL;
} else {
_path = new char[strlen(name) + 2];
sprintf(_path, "/%s", name);
}
}
int TextDisplay::_putc(int value) {
if(value == '\n') {
_column = 0;
_row++;
if(_row >= rows()) {
_row = 0;
}
} else {
character(_column, _row, value);
_column++;
if(_column >= columns()) {
_column = 0;
_row++;
if(_row >= rows()) {
_row = 0;
}
}
}
return value;
}
// crude cls implementation, should generally be overwritten in derived class
void TextDisplay::cls() {
locate(0, 0);
for(int i=0; i<columns()*rows(); i++) {
putc(' ');
}
}
void TextDisplay::locate(int column, int row) {
_column = column;
_row = row;
}
int TextDisplay::_getc() {
return -1;
}
void TextDisplay::foreground(uint16_t colour) {
_foreground = colour;
}
void TextDisplay::background(uint16_t colour) {
_background = colour;
}
bool TextDisplay::claim (FILE *stream) {
if ( _path == NULL) {
fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n");
return false;
}
if (freopen(_path, "w", stream) == NULL) {
// Failed, should not happen
return false;
}
// make sure we use line buffering
setvbuf(stdout, NULL, _IOLBF, columns());
return true;
}
/* mbed TextDisplay Display Library Base Class
* Copyright (c) 2007-2009 sford
* Released under the MIT License: http://mbed.org/license/mit
*/
#include "TextDisplay.h"
TextDisplay::TextDisplay(const char *name) : Stream(name){
_row = 0;
_column = 0;
if (name == NULL) {
_path = NULL;
} else {
_path = new char[strlen(name) + 2];
sprintf(_path, "/%s", name);
}
}
int TextDisplay::_putc(int value) {
if(value == '\n') {
_column = 0;
_row++;
if(_row >= rows()) {
_row = 0;
}
} else {
character(_column, _row, value);
_column++;
if(_column >= columns()) {
_column = 0;
_row++;
if(_row >= rows()) {
_row = 0;
}
}
}
return value;
}
// crude cls implementation, should generally be overwritten in derived class
void TextDisplay::cls() {
locate(0, 0);
for(int i=0; i<columns()*rows(); i++) {
putc(' ');
}
}
void TextDisplay::locate(int column, int row) {
_column = column;
_row = row;
}
int TextDisplay::_getc() {
return -1;
}
void TextDisplay::foreground(uint16_t colour) {
_foreground = colour;
}
void TextDisplay::background(uint16_t colour) {
_background = colour;
}
bool TextDisplay::claim (FILE *stream) {
if ( _path == NULL) {
fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n");
return false;
}
if (freopen(_path, "w", stream) == NULL) {
// Failed, should not happen
return false;
}
// make sure we use line buffering
setvbuf(stdout, NULL, _IOLBF, columns());
return true;
}
/* mbed TextDisplay Library Base Class
* Copyright (c) 2007-2009 sford
* Released under the MIT License: http://mbed.org/license/mit
*
* A common base class for Text displays
* To port a new display, derive from this class and implement
* the constructor (setup the display), character (put a character
* at a location), rows and columns (number of rows/cols) functions.
* Everything else (locate, printf, putc, cls) will come for free
*
* The model is the display will wrap at the right and bottom, so you can
* keep writing and will always get valid characters. The location is
* maintained internally to the class to make this easy
*/
#ifndef MBED_TEXTDISPLAY_H
#define MBED_TEXTDISPLAY_H
#include "mbed.h"
class TextDisplay : public Stream {
public:
// functions needing implementation in derived implementation class
/** Create a TextDisplay interface
*
* @param name The name used in the path to access the strean through the filesystem
*/
TextDisplay(const char *name = NULL);
/** output a character at the given position
*
* @param column column where charater must be written
* @param row where character must be written
* @param c the character to be written to the TextDisplay
*/
virtual void character(int column, int row, int c) = 0;
/** return number if rows on TextDisplay
* @result number of rows
*/
virtual int rows() = 0;
/** return number if columns on TextDisplay
* @result number of rows
*/
virtual int columns() = 0;
// functions that come for free, but can be overwritten
/** redirect output from a stream (stoud, sterr) to display
* @param stream stream that shall be redirected to the TextDisplay
*/
virtual bool claim (FILE *stream);
/** clear screen
*/
virtual void cls();
virtual void locate(int column, int row);
virtual void foreground(uint16_t colour);
virtual void background(uint16_t colour);
// putc (from Stream)
// printf (from Stream)
protected:
virtual int _putc(int value);
virtual int _getc();
// character location
uint16_t _column;
uint16_t _row;
// colours
uint16_t _foreground;
uint16_t _background;
char *_path;
};
#endif
/* mbed TextDisplay Library Base Class
* Copyright (c) 2007-2009 sford
* Released under the MIT License: http://mbed.org/license/mit
*
* A common base class for Text displays
* To port a new display, derive from this class and implement
* the constructor (setup the display), character (put a character
* at a location), rows and columns (number of rows/cols) functions.
* Everything else (locate, printf, putc, cls) will come for free
*
* The model is the display will wrap at the right and bottom, so you can
* keep writing and will always get valid characters. The location is
* maintained internally to the class to make this easy
*/
#ifndef MBED_TEXTDISPLAY_H
#define MBED_TEXTDISPLAY_H
#include "mbed.h"
class TextDisplay : public Stream {
public:
// functions needing implementation in derived implementation class
/** Create a TextDisplay interface
*
* @param name The name used in the path to access the strean through the filesystem
*/
TextDisplay(const char *name = NULL);
/** output a character at the given position
*
* @param column column where charater must be written
* @param row where character must be written
* @param c the character to be written to the TextDisplay
*/
virtual void character(int column, int row, int c) = 0;
/** return number if rows on TextDisplay
* @result number of rows
*/
virtual int rows() = 0;
/** return number if columns on TextDisplay
* @result number of rows
*/
virtual int columns() = 0;
// functions that come for free, but can be overwritten
/** redirect output from a stream (stoud, sterr) to display
* @param stream stream that shall be redirected to the TextDisplay
*/
virtual bool claim (FILE *stream);
/** clear screen
*/
virtual void cls();
virtual void locate(int column, int row);
virtual void foreground(uint16_t colour);
virtual void background(uint16_t colour);
// putc (from Stream)
// printf (from Stream)
protected:
virtual int _putc(int value);
virtual int _getc();
// character location
uint16_t _column;
uint16_t _row;
// colours
uint16_t _foreground;
uint16_t _background;
char *_path;
};
#endif
This diff is collapsed.
This diff is collapsed.
/* Copyright (c) 2017 Philippe Kalaf, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* Digmesa FHKSC flowmeter driver */
#include "fhksc.h"
FHKSC::FHKSC(PinName pin) : _interrupt(pin) { // create the InterruptIn on the pin specified to FHKSC
_interrupt.mode(PullDown); // an internal pull up is used, otherwise disable here
_interrupt.rise(callback(this, &FHKSC::increment)); // attach increment function of this counter instance
_flow_rate_timer.start();
_time_last_increment_us = 0;
}
void FHKSC::increment()
{
int time_us = _flow_rate_timer.read_us();
// Every 1925 pulses is 1L
// Each pulse is 1000000/1925 = 520 ul or 0.52 ml
_flow_ul += 520;
_interval_between_increments_us = time_us - _time_last_increment_us;
_time_last_increment_us = time_us;
}
// return in ml
float FHKSC::read()
{
return float(_flow_ul)/1000;
}
uint32_t FHKSC::read_ul()
{
return _flow_ul;
}
void FHKSC::reset_count()
{
_flow_ul = 0;
}
// flow rate in ml per second
float FHKSC::get_flow_rate()
{
return float(0.52 / (float(_interval_between_increments_us)/1000000));
/* Copyright (c) 2017 Philippe Kalaf, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* Digmesa FHKSC flowmeter driver */
#include "fhksc.h"
FHKSC::FHKSC(PinName pin) : _interrupt(pin) { // create the InterruptIn on the pin specified to FHKSC
_interrupt.mode(PullDown); // an internal pull up is used, otherwise disable here
_interrupt.rise(callback(this, &FHKSC::increment)); // attach increment function of this counter instance
_flow_rate_timer.start();
_time_last_increment_us = 0;
}
void FHKSC::increment()
{
int time_us = _flow_rate_timer.read_us();
// Every 1925 pulses is 1L
// Each pulse is 1000000/1925 = 520 ul or 0.52 ml
_flow_ul += 520;
_interval_between_increments_us = time_us - _time_last_increment_us;
_time_last_increment_us = time_us;
}
// return in ml
float FHKSC::read()
{
return float(_flow_ul)/1000;
}
uint32_t FHKSC::read_ul()
{
return _flow_ul;
}
void FHKSC::reset_count()
{
_flow_ul = 0;
}
// flow rate in ml per second
float FHKSC::get_flow_rate()
{
return float(0.52 / (float(_interval_between_increments_us)/1000000));
}
\ No newline at end of file
/* Copyright (c) 2017 Philippe Kalaf, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* Digmesa FHKSC flowmeter driver */
#ifndef fhksc_h
#define fhksc_h
#include "mbed.h"
class FHKSC
{
public:
FHKSC(PinName pin);
void increment();
float read();
uint32_t read_ul();
void reset_count();
float get_flow_rate();
private:
InterruptIn _interrupt;
volatile int _pulse_count;
volatile uint32_t _flow_ul;
Timer _flow_rate_timer;
int _time_last_increment_us;
int _interval_between_increments_us;
};
/* Copyright (c) 2017 Philippe Kalaf, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* Digmesa FHKSC flowmeter driver */
#ifndef fhksc_h
#define fhksc_h
#include "mbed.h"
class FHKSC
{
public:
FHKSC(PinName pin);
void increment();
float read();
uint32_t read_ul();
void reset_count();
float get_flow_rate();
private:
InterruptIn _interrupt;
volatile int _pulse_count;
volatile uint32_t _flow_ul;
Timer _flow_rate_timer;
int _time_last_increment_us;
int _interval_between_increments_us;
};
#endif// fhksc_h
\ No newline at end of file
/* Copyright (c) 2017 Philippe Kalaf, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/* LMT01 temperature sensor driver */
#include "lmt01.h"
/* Taken from datasheet */
const int LMT01::_pulse_temp_table[20][2] = {
{-40, 181}, {-30, 338}, {-20, 494}, {-10, 651}, {0, 808},
{10, 966}, {20, 1125}, {30, 1284}, {40, 1443}, {50, 1603},
{60, 1762}, {70, 1923}, {80, 2084}, {90, 2245}, {100, 2407},
{110, 2569}, {120, 2731}, {130, 2894}, {140, 3058}, {150, 3220}
};
LMT01::LMT01(PinName pin) : _interrupt(pin) { // create the InterruptIn on the pin specified to LMT01
_interrupt.mode(PullUp); // an internal pull up is used, otherwise disable here
_interrupt.fall(callback(this, &LMT01::increment)); // attach increment function of this counter instance
_pulse_timer.start();
}
void LMT01::increment()
{
// Detect when pulses stop so we convert the reading and reset timer
// 10ms is long enough to indicate pulses have stopped
if (_pulse_timer.read_ms() > 10)
{
_pulse_timer.reset();
// Find pulse/temp range from table
uint16_t i;
uint16_t pulse_count = _pulse_count;
for (i = 0; i < sizeof(_pulse_temp_table); i++)
if (pulse_count < _pulse_temp_table[i][1])
break;
// Read/convert/store count as temperature
_temperature =
(
(
((pulse_count - _pulse_temp_table[i-1][1]) * 1000) /
(_pulse_temp_table[i][1] - _pulse_temp_table[i-1][1])
) * 10 // at this point unit is 10^3 Celsius
)
+ _pulse_temp_table[i-1][0] * 1000;
_pulse_count = 0;
}
else
{
_pulse_timer.reset();
_pulse_count++;
}
}
// returns temperature in 10^3 Celsius
int LMT01::read_int()
{
return _temperature;
}
// return temperature in Celsius
float LMT01::read()
{
return float(_temperature)/1000;
}
/* Copyright (c) 2017 Philippe Kalaf, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*