├── LICENSE
├── README.md
├── doc
├── Adafruit_touchpaint_screenShot.png
├── Flappy.png
└── TSE_spaceInvader1.PNG
├── examples
├── Adafruit_pictureDragon
│ ├── Adafruit_pictureDragon.h
│ ├── Adafruit_pictureEmbed.ino
│ └── Makefile
├── Adafruit_touchpaint
│ ├── Adafruit_touchpaint.ino
│ └── Makefile
├── AnalogReadSerial
│ ├── AnalogReadSerial.ino
│ └── Makefile
├── Blink
│ ├── Blink.ino
│ └── Makefile
├── Flappy
│ ├── Flappy.ino
│ ├── Makefile
│ ├── collisions.cpp
│ ├── collisions.h
│ └── constants.h
├── HelloServer
│ ├── HTTP_Method.h
│ ├── HelloServer.ino
│ ├── Makefile
│ ├── WebServer.cpp
│ └── WebServer.h
├── SerialInput
│ ├── Makefile
│ └── SerialInput.ino
├── TFT_demo
│ ├── Makefile
│ └── TFT_demo.ino
├── TekSpriteEditor1
│ ├── Makefile
│ └── TekSpriteEditor1.ino
├── TekSpriteEditor2
│ ├── Makefile
│ └── TekSpriteEditor2.ino
├── ToneMelody
│ ├── Makefile
│ └── ToneMelody.ino
├── Touch
│ ├── Makefile
│ └── Touch.ino
├── cellArt
│ ├── Makefile
│ └── cellArt.ino
├── gameOfLife
│ ├── Makefile
│ └── gameOfLife.ino
├── gnuPlot
│ ├── Makefile
│ └── gnuPlot.ino
├── guiButton
│ ├── Makefile
│ └── guiButton.ino
├── guiLed
│ ├── Makefile
│ └── guiLed.ino
├── guiTest
│ ├── Makefile
│ └── guiTest.ino
├── input
│ ├── Makefile
│ └── main.ino
└── sketch
│ ├── Makefile
│ └── sketch.ino
├── libraries
├── Adafruit_GFX
│ ├── Adafruit_GFX.cpp
│ ├── Adafruit_GFX.h
│ ├── gfxfont.h
│ └── glcdfont.c
├── Adafruit_ILI9341
│ └── Adafruit_ILI9341.h
├── Adafruit_STMPE610
│ └── Adafruit_STMPE610.h
├── GuiPittix
│ ├── Gui.h
│ ├── TFT_Adapter.h
│ └── TFT_Pc.h
├── SPI
│ ├── SPI.cpp
│ └── SPI.h
└── Wire
│ ├── Wire.cpp
│ └── Wire.h
├── makeNativeArduino.mk
└── src
├── cores
└── arduino
│ ├── Arduino.h
│ ├── Print.cpp
│ ├── Print.h
│ ├── Printable.h
│ ├── SerialConsole.cpp
│ ├── SerialConsole.h
│ ├── Stream.cpp
│ ├── Stream.h
│ ├── WMath.cpp
│ ├── WString.cpp
│ ├── WString.h
│ ├── avr
│ ├── dtostrf.c
│ ├── dtostrf.h
│ ├── interrupt.h
│ └── pgmspace.h
│ ├── binary.h
│ ├── itoa.c
│ ├── itoa.h
│ ├── pins_arduino.h
│ ├── wiring_analog.cpp
│ ├── wiring_digital.cpp
│ └── wiring_private.h
├── main.cpp
└── system
├── TFT_LinuxWrapper.h
├── Touch_LinuxWrapper.cpp
├── Touch_LinuxWrapper.h
├── XWindow.cpp
├── XWindow.h
├── depreciated
├── posixWrapper.c
└── posixWrapper.h
├── posixTime.c
└── posixTime.h
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ArduinoOnPc
2 |
3 | ## What?
4 |
5 | With this software you can run an Arduino Sketch on your PC or a Raspberry Pi.
6 | You don't need an Arduino hardware.
7 | The focus here is mainly on TFTs connected to an Arduino.
8 |
9 | This software is made for Linux using the X11 window manager.
10 | If you want to use it on windows the only current option is a virtual machine.
11 |
12 | ## Why?
13 |
14 | Some Arduino boards do not have a debugging possibility.
15 | To find the errors in your sketches it might be usefull to be able to use a debugger.
16 | Using this tool you can debug your program locally, and develop without having
17 | to tinker with any additional hardware.
18 |
19 | # Installation
20 |
21 | ## Requirements
22 |
23 | You need [gcc](https://gcc.gnu.org/) and [make](https://www.gnu.org/software/make/) installed.
24 |
25 | ## X11
26 |
27 | To emulate a TFT this project uses X11. Therefore you have to install X11 support.
28 |
29 | ### Debian/Ubuntu
30 |
31 | ```
32 | sudo apt-get install libx11-dev
33 | ```
34 |
35 | ### Arch Linux
36 |
37 | ```
38 | sudo pacman -Sy libx11
39 | ```
40 | ## Compilation
41 |
42 | ### Makefile
43 |
44 | ```
45 | # cd into any example in examples folder, for example:
46 | cd examples/Adafruit_touchpaint
47 |
48 | # Compile the code
49 | make
50 |
51 | # Execute
52 | ./Adafruit_touchpaint
53 | ```
54 | ## Adding Libraries
55 |
56 | ### How to include other (non hardware dependent) libraries
57 | * copy them to the /libraries folder
58 | * add the relative path to the include file to your project's Makefile (including "src" if needed, e.g. like this: ARDUINO_LIBS += YACL/src)
59 |
--------------------------------------------------------------------------------
/doc/Adafruit_touchpaint_screenShot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChrisMicro/ArduinoOnPc/5708d9d037b045a04b38f57665e14dc8af2970f9/doc/Adafruit_touchpaint_screenShot.png
--------------------------------------------------------------------------------
/doc/Flappy.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChrisMicro/ArduinoOnPc/5708d9d037b045a04b38f57665e14dc8af2970f9/doc/Flappy.png
--------------------------------------------------------------------------------
/doc/TSE_spaceInvader1.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChrisMicro/ArduinoOnPc/5708d9d037b045a04b38f57665e14dc8af2970f9/doc/TSE_spaceInvader1.PNG
--------------------------------------------------------------------------------
/examples/Adafruit_pictureDragon/Adafruit_pictureEmbed.ino:
--------------------------------------------------------------------------------
1 | // ILI9341 example with embedded color bitmaps in sketch.
2 | // WILL NOT FIT ON ARDUINO UNO OR OTHER AVR BOARDS;
3 | // uses large bitmap image stored in array!
4 |
5 | // Options for converting images to the format used here include:
6 | // http://www.rinkydinkelectronics.com/t_imageconverter565.php
7 | // or
8 | // GIMP (https://www.gimp.org/) as follows:
9 | // 1. File -> Export As
10 | // 2. In Export Image dialog, use 'C source code (*.c)' as filetype.
11 | // 3. Press export to get the export options dialog.
12 | // 4. Type the desired variable name into the 'prefixed name' box.
13 | // 5. Uncheck 'GLIB types (guint8*)'
14 | // 6. Check 'Save as RGB565 (16-bit)'
15 | // 7. Press export to save your image.
16 | // Assuming 'image_name' was typed in the 'prefixed name' box of step 4,
17 | // you can have to include the c file, then using the image can be done with:
18 | // tft.drawRGBBitmap(0, 0, image_name.pixel_data, image_name.width, image_name.height);
19 | // See also https://forum.pjrc.com/threads/35575-Export-for-ILI9341_t3-with-GIMP
20 |
21 | /*
22 | #include "SPI.h"
23 | #include
24 | #include "dragon.h"
25 | */
26 | #include "Adafruit_ILI9341.h"
27 | #include "Adafruit_pictureDragon.h"
28 |
29 | // For the Adafruit shield, these are the default.
30 | //#define TFT_DC 9
31 | //#define TFT_CS 10
32 |
33 | // Feather 32u4 or M0 with TFT FeatherWing:
34 | #define TFT_DC 10
35 | #define TFT_CS 9
36 | // ESP8266:
37 | //#define TFT_DC 15
38 | //#define TFT_CS 0
39 | // Other boards (including Feather boards) may have other pinouts;
40 | // see learn.adafruit.com/adafruit-2-4-tft-touch-screen-featherwing/pinouts
41 |
42 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
43 | // If using the breakout, change pins as desired
44 | //Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
45 |
46 | void setup() {
47 | tft.begin();
48 | }
49 |
50 | void loop(void) {
51 | for(uint8_t r=0; r<4; r++) {
52 | tft.setRotation(r);
53 | tft.fillScreen(ILI9341_BLACK);
54 | for(uint8_t j=0; j<20; j++) {
55 | tft.drawRGBBitmap(
56 | random(-DRAGON_WIDTH , tft.width()),
57 | random(-DRAGON_HEIGHT, tft.height()),
58 | #if defined(__AVR__) || defined(ESP8266)
59 | dragonBitmap,
60 | #else
61 | // Some non-AVR MCU's have a "flat" memory model and don't
62 | // distinguish between flash and RAM addresses. In this case,
63 | // the RAM-resident-optimized drawRGBBitmap in the ILI9341
64 | // library can be invoked by forcibly type-converting the
65 | // PROGMEM bitmap pointer to a non-const uint16_t *.
66 | (uint16_t *)dragonBitmap,
67 | #endif
68 | DRAGON_WIDTH, DRAGON_HEIGHT);
69 | delay(1); // Allow ESP8266 to handle watchdog & WiFi stuff
70 | }
71 | delay(3000);
72 | }
73 | }
--------------------------------------------------------------------------------
/examples/Adafruit_pictureDragon/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += SPI
5 | ARDUINO_LIBS += Adafruit_ILI9341
6 |
7 | BUILD_ROOT := build
8 | include ../../makeNativeArduino.mk
9 |
10 |
--------------------------------------------------------------------------------
/examples/Adafruit_touchpaint/Adafruit_touchpaint.ino:
--------------------------------------------------------------------------------
1 |
2 |
3 | /***************************************************
4 | This is our touchscreen painting example for the Adafruit ILI9341 Shield
5 | ----> http://www.adafruit.com/products/1651
6 |
7 | Check out the links above for our tutorials and wiring diagrams
8 | These displays use SPI to communicate, 4 or 5 pins are required to
9 | interface (RST is optional)
10 | Adafruit invests time and resources providing this open source code,
11 | please support Adafruit and open-source hardware by purchasing
12 | products from Adafruit!
13 |
14 | Written by Limor Fried/Ladyada for Adafruit Industries.
15 | MIT license, all text above must be included in any redistribution
16 | ****************************************************/
17 |
18 |
19 | /*#include // Core graphics library
20 | #include
21 | #include // this is needed even tho we aren't using it
22 | #include
23 | #include */
24 |
25 | #include "Adafruit_ILI9341.h"
26 | #include "Adafruit_STMPE610.h"
27 |
28 | // This is calibration data for the raw touch data to the screen coordinates
29 | #define TS_MINX 150
30 | #define TS_MINY 130
31 | #define TS_MAXX 3800
32 | #define TS_MAXY 4000
33 |
34 | // The STMPE610 uses hardware SPI on the shield, and #8
35 | #define STMPE_CS 8
36 | Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
37 |
38 | // The display also uses hardware SPI, plus #9 & #10
39 | #define TFT_CS 10
40 | #define TFT_DC 9
41 | Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
42 |
43 | // Size of the color selection boxes and the paintbrush size
44 | #define BOXSIZE 40
45 | #define PENRADIUS 3
46 | int oldcolor, currentcolor;
47 |
48 | void setup(void) {
49 | // while (!Serial); // used for leonardo debugging
50 |
51 | Serial.begin(9600);
52 | Serial.println(F("Touch Paint!"));
53 |
54 | tft.begin();
55 |
56 | if (!ts.begin()) {
57 | Serial.println("Couldn't start touchscreen controller");
58 | while (1);
59 | }
60 | Serial.println("Touchscreen started");
61 |
62 | tft.fillScreen(ILI9341_BLACK);
63 |
64 | // make the color selection boxes
65 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
66 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
67 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
68 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
69 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
70 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
71 |
72 | // select the current color 'red'
73 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
74 | currentcolor = ILI9341_RED;
75 | }
76 |
77 |
78 | void loop()
79 | {
80 | // See if there's any touch data for us
81 | if (ts.bufferEmpty()) {
82 | return;
83 | }
84 | /*
85 | // You can also wait for a touch
86 | if (! ts.touched()) {
87 | return;
88 | }
89 | */
90 |
91 | // Retrieve a point
92 | TS_Point p = ts.getPoint();
93 |
94 | /*
95 | Serial.print("X = "); Serial.print(p.x);
96 | Serial.print("\tY = "); Serial.print(p.y);
97 | Serial.print("\tPressure = "); Serial.println(p.z);
98 | delay(100);
99 | */
100 |
101 | // Scale from ~0->4000 to tft.width using the calibration #'s
102 | p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
103 | p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
104 |
105 | /*
106 | Serial.print("("); Serial.print(p.x);
107 | Serial.print(", "); Serial.print(p.y);
108 | Serial.println(")");
109 | */
110 |
111 | if (p.y < BOXSIZE) {
112 | oldcolor = currentcolor;
113 |
114 | if (p.x < BOXSIZE) {
115 | currentcolor = ILI9341_RED;
116 | tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
117 | } else if (p.x < BOXSIZE*2) {
118 | currentcolor = ILI9341_YELLOW;
119 | tft.drawRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
120 | } else if (p.x < BOXSIZE*3) {
121 | currentcolor = ILI9341_GREEN;
122 | tft.drawRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
123 | } else if (p.x < BOXSIZE*4) {
124 | currentcolor = ILI9341_CYAN;
125 | tft.drawRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
126 | } else if (p.x < BOXSIZE*5) {
127 | currentcolor = ILI9341_BLUE;
128 | tft.drawRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
129 | } else if (p.x < BOXSIZE*6) {
130 | currentcolor = ILI9341_MAGENTA;
131 | tft.drawRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
132 | }
133 |
134 | if (oldcolor != currentcolor) {
135 | if (oldcolor == ILI9341_RED)
136 | tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
137 | if (oldcolor == ILI9341_YELLOW)
138 | tft.fillRect(BOXSIZE, 0, BOXSIZE, BOXSIZE, ILI9341_YELLOW);
139 | if (oldcolor == ILI9341_GREEN)
140 | tft.fillRect(BOXSIZE*2, 0, BOXSIZE, BOXSIZE, ILI9341_GREEN);
141 | if (oldcolor == ILI9341_CYAN)
142 | tft.fillRect(BOXSIZE*3, 0, BOXSIZE, BOXSIZE, ILI9341_CYAN);
143 | if (oldcolor == ILI9341_BLUE)
144 | tft.fillRect(BOXSIZE*4, 0, BOXSIZE, BOXSIZE, ILI9341_BLUE);
145 | if (oldcolor == ILI9341_MAGENTA)
146 | tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, ILI9341_MAGENTA);
147 | }
148 | }
149 | if (((p.y-PENRADIUS) > BOXSIZE) && ((p.y+PENRADIUS) < tft.height())) {
150 | tft.fillCircle(p.x, p.y, PENRADIUS, currentcolor);
151 | }
152 | }
--------------------------------------------------------------------------------
/examples/Adafruit_touchpaint/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += Adafruit_ILI9341
5 | ARDUINO_LIBS += SPI
6 | ARDUINO_LIBS += Adafruit_STMPE610
7 | BUILD_ROOT := build
8 | include ../../makeNativeArduino.mk
9 |
10 |
--------------------------------------------------------------------------------
/examples/AnalogReadSerial/AnalogReadSerial.ino:
--------------------------------------------------------------------------------
1 | /*
2 | AnalogReadSerial
3 | Reads an analog input on pin 0, prints the result to the serial monitor.
4 | Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
5 | Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
6 |
7 | This example code is in the public domain.
8 | */
9 |
10 | // the setup routine runs once when you press reset:
11 | void setup() {
12 | // initialize serial communication at 9600 bits per second:
13 | Serial.begin(9600);
14 | }
15 |
16 | // the loop routine runs over and over again forever:
17 | void loop() {
18 | // read the input on analog pin 0:
19 | int sensorValue = analogRead(A0);
20 | // print out the value you read:
21 | Serial.println(sensorValue);
22 | delay(1); // delay in between reads for stability
23 | }
--------------------------------------------------------------------------------
/examples/AnalogReadSerial/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += SPI
5 |
6 | BUILD_ROOT := build
7 | include ../../makeNativeArduino.mk
8 |
9 |
--------------------------------------------------------------------------------
/examples/Blink/Blink.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Blink
3 | Turns on an LED on for one second, then off for one second, repeatedly.
4 |
5 | Most Arduinos have an on-board LED you can control. On the Uno and
6 | Leonardo, it is attached to digital pin 13. If you're unsure what
7 | pin the on-board LED is connected to on your Arduino model, check
8 | the documentation at http://www.arduino.cc
9 |
10 | This example code is in the public domain.
11 |
12 | modified 8 May 2014
13 | by Scott Fitzgerald
14 | */
15 |
16 |
17 | // the setup function runs once when you press reset or power the board
18 | void setup() {
19 | // initialize digital pin 13 as an output.
20 | pinMode(13, OUTPUT);
21 | }
22 |
23 | // the loop function runs over and over again forever
24 | void loop() {
25 | digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
26 | delay(1000); // wait for a second
27 | digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
28 | delay(1000); // wait for a second
29 | }
--------------------------------------------------------------------------------
/examples/Blink/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += SPI
5 |
6 | BUILD_ROOT := build
7 | include ../../makeNativeArduino.mk
8 |
9 |
--------------------------------------------------------------------------------
/examples/Flappy/Flappy.ino:
--------------------------------------------------------------------------------
1 | /************************************************************************
2 |
3 | Flappy Bird from team POLITEHNIKA
4 |
5 | https://create.arduino.cc/projecthub/MakerRobotics/touch-display-game-flappy-bird-6ef267
6 |
7 | adapted for ArduinoOnPc
8 |
9 | ChrisMicro, July 2017
10 |
11 | ************************************************************************/
12 |
13 | #include "TFT_LinuxWrapper.h" // TFT
14 | #include "Touch_LinuxWrapper.h" // TOUCH
15 |
16 | #include "constants.h"
17 | #include "collisions.h" //Check bird collisions
18 |
19 | TFT_LinuxWrapper tft;
20 |
21 |
22 | TouchScreen ts;
23 |
24 | int wing;
25 | int fx, fy, fallRate;
26 | int pillarPos, gapPos;
27 | int score;
28 | int highScore = 0;
29 | bool running = false;
30 | bool crashed = false;
31 | bool scrPress = false;
32 | long nextDrawLoopRunTime;
33 |
34 | void startGame();
35 | void drawLoop();
36 |
37 | void setup()
38 | {
39 |
40 |
41 | tft.begin();
42 |
43 | //tft.setRotation(3);
44 |
45 | tft.fillScreen(BLACK);
46 | tft.setCursor (55, 50);
47 | tft.setTextSize (3);
48 | tft.setTextColor(GREEN);
49 | tft.println("Arduino");
50 | tft.setCursor (85, 85);
51 | tft.setTextSize (2);
52 | tft.setTextColor(WHITE);
53 | tft.println("team");
54 | tft.setCursor (55, 120);
55 | tft.setTextSize (2);
56 | tft.setTextColor(RED);
57 | tft.println("POLITEHNIKA");
58 | tft.println(""); tft.println(""); tft.print(" ");
59 | tft.setTextSize (4);
60 | tft.setTextColor(BLUE);
61 | delay(1000); tft.print("3 ");
62 | delay(1000); tft.print("2 ");
63 | delay(1000); tft.print("1 ");
64 | tft.setTextColor(RED);
65 | delay(1000); tft.print("start!!");
66 | delay(1000);
67 |
68 | running=true;
69 | // waitOneTouch(true);
70 | tft.fillScreen(BLUE);
71 | nextDrawLoopRunTime=millis()+100;
72 | startGame();
73 |
74 | }
75 |
76 | void loop(void)
77 | {
78 | if (millis() > nextDrawLoopRunTime )
79 | {
80 | drawLoop();
81 | checkCollision(fx, fy, pillarPos, gapPos, score, &crashed, &running, tft);
82 | nextDrawLoopRunTime += 50;
83 | }
84 |
85 | TSPoint p = ts.getPoint();
86 |
87 | if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
88 | if (!running) {
89 | // clear text & start scrolling
90 | tft.fillRect(0, 0, 320, 80, BLUE);
91 | running = true;
92 | }
93 | else
94 | {
95 | // fly up
96 | fallRate = -11;
97 | scrPress = true;
98 | }
99 | }
100 | else if (p.z == 0 && scrPress) {
101 | scrPress = false;
102 | }
103 |
104 | }
105 |
106 | void drawBorder () {
107 | uint16_t width = tft.width() - 1;
108 | uint16_t height = tft.height() - 1;
109 | uint8_t border = 10;
110 |
111 | tft.fillScreen(BLUE);
112 | tft.fillRect(border, border, (width - border * 2), (height - border * 2), WHITE);
113 | }
114 |
115 | void drawFlappy(int x, int y) {
116 | // Upper & lower body
117 | tft.fillRect(x + 2, y + 8, 2, 10, BLACK);
118 | tft.fillRect(x + 4, y + 6, 2, 2, BLACK);
119 | tft.fillRect(x + 6, y + 4, 2, 2, BLACK);
120 | tft.fillRect(x + 8, y + 2, 4, 2, BLACK);
121 | tft.fillRect(x + 12, y, 12, 2, BLACK);
122 | tft.fillRect(x + 24, y + 2, 2, 2, BLACK);
123 | tft.fillRect(x + 26, y + 4, 2, 2, BLACK);
124 | tft.fillRect(x + 28, y + 6, 2, 6, BLACK);
125 | tft.fillRect(x + 10, y + 22, 10, 2, BLACK);
126 | tft.fillRect(x + 4, y + 18, 2, 2, BLACK);
127 | tft.fillRect(x + 6, y + 20, 4, 2, BLACK);
128 |
129 | // Body fill
130 | tft.fillRect(x + 12, y + 2, 6, 2, YELLOW);
131 | tft.fillRect(x + 8, y + 4, 8, 2, YELLOW);
132 | tft.fillRect(x + 6, y + 6, 10, 2, YELLOW);
133 | tft.fillRect(x + 4, y + 8, 12, 2, YELLOW);
134 | tft.fillRect(x + 4, y + 10, 14, 2, YELLOW);
135 | tft.fillRect(x + 4, y + 12, 16, 2, YELLOW);
136 | tft.fillRect(x + 4, y + 14, 14, 2, YELLOW);
137 | tft.fillRect(x + 4, y + 16, 12, 2, YELLOW);
138 | tft.fillRect(x + 6, y + 18, 12, 2, YELLOW);
139 | tft.fillRect(x + 10, y + 20, 10, 2, YELLOW);
140 |
141 | // Eye
142 | tft.fillRect(x + 18, y + 2, 2, 2, BLACK);
143 | tft.fillRect(x + 16, y + 4, 2, 6, BLACK);
144 | tft.fillRect(x + 18, y + 10, 2, 2, BLACK);
145 | tft.fillRect(x + 18, y + 4, 2, 6, WHITE);
146 | tft.fillRect(x + 20, y + 2, 4, 10, WHITE);
147 | tft.fillRect(x + 24, y + 4, 2, 8, WHITE);
148 | tft.fillRect(x + 26, y + 6, 2, 6, WHITE);
149 | tft.fillRect(x + 24, y + 6, 2, 4, BLACK);
150 |
151 | // Beak
152 | tft.fillRect(x + 20, y + 12, 12, 2, BLACK);
153 | tft.fillRect(x + 18, y + 14, 2, 2, BLACK);
154 | tft.fillRect(x + 20, y + 14, 12, 2, RED);
155 | tft.fillRect(x + 32, y + 14, 2, 2, BLACK);
156 | tft.fillRect(x + 16, y + 16, 2, 2, BLACK);
157 | tft.fillRect(x + 18, y + 16, 2, 2, RED);
158 | tft.fillRect(x + 20, y + 16, 12, 2, BLACK);
159 | tft.fillRect(x + 18, y + 18, 2, 2, BLACK);
160 | tft.fillRect(x + 20, y + 18, 10, 2, RED);
161 | tft.fillRect(x + 30, y + 18, 2, 2, BLACK);
162 | tft.fillRect(x + 20, y + 20, 10, 2, BLACK);
163 | }
164 | void startGame() {
165 | //int fx = 50;
166 | //int fy = 125;
167 | //int fallRate = 1;
168 | //int pillarPos = 320;
169 | //int gapPos = 60;
170 | //bool crashed = false;
171 | //int score = 0;
172 |
173 | tft.fillScreen(BLUE);
174 | int ty = 230;
175 | for (int tx = 0; tx <= 300; tx += 20) {
176 | tft.fillTriangle(tx, ty, tx + 10, ty, tx, ty + 10, GREEN);
177 | tft.fillTriangle(tx + 10, ty + 10, tx + 10, ty, tx, ty + 10, YELLOW);
178 | tft.fillTriangle(tx + 10, ty, tx + 20, ty, tx + 10, ty + 10, YELLOW);
179 | tft.fillTriangle(tx + 20, ty + 10, tx + 20, ty, tx + 10, ty + 10, GREEN);
180 | }
181 | }
182 | void drawPillar(int x, int gap) {
183 | tft.fillRect(x + 2, 2, 46, gap - 4, GREEN);
184 | tft.fillRect(x + 2, gap + 92, 46, 136 - gap, GREEN);
185 |
186 | tft.drawRect(x, 0, 50, gap, BLACK);
187 | tft.drawRect(x + 1, 1, 48, gap - 2, BLACK);
188 | tft.drawRect(x, gap + 90, 50, 140 - gap, BLACK);
189 | tft.drawRect(x + 1, gap + 91 , 48, 138 - gap, BLACK);
190 | }
191 |
192 | void clearPillar(int x, int gap) {
193 | tft.fillRect(x + 45, 0, 5, gap, BLUE);
194 | tft.fillRect(x + 45, gap + 90, 5, 140 - gap, BLUE);
195 | }
196 |
197 | void clearFlappy(int x, int y) {
198 | tft.fillRect(x, y, 34, 24, BLUE);
199 | }
200 |
201 | void drawLoop() {
202 | // clear moving items
203 | clearPillar(pillarPos, gapPos);
204 | clearFlappy(fx, fy);
205 |
206 | // move items
207 | if (running) {
208 | fy += fallRate;
209 | fallRate++;
210 |
211 | pillarPos -= 5;
212 | if (pillarPos == 0) {
213 | score++;
214 | }
215 | else if (pillarPos < -50) {
216 | pillarPos = 320;
217 | gapPos = random(20, 120);
218 | //gapPos = 50;
219 | }
220 | }
221 |
222 | // draw moving items & animate
223 | drawPillar(pillarPos, gapPos);
224 | drawFlappy(fx, fy);
225 |
226 | }
227 |
228 |
229 |
230 |
--------------------------------------------------------------------------------
/examples/Flappy/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += SPI
5 |
6 | BUILD_ROOT := build
7 | include ../../makeNativeArduino.mk
8 |
9 |
--------------------------------------------------------------------------------
/examples/Flappy/collisions.cpp:
--------------------------------------------------------------------------------
1 | #include "collisions.h"
2 | #include "constants.h"
3 | #include "TFT_LinuxWrapper.h" // TFT
4 |
5 | void checkCollision(
6 | int fx, int fy,
7 | int pillarPos, int gapPos,
8 | int score,
9 | bool *crashed,
10 | bool *running,
11 | TFT_LinuxWrapper tft) {
12 | // Collision with ground
13 | if (fy > 206) *crashed = true;
14 |
15 | // Collision with pillar
16 | if (fx + 34 > pillarPos && fx < pillarPos + 50)
17 | if (fy < gapPos || fy + 24 > gapPos + 90)
18 | *crashed = true;
19 |
20 | if (*crashed) {
21 | tft.setTextColor(WHITE);
22 | tft.setTextSize(2);
23 | tft.setCursor(75, 75);
24 | tft.print("Game Over!");
25 | tft.setCursor(75, 125);
26 | tft.print("Score:");
27 | tft.setCursor(220, 125);
28 | tft.print(score);
29 |
30 | // stop animation
31 | *running = false;
32 |
33 | // delay to stop any last minute clicks from restarting immediately
34 | delay(1000);
35 | }
36 | }
--------------------------------------------------------------------------------
/examples/Flappy/collisions.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include "TFT_LinuxWrapper.h" // TFT
3 |
4 | void checkCollision (
5 | int fx, int fy,
6 | int pillarPos, int gapPos,
7 | int score,
8 | bool *crashed,
9 | bool *running,
10 | TFT_LinuxWrapper tft
11 | );
--------------------------------------------------------------------------------
/examples/Flappy/constants.h:
--------------------------------------------------------------------------------
1 | #ifndef CONSTANTS
2 | #define CONSTANTS
3 |
4 | #define BLACK 0x0000
5 | #define BLUE 0x001F
6 | #define RED 0xF800
7 | #define GREEN 0x07E0
8 | #define CYAN 0x07FF
9 | #define MAGENTA 0xF81F
10 | #define YELLOW 0xFFE0
11 | #define WHITE 0xFFFF
12 |
13 | #define SENSIBILITY 300
14 | #define MINPRESSURE 10
15 | #define MAXPRESSURE 1000
16 |
17 | #endif
--------------------------------------------------------------------------------
/examples/HelloServer/HTTP_Method.h:
--------------------------------------------------------------------------------
1 | // https://github.com/espressif/arduino-esp32/blob/master/libraries/WebServer/src/HTTP_Method.h
2 | #ifndef _HTTP_Method_H_
3 | #define _HTTP_Method_H_
4 |
5 | typedef enum {
6 | HTTP_GET = 0b00000001,
7 | HTTP_POST = 0b00000010,
8 | HTTP_DELETE = 0b00000100,
9 | HTTP_PUT = 0b00001000,
10 | HTTP_PATCH = 0b00010000,
11 | HTTP_HEAD = 0b00100000,
12 | HTTP_OPTIONS = 0b01000000,
13 | HTTP_ANY = 0b01111111,
14 | } HTTPMethod;
15 |
16 | #endif /* _HTTP_Method_H_ */
17 |
--------------------------------------------------------------------------------
/examples/HelloServer/HelloServer.ino:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | first experimental webserver for ArduinoOnPC
4 |
5 | modified from
6 | https://github.com/espressif/arduino-esp32/blob/master/libraries/WebServer/examples/HelloServer/HelloServer.ino
7 |
8 |
9 | 15.2.2019 ChrisMicro
10 |
11 | */
12 |
13 |
14 | #include "WebServer.h"
15 |
16 | // try http://127.0.0.1:8888/
17 | // in your browser
18 |
19 | WebServer server(8888);
20 |
21 | const int led = 13;
22 |
23 | void handleRoot() {
24 | digitalWrite(led, 1);
25 |
26 | String str="hello from PC";
27 |
28 | server.send(200, "text/plain", str);
29 | digitalWrite(led, 0);
30 | }
31 |
32 | void handleNotFound()
33 | {
34 | digitalWrite(led, 1);
35 | String message = "File Not Found\n\n";
36 | message += "URI: ";
37 | message += server.uri();
38 | message += "\nMethod: ";
39 | message += (server.method() == HTTP_GET) ? "GET" : "POST";
40 | message += "\nArguments: ";
41 | message += server.args();
42 | message += "\n";
43 | for (uint8_t i = 0; i < server.args(); i++) {
44 | message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
45 | }
46 | server.send(404, "text/plain", message);
47 | digitalWrite(led, 0);
48 | }
49 |
50 | void setup(void) {
51 | pinMode(led, OUTPUT);
52 | digitalWrite(led, 0);
53 | Serial.begin(115200);
54 |
55 | Serial.println("");
56 |
57 | server.on("/", handleRoot);
58 |
59 | /*
60 | server.on("/inline", []() {
61 | server.send(200, "text/plain", "this works as well");
62 | });
63 | */
64 |
65 | server.onNotFound(handleNotFound);
66 |
67 | server.begin();
68 | Serial.println("HTTP server started");
69 | }
70 |
71 | void loop(void)
72 | {
73 | server.handleClient();
74 | }
75 |
--------------------------------------------------------------------------------
/examples/HelloServer/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += SPI
5 |
6 | BUILD_ROOT := build
7 | include ../../makeNativeArduino.mk
8 |
9 |
--------------------------------------------------------------------------------
/examples/HelloServer/WebServer.cpp:
--------------------------------------------------------------------------------
1 |
2 |
3 | #include "WebServer.h"
4 | #include
5 | #include //inet_addr
6 | #include //write
7 |
8 | /*
9 | Socket procedure:
10 | 1. create socket
11 | 2. bind port
12 | 3. listen: wati for connection requests
13 | 4. accept connection
14 | 5. receive/send data
15 | 6. close connection
16 | */
17 |
18 | WebServer::WebServer(int port)
19 | {
20 | _port=port;
21 | }
22 |
23 | int socket_desc;
24 | int client_sock;
25 |
26 | struct sockaddr_in wserver;
27 | struct sockaddr_in client;
28 |
29 | void WebServer::begin()
30 | {
31 | _currentArgCount=0;
32 |
33 | //Create socket
34 | socket_desc = socket(AF_INET , SOCK_STREAM , 0);
35 | if (socket_desc == -1)
36 | {
37 | printf("Could not create socket");
38 | }
39 | puts("Socket created");
40 |
41 | // Prepare the sockaddr_in structure
42 | wserver.sin_family = AF_INET;
43 | wserver.sin_addr.s_addr = INADDR_ANY;
44 | wserver.sin_port = htons( _port );
45 |
46 | //Bind
47 | if( bind(socket_desc,(struct sockaddr *)&wserver , sizeof(wserver)) < 0)
48 | {
49 | //print the error message
50 | perror("bind failed. Error");
51 | //return 1;
52 | }
53 | puts("bind done");
54 | //************ Listen ***************************
55 | listen(socket_desc , 3);
56 |
57 | //Accept and incoming connection
58 | puts("Waiting for incoming connections...");
59 |
60 | }
61 |
62 | #define BUF 1024
63 |
64 | typedef void(*THandlerFunction)();
65 |
66 |
67 | THandlerFunction onHandler;
68 | THandlerFunction notFoundHandler;
69 |
70 | void WebServer::handleClient()
71 | {
72 | char buffer[BUF];
73 | int c;
74 | int len;
75 |
76 | //static int Counter=0;
77 |
78 | //************ accept ***************************
79 | //accept connection from an incoming client
80 | c = sizeof(struct sockaddr_in);
81 | client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c);
82 |
83 | if (client_sock > 0) printf ("client (%s) connected ...\n",inet_ntoa (client.sin_addr));
84 |
85 | len = recv (client_sock, buffer, BUF-1, 0);
86 | if( len > 0) buffer[len] = '\0';
87 | // printf ("got message: %s\n", buffer);
88 |
89 | // parse message
90 | String message=String(buffer);
91 |
92 | int i1=message.indexOf("GET")+4;
93 | int i2=message.indexOf("HTTP")-1;
94 | String content_GET=message.substring(i1,i2);
95 | //Serial.print("==>");
96 | //Serial.println(part1);
97 |
98 | /*
99 | char str[]=" dies ist ein kleiner test 1";
100 | str[0]=((uint8_t) Counter)+'1';
101 | write(client_sock , str , strlen(str));
102 | printf("%d\n",Counter++);
103 | */
104 |
105 | if (content_GET.equals("/favicon.ico"))
106 | {
107 | // we have no icon yet
108 | send(404,"","");
109 | }else
110 | if (content_GET.equals("/"))
111 | {
112 | if(onHandler!=NULL)
113 | {
114 | puts("on handler");
115 | onHandler();
116 | }
117 |
118 | //else puts("no handler");
119 | }
120 | else
121 | {
122 | Serial.print("not found ==>");
123 | Serial.println(content_GET);
124 | if(notFoundHandler!=NULL)
125 | {
126 | notFoundHandler();
127 | }
128 | }
129 |
130 | close (client_sock);
131 | }
132 |
133 | void WebServer::on(const String &uri, WebServer::THandlerFunction handler)
134 | {
135 | onHandler=handler;
136 | }
137 |
138 | void WebServer::onNotFound(THandlerFunction fn)
139 | {
140 | notFoundHandler=fn;
141 | }
142 |
143 | int WebServer::args()
144 | {
145 | return _currentArgCount;
146 | }
147 |
148 | void WebServer::send(int code, const char* content_type, const String& content)
149 | {
150 | char str[1024];
151 | content.toCharArray(str,1024);
152 |
153 | write(client_sock , str , strlen(str));
154 | }
155 |
156 |
157 | void WebServer::send(int code, char* content_type, const String& content)
158 | {
159 | send(code, (const char*)content_type, content);
160 | }
161 |
162 | void WebServer::send(int code, const String& content_type, const String& content)
163 | {
164 | char str[1024];
165 | content_type.toCharArray(str,1024);
166 | send(code,str,content);
167 | }
168 |
169 | String WebServer::arg(String name)
170 | {
171 | return "";
172 | }
173 |
174 | String WebServer::arg(int i)
175 | {
176 | return "";
177 | }
178 |
179 | String WebServer::argName(int i)
180 | {
181 | return "";
182 | }
183 |
184 | /*
185 | WebServer.cpp - Dead simple web-server.
186 | Supports only one simultaneous client, knows how to handle GET and POST.
187 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
188 | This library is free software; you can redistribute it and/or
189 | modify it under the terms of the GNU Lesser General Public
190 | License as published by the Free Software Foundation; either
191 | version 2.1 of the License, or (at your option) any later version.
192 | This library is distributed in the hope that it will be useful,
193 | but WITHOUT ANY WARRANTY; without even the implied warranty of
194 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
195 | Lesser General Public License for more details.
196 | You should have received a copy of the GNU Lesser General Public
197 | License along with this library; if not, write to the Free Software
198 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
199 | Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling)
200 | */
201 |
202 |
--------------------------------------------------------------------------------
/examples/HelloServer/WebServer.h:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ifndef WEBSERVER_H
4 | #define WEBSERVER_H
5 |
6 | #include "Arduino.h"
7 | #include "HTTP_Method.h"
8 |
9 |
10 | class WebServer
11 | {
12 | public:
13 | WebServer(int port = 8080);
14 |
15 | void begin();
16 | void handleClient();
17 |
18 | typedef void(*THandlerFunction)();
19 |
20 | void on(const String &uri, THandlerFunction handler);
21 |
22 | void onNotFound(THandlerFunction fn); //called when handler is not assigned
23 | String uri() { return _currentUri; }
24 | HTTPMethod method() { return _currentMethod; }
25 | int args(); // get arguments count
26 |
27 | String arg(String name); // get request argument value by name
28 | String arg(int i); // get request argument value by number
29 | String argName(int i); // get request argument name by number
30 |
31 | void send(int code, const char* content_type = NULL, const String& content = String(""));
32 | void send(int code, char* content_type, const String& content);
33 | void send(int code, const String& content_type, const String& content);
34 |
35 | protected:
36 |
37 | struct RequestArgument {
38 | String key;
39 | String value;
40 | };
41 |
42 | int _port;
43 |
44 |
45 | HTTPMethod _currentMethod;
46 | String _currentUri;
47 | int _currentArgCount;
48 | RequestArgument* _currentArgs;
49 | int _postArgsLen;
50 | RequestArgument* _postArgs;
51 |
52 | String _responseHeaders;
53 |
54 | };
55 |
56 |
57 | #endif //WEBSERVER_H
58 |
59 | // template functions from
60 | // https://github.com/espressif/arduino-esp32/blob/master/libraries/WebServer/src/WebServer.h
61 | /*
62 | WebServer.h - Dead simple web-server.
63 | Supports only one simultaneous client, knows how to handle GET and POST.
64 | Copyright (c) 2014 Ivan Grokhotkov. All rights reserved.
65 | This library is free software; you can redistribute it and/or
66 | modify it under the terms of the GNU Lesser General Public
67 | License as published by the Free Software Foundation; either
68 | version 2.1 of the License, or (at your option) any later version.
69 | This library is distributed in the hope that it will be useful,
70 | but WITHOUT ANY WARRANTY; without even the implied warranty of
71 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
72 | Lesser General Public License for more details.
73 | You should have received a copy of the GNU Lesser General Public
74 | License along with this library; if not, write to the Free Software
75 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
76 | Modified 8 May 2015 by Hristo Gochkov (proper post and file upload handling)
77 | */
78 |
79 |
--------------------------------------------------------------------------------
/examples/SerialInput/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += SPI
5 |
6 | BUILD_ROOT := build
7 | include ../../makeNativeArduino.mk
8 |
9 |
--------------------------------------------------------------------------------
/examples/SerialInput/SerialInput.ino:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | How to use serial input with ArduinoOnPc?
4 |
5 | At the momemt the keyboard of the PC is used as serial input.
6 | Due to the limitations of the linux console only whole lines can be read ( terminated with 'return key').
7 |
8 | Original Code is found here:
9 |
10 | https://www.arduino.cc/reference/de/language/functions/communication/serial/available/
11 |
12 |
13 | 26 December 2019, ChrisMicro
14 |
15 | */
16 |
17 | int incomingByte = 0;
18 |
19 | void setup()
20 | {
21 | Serial.begin(9600);
22 | }
23 |
24 | void loop()
25 | {
26 | if (Serial.available() > 0) // serial chars are available, when a whole line was read and the return key was pressed
27 | {
28 | incomingByte = Serial.read();
29 |
30 | Serial.print("I received: ");
31 | Serial.println(incomingByte, DEC);
32 | }else // if the return key on the keyboard was not pressed
33 | {
34 | Serial.println("waiting");
35 | delay(1000);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/examples/TFT_demo/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += SPI
5 |
6 | BUILD_ROOT := build
7 | include ../../makeNativeArduino.mk
8 |
9 |
--------------------------------------------------------------------------------
/examples/TFT_demo/TFT_demo.ino:
--------------------------------------------------------------------------------
1 | #include "TFT_LinuxWrapper.h"
2 |
3 | TFT_LinuxWrapper tft;
4 |
5 | unsigned long testFillScreen() {
6 | unsigned long start = micros();
7 | tft.fillScreen(LTDC_BLACK);
8 | yield();
9 | tft.fillScreen(LTDC_RED);
10 | yield();
11 | tft.fillScreen(LTDC_GREEN);
12 | yield();
13 | tft.fillScreen(LTDC_BLUE);
14 | yield();
15 | tft.fillScreen(LTDC_BLACK);
16 | yield();
17 | return micros() - start;
18 | }
19 |
20 | unsigned long testText() {
21 | tft.fillScreen(LTDC_BLACK);
22 | unsigned long start = micros();
23 | tft.setCursor(0, 0);
24 | tft.setTextColor(LTDC_WHITE); tft.setTextSize(1);
25 | tft.println("Hello World!");
26 | tft.setTextColor(LTDC_YELLOW); tft.setTextSize(2);
27 | tft.println(1234.56);
28 | tft.setTextColor(LTDC_RED); tft.setTextSize(3);
29 | tft.println(0xDEADBEEF, HEX);
30 | tft.println();
31 | tft.setTextColor(LTDC_GREEN);
32 | tft.setTextSize(5);
33 | tft.println("Groop");
34 | tft.setTextSize(2);
35 | tft.println("I implore thee,");
36 | tft.setTextSize(1);
37 | tft.println("my foonting turlingdromes.");
38 | tft.println("And hooptiously drangle me");
39 | tft.println("with crinkly bindlewurdles,");
40 | tft.println("Or I will rend thee");
41 | tft.println("in the gobberwarts");
42 | tft.println("with my blurglecruncheon,");
43 | tft.println("see if I don't!");
44 | return micros() - start;
45 | }
46 |
47 | unsigned long testLines(uint16_t color) {
48 | unsigned long start, t;
49 | int x1, y1, x2, y2,
50 | w = tft.width(),
51 | h = tft.height();
52 |
53 | tft.fillScreen(LTDC_BLACK);
54 | yield();
55 |
56 | x1 = y1 = 0;
57 | y2 = h - 1;
58 | start = micros();
59 | for(x2=0; x20; i-=6) {
144 |
145 | i2 = i / 2;
146 | start = micros();
147 | tft.fillRect(cx-i2, cy-i2, i, i, color1);
148 | t += micros() - start;
149 | // Outlines are not included in timing results
150 | tft.drawRect(cx-i2, cy-i2, i, i, color2);
151 | yield();
152 | }
153 |
154 | return t;
155 | }
156 |
157 | unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
158 | unsigned long start;
159 | int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
160 |
161 | tft.fillScreen(LTDC_BLACK);
162 | start = micros();
163 | for(x=radius; x10; i-=5) {
217 | start = micros();
218 | tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
219 | tft.color565(0, i*10, i*10));
220 | t += micros() - start;
221 | tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
222 | tft.color565(i*10, i*10, 0));
223 | yield();
224 | }
225 |
226 | return t;
227 | }
228 |
229 | unsigned long testRoundRects() {
230 | unsigned long start;
231 | int w, i, i2,
232 | cx = tft.width() / 2 - 1,
233 | cy = tft.height() / 2 - 1;
234 |
235 | tft.fillScreen(LTDC_BLACK);
236 | w = min(tft.width(), tft.height());
237 | start = micros();
238 | for(i=0; i20; i-=6) {
255 | i2 = i / 2;
256 | tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
257 | yield();
258 | }
259 |
260 | return micros() - start;
261 | }
262 |
263 |
264 | void setup()
265 | {
266 | tft.begin();
267 | tft.fillScreen(LTDC_BLACK);
268 |
269 | tft.setRotation(1);
270 | tft.setCursor(0, 0);
271 | tft.setTextColor(LTDC_GREEN); tft.setTextSize(3);
272 | tft.println("Arduino TFT");
273 | tft.setTextColor(LTDC_YELLOW); tft.setTextSize(2);
274 | delay(1000);
275 | testFillScreen();
276 | delay(500);
277 |
278 |
279 | testText();
280 | delay(3000);
281 |
282 |
283 | testLines(LTDC_CYAN);
284 | delay(500);
285 |
286 |
287 | testFastLines(LTDC_RED, LTDC_BLUE);
288 | delay(500);
289 |
290 |
291 | testRects(LTDC_GREEN);
292 | delay(500);
293 |
294 |
295 | testFilledRects(LTDC_YELLOW, LTDC_MAGENTA);
296 | delay(500);
297 |
298 |
299 | testFilledCircles(10, LTDC_MAGENTA);
300 |
301 |
302 | testCircles(10, LTDC_WHITE);
303 | delay(500);
304 |
305 |
306 | testTriangles();
307 | delay(500);
308 |
309 |
310 | testFilledTriangles();
311 | delay(500);
312 |
313 |
314 | testRoundRects();
315 | delay(500);
316 |
317 |
318 | testFilledRoundRects();
319 | delay(3000);
320 | tft.fillScreen(LTDC_BLACK);
321 | tft.setCursor(0, 0);
322 |
323 | }
324 |
325 | int Counter=0;
326 |
327 | void loop(void)
328 | {
329 |
330 | tft.print( Counter ); tft.print(" ");
331 | Counter ++;
332 | delay(1000);
333 |
334 | }
335 |
--------------------------------------------------------------------------------
/examples/TekSpriteEditor1/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += SPI
5 |
6 | BUILD_ROOT := build
7 | include ../../makeNativeArduino.mk
8 |
9 |
--------------------------------------------------------------------------------
/examples/TekSpriteEditor1/TekSpriteEditor1.ino:
--------------------------------------------------------------------------------
1 | /*
2 | Sprite Editor
3 |
4 | July 2017, ChrisMicro
5 | */
6 |
7 | #include "TFT_LinuxWrapper.h" // TFT
8 | #include "Touch_LinuxWrapper.h" // TOUCH
9 |
10 | TFT_LinuxWrapper tft;
11 |
12 | TouchScreen ts;
13 |
14 | // sprite field dimension
15 | #define DIMENSION_X 16
16 | #define DIMENSION_Y 16
17 |
18 | #define POINT_SIZE 16
19 |
20 | typedef uint16_t color_t;
21 |
22 | // this needs a lot of memroy ...
23 | color_t Field[DIMENSION_X][DIMENSION_Y];
24 |
25 | void showField()
26 | {
27 | for( int x=0; x= 0) && (y>0) && (x= 0) && (y>=0) && (x= 0) && (y>0) && (xoy ) c='D';
193 | if( dx>ox && dy>oy ) c='E';
194 | if( dx>ox && dy==oy ) c='A';
195 | if( dx>ox && dyoy ) c='F';
200 |
201 | //Serial.print("ox,dx");Serial.print(ox);Serial.print(" ");Serial.println(dx);
202 | //Serial.print("oy,dy");Serial.print(oy);Serial.print(" ");Serial.println(dy);
203 |
204 | // walk to the point
205 | if(oxdx) ox--;
207 | if(oydy) oy--;
209 |
210 | // Serial.write(c);Serial.println("");
211 | if (c!='-') SpriteBuffer[SpriteBufferIndex++]=c;
212 |
213 | if(penState)
214 | {
215 | //Field[ox][DIMENSION_Y-oy]=COLOR_RED;
216 | setPoint ( p.x,p.y,COLOR_RED );
217 | showField();
218 | //setPoint ( p.x,p.y,COLOR_RED );
219 | }//else Field[ox][DIMENSION_Y-oy]=COLOR_DARKGREY/2;
220 |
221 | if( OldPoint != p )
222 | {
223 | drawPoint( OldPoint.x, OldPoint.y, getColor( OldPoint.x, OldPoint.y ) );
224 |
225 | OldPoint=p;
226 |
227 | if ( penState )
228 | {
229 | drawPoint( p.x,p.y,COLOR_RED );
230 | //setPoint ( p.x,p.y,COLOR_RED );
231 |
232 | }else drawPoint(p.x,p.y,COLOR_GREEN);
233 |
234 | delay(10);
235 |
236 | }
237 |
238 |
239 | static boolean onState=false;
240 | static boolean oldOnState=false;
241 |
242 | onState = ( Field[ox][DIMENSION_Y-oy] == COLOR_RED );
243 |
244 |
245 | // penDownChange
246 | if(oldOnState==false && onState==true)
247 | {
248 | //Serial.println("P");
249 | SpriteBuffer[SpriteBufferIndex++]='P';
250 | }
251 | // pen up change
252 | if(oldOnState==true && onState==false)
253 | {
254 | //Serial.println(" ");
255 | SpriteBuffer[SpriteBufferIndex++]=' ';
256 | }
257 | oldOnState = onState;
258 |
259 | if(penState)
260 | {
261 | dx=x;
262 | dy=y;
263 | }
264 |
265 |
266 | if(penState&&p.x>350)
267 | {
268 | if(p.y>200)
269 | {
270 | // init field
271 | for( int x=0; x0) SpriteBufferIndex--;
155 | SpriteBuffer[SpriteBufferIndex]=0;
156 | }
157 |
158 | static int oldIndex=0;
159 | if(oldIndex!=SpriteBufferIndex)
160 | {
161 | oldIndex=SpriteBufferIndex;
162 | showSprite(SpriteBuffer);
163 | Serial.println(SpriteBuffer);
164 | }
165 |
166 | delay(50);
167 | }
168 |
--------------------------------------------------------------------------------
/examples/ToneMelody/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += SPI
5 |
6 | BUILD_ROOT := build
7 | include ../../makeNativeArduino.mk
8 |
9 |
--------------------------------------------------------------------------------
/examples/ToneMelody/ToneMelody.ino:
--------------------------------------------------------------------------------
1 | /*
2 | * ToneMelody test for ArduinoOnPC
3 | *
4 | * use a linux pipe to aplay for sound output
5 | *
6 | * 2019 February ChrisMicro
7 | *
8 | */
9 |
10 | #define APLAY "aplay -q --file-type wav --format S16_LE"
11 |
12 |
13 | #define SAMPLINGFREQUENCY 8000
14 | #define BUFFERLENGTH SAMPLINGFREQUENCY*2 // buffer for 10 seconds
15 |
16 | int16_t SignalBuffer[BUFFERLENGTH];
17 |
18 | void tone(uint8_t pin, uint16_t frequency_Hz, uint32_t duration_ms)
19 | {
20 | FILE *pipeDescriptor;
21 | int16_t signal;
22 |
23 |
24 | pipeDescriptor = popen(APLAY,"w");
25 | if (pipeDescriptor==NULL)
26 | {
27 | printf("Error opening pipe to aplay. Check if you have it! \n");
28 | exit(0);
29 | }
30 |
31 | uint32_t len=SAMPLINGFREQUENCY*duration_ms/1000;
32 |
33 | if(len>BUFFERLENGTH) len=BUFFERLENGTH; // limit size, prevent buffer overflow
34 |
35 | for(uint32_t n=0;n random(8))Field [!nextField] [x] [y] = color;
107 | }else
108 | {
109 | Field [!nextField] [x] [y] = color;
110 | //Field [!nextField] [x] [y] = getSurrounding(x,y,random(0,9));
111 | }
112 |
113 |
114 | }
115 | }
116 | SelectedField = !SelectedField;
117 | showField();
118 |
119 | }
120 |
121 | /*
122 |
123 | https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life
124 |
125 | Any live cell with fewer than two live neighbours dies, as if caused by underpopulation.
126 | Any live cell with two or three live neighbours lives on to the next generation.
127 | Any live cell with more than three live neighbours dies, as if by overpopulation.
128 | Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
129 |
130 | */
131 |
132 | void gameOfLife()
133 | {
134 | boolean nextField;
135 |
136 | for( int x=1; x 3 ) color = COLOR_BLACK; // die
156 | if( numberOfSurroundingCells == 3 ) color = COLOR_GREEN; // born
157 |
158 |
159 | Field [nextField] [x] [y] = color;
160 | }
161 | }
162 | SelectedField = nextField;
163 | showField();
164 |
165 | }
166 |
167 | void setup()
168 | {
169 | Serial.begin(115200);
170 | Serial.print("test");
171 | tft.begin();
172 | tft.fillScreen(LTDC_BLACK);
173 |
174 | //tft.setRotation(1);
175 | tft.setCursor(0, 0);
176 | tft.setTextColor(LTDC_GREEN); tft.setTextSize(3);
177 | tft.println("cell art");
178 | tft.setTextColor(LTDC_YELLOW); tft.setTextSize(2);
179 | tft.fillScreen(LTDC_BLACK);
180 |
181 | }
182 |
183 | void loop(void)
184 | {
185 | Field[SelectedField][1+random(DIMENSION_X-2)][1+random(DIMENSION_Y-2)]=COLOR_GREEN;
186 | Field[SelectedField][1+random(DIMENSION_X-2)][1+random(DIMENSION_Y-2)]=COLOR_RED;
187 | Field[SelectedField][1+random(DIMENSION_X-2)][1+random(DIMENSION_Y-2)]=COLOR_BLUE;
188 | Field[SelectedField][1+random(DIMENSION_X-2)][1+random(DIMENSION_Y-2)]=COLOR_YELLOW;
189 |
190 | showField();
191 | delay(2000);
192 |
193 | long startTime=millis();
194 | while(millis()-startTime<60000) calcNextField();
195 |
196 | delay(3000);
197 | clearField();
198 | }
199 |
200 | /* ArduinoOnPc
201 | © ChrisMicro 2017.
202 |
203 | This file is part of ArduinoOnPc.
204 |
205 | ArduinoOnPc is free software: you can redistribute it and/or modify
206 | it under the terms of the GNU Lesser General Public License as published by
207 | the Free Software Foundation, either version 3 of the License, or
208 | (at your option) any later version.
209 | GuiPittix is distributed in the hope that it will be useful,
210 | but WITHOUT ANY WARRANTY; without even the implied warranty of
211 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
212 | GNU Lesser General Public License for more details.
213 | You should have received a copy of the GNU Lesser General Public License
214 | along with simple_GUI_elements. If not, see .
215 |
216 | web-site: https://github.com/ChrisMicro/ArduinoOnPc
217 | */
218 |
--------------------------------------------------------------------------------
/examples/gameOfLife/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += SPI
5 |
6 | BUILD_ROOT := build
7 | include ../../makeNativeArduino.mk
8 |
9 |
--------------------------------------------------------------------------------
/examples/gameOfLife/gameOfLife.ino:
--------------------------------------------------------------------------------
1 | /*
2 | * game of life
3 | *
4 | * Created on: 21.07.2017
5 | * Author: ChrisMicro
6 | *
7 | * Copyright see below. Please maintain the list of authors.
8 | *
9 | */
10 |
11 | #include "TFT_LinuxWrapper.h"
12 |
13 | TFT_LinuxWrapper tft;
14 |
15 | // play field dimension
16 | #define DIMENSION_X 320
17 | #define DIMENSION_Y 240
18 |
19 | typedef uint16_t color_t;
20 |
21 | // this needs a lot of memroy ...
22 | color_t Field[2][DIMENSION_X][DIMENSION_Y];
23 | boolean SelectedField=false;
24 |
25 |
26 | void showField()
27 | {
28 | for( int x=0; x 3 ) color = COLOR_BLACK; // die
98 | if( numberOfSurroundingCells == 3 ) color = COLOR_GREEN; // born
99 |
100 |
101 | Field [nextField] [x] [y] = color;
102 | }
103 | }
104 | SelectedField = nextField;
105 | showField();
106 |
107 | }
108 |
109 | void setup()
110 | {
111 | Serial.begin(115200);
112 | Serial.print("test");
113 | tft.begin();
114 | tft.fillScreen(LTDC_BLACK);
115 |
116 | tft.setRotation(1);
117 | tft.setCursor(0, 0);
118 | tft.setTextColor(LTDC_GREEN); tft.setTextSize(3);
119 | tft.println("Game of Life");
120 | tft.setTextColor(LTDC_YELLOW); tft.setTextSize(2);
121 | tft.fillScreen(LTDC_BLACK);
122 |
123 | // initialize play field with ramdom living cells
124 | int initialNumberOfLivingCells=DIMENSION_X*DIMENSION_Y/5;
125 | for(int n=0;n.
156 |
157 | web-site: https://github.com/ChrisMicro/ArduinoOnPc
158 | */
159 |
--------------------------------------------------------------------------------
/examples/gnuPlot/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += SPI
5 |
6 | BUILD_ROOT := build
7 | include ../../makeNativeArduino.mk
8 |
9 |
--------------------------------------------------------------------------------
/examples/gnuPlot/gnuPlot.ino:
--------------------------------------------------------------------------------
1 |
2 | /*
3 | gnuplot
4 |
5 | use a linux pipe to gnuplot to visualize data
6 |
7 |
8 | v0.1 14 Feb 2019 ChrisMicro initial version
9 |
10 | */
11 |
12 | FILE *pipe=NULL;
13 |
14 | void plot(double y[],int32_t length)
15 | {
16 | if(pipe==NULL)
17 | {
18 | pipe = popen("gnuplot -persist","w");
19 | if (pipe==NULL)
20 | {
21 | printf("gnuplot missing ... \n");
22 | }
23 | delay(100);
24 |
25 | }
26 | if(pipe!=NULL)
27 | {
28 | fprintf(pipe, "set title 'sine wave online plot'\n");
29 | fprintf(pipe, "set xlabel 'time[s]'\n");
30 | fprintf(pipe, "set ylabel 'amplitude [V]'\n");
31 | fprintf(pipe, "set style data lines\n");
32 | fprintf(pipe, "set yrange [-200:200]\n");
33 | fprintf(pipe, "set ytics 100\n");
34 | fprintf(pipe, "set grid\n");
35 | fprintf(pipe, "set key off\n");
36 |
37 | fprintf(pipe, "plot '-'\n");
38 |
39 | for(int32_t n=0;n");
6 | }
7 |
8 | void loop() {
9 | if (Serial.available() > 0) {
10 | receivedChar = Serial.read();
11 | Serial.print("Received:[");
12 | if(receivedChar!='\n')
13 | Serial.print(receivedChar);
14 | else
15 | Serial.print("\\n");
16 | Serial.println("]");
17 | }
18 | Serial.println("Waiting for input");
19 | delay(1000);
20 | }
21 |
--------------------------------------------------------------------------------
/examples/sketch/Makefile:
--------------------------------------------------------------------------------
1 | CUSTOM_LIBS := libraries
2 |
3 | ARDUINO_LIBS += Adafruit_GFX
4 | ARDUINO_LIBS += SPI
5 |
6 | BUILD_ROOT := build
7 | include ../../makeNativeArduino.mk
8 |
9 |
--------------------------------------------------------------------------------
/examples/sketch/sketch.ino:
--------------------------------------------------------------------------------
1 | #include "TFT_LinuxWrapper.h"
2 |
3 | TFT_LinuxWrapper tft;
4 |
5 | void setup()
6 | {
7 | Serial.begin(115200);
8 | Serial.print("test");
9 | tft.begin();
10 | tft.fillScreen(LTDC_BLACK);
11 |
12 | //tft.setRotation(1);
13 | tft.setCursor(0, 0);
14 | tft.setTextColor(LTDC_GREEN); tft.setTextSize(3);
15 | tft.println("Arduino TFT emulation on PC");
16 | tft.setTextColor(LTDC_YELLOW); tft.setTextSize(2);
17 | }
18 |
19 | int Counter=0;
20 |
21 | void loop(void)
22 | {
23 |
24 | tft.print( Counter ); tft.print(" ");
25 | Counter++;
26 | analogWrite(1,Counter);
27 | delay(1000);
28 | Serial.println(Counter);
29 | }
30 |
--------------------------------------------------------------------------------
/libraries/Adafruit_GFX/Adafruit_GFX.h:
--------------------------------------------------------------------------------
1 | #ifndef _ADAFRUIT_GFX_H
2 | #define _ADAFRUIT_GFX_H
3 |
4 |
5 | #if ARDUINO >= 100
6 | #include "Arduino.h"
7 | #include "Print.h"
8 | #else
9 | #include "Arduino.h"
10 | //#include "WProgram.h"
11 | #endif
12 | #include "gfxfont.h"
13 |
14 | #include
15 | #include
16 | #include "Print.h"
17 |
18 | class Adafruit_GFX : public Print {
19 |
20 | public:
21 |
22 | Adafruit_GFX(int16_t w, int16_t h); // Constructor
23 |
24 | // This MUST be defined by the subclass:
25 | virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0;
26 |
27 | // TRANSACTION API / CORE DRAW API
28 | // These MAY be overridden by the subclass to provide device-specific
29 | // optimized code. Otherwise 'generic' versions are used.
30 | virtual void startWrite(void);
31 | virtual void writePixel(int16_t x, int16_t y, uint16_t color);
32 | virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
33 | virtual void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
34 | virtual void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
35 | virtual void writeLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
36 | virtual void endWrite(void);
37 |
38 | // CONTROL API
39 | // These MAY be overridden by the subclass to provide device-specific
40 | // optimized code. Otherwise 'generic' versions are used.
41 | virtual void setRotation(uint8_t r);
42 | virtual void invertDisplay(boolean i);
43 |
44 | // BASIC DRAW API
45 | // These MAY be overridden by the subclass to provide device-specific
46 | // optimized code. Otherwise 'generic' versions are used.
47 | virtual void
48 | // It's good to implement those, even if using transaction API
49 | drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
50 | drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
51 | fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
52 | fillScreen(uint16_t color),
53 | // Optional and probably not necessary to change
54 | drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
55 | drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
56 |
57 | // These exist only with Adafruit_GFX (no subclass overrides)
58 | void
59 | drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
60 | drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
61 | uint16_t color),
62 | fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
63 | fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
64 | int16_t delta, uint16_t color),
65 | drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
66 | int16_t x2, int16_t y2, uint16_t color),
67 | fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
68 | int16_t x2, int16_t y2, uint16_t color),
69 | drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
70 | int16_t radius, uint16_t color),
71 | fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
72 | int16_t radius, uint16_t color),
73 | drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
74 | int16_t w, int16_t h, uint16_t color),
75 | drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
76 | int16_t w, int16_t h, uint16_t color, uint16_t bg),
77 | drawBitmap(int16_t x, int16_t y, uint8_t *bitmap,
78 | int16_t w, int16_t h, uint16_t color),
79 | drawBitmap(int16_t x, int16_t y, uint8_t *bitmap,
80 | int16_t w, int16_t h, uint16_t color, uint16_t bg),
81 | drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
82 | int16_t w, int16_t h, uint16_t color),
83 | drawGrayscaleBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
84 | int16_t w, int16_t h),
85 | drawGrayscaleBitmap(int16_t x, int16_t y, uint8_t *bitmap,
86 | int16_t w, int16_t h),
87 | drawGrayscaleBitmap(int16_t x, int16_t y,
88 | const uint8_t bitmap[], const uint8_t mask[],
89 | int16_t w, int16_t h),
90 | drawGrayscaleBitmap(int16_t x, int16_t y,
91 | uint8_t *bitmap, uint8_t *mask, int16_t w, int16_t h),
92 | drawRGBBitmap(int16_t x, int16_t y, const uint16_t bitmap[],
93 | int16_t w, int16_t h),
94 | drawRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap,
95 | int16_t w, int16_t h),
96 | drawRGBBitmap(int16_t x, int16_t y,
97 | const uint16_t bitmap[], const uint8_t mask[],
98 | int16_t w, int16_t h),
99 | drawRGBBitmap(int16_t x, int16_t y,
100 | uint16_t *bitmap, uint8_t *mask, int16_t w, int16_t h),
101 | drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
102 | uint16_t bg, uint8_t size),
103 | setCursor(int16_t x, int16_t y),
104 | setTextColor(uint16_t c),
105 | setTextColor(uint16_t c, uint16_t bg),
106 | setTextSize(uint8_t s),
107 | setTextWrap(boolean w),
108 | cp437(boolean x=true),
109 | setFont(const GFXfont *f = NULL),
110 | getTextBounds(char *string, int16_t x, int16_t y,
111 | int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
112 | getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
113 | int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
114 |
115 | //#if ARDUINO >= 100
116 | virtual size_t write(uint8_t);
117 | /*#else
118 | virtual void write(uint8_t);
119 | #endif
120 | */
121 | int16_t height(void) const;
122 | int16_t width(void) const;
123 |
124 | uint8_t getRotation(void) const;
125 |
126 | // get current cursor position (get rotation safe maximum values, using: width() for x, height() for y)
127 | int16_t getCursorX(void) const;
128 | int16_t getCursorY(void) const;
129 |
130 | protected:
131 | void
132 | charBounds(char c, int16_t *x, int16_t *y,
133 | int16_t *minx, int16_t *miny, int16_t *maxx, int16_t *maxy);
134 | const int16_t
135 | WIDTH, HEIGHT; // This is the 'raw' display w/h - never changes
136 | int16_t
137 | _width, _height, // Display w/h as modified by current rotation
138 | cursor_x, cursor_y;
139 | uint16_t
140 | textcolor, textbgcolor;
141 | uint8_t
142 | textsize,
143 | rotation;
144 | boolean
145 | wrap, // If set, 'wrap' text at right edge of display
146 | _cp437; // If set, use correct CP437 charset (default is off)
147 | GFXfont
148 | *gfxFont;
149 | };
150 |
151 | class Adafruit_GFX_Button {
152 |
153 | public:
154 | Adafruit_GFX_Button(void);
155 | // "Classic" initButton() uses center & size
156 | void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
157 | uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
158 | uint16_t textcolor, char *label, uint8_t textsize);
159 | // New/alt initButton() uses upper-left corner & size
160 | void initButtonUL(Adafruit_GFX *gfx, int16_t x1, int16_t y1,
161 | uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
162 | uint16_t textcolor, char *label, uint8_t textsize);
163 | void drawButton(boolean inverted = false);
164 | boolean contains(int16_t x, int16_t y);
165 |
166 | void press(boolean p);
167 | boolean isPressed();
168 | boolean justPressed();
169 | boolean justReleased();
170 |
171 | private:
172 | Adafruit_GFX *_gfx;
173 | int16_t _x1, _y1; // Coordinates of top-left corner
174 | uint16_t _w, _h;
175 | uint8_t _textsize;
176 | uint16_t _outlinecolor, _fillcolor, _textcolor;
177 | char _label[10];
178 |
179 | boolean currstate, laststate;
180 | };
181 |
182 | class GFXcanvas1 : public Adafruit_GFX {
183 | public:
184 | GFXcanvas1(uint16_t w, uint16_t h);
185 | ~GFXcanvas1(void);
186 | void drawPixel(int16_t x, int16_t y, uint16_t color),
187 | fillScreen(uint16_t color);
188 | uint8_t *getBuffer(void);
189 | private:
190 | uint8_t *buffer;
191 | };
192 |
193 | class GFXcanvas8 : public Adafruit_GFX {
194 | public:
195 | GFXcanvas8(uint16_t w, uint16_t h);
196 | ~GFXcanvas8(void);
197 | void drawPixel(int16_t x, int16_t y, uint16_t color),
198 | fillScreen(uint16_t color),
199 | writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
200 |
201 | uint8_t *getBuffer(void);
202 | private:
203 | uint8_t *buffer;
204 | };
205 |
206 | class GFXcanvas16 : public Adafruit_GFX {
207 | public:
208 | GFXcanvas16(uint16_t w, uint16_t h);
209 | ~GFXcanvas16(void);
210 | void drawPixel(int16_t x, int16_t y, uint16_t color),
211 | fillScreen(uint16_t color);
212 | uint16_t *getBuffer(void);
213 | private:
214 | uint16_t *buffer;
215 | };
216 |
217 | #endif // _ADAFRUIT_GFX_H
218 |
--------------------------------------------------------------------------------
/libraries/Adafruit_GFX/gfxfont.h:
--------------------------------------------------------------------------------
1 | // Font structures for newer Adafruit_GFX (1.1 and later).
2 | // Example fonts are included in 'Fonts' directory.
3 | // To use a font in your Arduino sketch, #include the corresponding .h
4 | // file and pass address of GFXfont struct to setFont(). Pass NULL to
5 | // revert to 'classic' fixed-space bitmap font.
6 |
7 | #ifndef _GFXFONT_H_
8 | #define _GFXFONT_H_
9 |
10 | typedef struct { // Data stored PER GLYPH
11 | uint16_t bitmapOffset; // Pointer into GFXfont->bitmap
12 | uint8_t width, height; // Bitmap dimensions in pixels
13 | uint8_t xAdvance; // Distance to advance cursor (x axis)
14 | int8_t xOffset, yOffset; // Dist from cursor pos to UL corner
15 | } GFXglyph;
16 |
17 | typedef struct { // Data stored for FONT AS A WHOLE:
18 | uint8_t *bitmap; // Glyph bitmaps, concatenated
19 | GFXglyph *glyph; // Glyph array
20 | uint8_t first, last; // ASCII extents
21 | uint8_t yAdvance; // Newline distance (y axis)
22 | } GFXfont;
23 |
24 | #endif // _GFXFONT_H_
25 |
--------------------------------------------------------------------------------
/libraries/Adafruit_GFX/glcdfont.c:
--------------------------------------------------------------------------------
1 | // This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0.
2 | // See gfxfont.h for newer custom bitmap font info.
3 |
4 | #ifndef FONT5X7_H
5 | #define FONT5X7_H
6 |
7 | #ifdef __AVR__
8 | #include
9 | #include
10 | #elif defined(ESP8266)
11 | #include
12 | #else
13 | #define PROGMEM
14 | #endif
15 |
16 | // Standard ASCII 5x7 font
17 |
18 | static const unsigned char font[] PROGMEM = {
19 | 0x00, 0x00, 0x00, 0x00, 0x00,
20 | 0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
21 | 0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
22 | 0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
23 | 0x18, 0x3C, 0x7E, 0x3C, 0x18,
24 | 0x1C, 0x57, 0x7D, 0x57, 0x1C,
25 | 0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
26 | 0x00, 0x18, 0x3C, 0x18, 0x00,
27 | 0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
28 | 0x00, 0x18, 0x24, 0x18, 0x00,
29 | 0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
30 | 0x30, 0x48, 0x3A, 0x06, 0x0E,
31 | 0x26, 0x29, 0x79, 0x29, 0x26,
32 | 0x40, 0x7F, 0x05, 0x05, 0x07,
33 | 0x40, 0x7F, 0x05, 0x25, 0x3F,
34 | 0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
35 | 0x7F, 0x3E, 0x1C, 0x1C, 0x08,
36 | 0x08, 0x1C, 0x1C, 0x3E, 0x7F,
37 | 0x14, 0x22, 0x7F, 0x22, 0x14,
38 | 0x5F, 0x5F, 0x00, 0x5F, 0x5F,
39 | 0x06, 0x09, 0x7F, 0x01, 0x7F,
40 | 0x00, 0x66, 0x89, 0x95, 0x6A,
41 | 0x60, 0x60, 0x60, 0x60, 0x60,
42 | 0x94, 0xA2, 0xFF, 0xA2, 0x94,
43 | 0x08, 0x04, 0x7E, 0x04, 0x08,
44 | 0x10, 0x20, 0x7E, 0x20, 0x10,
45 | 0x08, 0x08, 0x2A, 0x1C, 0x08,
46 | 0x08, 0x1C, 0x2A, 0x08, 0x08,
47 | 0x1E, 0x10, 0x10, 0x10, 0x10,
48 | 0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
49 | 0x30, 0x38, 0x3E, 0x38, 0x30,
50 | 0x06, 0x0E, 0x3E, 0x0E, 0x06,
51 | 0x00, 0x00, 0x00, 0x00, 0x00,
52 | 0x00, 0x00, 0x5F, 0x00, 0x00,
53 | 0x00, 0x07, 0x00, 0x07, 0x00,
54 | 0x14, 0x7F, 0x14, 0x7F, 0x14,
55 | 0x24, 0x2A, 0x7F, 0x2A, 0x12,
56 | 0x23, 0x13, 0x08, 0x64, 0x62,
57 | 0x36, 0x49, 0x56, 0x20, 0x50,
58 | 0x00, 0x08, 0x07, 0x03, 0x00,
59 | 0x00, 0x1C, 0x22, 0x41, 0x00,
60 | 0x00, 0x41, 0x22, 0x1C, 0x00,
61 | 0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
62 | 0x08, 0x08, 0x3E, 0x08, 0x08,
63 | 0x00, 0x80, 0x70, 0x30, 0x00,
64 | 0x08, 0x08, 0x08, 0x08, 0x08,
65 | 0x00, 0x00, 0x60, 0x60, 0x00,
66 | 0x20, 0x10, 0x08, 0x04, 0x02,
67 | 0x3E, 0x51, 0x49, 0x45, 0x3E,
68 | 0x00, 0x42, 0x7F, 0x40, 0x00,
69 | 0x72, 0x49, 0x49, 0x49, 0x46,
70 | 0x21, 0x41, 0x49, 0x4D, 0x33,
71 | 0x18, 0x14, 0x12, 0x7F, 0x10,
72 | 0x27, 0x45, 0x45, 0x45, 0x39,
73 | 0x3C, 0x4A, 0x49, 0x49, 0x31,
74 | 0x41, 0x21, 0x11, 0x09, 0x07,
75 | 0x36, 0x49, 0x49, 0x49, 0x36,
76 | 0x46, 0x49, 0x49, 0x29, 0x1E,
77 | 0x00, 0x00, 0x14, 0x00, 0x00,
78 | 0x00, 0x40, 0x34, 0x00, 0x00,
79 | 0x00, 0x08, 0x14, 0x22, 0x41,
80 | 0x14, 0x14, 0x14, 0x14, 0x14,
81 | 0x00, 0x41, 0x22, 0x14, 0x08,
82 | 0x02, 0x01, 0x59, 0x09, 0x06,
83 | 0x3E, 0x41, 0x5D, 0x59, 0x4E,
84 | 0x7C, 0x12, 0x11, 0x12, 0x7C,
85 | 0x7F, 0x49, 0x49, 0x49, 0x36,
86 | 0x3E, 0x41, 0x41, 0x41, 0x22,
87 | 0x7F, 0x41, 0x41, 0x41, 0x3E,
88 | 0x7F, 0x49, 0x49, 0x49, 0x41,
89 | 0x7F, 0x09, 0x09, 0x09, 0x01,
90 | 0x3E, 0x41, 0x41, 0x51, 0x73,
91 | 0x7F, 0x08, 0x08, 0x08, 0x7F,
92 | 0x00, 0x41, 0x7F, 0x41, 0x00,
93 | 0x20, 0x40, 0x41, 0x3F, 0x01,
94 | 0x7F, 0x08, 0x14, 0x22, 0x41,
95 | 0x7F, 0x40, 0x40, 0x40, 0x40,
96 | 0x7F, 0x02, 0x1C, 0x02, 0x7F,
97 | 0x7F, 0x04, 0x08, 0x10, 0x7F,
98 | 0x3E, 0x41, 0x41, 0x41, 0x3E,
99 | 0x7F, 0x09, 0x09, 0x09, 0x06,
100 | 0x3E, 0x41, 0x51, 0x21, 0x5E,
101 | 0x7F, 0x09, 0x19, 0x29, 0x46,
102 | 0x26, 0x49, 0x49, 0x49, 0x32,
103 | 0x03, 0x01, 0x7F, 0x01, 0x03,
104 | 0x3F, 0x40, 0x40, 0x40, 0x3F,
105 | 0x1F, 0x20, 0x40, 0x20, 0x1F,
106 | 0x3F, 0x40, 0x38, 0x40, 0x3F,
107 | 0x63, 0x14, 0x08, 0x14, 0x63,
108 | 0x03, 0x04, 0x78, 0x04, 0x03,
109 | 0x61, 0x59, 0x49, 0x4D, 0x43,
110 | 0x00, 0x7F, 0x41, 0x41, 0x41,
111 | 0x02, 0x04, 0x08, 0x10, 0x20,
112 | 0x00, 0x41, 0x41, 0x41, 0x7F,
113 | 0x04, 0x02, 0x01, 0x02, 0x04,
114 | 0x40, 0x40, 0x40, 0x40, 0x40,
115 | 0x00, 0x03, 0x07, 0x08, 0x00,
116 | 0x20, 0x54, 0x54, 0x78, 0x40,
117 | 0x7F, 0x28, 0x44, 0x44, 0x38,
118 | 0x38, 0x44, 0x44, 0x44, 0x28,
119 | 0x38, 0x44, 0x44, 0x28, 0x7F,
120 | 0x38, 0x54, 0x54, 0x54, 0x18,
121 | 0x00, 0x08, 0x7E, 0x09, 0x02,
122 | 0x18, 0xA4, 0xA4, 0x9C, 0x78,
123 | 0x7F, 0x08, 0x04, 0x04, 0x78,
124 | 0x00, 0x44, 0x7D, 0x40, 0x00,
125 | 0x20, 0x40, 0x40, 0x3D, 0x00,
126 | 0x7F, 0x10, 0x28, 0x44, 0x00,
127 | 0x00, 0x41, 0x7F, 0x40, 0x00,
128 | 0x7C, 0x04, 0x78, 0x04, 0x78,
129 | 0x7C, 0x08, 0x04, 0x04, 0x78,
130 | 0x38, 0x44, 0x44, 0x44, 0x38,
131 | 0xFC, 0x18, 0x24, 0x24, 0x18,
132 | 0x18, 0x24, 0x24, 0x18, 0xFC,
133 | 0x7C, 0x08, 0x04, 0x04, 0x08,
134 | 0x48, 0x54, 0x54, 0x54, 0x24,
135 | 0x04, 0x04, 0x3F, 0x44, 0x24,
136 | 0x3C, 0x40, 0x40, 0x20, 0x7C,
137 | 0x1C, 0x20, 0x40, 0x20, 0x1C,
138 | 0x3C, 0x40, 0x30, 0x40, 0x3C,
139 | 0x44, 0x28, 0x10, 0x28, 0x44,
140 | 0x4C, 0x90, 0x90, 0x90, 0x7C,
141 | 0x44, 0x64, 0x54, 0x4C, 0x44,
142 | 0x00, 0x08, 0x36, 0x41, 0x00,
143 | 0x00, 0x00, 0x77, 0x00, 0x00,
144 | 0x00, 0x41, 0x36, 0x08, 0x00,
145 | 0x02, 0x01, 0x02, 0x04, 0x02,
146 | 0x3C, 0x26, 0x23, 0x26, 0x3C,
147 | 0x1E, 0xA1, 0xA1, 0x61, 0x12,
148 | 0x3A, 0x40, 0x40, 0x20, 0x7A,
149 | 0x38, 0x54, 0x54, 0x55, 0x59,
150 | 0x21, 0x55, 0x55, 0x79, 0x41,
151 | 0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
152 | 0x21, 0x55, 0x54, 0x78, 0x40,
153 | 0x20, 0x54, 0x55, 0x79, 0x40,
154 | 0x0C, 0x1E, 0x52, 0x72, 0x12,
155 | 0x39, 0x55, 0x55, 0x55, 0x59,
156 | 0x39, 0x54, 0x54, 0x54, 0x59,
157 | 0x39, 0x55, 0x54, 0x54, 0x58,
158 | 0x00, 0x00, 0x45, 0x7C, 0x41,
159 | 0x00, 0x02, 0x45, 0x7D, 0x42,
160 | 0x00, 0x01, 0x45, 0x7C, 0x40,
161 | 0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
162 | 0xF0, 0x28, 0x25, 0x28, 0xF0,
163 | 0x7C, 0x54, 0x55, 0x45, 0x00,
164 | 0x20, 0x54, 0x54, 0x7C, 0x54,
165 | 0x7C, 0x0A, 0x09, 0x7F, 0x49,
166 | 0x32, 0x49, 0x49, 0x49, 0x32,
167 | 0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
168 | 0x32, 0x4A, 0x48, 0x48, 0x30,
169 | 0x3A, 0x41, 0x41, 0x21, 0x7A,
170 | 0x3A, 0x42, 0x40, 0x20, 0x78,
171 | 0x00, 0x9D, 0xA0, 0xA0, 0x7D,
172 | 0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
173 | 0x3D, 0x40, 0x40, 0x40, 0x3D,
174 | 0x3C, 0x24, 0xFF, 0x24, 0x24,
175 | 0x48, 0x7E, 0x49, 0x43, 0x66,
176 | 0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
177 | 0xFF, 0x09, 0x29, 0xF6, 0x20,
178 | 0xC0, 0x88, 0x7E, 0x09, 0x03,
179 | 0x20, 0x54, 0x54, 0x79, 0x41,
180 | 0x00, 0x00, 0x44, 0x7D, 0x41,
181 | 0x30, 0x48, 0x48, 0x4A, 0x32,
182 | 0x38, 0x40, 0x40, 0x22, 0x7A,
183 | 0x00, 0x7A, 0x0A, 0x0A, 0x72,
184 | 0x7D, 0x0D, 0x19, 0x31, 0x7D,
185 | 0x26, 0x29, 0x29, 0x2F, 0x28,
186 | 0x26, 0x29, 0x29, 0x29, 0x26,
187 | 0x30, 0x48, 0x4D, 0x40, 0x20,
188 | 0x38, 0x08, 0x08, 0x08, 0x08,
189 | 0x08, 0x08, 0x08, 0x08, 0x38,
190 | 0x2F, 0x10, 0xC8, 0xAC, 0xBA,
191 | 0x2F, 0x10, 0x28, 0x34, 0xFA,
192 | 0x00, 0x00, 0x7B, 0x00, 0x00,
193 | 0x08, 0x14, 0x2A, 0x14, 0x22,
194 | 0x22, 0x14, 0x2A, 0x14, 0x08,
195 | 0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
196 | 0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
197 | 0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
198 | 0x00, 0x00, 0x00, 0xFF, 0x00,
199 | 0x10, 0x10, 0x10, 0xFF, 0x00,
200 | 0x14, 0x14, 0x14, 0xFF, 0x00,
201 | 0x10, 0x10, 0xFF, 0x00, 0xFF,
202 | 0x10, 0x10, 0xF0, 0x10, 0xF0,
203 | 0x14, 0x14, 0x14, 0xFC, 0x00,
204 | 0x14, 0x14, 0xF7, 0x00, 0xFF,
205 | 0x00, 0x00, 0xFF, 0x00, 0xFF,
206 | 0x14, 0x14, 0xF4, 0x04, 0xFC,
207 | 0x14, 0x14, 0x17, 0x10, 0x1F,
208 | 0x10, 0x10, 0x1F, 0x10, 0x1F,
209 | 0x14, 0x14, 0x14, 0x1F, 0x00,
210 | 0x10, 0x10, 0x10, 0xF0, 0x00,
211 | 0x00, 0x00, 0x00, 0x1F, 0x10,
212 | 0x10, 0x10, 0x10, 0x1F, 0x10,
213 | 0x10, 0x10, 0x10, 0xF0, 0x10,
214 | 0x00, 0x00, 0x00, 0xFF, 0x10,
215 | 0x10, 0x10, 0x10, 0x10, 0x10,
216 | 0x10, 0x10, 0x10, 0xFF, 0x10,
217 | 0x00, 0x00, 0x00, 0xFF, 0x14,
218 | 0x00, 0x00, 0xFF, 0x00, 0xFF,
219 | 0x00, 0x00, 0x1F, 0x10, 0x17,
220 | 0x00, 0x00, 0xFC, 0x04, 0xF4,
221 | 0x14, 0x14, 0x17, 0x10, 0x17,
222 | 0x14, 0x14, 0xF4, 0x04, 0xF4,
223 | 0x00, 0x00, 0xFF, 0x00, 0xF7,
224 | 0x14, 0x14, 0x14, 0x14, 0x14,
225 | 0x14, 0x14, 0xF7, 0x00, 0xF7,
226 | 0x14, 0x14, 0x14, 0x17, 0x14,
227 | 0x10, 0x10, 0x1F, 0x10, 0x1F,
228 | 0x14, 0x14, 0x14, 0xF4, 0x14,
229 | 0x10, 0x10, 0xF0, 0x10, 0xF0,
230 | 0x00, 0x00, 0x1F, 0x10, 0x1F,
231 | 0x00, 0x00, 0x00, 0x1F, 0x14,
232 | 0x00, 0x00, 0x00, 0xFC, 0x14,
233 | 0x00, 0x00, 0xF0, 0x10, 0xF0,
234 | 0x10, 0x10, 0xFF, 0x10, 0xFF,
235 | 0x14, 0x14, 0x14, 0xFF, 0x14,
236 | 0x10, 0x10, 0x10, 0x1F, 0x00,
237 | 0x00, 0x00, 0x00, 0xF0, 0x10,
238 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
239 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
240 | 0xFF, 0xFF, 0xFF, 0x00, 0x00,
241 | 0x00, 0x00, 0x00, 0xFF, 0xFF,
242 | 0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
243 | 0x38, 0x44, 0x44, 0x38, 0x44,
244 | 0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
245 | 0x7E, 0x02, 0x02, 0x06, 0x06,
246 | 0x02, 0x7E, 0x02, 0x7E, 0x02,
247 | 0x63, 0x55, 0x49, 0x41, 0x63,
248 | 0x38, 0x44, 0x44, 0x3C, 0x04,
249 | 0x40, 0x7E, 0x20, 0x1E, 0x20,
250 | 0x06, 0x02, 0x7E, 0x02, 0x02,
251 | 0x99, 0xA5, 0xE7, 0xA5, 0x99,
252 | 0x1C, 0x2A, 0x49, 0x2A, 0x1C,
253 | 0x4C, 0x72, 0x01, 0x72, 0x4C,
254 | 0x30, 0x4A, 0x4D, 0x4D, 0x30,
255 | 0x30, 0x48, 0x78, 0x48, 0x30,
256 | 0xBC, 0x62, 0x5A, 0x46, 0x3D,
257 | 0x3E, 0x49, 0x49, 0x49, 0x00,
258 | 0x7E, 0x01, 0x01, 0x01, 0x7E,
259 | 0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
260 | 0x44, 0x44, 0x5F, 0x44, 0x44,
261 | 0x40, 0x51, 0x4A, 0x44, 0x40,
262 | 0x40, 0x44, 0x4A, 0x51, 0x40,
263 | 0x00, 0x00, 0xFF, 0x01, 0x03,
264 | 0xE0, 0x80, 0xFF, 0x00, 0x00,
265 | 0x08, 0x08, 0x6B, 0x6B, 0x08,
266 | 0x36, 0x12, 0x36, 0x24, 0x36,
267 | 0x06, 0x0F, 0x09, 0x0F, 0x06,
268 | 0x00, 0x00, 0x18, 0x18, 0x00,
269 | 0x00, 0x00, 0x10, 0x10, 0x00,
270 | 0x30, 0x40, 0xFF, 0x01, 0x01,
271 | 0x00, 0x1F, 0x01, 0x01, 0x1E,
272 | 0x00, 0x19, 0x1D, 0x17, 0x12,
273 | 0x00, 0x3C, 0x3C, 0x3C, 0x3C,
274 | 0x00, 0x00, 0x00, 0x00, 0x00 // #255 NBSP
275 | };
276 | #endif // FONT5X7_H
277 |
--------------------------------------------------------------------------------
/libraries/Adafruit_ILI9341/Adafruit_ILI9341.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Adafruit_ILI9341.h
3 | *
4 | * Created on: 08.07.2017
5 | * Author: christoph
6 | */
7 |
8 | #ifndef ADAFRUIT_ILI9341_H_
9 | #define ADAFRUIT_ILI9341_H_
10 |
11 | #define ILI9341_TFTWIDTH 240
12 | #define ILI9341_TFTHEIGHT 320
13 | //#define ILI9341_TFTWIDTH 128 // ChrisMicro
14 | //#define ILI9341_TFTHEIGHT 160
15 |
16 | #define ILI9341_NOP 0x00
17 | #define ILI9341_SWRESET 0x01
18 | #define ILI9341_RDDID 0x04
19 | #define ILI9341_RDDST 0x09
20 |
21 | #define ILI9341_SLPIN 0x10
22 | #define ILI9341_SLPOUT 0x11
23 | #define ILI9341_PTLON 0x12
24 | #define ILI9341_NORON 0x13
25 |
26 | #define ILI9341_RDMODE 0x0A
27 | #define ILI9341_RDMADCTL 0x0B
28 | #define ILI9341_RDPIXFMT 0x0C
29 | #define ILI9341_RDIMGFMT 0x0D
30 | #define ILI9341_RDSELFDIAG 0x0F
31 |
32 | #define ILI9341_INVOFF 0x20
33 | #define ILI9341_INVON 0x21
34 | #define ILI9341_GAMMASET 0x26
35 | #define ILI9341_DISPOFF 0x28
36 | #define ILI9341_DISPON 0x29
37 |
38 | #define ILI9341_CASET 0x2A
39 | #define ILI9341_PASET 0x2B
40 | #define ILI9341_RAMWR 0x2C
41 | #define ILI9341_RAMRD 0x2E
42 |
43 | #define ILI9341_PTLAR 0x30
44 | #define ILI9341_MADCTL 0x36
45 | #define ILI9341_VSCRSADD 0x37
46 | #define ILI9341_PIXFMT 0x3A
47 |
48 | #define ILI9341_FRMCTR1 0xB1
49 | #define ILI9341_FRMCTR2 0xB2
50 | #define ILI9341_FRMCTR3 0xB3
51 | #define ILI9341_INVCTR 0xB4
52 | #define ILI9341_DFUNCTR 0xB6
53 |
54 | #define ILI9341_PWCTR1 0xC0
55 | #define ILI9341_PWCTR2 0xC1
56 | #define ILI9341_PWCTR3 0xC2
57 | #define ILI9341_PWCTR4 0xC3
58 | #define ILI9341_PWCTR5 0xC4
59 | #define ILI9341_VMCTR1 0xC5
60 | #define ILI9341_VMCTR2 0xC7
61 |
62 | #define ILI9341_RDID1 0xDA
63 | #define ILI9341_RDID2 0xDB
64 | #define ILI9341_RDID3 0xDC
65 | #define ILI9341_RDID4 0xDD
66 |
67 | #define ILI9341_GMCTRP1 0xE0
68 | #define ILI9341_GMCTRN1 0xE1
69 | /*
70 | #define ILI9341_PWCTR6 0xFC
71 |
72 | */
73 |
74 | // Color definitions
75 | #define ILI9341_BLACK 0x0000 /* 0, 0, 0 */
76 | #define ILI9341_NAVY 0x000F /* 0, 0, 128 */
77 | #define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */
78 | #define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */
79 | #define ILI9341_MAROON 0x7800 /* 128, 0, 0 */
80 | #define ILI9341_PURPLE 0x780F /* 128, 0, 128 */
81 | #define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */
82 | #define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */
83 | #define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */
84 | #define ILI9341_BLUE 0x001F /* 0, 0, 255 */
85 | #define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */
86 | #define ILI9341_CYAN 0x07FF /* 0, 255, 255 */
87 | #define ILI9341_RED 0xF800 /* 255, 0, 0 */
88 | #define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */
89 | #define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */
90 | #define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */
91 | #define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */
92 | #define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
93 | #define ILI9341_PINK 0xF81F
94 |
95 | #include "TFT_LinuxWrapper.h"
96 |
97 | class Adafruit_ILI9341 : public TFT_LinuxWrapper{
98 | public:
99 | Adafruit_ILI9341(int dummy1, int dummy2)
100 | {
101 |
102 | }
103 |
104 | };
105 |
106 | #endif /* ADAFRUIT_ILI9341_H_ */
107 |
--------------------------------------------------------------------------------
/libraries/Adafruit_STMPE610/Adafruit_STMPE610.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Adafruit_STMPE610.h
3 | *
4 | * Created on: 08.07.2017
5 | * Author: christoph
6 | */
7 |
8 | #ifndef ADAFRUIT_STMPE610_H_
9 | #define ADAFRUIT_STMPE610_H_
10 |
11 | #include "Touch_LinuxWrapper.h"
12 |
13 | #define TS_Point TSPoint
14 |
15 | #define _TS_MINX 150
16 | #define _TS_MINY 130
17 | #define _TS_MAXX 3800
18 | #define _TS_MAXY 4000
19 | #define _TFT_WIDTH 480
20 | #define _TFT_HEIGHT 270
21 |
22 | class Adafruit_STMPE610 : public TouchScreen {
23 | public:
24 | Adafruit_STMPE610(int dummy)
25 | {
26 |
27 | }
28 | bool begin()
29 | {
30 | return 1;
31 | }
32 | TS_Point getPoint()
33 | {
34 | TS_Point p;
35 | p=TouchScreen::getPoint();
36 | //p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
37 | //p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
38 | p.x = map(p.x, 0, _TFT_WIDTH,_TS_MINX, _TS_MAXX );
39 | p.y = map(p.y, 0, _TFT_HEIGHT,_TS_MINY, _TS_MAXY );
40 | return p;
41 | }
42 |
43 | bool bufferEmpty()
44 | {
45 | TS_Point p;
46 | p=TouchScreen::getPoint();
47 | return (p.z==0);
48 | }
49 | };
50 |
51 | #endif /* ADAFRUIT_STMPE610_H_ */
52 |
--------------------------------------------------------------------------------
/libraries/GuiPittix/TFT_Adapter.h:
--------------------------------------------------------------------------------
1 | #ifdef TFT_Adapter_STM32F746_Discovery
2 | #include "TFT_Adapter_STM32F746_Discovery.h"
3 | #elif defined TFT_Adapter_ILI9341_BluePill
4 | #include "TFT_Adapter_ILI9341_BluePill.h"
5 | #elif defined TFT_Adapter_SPFD5408_UNO
6 | #include "TFT_Adapter_SPFD5408_UNO.h"
7 | #elif defined TFT_TEK
8 | #include "TFT_TEK_wrapper.h"
9 | #elif defined TFT_PC
10 | #include "TFT_Pc.h"
11 | #endif
12 |
--------------------------------------------------------------------------------
/libraries/GuiPittix/TFT_Pc.h:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | by ChrisMicro
4 |
5 | */
6 | #ifndef _TFT_ADAPTER_
7 | #define _TFT_ADAPTER_
8 |
9 | #include
10 |
11 | //#include "SPI.h"
12 | #include "Adafruit_GFX.h"
13 | #include "Adafruit_ILI9341.h"
14 |
15 |
16 |
17 |
18 |
19 | class TFT_Adapter : public Adafruit_ILI9341
20 | {
21 | public:
22 | TFT_Adapter():Adafruit_ILI9341(480,272){};
23 | void begin()
24 | {
25 | Adafruit_ILI9341::begin();
26 | //Adafruit_ILI9341::setRotation(1);
27 | };
28 |
29 | };
30 |
31 | #define COLOR_BLACK 0x0000 /* 0, 0, 0 */
32 | #define COLOR_NAVY 0x000F /* 0, 0, 128 */
33 | #define COLOR_DARKGREEN 0x03E0 /* 0, 128, 0 */
34 | #define COLOR_DARKCYAN 0x03EF /* 0, 128, 128 */
35 | #define COLOR_MAROON 0x7800 /* 128, 0, 0 */
36 | #define COLOR_PURPLE 0x780F /* 128, 0, 128 */
37 | #define COLOR_OLIVE 0x7BE0 /* 128, 128, 0 */
38 | #define COLOR_LIGHTGREY 0xC618 /* 192, 192, 192 */
39 | #define COLOR_DARKGREY 0x7BEF /* 128, 128, 128 */
40 | #define COLOR_GREY COLOR_LIGHTGREY
41 | #define COLOR_BLUE 0x001F /* 0, 0, 255 */
42 | #define COLOR_GREEN 0x07E0 /* 0, 255, 0 */
43 | #define COLOR_CYAN 0x07FF /* 0, 255, 255 */
44 | #define COLOR_RED 0xF800 /* 255, 0, 0 */
45 | #define COLOR_MAGENTA 0xF81F /* 255, 0, 255 */
46 | #define COLOR_YELLOW 0xFFE0 /* 255, 255, 0 */
47 | #define COLOR_WHITE 0xFFFF /* 255, 255, 255 */
48 | #define COLOR_ORANGE 0xFD20 /* 255, 165, 0 */
49 | #define COLOR_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
50 | #define COLOR_PINK 0xF81F
51 |
52 | #endif // _TFT_ADAPTER_
53 |
54 | /* GuiPittix simple graphical user interface elemetns
55 | *
56 | * © ChrisMicro 2017.
57 | *
58 | * This file is part of GuiPittix.
59 | *
60 | * GuiPittix is free software: you can redistribute it and/or modify
61 | * it under the terms of the GNU Lesser General Public License as published by
62 | * the Free Software Foundation, either version 3 of the License, or
63 | * (at your option) any later version.
64 | *
65 | * GuiPittix is distributed in the hope that it will be useful,
66 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
67 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68 | * GNU Lesser General Public License for more details.
69 | *
70 | * You should have received a copy of the GNU Lesser General Public License
71 | * along with simple_GUI_elements. If not, see .
72 | *
73 | * If you use simple_GUI_elements in public project you can inform me about this by e-mail,
74 | * of course if you want it.
75 | *
76 | * web-site: https://github.com/ChrisMicro/GuiPittix
77 | */
78 |
79 |
80 |
--------------------------------------------------------------------------------
/libraries/SPI/SPI.cpp:
--------------------------------------------------------------------------------
1 | #include "SPI.h"
2 |
3 | // Preinstantiate Objects
4 | SPIClass SPI;
5 | static SPIClass* p_SPIMock = &SPI;
6 |
7 | void SPIClass::begin() {
8 | p_SPIMock->begin();
9 | }
10 |
11 | void SPIClass::usingInterrupt(uint8_t a) {
12 | p_SPIMock->usingInterrupt(a);
13 | }
14 |
15 | void SPIClass::notUsingInterrupt(uint8_t a) {
16 | p_SPIMock->notUsingInterrupt(a);
17 | }
18 |
19 |
20 | void SPIClass::beginTransaction(SPISettings a) {
21 | return p_SPIMock->beginTransaction(a);
22 | }
23 |
24 | uint8_t SPIClass::transfer(uint8_t a) {
25 | return p_SPIMock->transfer(a);
26 | }
27 |
28 | uint16_t SPIClass::transfer16(uint16_t a) {
29 | return p_SPIMock->transfer16(a);
30 | }
31 |
32 | void SPIClass::transfer(void * a, size_t b) {
33 | return p_SPIMock->transfer(a, b);
34 | }
35 |
36 | void SPIClass::endTransaction(void) {
37 | return p_SPIMock->endTransaction();
38 | }
39 |
40 | void SPIClass::end(void) {
41 | return p_SPIMock->end();
42 | }
43 |
44 | void SPIClass::setBitOrder(uint8_t a) {
45 | p_SPIMock->setBitOrder(a);
46 | }
47 |
48 | void SPIClass::setDataMode(uint8_t a) {
49 | p_SPIMock->setDataMode(a);
50 | }
51 |
52 | void SPIClass::setClockDivider(uint8_t a) {
53 | return p_SPIMock->setClockDivider(a);
54 | }
55 |
56 | void SPIClass::attachInterrupt() {
57 | return p_SPIMock->attachInterrupt();
58 | }
59 |
60 | void SPIClass::detachInterrupt() {
61 | return p_SPIMock->detachInterrupt();
62 | }
63 |
--------------------------------------------------------------------------------
/libraries/SPI/SPI.h:
--------------------------------------------------------------------------------
1 | // Header for SPI Mock
2 |
3 | #ifndef __SPI_h__
4 | #define __SPI_h__
5 |
6 | #include
7 | #include
8 |
9 | const uint8_t SPI_MODE0 = 0x00; ///< CPOL: 0 CPHA: 0
10 | const uint8_t SPI_MODE1 = 0x01; ///< CPOL: 0 CPHA: 1
11 | const uint8_t SPI_MODE2 = 0x10; ///< CPOL: 1 CPHA: 0
12 | const uint8_t SPI_MODE3 = 0x11; ///< CPOL: 1 CPHA: 1
13 |
14 | class SPISettings {
15 | uint32_t _a;
16 | uint8_t _b;
17 | uint8_t _c;
18 | public:
19 | SPISettings(uint32_t a, uint8_t b, uint8_t c): _a(a), _b(b), _c(c) {}
20 | SPISettings();
21 | bool operator==(const SPISettings& rhs)const {
22 | return _a == rhs._a && _b == rhs._b && _c == rhs._c;
23 | }
24 | };
25 |
26 | class SPIClass {
27 | public:
28 | void begin();
29 | void usingInterrupt(uint8_t );
30 | void notUsingInterrupt(uint8_t );
31 | void beginTransaction(SPISettings );
32 | uint8_t transfer(uint8_t );
33 | uint16_t transfer16(uint16_t );
34 | void transfer(void *, size_t );
35 | void endTransaction(void);
36 | void end();
37 | void setBitOrder(uint8_t);
38 | void setDataMode(uint8_t );
39 | void setClockDivider(uint8_t clockDiv);
40 | void attachInterrupt();
41 | void detachInterrupt();
42 | };
43 |
44 | extern SPIClass SPI;
45 | #endif
46 |
--------------------------------------------------------------------------------
/libraries/Wire/Wire.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Wire.cpp
3 | *
4 | * only dummy functions
5 | *
6 | * Created on: 27.07.2017
7 | * Author: ChrisMicro
8 | */
9 |
10 | #include "Wire.h"
11 | #include
12 |
13 | /** TwoWire object used when in slave interrupt
14 | */
15 | TwoWire *slaveTwoWire[4];
16 |
17 | TwoWire::TwoWire(I2C_TypeDef *instance)
18 | {
19 | handle.Instance = instance;
20 | }
21 |
22 | TwoWire::TwoWire(I2C_TypeDef *instance, uint8_t sda, uint8_t scl)
23 | {
24 | handle.Instance = instance;
25 | }
26 |
27 | void TwoWire::begin(void)
28 | {
29 | }
30 |
31 | void TwoWire::begin(uint8_t address)
32 | {
33 | }
34 |
35 | void TwoWire::begin(int address)
36 | {
37 | }
38 |
39 | void TwoWire::end(void)
40 | {
41 | }
42 |
43 |
44 | void TwoWire::setClock(uint32_t frequency)
45 | {
46 | }
47 |
48 | uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint32_t iaddress, uint8_t isize, uint8_t sendStop)
49 | {
50 | return 0;
51 | }
52 |
53 | uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity, uint8_t sendStop)
54 | {
55 | return requestFrom((uint8_t)address, (uint8_t)quantity, (uint32_t)0, (uint8_t)0, (uint8_t)sendStop);
56 | }
57 |
58 | uint8_t TwoWire::requestFrom(uint8_t address, uint8_t quantity)
59 | {
60 | return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
61 | }
62 |
63 | uint8_t TwoWire::requestFrom(int address, int quantity)
64 | {
65 | return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)true);
66 | }
67 |
68 | uint8_t TwoWire::requestFrom(int address, int quantity, int sendStop)
69 | {
70 | return requestFrom((uint8_t)address, (uint8_t)quantity, (uint8_t)sendStop);
71 | }
72 |
73 | void TwoWire::beginTransmission(uint8_t address)
74 | {
75 | }
76 |
77 | void TwoWire::beginTransmission(int address)
78 | {
79 | beginTransmission((uint8_t)address);
80 | }
81 |
82 | uint8_t TwoWire::endTransmission(uint8_t sendStop)
83 | {
84 | int8_t ret = 4;
85 | return ret;
86 | }
87 |
88 | // This provides backwards compatibility with the original
89 | // definition, and expected behaviour, of endTransmission
90 | //
91 | uint8_t TwoWire::endTransmission(void)
92 | {
93 | return endTransmission(true);
94 | }
95 |
96 | // must be called in:
97 | // slave tx event callback
98 | // or after beginTransmission(address)
99 | size_t TwoWire::write(uint8_t data)
100 | {
101 | return 1;
102 | }
103 |
104 | // must be called in:
105 | // slave tx event callback
106 | // or after beginTransmission(address)
107 | size_t TwoWire::write(const uint8_t *data, size_t quantity)
108 | {
109 | return quantity;
110 | }
111 |
112 | // must be called in:
113 | // slave rx event callback
114 | // or after requestFrom(address, numBytes)
115 | int TwoWire::available(void)
116 | {
117 | return rxBufferLength - rxBufferIndex;
118 | }
119 |
120 | // must be called in:
121 | // slave rx event callback
122 | // or after requestFrom(address, numBytes)
123 | int TwoWire::read(void)
124 | {
125 | int value = -1;
126 | return value;
127 | }
128 |
129 | // must be called in:
130 | // slave rx event callback
131 | // or after requestFrom(address, numBytes)
132 | int TwoWire::peek(void)
133 | {
134 | int value = -1;
135 | return value;
136 | }
137 |
138 | void TwoWire::flush(void)
139 | {
140 | }
141 |
142 | void TwoWire::stm32SetInstance(I2C_TypeDef *instance)
143 | {
144 | handle.Instance = instance;
145 | }
146 |
147 | void TwoWire::stm32SetSDA(uint8_t sda)
148 | {
149 | }
150 |
151 | void TwoWire::stm32SetSCL(uint8_t scl)
152 | {
153 | }
154 |
155 | TwoWire *interruptWire;
156 |
157 |
158 | extern "C" void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *handle)
159 | {
160 | }
161 |
162 | // behind the scenes function that is called when data is received
163 | void TwoWire::onReceiveService(uint8_t* inBytes, int numBytes)
164 | {
165 | }
166 |
167 | // behind the scenes function that is called when data is requested
168 | void TwoWire::onRequestService()
169 | {
170 | }I2C_TypeDef *instance;
171 |
172 | // sets function called on slave write
173 | void TwoWire::onReceive( void (*function)(int) )
174 | {
175 | }
176 |
177 | // sets function called on slave read
178 | void TwoWire::onRequest( void (*function)(void) )
179 | {
180 | }
181 |
182 | TwoWire Wire(instance);
183 |
184 |
185 |
--------------------------------------------------------------------------------
/libraries/Wire/Wire.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Wire.h
3 | *
4 | * only dummy functions
5 | *
6 | * Created on: 27.07.2017
7 | * Author: ChrisMicro
8 | *
9 | */
10 |
11 | #ifndef LIBRARIES_WIRE_WIRE_H_
12 | #define LIBRARIES_WIRE_WIRE_H_
13 |
14 | /*
15 | TwoWire.h - TWI/I2C library for Arduino & Wiring
16 | Copyright (c) 2006 Nicholas Zambetti. All right reserved.
17 |
18 | This library is free software; you can redistribute it and/or
19 | modify it under the terms of the GNU Lesser General Public
20 | License as published by the Free Software Foundation; either
21 | version 2.1 of the License, or (at your option) any later version.
22 |
23 | This library is distributed in the hope that it will be useful,
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
26 | Lesser General Public License for more details.
27 |
28 | You should have received a copy of the GNU Lesser General Public
29 | License along with this library; if not, write to the Free Software
30 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 |
32 | Modified 2012 by Todd Krein (todd@krein.org) to implement repeated starts
33 | */
34 |
35 | #ifndef TwoWire_h
36 | #define TwoWire_h
37 |
38 | #include
39 | #include "Stream.h"
40 |
41 | typedef struct
42 | {
43 |
44 | } I2C_TypeDef;
45 |
46 | typedef struct __I2C_HandleTypeDef
47 | {
48 | I2C_TypeDef *Instance; /*!< I2C registers base address */
49 |
50 | }I2C_HandleTypeDef;
51 |
52 |
53 | #define BUFFER_LENGTH 32
54 |
55 | // WIRE_HAS_END means Wire has end()
56 | #define WIRE_HAS_END 1
57 |
58 | class TwoWire : public Stream {
59 | public:
60 | uint8_t rxBuffer[BUFFER_LENGTH];
61 | uint8_t rxBufferIndex;
62 | uint8_t rxBufferLength;
63 |
64 | uint8_t txAddress;
65 | uint8_t txBuffer[BUFFER_LENGTH];
66 | uint8_t txBufferIndex;
67 | uint8_t txBufferLength;
68 |
69 | uint8_t isMaster;
70 | uint8_t address;
71 |
72 | uint8_t slaveBuffer;
73 |
74 | void (*user_onRequest)(void) = NULL;
75 | void (*user_onReceive)(int) = NULL;
76 | void onRequestService(void);
77 | void onReceiveService(uint8_t*, int);
78 |
79 | TwoWire(I2C_TypeDef *instance);
80 |
81 | TwoWire(I2C_TypeDef *instance, uint8_t sda, uint8_t scl);
82 |
83 | void begin();
84 | void begin(uint8_t);
85 | void begin(int);
86 | void end();
87 | void setClock(uint32_t);
88 | void beginTransmission(uint8_t);
89 | void beginTransmission(int);
90 | uint8_t endTransmission(void);
91 | uint8_t endTransmission(uint8_t);
92 | uint8_t requestFrom(uint8_t, uint8_t);
93 | uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
94 | uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
95 | uint8_t requestFrom(int, int);
96 | uint8_t requestFrom(int, int, int);
97 | virtual size_t write(uint8_t);
98 | virtual size_t write(const uint8_t *, size_t);
99 | virtual int available(void);
100 | virtual int read(void);
101 | virtual int peek(void);
102 | virtual void flush(void);
103 | void onReceive( void (*)(int) );
104 | void onRequest( void (*)(void) );
105 |
106 | void stm32SetInstance(I2C_TypeDef *instance);
107 | void stm32SetSDA(uint8_t sda);
108 | void stm32SetSCL(uint8_t scl);
109 |
110 | inline size_t write(unsigned long n) { return write((uint8_t)n); }
111 | inline size_t write(long n) { return write((uint8_t)n); }
112 | inline size_t write(unsigned int n) { return write((uint8_t)n); }
113 | inline size_t write(int n) { return write((uint8_t)n); }
114 | using Print::write;
115 |
116 | I2C_HandleTypeDef handle;
117 | };
118 |
119 | extern TwoWire Wire;
120 |
121 | #endif
122 |
123 |
124 | #endif /* LIBRARIES_WIRE_WIRE_H_ */
125 |
--------------------------------------------------------------------------------
/makeNativeArduino.mk:
--------------------------------------------------------------------------------
1 | penultimateword = $(wordlist $(words $1),$(words $1), x $1)
2 |
3 | SKETCH_ROOT := $(shell dirname $(abspath $(call penultimateword, $(MAKEFILE_LIST))))
4 | NATIVE_ROOT := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
5 |
6 | Q ?= @
7 |
8 | BUILD_ROOT ?= build
9 | SKETCH ?= $(shell find $(SKETCH_ROOT) -maxdepth 1 -name "*.ino")
10 |
11 | TARGET := $(shell basename -s .ino $(SKETCH))
12 |
13 | $(shell mkdir -p $(BUILD_ROOT))
14 |
15 | CFLAGS += -Wall -Wextra -Wno-unused-parameter
16 | CFLAGS += -DARDUINO=101 -DSKETCH_FILE=\"$(SKETCH)\"
17 | CFLAGS += -std=gnu11
18 | CFLAGS += -lm
19 | CFLAGS += -DARDUINOONPC
20 | #CFLAGS += -DFASTLED_SDL $(shell sdl2-config --cflags)
21 |
22 | CXXFLAGS += -Wall -Wextra -Wno-unused-parameter
23 | CXXFLAGS += -DARDUINO=101 -DSKETCH_FILE=\"$(SKETCH)\"
24 | CXXFLAGS += -Wno-class-memaccess # FastLED does some naughty things
25 | CXXFLAGS += -std=gnu++11
26 | CXXFLAGS += -DARDUINOONPC
27 | #CXXFLAGS += -DFASTLED_SDL $(shell sdl2-config --cflags)
28 |
29 | LDFLAGS += -Wl,--gc-sections
30 | LDFLAGS += -L/usr/X11R6/lib -lX11 # include X11 library
31 | LDFLAGS += -pthread # include linux thread library
32 | #LDFLAGS += $(shell sdl2-config --libs)
33 |
34 | DEPDIR := $(BUILD_ROOT)
35 | DEPFLAGS = -MT $@ -MMD -MP -MF $(DEPDIR)/$*.Td
36 | POSTCOMPILE = @mv -f $(DEPDIR)/$*.Td $(DEPDIR)/$*.d && touch $@
37 |
38 | define add_lib
39 | SRC_C += $(shell find $1 -name '*.c')
40 | SRC_CXX += $(shell find $1 -name '*.cpp')
41 | SRC_USER_C = $(shell find $(SKETCH_ROOT) -name "*.c")
42 | SRC_USER_CXX = $(shell find $(SKETCH_ROOT) -name "*.cpp")
43 |
44 | INCLUDES += -I$1
45 | endef
46 |
47 | INCLUDES += -I$(SKETCH_ROOT)
48 | INCLUDES += -I$(NATIVE_ROOT)/src/cores/arduino -I$(NATIVE_ROOT)/src/system
49 | $(eval $(call add_lib,$(NATIVE_ROOT)/src))
50 |
51 | $(foreach lib, $(ARDUINO_LIBS), $(eval $(call add_lib,$(NATIVE_ROOT)/libraries/$(lib))))
52 |
53 | USER_FOLDERS = $(shell find $(SKETCH_ROOT) -path $(SKETCH_ROOT)/build -prune -o -type d -print)
54 | INC_USER_FOLDERS = $(foreach folder, $(USER_FOLDERS), -I$(folder))
55 |
56 |
57 | OBJECTS += $(SRC_C:%.c=$(BUILD_ROOT)/%.o)
58 | OBJECTS += $(SRC_CXX:%.cpp=$(BUILD_ROOT)/%.o)
59 | OBJECTS += $(SRC_USER_C:%.c=$(BUILD_ROOT)/%.o)
60 | OBJECTS += $(SRC_USER_CXX:%.cpp=$(BUILD_ROOT)/%.o)
61 |
62 | SRCS += $(SRC_C)
63 | SRCS += $(SRC_CXX)
64 | SRCS += $(SRC_USER_C)
65 | SRCS += $(SRC_USER_CXX)
66 |
67 | $(TARGET): $(OBJECTS)
68 | $(Q)$(CXX) $(INC_USER_FOLDERS) $(INCLUDES) $(OBJECTS) $(LDFLAGS) -o $@
69 | @size $@
70 |
71 | clean:
72 | rm -r $(BUILD_ROOT)
73 | rm $(TARGET)
74 |
75 | print:
76 | @echo "BUILD_ROOT:\t $(BUILD_ROOT)"
77 | @echo "INCLUDES:\t $(INCLUDES)"
78 | @echo "OBJECTS:\t $(OBJECTS)"
79 | @echo "SRCS:\t $(SRCS)"
80 | @echo "SKETCH:\t $(SKETCH)"
81 | @echo "ROOT:\t $(NATIVE_ROOT)"
82 | @echo "SRC_C :\t $(SRC_C)"
83 | @echo "SRC_CXX :\t $(SRC_CXX)"
84 | @echo "SRC_USER:\t $(SRC_USER)"
85 | @echo ":\t $(INC_USER_FOLDERS)"
86 |
87 |
88 | $(BUILD_ROOT)/%.o : %.c $(DEPDIR)/%.d
89 | @mkdir -p `dirname $@`
90 | $(Q)$(CC) $(DEPFLAGS) $(CFLAGS) $(INCLUDES) -c $< -o $@
91 | $(POSTCOMPILE)
92 |
93 | $(BUILD_ROOT)/%.o : %.cpp $(DEPDIR)/%.d
94 | @mkdir -p `dirname $@`
95 | $(Q)$(CXX) $(DEPFLAGS) $(CXXFLAGS) $(INCLUDES) -c $< -o $@
96 | $(POSTCOMPILE)
97 |
98 | $(DEPDIR)/%.d: ;
99 | .PRECIOUS: $(DEPDIR)/%.d
100 |
101 | include $(wildcard $(patsubst %,$(DEPDIR)/%.d,$(basename $(SRCS))))
102 |
--------------------------------------------------------------------------------
/src/cores/arduino/Arduino.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Arduino.h
3 | *
4 | * Created on: 06.07.2017
5 | * Author: christoph
6 | */
7 |
8 | #ifndef ARDUINO_H_
9 | #define ARDUINO_H_
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include
16 |
17 | //#include "posixWrapper.h"
18 | #include "binary.h"
19 | #include "posixTime.h"
20 |
21 | #include "SerialConsole.h"
22 |
23 | #define A0 0
24 | #define A1 1
25 | #define A2 2
26 | #define A3 3
27 | #define A4 4
28 | #define A5 5
29 |
30 | #define HIGH 0x1
31 | #define LOW 0x0
32 |
33 | #define INPUT 0x0
34 | #define OUTPUT 0x1
35 | #define INPUT_PULLUP 0x2
36 |
37 | #define LSBFIRST 0
38 | #define MSBFIRST 1
39 |
40 | #define PI 3.1415926535897932384626433832795
41 | #define HALF_PI 1.5707963267948966192313216916398
42 | #define TWO_PI 6.283185307179586476925286766559
43 | #define DEG_TO_RAD 0.017453292519943295769236907684886
44 | #define RAD_TO_DEG 57.295779513082320876798154814105
45 | #define EULER 2.718281828459045235360287471352
46 |
47 | typedef int boolean;
48 | //#define NULL 0
49 |
50 |
51 | #define min(a,b) ((a)<(b)?(a):(b))
52 | #define max(a,b) ((a)>(b)?(a):(b))
53 | //#define abs(x) ((x)>0?(x):-(x))
54 | #define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt)))
55 | #define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5))
56 | #define radians(deg) ((deg)*DEG_TO_RAD)
57 | #define degrees(rad) ((rad)*RAD_TO_DEG)
58 | #define sq(x) ((x)*(x))
59 |
60 | typedef unsigned int word;
61 |
62 | #define bit(b) (1UL << (b))
63 |
64 | //typedef bool int;
65 | typedef uint8_t byte;
66 |
67 | // WMath prototypes
68 | long random(long);
69 | long random(long, long);
70 | void randomSeed(unsigned long);
71 | long map(long, long, long, long, long);
72 |
73 | // wiring_digital.cpp
74 | void pinMode(uint8_t, uint8_t);
75 | void digitalWrite(uint8_t, uint8_t);
76 | int digitalRead(uint8_t);
77 |
78 | // wiring_analog.cpp
79 | int analogRead(uint8_t);
80 | void analogReference(uint8_t mode);
81 | void analogWrite(uint8_t, int);
82 |
83 |
84 | #endif /* ARDUINO_H_ */
85 |
--------------------------------------------------------------------------------
/src/cores/arduino/Print.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Print.cpp - Base class that provides print() and println()
3 | Copyright (c) 2008 David A. Mellis. All right reserved.
4 |
5 | This library is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU Lesser General Public
7 | License as published by the Free Software Foundation; either
8 | version 2.1 of the License, or (at your option) any later version.
9 |
10 | This library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 |
19 | Modified 23 November 2006 by David A. Mellis
20 | Modified 03 August 2015 by Chuck Todd
21 | */
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include "Arduino.h"
28 |
29 | #include "Print.h"
30 |
31 | using namespace std;
32 |
33 | // Public Methods //////////////////////////////////////////////////////////////
34 |
35 | /* default implementation: may be overridden */
36 | size_t Print::write(const uint8_t *buffer, size_t size)
37 | {
38 | size_t n = 0;
39 | while (size--) {
40 | if (write(*buffer++)) n++;
41 | else break;
42 | }
43 | return n;
44 | }
45 |
46 | size_t Print::print(const __FlashStringHelper *ifsh)
47 | {
48 | return print(reinterpret_cast(ifsh));
49 | }
50 |
51 | size_t Print::print(const String &s)
52 | {
53 | return write(s.c_str(), s.length());
54 | }
55 |
56 | size_t Print::print(const char str[])
57 | {
58 | return write(str);
59 | }
60 |
61 | size_t Print::print(char c)
62 | {
63 | return write(c);
64 | }
65 |
66 | size_t Print::print(unsigned char b, int base)
67 | {
68 | return print((unsigned long) b, base);
69 | }
70 |
71 | size_t Print::print(int n, int base)
72 | {
73 | return print((long) n, base);
74 | }
75 |
76 | size_t Print::print(unsigned int n, int base)
77 | {
78 | return print((unsigned long) n, base);
79 | }
80 |
81 | size_t Print::print(long n, int base)
82 | {
83 | if (base == 0) {
84 | return write(n);
85 | } else if (base == 10) {
86 | if (n < 0) {
87 | int t = print('-');
88 | n = -n;
89 | return printNumber(n, 10) + t;
90 | }
91 | return printNumber(n, 10);
92 | } else {
93 | return printNumber(n, base);
94 | }
95 | }
96 |
97 | size_t Print::print(unsigned long n, int base)
98 | {
99 | if (base == 0) return write(n);
100 | else return printNumber(n, base);
101 | }
102 |
103 | size_t Print::print(long long n, int base)
104 | {
105 | if (base == 0) {
106 | return write(n);
107 | } else if (base == 10) {
108 | if (n < 0) {
109 | int t = print('-');
110 | n = -n;
111 | return printNumber(n, 10) + t;
112 | }
113 | return printNumber(n, 10);
114 | } else {
115 | return printNumber(n, base);
116 | }
117 | }
118 |
119 | size_t Print::print(unsigned long long n, int base)
120 | {
121 | if (base == 0) return write(n);
122 | else return printNumber(n, base);
123 | }
124 |
125 | size_t Print::print(double n, int digits)
126 | {
127 | return printFloat(n, digits);
128 | }
129 |
130 | size_t Print::println(const __FlashStringHelper *ifsh)
131 | {
132 | size_t n = print(ifsh);
133 | n += println();
134 | return n;
135 | }
136 |
137 | size_t Print::print(const Printable& x)
138 | {
139 | return x.printTo(*this);
140 | }
141 |
142 | size_t Print::println(void)
143 | {
144 | return write("\r\n");
145 | }
146 |
147 | size_t Print::println(const String &s)
148 | {
149 | size_t n = print(s);
150 | n += println();
151 | return n;
152 | }
153 |
154 | size_t Print::println(const char c[])
155 | {
156 | size_t n = print(c);
157 | n += println();
158 | return n;
159 | }
160 |
161 | size_t Print::println(char c)
162 | {
163 | size_t n = print(c);
164 | n += println();
165 | return n;
166 | }
167 |
168 | size_t Print::println(unsigned char b, int base)
169 | {
170 | size_t n = print(b, base);
171 | n += println();
172 | return n;
173 | }
174 |
175 | size_t Print::println(int num, int base)
176 | {
177 | size_t n = print(num, base);
178 | n += println();
179 | return n;
180 | }
181 |
182 | size_t Print::println(unsigned int num, int base)
183 | {
184 | size_t n = print(num, base);
185 | n += println();
186 | return n;
187 | }
188 |
189 | size_t Print::println(long num, int base)
190 | {
191 | size_t n = print(num, base);
192 | n += println();
193 | return n;
194 | }
195 |
196 | size_t Print::println(unsigned long num, int base)
197 | {
198 | size_t n = print(num, base);
199 | n += println();
200 | return n;
201 | }
202 |
203 | size_t Print::println(long long num, int base)
204 | {
205 | size_t n = print(num, base);
206 | n += println();
207 | return n;
208 | }
209 |
210 | size_t Print::println(unsigned long long num, int base)
211 | {
212 | size_t n = print(num, base);
213 | n += println();
214 | return n;
215 | }
216 |
217 | size_t Print::println(double num, int digits)
218 | {
219 | size_t n = print(num, digits);
220 | n += println();
221 | return n;
222 | }
223 |
224 | size_t Print::println(const Printable& x)
225 | {
226 | size_t n = print(x);
227 | n += println();
228 | return n;
229 | }
230 |
231 | // Private Methods /////////////////////////////////////////////////////////////
232 |
233 | size_t Print::printNumber(unsigned long long n, uint8_t base)
234 | {
235 | char buf[8 * sizeof(long long) + 1]; // Assumes 8-bit chars plus zero byte.
236 | char *str = &buf[sizeof(buf) - 1];
237 |
238 | *str = '\0';
239 |
240 | // prevent crash if called with base == 1
241 | if (base < 2) base = 10;
242 |
243 | do {
244 | char c = n % base;
245 | n /= base;
246 |
247 | *--str = c < 10 ? c + '0' : c + 'A' - 10;
248 | } while(n);
249 |
250 | return write(str);
251 | }
252 |
253 | size_t Print::printFloat(double number, uint8_t digits)
254 | {
255 | size_t n = 0;
256 |
257 | if (isnan(number)) return print("nan");
258 | if (isinf(number)) return print("inf");
259 | if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
260 | if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
261 |
262 | // Handle negative numbers
263 | if (number < 0.0)
264 | {
265 | n += print('-');
266 | number = -number;
267 | }
268 |
269 | // Round correctly so that print(1.999, 2) prints as "2.00"
270 | double rounding = 0.5;
271 | for (uint8_t i=0; i 0) {
283 | n += print('.');
284 | }
285 |
286 | // Extract digits from the remainder one at a time
287 | while (digits-- > 0)
288 | {
289 | remainder *= 10.0;
290 | unsigned int toPrint = (unsigned int)(remainder);
291 | n += print(toPrint);
292 | remainder -= toPrint;
293 | }
294 |
295 | return n;
296 | }
297 |
--------------------------------------------------------------------------------
/src/cores/arduino/Print.h:
--------------------------------------------------------------------------------
1 | /*
2 | Print.h - Base class that provides print() and println()
3 | Copyright (c) 2008 David A. Mellis. All right reserved.
4 |
5 | This library is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU Lesser General Public
7 | License as published by the Free Software Foundation; either
8 | version 2.1 of the License, or (at your option) any later version.
9 |
10 | This library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | #ifndef Print_h
21 | #define Print_h
22 |
23 | #include
24 | #include // for size_t
25 |
26 | #include "WString.h"
27 | #include "Printable.h"
28 |
29 | #define DEC 10
30 | #define HEX 16
31 | #define OCT 8
32 | #ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar
33 | #undef BIN
34 | #endif
35 | #define BIN 2
36 |
37 | //typedef unsigned long long uint64_t;
38 | //typedef long long int64_t;
39 |
40 | class Print
41 | {
42 | private:
43 | int write_error;
44 | size_t printNumber(unsigned long long, uint8_t);
45 | size_t printFloat(double, uint8_t);
46 | protected:
47 | void setWriteError(int err = 1) { write_error = err; }
48 | public:
49 | Print() : write_error(0) {}
50 |
51 | int getWriteError() { return write_error; }
52 | void clearWriteError() { setWriteError(0); }
53 |
54 | virtual size_t write(uint8_t) = 0;
55 | size_t write(const char *str) {
56 | if (str == NULL) return 0;
57 | return write((const uint8_t *)str, strlen(str));
58 | }
59 | virtual size_t write(const uint8_t *buffer, size_t size);
60 | size_t write(const char *buffer, size_t size) {
61 | return write((const uint8_t *)buffer, size);
62 | }
63 |
64 | size_t print(const __FlashStringHelper *);
65 | size_t print(const String &);
66 | size_t print(const char[]);
67 | size_t print(char);
68 | size_t print(unsigned char, int = DEC);
69 | size_t print(int, int = DEC);
70 | size_t print(unsigned int, int = DEC);
71 | size_t print(long, int = DEC);
72 | size_t print(unsigned long, int = DEC);
73 | size_t print(long long, int = DEC);
74 | size_t print(unsigned long long, int = DEC);
75 | size_t print(double, int = 2);
76 | size_t print(const Printable&);
77 |
78 | size_t println(const __FlashStringHelper *);
79 | size_t println(const String &s);
80 | size_t println(const char[]);
81 | size_t println(char);
82 | size_t println(unsigned char, int = DEC);
83 | size_t println(int, int = DEC);
84 | size_t println(unsigned int, int = DEC);
85 | size_t println(long, int = DEC);
86 | size_t println(unsigned long, int = DEC);
87 | size_t println(long long, int = DEC);
88 | size_t println(unsigned long long, int = DEC);
89 | size_t println(double, int = 2);
90 | size_t println(const Printable&);
91 | size_t println(void);
92 | };
93 |
94 | #endif
95 |
--------------------------------------------------------------------------------
/src/cores/arduino/Printable.h:
--------------------------------------------------------------------------------
1 | /*
2 | Printable.h - Interface class that allows printing of complex types
3 | Copyright (c) 2011 Adrian McEwen. All right reserved.
4 |
5 | This library is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU Lesser General Public
7 | License as published by the Free Software Foundation; either
8 | version 2.1 of the License, or (at your option) any later version.
9 |
10 | This library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | #ifndef Printable_h
21 | #define Printable_h
22 |
23 | #include
24 |
25 | class Print;
26 |
27 | /** The Printable class provides a way for new classes to allow themselves to be printed.
28 | By deriving from Printable and implementing the printTo method, it will then be possible
29 | for users to print out instances of this class by passing them into the usual
30 | Print::print and Print::println methods.
31 | */
32 |
33 | class Printable
34 | {
35 | public:
36 | virtual size_t printTo(Print& p) const = 0;
37 | };
38 |
39 | #endif
40 |
41 |
--------------------------------------------------------------------------------
/src/cores/arduino/SerialConsole.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * SerialConsole.cpp
3 | *
4 | * Created on: 08.07.2017
5 | * Author: christoph
6 | */
7 |
8 | #include
9 | #include
10 | #include
11 | #include "SerialConsole.h"
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 |
18 | std::queue < char > avaliableInput;
19 | std::mutex inputMutex;
20 | std::thread t1;
21 | std::atomic active(true);
22 |
23 | SerialConsole::SerialConsole()
24 | {
25 |
26 | }
27 |
28 | void loadData() {
29 | while(active){
30 | char c = getchar();
31 | // Avoid race conditions
32 | std::lock_guard guard(inputMutex);
33 | avaliableInput.push(c);
34 | }
35 | }
36 |
37 | void SerialConsole:: begin(const uint32_t baud)
38 | {
39 | // Worker that reads from stdin.
40 | // This is needed so as not to block the main thread.
41 | active=true;
42 | t1 = std::thread(loadData);
43 | t1.detach();
44 | }
45 |
46 | void SerialConsole::end(void)
47 | {
48 | /*Stop reading input. It will read 1 extra character but
49 | * thats inevitable*/
50 | active = false;
51 | }
52 |
53 | int SerialConsole::available(void)
54 | {
55 | std::lock_guard guard(inputMutex);
56 | return !avaliableInput.empty();
57 | }
58 |
59 | int SerialConsole::peek(void)
60 | {
61 | if(available()) {
62 | std::lock_guard guard(inputMutex);
63 | return avaliableInput.front();
64 | }
65 | return -1;
66 | }
67 |
68 | int SerialConsole::read(void)
69 | {
70 | if(available()) {
71 | std::lock_guard guard(inputMutex);
72 | char c = avaliableInput.front();
73 | avaliableInput.pop();
74 | return c;
75 | }
76 | return -1;
77 | }
78 |
79 | void SerialConsole::flush(void)
80 | {
81 | fflush(stdin);
82 | }
83 |
84 | size_t SerialConsole::write(const uint8_t c)
85 | {
86 | putchar(c);
87 | return 1;
88 | }
89 |
90 | SerialConsole Serial;
91 |
92 |
--------------------------------------------------------------------------------
/src/cores/arduino/SerialConsole.h:
--------------------------------------------------------------------------------
1 | /*
2 | * SerialConsole.h
3 | *
4 | * Created on: 08.07.2017
5 | * Author: ChrisMicro
6 | */
7 |
8 | #ifndef CORES_ARDUINO_SERIALCONSOLE_H_
9 | #define CORES_ARDUINO_SERIALCONSOLE_H_
10 |
11 | #include "Stream.h"
12 |
13 | class SerialConsole : public Stream {
14 | public:
15 | SerialConsole();
16 | void begin(const uint32_t baud);
17 | void end(void);
18 | int available(void);
19 | int peek(void);
20 | int read(void);
21 | void flush(void);
22 | size_t write(const uint8_t c);
23 | using Print::write; // pull in write(str) and write(buf, size) from Print
24 | operator bool() { return true; }; // UART always active
25 | };
26 |
27 | extern SerialConsole Serial;
28 |
29 | #endif /* CORES_ARDUINO_SERIALCONSOLE_H_ */
30 |
--------------------------------------------------------------------------------
/src/cores/arduino/Stream.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Stream.cpp - adds parsing methods to Stream class
3 | Copyright (c) 2008 David A. Mellis. All right reserved.
4 |
5 | This library is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU Lesser General Public
7 | License as published by the Free Software Foundation; either
8 | version 2.1 of the License, or (at your option) any later version.
9 |
10 | This library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 |
19 | Created July 2011
20 | parsing functions based on TextFinder library by Michael Margolis
21 |
22 | findMulti/findUntil routines written by Jim Leonard/Xuth
23 | */
24 |
25 | #include "Arduino.h"
26 | #include "Stream.h"
27 |
28 | #define PARSE_TIMEOUT 1000 // default number of milli-seconds to wait
29 |
30 | // private method to read stream with timeout
31 | int Stream::timedRead()
32 | {
33 | int c;
34 | _startMillis = millis();
35 | do {
36 | c = read();
37 | if (c >= 0) return c;
38 | } while(millis() - _startMillis < _timeout);
39 | return -1; // -1 indicates timeout
40 | }
41 |
42 | // private method to peek stream with timeout
43 | int Stream::timedPeek()
44 | {
45 | int c;
46 | _startMillis = millis();
47 | do {
48 | c = peek();
49 | if (c >= 0) return c;
50 | } while(millis() - _startMillis < _timeout);
51 | return -1; // -1 indicates timeout
52 | }
53 |
54 | // returns peek of the next digit in the stream or -1 if timeout
55 | // discards non-numeric characters
56 | int Stream::peekNextDigit(LookaheadMode lookahead, bool detectDecimal)
57 | {
58 | int c;
59 | while (1) {
60 | c = timedPeek();
61 |
62 | if( c < 0 ||
63 | c == '-' ||
64 | (c >= '0' && c <= '9') ||
65 | (detectDecimal && c == '.')) return c;
66 |
67 | switch( lookahead ){
68 | case SKIP_NONE: return -1; // Fail code.
69 | case SKIP_WHITESPACE:
70 | switch( c ){
71 | case ' ':
72 | case '\t':
73 | case '\r':
74 | case '\n': break;
75 | default: return -1; // Fail code.
76 | }
77 | case SKIP_ALL:
78 | break;
79 | }
80 | read(); // discard non-numeric
81 | }
82 | }
83 |
84 | // Public Methods
85 | //////////////////////////////////////////////////////////////
86 |
87 | void Stream::setTimeout(unsigned long timeout) // sets the maximum number of milliseconds to wait
88 | {
89 | _timeout = timeout;
90 | }
91 |
92 | // find returns true if the target string is found
93 | bool Stream::find(char *target)
94 | {
95 | return findUntil(target, strlen(target), NULL, 0);
96 | }
97 |
98 | // reads data from the stream until the target string of given length is found
99 | // returns true if target string is found, false if timed out
100 | bool Stream::find(char *target, size_t length)
101 | {
102 | return findUntil(target, length, NULL, 0);
103 | }
104 |
105 | // as find but search ends if the terminator string is found
106 | bool Stream::findUntil(char *target, char *terminator)
107 | {
108 | return findUntil(target, strlen(target), terminator, strlen(terminator));
109 | }
110 |
111 | // reads data from the stream until the target string of the given length is found
112 | // search terminated if the terminator string is found
113 | // returns true if target string is found, false if terminated or timed out
114 | bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen)
115 | {
116 | if (terminator == NULL) {
117 | MultiTarget t[1] = {{target, targetLen, 0}};
118 | return findMulti(t, 1) == 0 ? true : false;
119 | } else {
120 | MultiTarget t[2] = {{target, targetLen, 0}, {terminator, termLen, 0}};
121 | return findMulti(t, 2) == 0 ? true : false;
122 | }
123 | }
124 |
125 | // returns the first valid (long) integer value from the current position.
126 | // lookahead determines how parseInt looks ahead in the stream.
127 | // See LookaheadMode enumeration at the top of the file.
128 | // Lookahead is terminated by the first character that is not a valid part of an integer.
129 | // Once parsing commences, 'ignore' will be skipped in the stream.
130 | long Stream::parseInt(LookaheadMode lookahead, char ignore)
131 | {
132 | bool isNegative = false;
133 | long value = 0;
134 | int c;
135 |
136 | c = peekNextDigit(lookahead, false);
137 | // ignore non numeric leading characters
138 | if(c < 0)
139 | return 0; // zero returned if timeout
140 |
141 | do{
142 | if(c == ignore)
143 | ; // ignore this character
144 | else if(c == '-')
145 | isNegative = true;
146 | else if(c >= '0' && c <= '9') // is c a digit?
147 | value = value * 10 + c - '0';
148 | read(); // consume the character we got with peek
149 | c = timedPeek();
150 | }
151 | while( (c >= '0' && c <= '9') || c == ignore );
152 |
153 | if(isNegative)
154 | value = -value;
155 | return value;
156 | }
157 |
158 | // as parseInt but returns a floating point value
159 | float Stream::parseFloat(LookaheadMode lookahead, char ignore)
160 | {
161 | bool isNegative = false;
162 | bool isFraction = false;
163 | long value = 0;
164 | int c;
165 | float fraction = 1.0;
166 |
167 | c = peekNextDigit(lookahead, true);
168 | // ignore non numeric leading characters
169 | if(c < 0)
170 | return 0; // zero returned if timeout
171 |
172 | do{
173 | if(c == ignore)
174 | ; // ignore
175 | else if(c == '-')
176 | isNegative = true;
177 | else if (c == '.')
178 | isFraction = true;
179 | else if(c >= '0' && c <= '9') { // is c a digit?
180 | value = value * 10 + c - '0';
181 | if(isFraction)
182 | fraction *= 0.1;
183 | }
184 | read(); // consume the character we got with peek
185 | c = timedPeek();
186 | }
187 | while( (c >= '0' && c <= '9') || (c == '.' && !isFraction) || c == ignore );
188 |
189 | if(isNegative)
190 | value = -value;
191 | if(isFraction)
192 | return value * fraction;
193 | else
194 | return value;
195 | }
196 |
197 | // read characters from stream into buffer
198 | // terminates if length characters have been read, or timeout (see setTimeout)
199 | // returns the number of characters placed in the buffer
200 | // the buffer is NOT null terminated.
201 | //
202 | size_t Stream::readBytes(char *buffer, size_t length)
203 | {
204 | size_t count = 0;
205 | while (count < length) {
206 | int c = timedRead();
207 | if (c < 0) break;
208 | *buffer++ = (char)c;
209 | count++;
210 | }
211 | return count;
212 | }
213 |
214 |
215 | // as readBytes with terminator character
216 | // terminates if length characters have been read, timeout, or if the terminator character detected
217 | // returns the number of characters placed in the buffer (0 means no valid data found)
218 |
219 | size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
220 | {
221 | if (length < 1) return 0;
222 | size_t index = 0;
223 | while (index < length) {
224 | int c = timedRead();
225 | if (c < 0 || c == terminator) break;
226 | *buffer++ = (char)c;
227 | index++;
228 | }
229 | return index; // return number of characters, not including null terminator
230 | }
231 |
232 | String Stream::readString()
233 | {
234 | String ret;
235 | int c = timedRead();
236 | while (c >= 0)
237 | {
238 | ret += (char)c;
239 | c = timedRead();
240 | }
241 | return ret;
242 | }
243 |
244 | String Stream::readStringUntil(char terminator)
245 | {
246 | String ret;
247 | int c = timedRead();
248 | while (c >= 0 && c != terminator)
249 | {
250 | ret += (char)c;
251 | c = timedRead();
252 | }
253 | return ret;
254 | }
255 |
256 | int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) {
257 | // any zero length target string automatically matches and would make
258 | // a mess of the rest of the algorithm.
259 | for (struct MultiTarget *t = targets; t < targets+tCount; ++t) {
260 | if (t->len <= 0)
261 | return t - targets;
262 | }
263 |
264 | while (1) {
265 | int c = timedRead();
266 | if (c < 0)
267 | return -1;
268 |
269 | for (struct MultiTarget *t = targets; t < targets+tCount; ++t) {
270 | // the simple case is if we match, deal with that first.
271 | if (c == t->str[t->index]) {
272 | if (++t->index == t->len)
273 | return t - targets;
274 | else
275 | continue;
276 | }
277 |
278 | // if not we need to walk back and see if we could have matched further
279 | // down the stream (ie '1112' doesn't match the first position in '11112'
280 | // but it will match the second position so we can't just reset the current
281 | // index to 0 when we find a mismatch.
282 | if (t->index == 0)
283 | continue;
284 |
285 | int origIndex = t->index;
286 | do {
287 | --t->index;
288 | // first check if current char works against the new current index
289 | if (c != t->str[t->index])
290 | continue;
291 |
292 | // if it's the only char then we're good, nothing more to check
293 | if (t->index == 0) {
294 | t->index++;
295 | break;
296 | }
297 |
298 | // otherwise we need to check the rest of the found string
299 | int diff = origIndex - t->index;
300 | size_t i;
301 | for (i = 0; i < t->index; ++i) {
302 | if (t->str[i] != t->str[i + diff])
303 | break;
304 | }
305 |
306 | // if we successfully got through the previous loop then our current
307 | // index is good.
308 | if (i == t->index) {
309 | t->index++;
310 | break;
311 | }
312 |
313 | // otherwise we just try the next index
314 | } while (t->index);
315 | }
316 | }
317 | // unreachable
318 | return -1;
319 | }
320 |
--------------------------------------------------------------------------------
/src/cores/arduino/Stream.h:
--------------------------------------------------------------------------------
1 | /*
2 | Stream.h - base class for character-based streams.
3 | Copyright (c) 2010 David A. Mellis. All right reserved.
4 |
5 | This library is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU Lesser General Public
7 | License as published by the Free Software Foundation; either
8 | version 2.1 of the License, or (at your option) any later version.
9 |
10 | This library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 |
19 | parsing functions based on TextFinder library by Michael Margolis
20 | */
21 |
22 | #ifndef Stream_h
23 | #define Stream_h
24 |
25 | #include
26 | #include "Print.h"
27 |
28 | // compatability macros for testing
29 | /*
30 | #define getInt() parseInt()
31 | #define getInt(ignore) parseInt(ignore)
32 | #define getFloat() parseFloat()
33 | #define getFloat(ignore) parseFloat(ignore)
34 | #define getString( pre_string, post_string, buffer, length)
35 | readBytesBetween( pre_string, terminator, buffer, length)
36 | */
37 |
38 | // This enumeration provides the lookahead options for parseInt(), parseFloat()
39 | // The rules set out here are used until either the first valid character is found
40 | // or a time out occurs due to lack of input.
41 | enum LookaheadMode{
42 | SKIP_ALL, // All invalid characters are ignored.
43 | SKIP_NONE, // Nothing is skipped, and the stream is not touched unless the first waiting character is valid.
44 | SKIP_WHITESPACE // Only tabs, spaces, line feeds & carriage returns are skipped.
45 | };
46 |
47 | #define NO_IGNORE_CHAR '\x01' // a char not found in a valid ASCII numeric field
48 |
49 | class Stream : public Print
50 | {
51 | protected:
52 | unsigned long _timeout; // number of milliseconds to wait for the next char before aborting timed read
53 | unsigned long _startMillis; // used for timeout measurement
54 | int timedRead(); // private method to read stream with timeout
55 | int timedPeek(); // private method to peek stream with timeout
56 | int peekNextDigit(LookaheadMode lookahead, bool detectDecimal); // returns the next numeric digit in the stream or -1 if timeout
57 |
58 | public:
59 | virtual int available() = 0;
60 | virtual int read() = 0;
61 | virtual int peek() = 0;
62 | virtual void flush() = 0;
63 |
64 | Stream() {_timeout=1000;}
65 |
66 | // parsing methods
67 |
68 | void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
69 | unsigned long getTimeout(void) { return _timeout; }
70 |
71 | bool find(char *target); // reads data from the stream until the target string is found
72 | bool find(uint8_t *target) { return find ((char *)target); }
73 | // returns true if target string is found, false if timed out (see setTimeout)
74 |
75 | bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
76 | bool find(uint8_t *target, size_t length) { return find ((char *)target, length); }
77 | // returns true if target string is found, false if timed out
78 |
79 | bool find(char target) { return find (&target, 1); }
80 |
81 | bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
82 | bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); }
83 |
84 | bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
85 | bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); }
86 |
87 | long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
88 | // returns the first valid (long) integer value from the current position.
89 | // lookahead determines how parseInt looks ahead in the stream.
90 | // See LookaheadMode enumeration at the top of the file.
91 | // Lookahead is terminated by the first character that is not a valid part of an integer.
92 | // Once parsing commences, 'ignore' will be skipped in the stream.
93 |
94 | float parseFloat(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
95 | // float version of parseInt
96 |
97 | size_t readBytes( char *buffer, size_t length); // read chars from stream into buffer
98 | size_t readBytes( uint8_t *buffer, size_t length) { return readBytes((char *)buffer, length); }
99 | // terminates if length characters have been read or timeout (see setTimeout)
100 | // returns the number of characters placed in the buffer (0 means no valid data found)
101 |
102 | size_t readBytesUntil( char terminator, char *buffer, size_t length); // as readBytes with terminator character
103 | size_t readBytesUntil( char terminator, uint8_t *buffer, size_t length) { return readBytesUntil(terminator, (char *)buffer, length); }
104 | // terminates if length characters have been read, timeout, or if the terminator character detected
105 | // returns the number of characters placed in the buffer (0 means no valid data found)
106 |
107 | // Arduino String functions to be added here
108 | String readString();
109 | String readStringUntil(char terminator);
110 |
111 | protected:
112 | long parseInt(char ignore) { return parseInt(SKIP_ALL, ignore); }
113 | float parseFloat(char ignore) { return parseFloat(SKIP_ALL, ignore); }
114 | // These overload exists for compatibility with any class that has derived
115 | // Stream and used parseFloat/Int with a custom ignore character. To keep
116 | // the public API simple, these overload remains protected.
117 |
118 | struct MultiTarget {
119 | const char *str; // string you're searching for
120 | size_t len; // length of string you're searching for
121 | size_t index; // index used by the search routine.
122 | };
123 |
124 | // This allows you to search for an arbitrary number of strings.
125 | // Returns index of the target that is found first or -1 if timeout occurs.
126 | int findMulti(struct MultiTarget *targets, int tCount);
127 | };
128 |
129 | #undef NO_IGNORE_CHAR
130 | #endif
131 |
--------------------------------------------------------------------------------
/src/cores/arduino/WMath.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2011 Arduino. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 | See the GNU Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | extern "C" {
20 | #include "stdlib.h"
21 | #include "stdint.h"
22 | }
23 |
24 | extern void randomSeed( uint32_t dwSeed )
25 | {
26 | if ( dwSeed != 0 )
27 | {
28 | srand( dwSeed ) ;
29 | }
30 | }
31 |
32 | extern long random( long howbig )
33 | {
34 | if ( howbig == 0 )
35 | {
36 | return 0 ;
37 | }
38 |
39 | return rand() % howbig;
40 | }
41 |
42 | extern long random( long howsmall, long howbig )
43 | {
44 | if (howsmall >= howbig)
45 | {
46 | return howsmall;
47 | }
48 |
49 | long diff = howbig - howsmall;
50 |
51 | return random(diff) + howsmall;
52 | }
53 |
54 | extern long map(long x, long in_min, long in_max, long out_min, long out_max)
55 | {
56 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
57 | }
58 |
59 | extern uint16_t makeWord( uint16_t w )
60 | {
61 | return w ;
62 | }
63 |
64 | extern uint16_t makeWord( uint8_t h, uint8_t l )
65 | {
66 | return (h << 8) | l ;
67 | }
68 |
--------------------------------------------------------------------------------
/src/cores/arduino/WString.h:
--------------------------------------------------------------------------------
1 | /*
2 | WString.h - String library for Wiring & Arduino
3 | ...mostly rewritten by Paul Stoffregen...
4 | Copyright (c) 2009-10 Hernando Barragan. All right reserved.
5 | Copyright 2011, Paul Stoffregen, paul@pjrc.com
6 |
7 | This library is free software; you can redistribute it and/or
8 | modify it under the terms of the GNU Lesser General Public
9 | License as published by the Free Software Foundation; either
10 | version 2.1 of the License, or (at your option) any later version.
11 |
12 | This library is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | Lesser General Public License for more details.
16 |
17 | You should have received a copy of the GNU Lesser General Public
18 | License along with this library; if not, write to the Free Software
19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 | */
21 |
22 | #ifndef String_class_h
23 | #define String_class_h
24 | #ifdef __cplusplus
25 |
26 | #include
27 | #include
28 | #include
29 | #include "avr/pgmspace.h"
30 |
31 | // When compiling programs with this class, the following gcc parameters
32 | // dramatically increase performance and memory (RAM) efficiency, typically
33 | // with little or no increase in code size.
34 | // -felide-constructors
35 | // -std=c++0x
36 |
37 | class __FlashStringHelper;
38 | #define F(string_literal) (reinterpret_cast(PSTR(string_literal)))
39 |
40 | // An inherited class for holding the result of a concatenation. These
41 | // result objects are assumed to be writable by subsequent concatenations.
42 | class StringSumHelper;
43 |
44 | // The string class
45 | class String
46 | {
47 | // use a function pointer to allow for "if (s)" without the
48 | // complications of an operator bool(). for more information, see:
49 | // http://www.artima.com/cppsource/safebool.html
50 | typedef void (String::*StringIfHelperType)() const;
51 | void StringIfHelper() const {}
52 |
53 | public:
54 | // constructors
55 | // creates a copy of the initial value.
56 | // if the initial value is null or invalid, or if memory allocation
57 | // fails, the string will be marked as invalid (i.e. "if (s)" will
58 | // be false).
59 | String(const char *cstr = "");
60 | String(const String &str);
61 | String(const __FlashStringHelper *str);
62 | #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
63 | String(String &&rval);
64 | String(StringSumHelper &&rval);
65 | #endif
66 | explicit String(char c);
67 | explicit String(unsigned char, unsigned char base=10);
68 | explicit String(int, unsigned char base=10);
69 | explicit String(unsigned int, unsigned char base=10);
70 | explicit String(long, unsigned char base=10);
71 | explicit String(unsigned long, unsigned char base=10);
72 | explicit String(float, unsigned char decimalPlaces=2);
73 | explicit String(double, unsigned char decimalPlaces=2);
74 | ~String(void);
75 |
76 | // memory management
77 | // return true on success, false on failure (in which case, the string
78 | // is left unchanged). reserve(0), if successful, will validate an
79 | // invalid string (i.e., "if (s)" will be true afterwards)
80 | unsigned char reserve(unsigned int size);
81 | inline unsigned int length(void) const {return len;}
82 |
83 | // creates a copy of the assigned value. if the value is null or
84 | // invalid, or if the memory allocation fails, the string will be
85 | // marked as invalid ("if (s)" will be false).
86 | String & operator = (const String &rhs);
87 | String & operator = (const char *cstr);
88 | String & operator = (const __FlashStringHelper *str);
89 | #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
90 | String & operator = (String &&rval);
91 | String & operator = (StringSumHelper &&rval);
92 | #endif
93 |
94 | // concatenate (works w/ built-in types)
95 |
96 | // returns true on success, false on failure (in which case, the string
97 | // is left unchanged). if the argument is null or invalid, the
98 | // concatenation is considered unsucessful.
99 | unsigned char concat(const String &str);
100 | unsigned char concat(const char *cstr);
101 | unsigned char concat(char c);
102 | unsigned char concat(unsigned char c);
103 | unsigned char concat(int num);
104 | unsigned char concat(unsigned int num);
105 | unsigned char concat(long num);
106 | unsigned char concat(unsigned long num);
107 | unsigned char concat(float num);
108 | unsigned char concat(double num);
109 | unsigned char concat(const __FlashStringHelper * str);
110 |
111 | // if there's not enough memory for the concatenated value, the string
112 | // will be left unchanged (but this isn't signalled in any way)
113 | String & operator += (const String &rhs) {concat(rhs); return (*this);}
114 | String & operator += (const char *cstr) {concat(cstr); return (*this);}
115 | String & operator += (char c) {concat(c); return (*this);}
116 | String & operator += (unsigned char num) {concat(num); return (*this);}
117 | String & operator += (int num) {concat(num); return (*this);}
118 | String & operator += (unsigned int num) {concat(num); return (*this);}
119 | String & operator += (long num) {concat(num); return (*this);}
120 | String & operator += (unsigned long num) {concat(num); return (*this);}
121 | String & operator += (float num) {concat(num); return (*this);}
122 | String & operator += (double num) {concat(num); return (*this);}
123 | String & operator += (const __FlashStringHelper *str){concat(str); return (*this);}
124 |
125 | friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
126 | friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
127 | friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
128 | friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char num);
129 | friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
130 | friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num);
131 | friend StringSumHelper & operator + (const StringSumHelper &lhs, long num);
132 | friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num);
133 | friend StringSumHelper & operator + (const StringSumHelper &lhs, float num);
134 | friend StringSumHelper & operator + (const StringSumHelper &lhs, double num);
135 | friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *rhs);
136 |
137 | // comparison (only works w/ Strings and "strings")
138 | operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; }
139 | int compareTo(const String &s) const;
140 | unsigned char equals(const String &s) const;
141 | unsigned char equals(const char *cstr) const;
142 | unsigned char operator == (const String &rhs) const {return equals(rhs);}
143 | unsigned char operator == (const char *cstr) const {return equals(cstr);}
144 | unsigned char operator != (const String &rhs) const {return !equals(rhs);}
145 | unsigned char operator != (const char *cstr) const {return !equals(cstr);}
146 | unsigned char operator < (const String &rhs) const;
147 | unsigned char operator > (const String &rhs) const;
148 | unsigned char operator <= (const String &rhs) const;
149 | unsigned char operator >= (const String &rhs) const;
150 | unsigned char equalsIgnoreCase(const String &s) const;
151 | unsigned char startsWith( const String &prefix) const;
152 | unsigned char startsWith(const String &prefix, unsigned int offset) const;
153 | unsigned char endsWith(const String &suffix) const;
154 |
155 | // character acccess
156 | char charAt(unsigned int index) const;
157 | void setCharAt(unsigned int index, char c);
158 | char operator [] (unsigned int index) const;
159 | char& operator [] (unsigned int index);
160 | void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const;
161 | void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
162 | { getBytes((unsigned char *)buf, bufsize, index); }
163 | const char* c_str() const { return buffer; }
164 | char* begin() { return buffer; }
165 | char* end() { return buffer + length(); }
166 | const char* begin() const { return c_str(); }
167 | const char* end() const { return c_str() + length(); }
168 |
169 | // search
170 | int indexOf( char ch ) const;
171 | int indexOf( char ch, unsigned int fromIndex ) const;
172 | int indexOf( const String &str ) const;
173 | int indexOf( const String &str, unsigned int fromIndex ) const;
174 | int lastIndexOf( char ch ) const;
175 | int lastIndexOf( char ch, unsigned int fromIndex ) const;
176 | int lastIndexOf( const String &str ) const;
177 | int lastIndexOf( const String &str, unsigned int fromIndex ) const;
178 | String substring( unsigned int beginIndex ) const { return substring(beginIndex, len); };
179 | String substring( unsigned int beginIndex, unsigned int endIndex ) const;
180 |
181 | // modification
182 | void replace(char find, char replace);
183 | void replace(const String& find, const String& replace);
184 | void remove(unsigned int index);
185 | void remove(unsigned int index, unsigned int count);
186 | void toLowerCase(void);
187 | void toUpperCase(void);
188 | void trim(void);
189 |
190 | // parsing/conversion
191 | long toInt(void) const;
192 | float toFloat(void) const;
193 | double toDouble(void) const;
194 |
195 | protected:
196 | char *buffer; // the actual char array
197 | unsigned int capacity; // the array length minus one (for the '\0')
198 | unsigned int len; // the String length (not counting the '\0')
199 | protected:
200 | void init(void);
201 | void invalidate(void);
202 | unsigned char changeBuffer(unsigned int maxStrLen);
203 | unsigned char concat(const char *cstr, unsigned int length);
204 |
205 | // copy and move
206 | String & copy(const char *cstr, unsigned int length);
207 | String & copy(const __FlashStringHelper *pstr, unsigned int length);
208 | #if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
209 | void move(String &rhs);
210 | #endif
211 | };
212 |
213 | class StringSumHelper : public String
214 | {
215 | public:
216 | StringSumHelper(const String &s) : String(s) {}
217 | StringSumHelper(const char *p) : String(p) {}
218 | StringSumHelper(char c) : String(c) {}
219 | StringSumHelper(unsigned char num) : String(num) {}
220 | StringSumHelper(int num) : String(num) {}
221 | StringSumHelper(unsigned int num) : String(num) {}
222 | StringSumHelper(long num) : String(num) {}
223 | StringSumHelper(unsigned long num) : String(num) {}
224 | StringSumHelper(float num) : String(num) {}
225 | StringSumHelper(double num) : String(num) {}
226 | };
227 |
228 | #endif // __cplusplus
229 | #endif // String_class_h
230 |
--------------------------------------------------------------------------------
/src/cores/arduino/avr/dtostrf.c:
--------------------------------------------------------------------------------
1 | /*
2 | dtostrf - Emulation for dtostrf function from avr-libc
3 | Copyright (c) 2013 Arduino. All rights reserved.
4 | Written by Cristian Maglie
5 |
6 | This library is free software; you can redistribute it and/or
7 | modify it under the terms of the GNU Lesser General Public
8 | License as published by the Free Software Foundation; either
9 | version 2.1 of the License, or (at your option) any later version.
10 |
11 | This library is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | Lesser General Public License for more details.
15 |
16 | You should have received a copy of the GNU Lesser General Public
17 | License along with this library; if not, write to the Free Software
18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #include
22 |
23 | char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
24 | char fmt[20];
25 | sprintf(fmt, "%%%d.%df", width, prec);
26 | sprintf(sout, fmt, val);
27 | return sout;
28 | }
29 |
30 |
--------------------------------------------------------------------------------
/src/cores/arduino/avr/dtostrf.h:
--------------------------------------------------------------------------------
1 | /*
2 | dtostrf - Emulation for dtostrf function from avr-libc
3 | Copyright (c) 2013 Arduino. All rights reserved.
4 | Written by Cristian Maglie
5 |
6 | This library is free software; you can redistribute it and/or
7 | modify it under the terms of the GNU Lesser General Public
8 | License as published by the Free Software Foundation; either
9 | version 2.1 of the License, or (at your option) any later version.
10 |
11 | This library is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 | Lesser General Public License for more details.
15 |
16 | You should have received a copy of the GNU Lesser General Public
17 | License along with this library; if not, write to the Free Software
18 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 | */
20 |
21 | #ifdef __cplusplus
22 | extern "C" {
23 | #endif
24 |
25 | char *dtostrf (double val, signed char width, unsigned char prec, char *sout);
26 |
27 | #ifdef __cplusplus
28 | }
29 | #endif
30 |
--------------------------------------------------------------------------------
/src/cores/arduino/avr/interrupt.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ChrisMicro/ArduinoOnPc/5708d9d037b045a04b38f57665e14dc8af2970f9/src/cores/arduino/avr/interrupt.h
--------------------------------------------------------------------------------
/src/cores/arduino/avr/pgmspace.h:
--------------------------------------------------------------------------------
1 | #ifndef __PGMSPACE_H_
2 | #define __PGMSPACE_H_ 1
3 |
4 | #include
5 |
6 | #define PROGMEM
7 | #define PGM_P const char *
8 | #define PSTR(str) (str)
9 |
10 | #define _SFR_BYTE(n) (n)
11 |
12 | typedef void prog_void;
13 | typedef char prog_char;
14 | typedef unsigned char prog_uchar;
15 | typedef int8_t prog_int8_t;
16 | typedef uint8_t prog_uint8_t;
17 | typedef int16_t prog_int16_t;
18 | typedef uint16_t prog_uint16_t;
19 | typedef int32_t prog_int32_t;
20 | typedef uint32_t prog_uint32_t;
21 |
22 | #define memcpy_P(dest, src, num) memcpy((dest), (src), (num))
23 | #define strcpy_P(dest, src) strcpy((dest), (src))
24 | #define strcat_P(dest, src) strcat((dest), (src))
25 | #define strcmp_P(a, b) strcmp((a), (b))
26 | #define strstr_P(a, b) strstr((a), (b))
27 | #define strlen_P(a) strlen((a))
28 | #define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__)
29 |
30 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
31 | #define pgm_read_word(addr) (*(const unsigned short *)(addr))
32 | #define pgm_read_dword(addr) (*(const unsigned long *)(addr))
33 | #define pgm_read_float(addr) (*(const float *)(addr))
34 |
35 | #define pgm_read_byte_near(addr) pgm_read_byte(addr)
36 | #define pgm_read_word_near(addr) pgm_read_word(addr)
37 | #define pgm_read_dword_near(addr) pgm_read_dword(addr)
38 | #define pgm_read_float_near(addr) pgm_read_float(addr)
39 | #define pgm_read_byte_far(addr) pgm_read_byte(addr)
40 | #define pgm_read_word_far(addr) pgm_read_word(addr)
41 | #define pgm_read_dword_far(addr) pgm_read_dword(addr)
42 | #define pgm_read_float_far(addr) pgm_read_float(addr)
43 |
44 | #endif
45 |
--------------------------------------------------------------------------------
/src/cores/arduino/itoa.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2011 Arduino. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 | See the GNU Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #include "itoa.h"
20 | #include
21 |
22 | #ifdef __cplusplus
23 | extern "C"{
24 | #endif // __cplusplus
25 |
26 | #if 0
27 | /* reverse: reverse string s in place */
28 | static void reverse( char s[] )
29 | {
30 | int i, j ;
31 | char c ;
32 |
33 | for ( i = 0, j = strlen(s)-1 ; i < j ; i++, j-- )
34 | {
35 | c = s[i] ;
36 | s[i] = s[j] ;
37 | s[j] = c ;
38 | }
39 | }
40 |
41 | /* itoa: convert n to characters in s */
42 | extern void itoa( int n, char s[] )
43 | {
44 | int i, sign ;
45 |
46 | if ( (sign = n) < 0 ) /* record sign */
47 | {
48 | n = -n; /* make n positive */
49 | }
50 |
51 | i = 0;
52 | do
53 | { /* generate digits in reverse order */
54 | s[i++] = n % 10 + '0'; /* get next digit */
55 | } while ((n /= 10) > 0) ; /* delete it */
56 |
57 | if (sign < 0 )
58 | {
59 | s[i++] = '-';
60 | }
61 |
62 | s[i] = '\0';
63 |
64 | reverse( s ) ;
65 | }
66 |
67 | #else
68 |
69 | extern char* itoa( int value, char *string, int radix )
70 | {
71 | return ltoa( value, string, radix ) ;
72 | }
73 |
74 | extern char* ltoa( long value, char *string, int radix )
75 | {
76 | char tmp[33];
77 | char *tp = tmp;
78 | long i;
79 | unsigned long v;
80 | int sign;
81 | char *sp;
82 |
83 | if ( string == NULL )
84 | {
85 | return 0 ;
86 | }
87 |
88 | if (radix > 36 || radix <= 1)
89 | {
90 | return 0 ;
91 | }
92 |
93 | sign = (radix == 10 && value < 0);
94 | if (sign)
95 | {
96 | v = -value;
97 | }
98 | else
99 | {
100 | v = (unsigned long)value;
101 | }
102 |
103 | while (v || tp == tmp)
104 | {
105 | i = v % radix;
106 | v = v / radix;
107 | if (i < 10)
108 | *tp++ = i+'0';
109 | else
110 | *tp++ = i + 'a' - 10;
111 | }
112 |
113 | sp = string;
114 |
115 | if (sign)
116 | *sp++ = '-';
117 | while (tp > tmp)
118 | *sp++ = *--tp;
119 | *sp = 0;
120 |
121 | return string;
122 | }
123 |
124 | extern char* utoa( unsigned long value, char *string, int radix )
125 | {
126 | return ultoa( value, string, radix ) ;
127 | }
128 |
129 | extern char* ultoa( unsigned long value, char *string, int radix )
130 | {
131 | char tmp[33];
132 | char *tp = tmp;
133 | long i;
134 | unsigned long v = value;
135 | char *sp;
136 |
137 | if ( string == NULL )
138 | {
139 | return 0;
140 | }
141 |
142 | if (radix > 36 || radix <= 1)
143 | {
144 | return 0;
145 | }
146 |
147 | while (v || tp == tmp)
148 | {
149 | i = v % radix;
150 | v = v / radix;
151 | if (i < 10)
152 | *tp++ = i+'0';
153 | else
154 | *tp++ = i + 'a' - 10;
155 | }
156 |
157 | sp = string;
158 |
159 |
160 | while (tp > tmp)
161 | *sp++ = *--tp;
162 | *sp = 0;
163 |
164 | return string;
165 | }
166 | #endif /* 0 */
167 |
168 | #ifdef __cplusplus
169 | } // extern "C"
170 | #endif // __cplusplus
171 |
--------------------------------------------------------------------------------
/src/cores/arduino/itoa.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2011 Arduino. All right reserved.
3 |
4 | This library is free software; you can redistribute it and/or
5 | modify it under the terms of the GNU Lesser General Public
6 | License as published by the Free Software Foundation; either
7 | version 2.1 of the License, or (at your option) any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 | See the GNU Lesser General Public License for more details.
13 |
14 | You should have received a copy of the GNU Lesser General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 | */
18 |
19 | #ifndef _ITOA_
20 | #define _ITOA_
21 |
22 | #ifdef __cplusplus
23 | extern "C"{
24 | #endif // __cplusplus
25 |
26 | #if 0
27 |
28 | extern void itoa( int n, char s[] ) ;
29 |
30 | #else
31 |
32 | #if __GNUC__ < 5
33 |
34 | extern char* utoa( unsigned long value, char *string, int radix ) ;
35 |
36 | #endif
37 |
38 | extern char* itoa( int value, char *string, int radix ) ;
39 | extern char* ltoa( long value, char *string, int radix ) ;
40 | extern char* ultoa( unsigned long value, char *string, int radix ) ;
41 | //#pragma warning : there seems to be a problem with utoa depending on the compiler version
42 | extern char* utoa( unsigned long value, char *string, int radix ) ;
43 | #endif /* 0 */
44 |
45 | #ifdef __cplusplus
46 | } // extern "C"
47 | #endif // __cplusplus
48 |
49 | #endif // _ITOA_
50 |
--------------------------------------------------------------------------------
/src/cores/arduino/pins_arduino.h:
--------------------------------------------------------------------------------
1 | /*
2 | pins_arduino.h - Pin definition functions for Arduino
3 | Part of Arduino - http://www.arduino.cc/
4 |
5 | Copyright (c) 2007 David A. Mellis
6 |
7 | This library is free software; you can redistribute it and/or
8 | modify it under the terms of the GNU Lesser General Public
9 | License as published by the Free Software Foundation; either
10 | version 2.1 of the License, or (at your option) any later version.
11 |
12 | This library is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | Lesser General Public License for more details.
16 |
17 | You should have received a copy of the GNU Lesser General
18 | Public License along with this library; if not, write to the
19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 | Boston, MA 02111-1307 USA
21 | */
22 |
23 | #ifndef Pins_Arduino_h
24 | #define Pins_Arduino_h
25 |
26 | #define NUM_DIGITAL_PINS 20
27 | #define NUM_ANALOG_INPUTS 6
28 | #define analogInputToDigitalPin(p) ((p < 6) ? (p) + 14 : -1)
29 |
30 | #define digitalPinHasPWM(p) ((p) == 3 || (p) == 5 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 11)
31 |
32 | #define PIN_SPI_SS (10)
33 | #define PIN_SPI_MOSI (11)
34 | #define PIN_SPI_MISO (12)
35 | #define PIN_SPI_SCK (13)
36 |
37 | static const uint8_t SS = PIN_SPI_SS;
38 | static const uint8_t MOSI = PIN_SPI_MOSI;
39 | static const uint8_t MISO = PIN_SPI_MISO;
40 | static const uint8_t SCK = PIN_SPI_SCK;
41 |
42 | #define PIN_WIRE_SDA (18)
43 | #define PIN_WIRE_SCL (19)
44 |
45 | static const uint8_t SDA = PIN_WIRE_SDA;
46 | static const uint8_t SCL = PIN_WIRE_SCL;
47 |
48 | #define LED_BUILTIN 13
49 |
50 | #define PIN_A0 (14)
51 | #define PIN_A1 (15)
52 | #define PIN_A2 (16)
53 | #define PIN_A3 (17)
54 | #define PIN_A4 (18)
55 | #define PIN_A5 (19)
56 | #define PIN_A6 (20)
57 | #define PIN_A7 (21)
58 |
59 | static const uint8_t A0 = PIN_A0;
60 | static const uint8_t A1 = PIN_A1;
61 | static const uint8_t A2 = PIN_A2;
62 | static const uint8_t A3 = PIN_A3;
63 | static const uint8_t A4 = PIN_A4;
64 | static const uint8_t A5 = PIN_A5;
65 | static const uint8_t A6 = PIN_A6;
66 | static const uint8_t A7 = PIN_A7;
67 |
68 | #define digitalPinToPCICR(p) (((p) >= 0 && (p) <= 21) ? (&PCICR) : ((uint8_t *)0))
69 | #define digitalPinToPCICRbit(p) (((p) <= 7) ? 2 : (((p) <= 13) ? 0 : 1))
70 | #define digitalPinToPCMSK(p) (((p) <= 7) ? (&PCMSK2) : (((p) <= 13) ? (&PCMSK0) : (((p) <= 21) ? (&PCMSK1) : ((uint8_t *)0))))
71 | #define digitalPinToPCMSKbit(p) (((p) <= 7) ? (p) : (((p) <= 13) ? ((p) - 8) : ((p) - 14)))
72 |
73 | #define digitalPinToInterrupt(p) ((p) == 2 ? 0 : ((p) == 3 ? 1 : NOT_AN_INTERRUPT))
74 |
75 |
76 | // These serial port names are intended to allow libraries and architecture-neutral
77 | // sketches to automatically default to the correct port name for a particular type
78 | // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
79 | // the first hardware serial port whose RX/TX pins are not dedicated to another use.
80 | //
81 | // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
82 | //
83 | // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
84 | //
85 | // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
86 | //
87 | // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
88 | //
89 | // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
90 | // pins are NOT connected to anything by default.
91 | #define SERIAL_PORT_MONITOR Serial
92 | #define SERIAL_PORT_HARDWARE Serial
93 |
94 | #endif
95 |
--------------------------------------------------------------------------------
/src/cores/arduino/wiring_analog.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * wiring_analog.cpp
3 | *
4 | * Created on: 12.07.2017
5 | * Author: ChrisMicro
6 | */
7 |
8 | #include
9 | #include
10 |
11 | void analogReference(uint8_t mode)
12 | {
13 |
14 | }
15 |
16 | int analogRead(uint8_t pin)
17 | {
18 | return 123;
19 | }
20 |
21 | void analogWrite(uint8_t pin, int val)
22 | {
23 | std::cout << "analog pin " << (int)pin << " : " << (int)val << std::endl;
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/src/cores/arduino/wiring_digital.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * wiring_digital.c
3 | *
4 | * Created on: 11.07.2017
5 | * Author: ChrisMicro
6 | */
7 |
8 |
9 |
10 | #include
11 | #include
12 | #include "Arduino.h"
13 |
14 |
15 | void pinMode(uint8_t pin, uint8_t mode)
16 | {
17 | std::cout << "pinMode pin " << (int)pin << " set to : ";
18 |
19 | if(mode==INPUT) std::cout << "INPUT" << std::endl;
20 | if(mode==OUTPUT) std::cout << "OUTPUT" << std::endl;
21 | if(mode==INPUT_PULLUP) std::cout << "INPUT_PULLUP" << std::endl;
22 | }
23 |
24 |
25 | void turnOffPWM(uint8_t timer)
26 | {
27 | std::cout << " turnOffPWM " << std::endl ;
28 | }
29 |
30 | void digitalWrite(uint8_t pin, uint8_t val)
31 | {
32 | std::cout << "pin " << (int)pin << " : " << (int)val << std::endl;
33 | }
34 |
35 | int digitalRead(uint8_t pin)
36 | {
37 | return 0; // write your onw simulation here
38 | }
39 |
40 |
--------------------------------------------------------------------------------
/src/cores/arduino/wiring_private.h:
--------------------------------------------------------------------------------
1 | /*
2 | wiring_private.h - Internal header file.
3 | Part of Arduino - http://www.arduino.cc/
4 |
5 | Copyright (c) 2005-2006 David A. Mellis
6 |
7 | This library is free software; you can redistribute it and/or
8 | modify it under the terms of the GNU Lesser General Public
9 | License as published by the Free Software Foundation; either
10 | version 2.1 of the License, or (at your option) any later version.
11 |
12 | This library is distributed in the hope that it will be useful,
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 | Lesser General Public License for more details.
16 |
17 | You should have received a copy of the GNU Lesser General
18 | Public License along with this library; if not, write to the
19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 | Boston, MA 02111-1307 USA
21 |
22 | $Id: wiring.h 239 2007-01-12 17:58:39Z mellis $
23 | */
24 |
25 | #ifndef WiringPrivate_h
26 | #define WiringPrivate_h
27 |
28 | #include
29 | #include
30 |
31 | #include "Arduino.h"
32 |
33 | #ifdef __cplusplus
34 | extern "C" {
35 | #endif
36 |
37 | typedef void (*voidFuncPtr)(void);
38 |
39 | void initPins();
40 |
41 | #ifdef __cplusplus
42 | } // extern "C"
43 | #endif
44 |
45 | #endif
46 |
--------------------------------------------------------------------------------
/src/main.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * main.cpp
3 | *
4 | *
5 | * 2017 July ChrisMicro
6 | *
7 | */
8 |
9 | //#include
10 | //using namespace std;
11 | //#include "./cores/arduino/SerialConsole.h"
12 | #include "Arduino.h"
13 | #include SKETCH_FILE
14 |
15 |
16 | //SerialConsole Serial;
17 |
18 | //#include "sketch.ino"
19 | //#include "Blink.ino"
20 | //#include "AnalogReadSerial.ino"
21 | //#include "TFT_demo.ino"
22 | //#include "Touch.ino"
23 | //#include "Flappy.ino"
24 | //#include "Adafruit_touchpaint.ino"
25 | //#include "Adafruit_pictureEmbed.ino"
26 | //#include "gameOfLife.ino"
27 | //#include "cellArt.ino"
28 | //#include "TekSpriteEditor.ino"
29 | //#include "guiTest.ino"
30 | //#include
31 |
32 | int main()
33 | {
34 | //XWindow win(480,270,"test");
35 | //win.initScreen();
36 |
37 | //initScreen();
38 |
39 | setup();
40 | //XWindow staticTFT;
41 | //while(!staticTFT.MouseButtonRight_flag) // mousebutton flag of any window used for exit
42 | //while(!staticTFT.exitRequested())
43 | while(1) // tbd: no clean exit yet
44 | {
45 | loop();
46 | delayMicroseconds(10); // leave a little bit calculation time to other applications
47 | }
48 |
49 | //closeScreen();
50 |
51 | //win.closeScreen();
52 | return 0;
53 | }
54 |
55 |
56 | /*
57 | ArduinoOnPc
58 |
59 | © ChrisMicro 2017.
60 | This file is part of ArduinoOnPc.
61 | ArduinoOnPc is free software: you can redistribute it and/or modify
62 | it under the terms of the GNU Lesser General Public License as published by
63 | the Free Software Foundation, either version 3 of the License, or
64 | (at your option) any later version.
65 | GuiPittix is distributed in the hope that it will be useful,
66 | but WITHOUT ANY WARRANTY; without even the implied warranty of
67 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
68 | GNU Lesser General Public License for more details.
69 | You should have received a copy of the GNU Lesser General Public License
70 | along with ArduinoOnPc. If not, see .
71 |
72 | web-site: https://github.com/ChrisMicro/ArduinoOnPc
73 | */
74 |
--------------------------------------------------------------------------------
/src/system/TFT_LinuxWrapper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Adafruit_GFX to Posix interface
3 | *
4 | *
5 | * 2017 July ChrisMicro
6 | *
7 | */
8 | #ifndef _TFT_LinuxWrapper_
9 | #define _TFT_LinuxWrapper_
10 |
11 | #include "Arduino.h"
12 |
13 | #include "Adafruit_GFX.h"
14 | #include "XWindow.h"
15 | #include "Touch_LinuxWrapper.h"
16 |
17 | #define LTDC_BLACK 0x0000 /* 0, 0, 0 */
18 | #define LTDC_NAVY 0x000F /* 0, 0, 128 */
19 | #define LTDC_DARKGREEN 0x03E0 /* 0, 128, 0 */
20 | #define LTDC_DARKCYAN 0x03EF /* 0, 128, 128 */
21 | #define LTDC_MAROON 0x7800 /* 128, 0, 0 */
22 | #define LTDC_PURPLE 0x780F /* 128, 0, 128 */
23 | #define LTDC_OLIVE 0x7BE0 /* 128, 128, 0 */
24 | #define LTDC_LIGHTGREY 0xC618 /* 192, 192, 192 */
25 | #define LTDC_DARKGREY 0x7BEF /* 128, 128, 128 */
26 | #define LTDC_BLUE 0x001F /* 0, 0, 255 */
27 | #define LTDC_GREEN 0x07E0 /* 0, 255, 0 */
28 | #define LTDC_CYAN 0x07FF /* 0, 255, 255 */
29 | #define LTDC_RED 0xF800 /* 255, 0, 0 */
30 | #define LTDC_MAGENTA 0xF81F /* 255, 0, 255 */
31 | #define LTDC_YELLOW 0xFFE0 /* 255, 255, 0 */
32 | #define LTDC_WHITE 0xFFFF /* 255, 255, 255 */
33 | #define LTDC_ORANGE 0xFD20 /* 255, 165, 0 */
34 | #define LTDC_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
35 | #define LTDC_PINK 0xF81F
36 |
37 | // attention: size optitions to be reworked!
38 |
39 | #define TFT_WIDTH 480
40 | #define TFT_HEIGHT 272
41 |
42 | class TFT_LinuxWrapper : public Adafruit_GFX
43 | {
44 |
45 |
46 | public:
47 |
48 | XWindow *win;
49 |
50 | // FIXME: add comment, why are X and Y reversed and setRotation(1) used below?
51 | TFT_LinuxWrapper(): Adafruit_GFX((int16_t) TFT_HEIGHT, (int16_t) TFT_WIDTH)
52 | {
53 | win=new XWindow(TFT_WIDTH,TFT_HEIGHT,"TFT emulation");
54 | }
55 |
56 | // FIXME: reversed too, see above.
57 | TFT_LinuxWrapper(uint16_t sizex, uint16_t sizey): Adafruit_GFX(sizey, sizex)
58 | {
59 | win=new XWindow(sizex, sizey,"TFT emulation");
60 | }
61 |
62 | void init()
63 | {
64 |
65 | };
66 |
67 | void begin()
68 | {
69 | win->initScreen();
70 | TouchScreen::setWindow(win);
71 | setRotation(1);
72 | delay(500); // give time to setup window
73 |
74 | };
75 |
76 | uint32_t RGB565TORGB8888(int16_t RGB565)
77 | {
78 | int color = RGB565;
79 | uint8_t r = ((color >> 11) & 0x1F) << 3;
80 | uint8_t g = ((color >> 5) & 0x3F) << 2;
81 | uint8_t b = (color & 0x1F) << 3;
82 | uint32_t RGB8888 = 0XFF000000 | r << 16 | g << 8 | b;
83 |
84 | return RGB8888;
85 | }
86 | /*
87 | void setColor(int16_t RGB565)
88 | {
89 |
90 | }
91 | */
92 | void drawPixel(int16_t x, int16_t y, uint16_t color)
93 | {
94 | win->drawPoint_Color565 ( x,y, color );
95 | };
96 |
97 | void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
98 | {
99 | //for(int n=0;ndrawLine_Color565(x,y,x,y+h,color);
101 | };
102 |
103 | void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
104 | {
105 | //for(int n=0;ndrawLine_Color565(x,y,x+w,y,color);
107 | };
108 |
109 | void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
110 | {
111 | for(int n=0;n> 3);
118 | }
119 |
120 | };
121 | #endif // TFT_LinuxWrapper
122 |
123 | /*
124 | ArduinoOnPc
125 |
126 | © ChrisMicro 2017.
127 | This file is part of ArduinoOnPc.
128 | ArduinoOnPc is free software: you can redistribute it and/or modify
129 | it under the terms of the GNU Lesser General Public License as published by
130 | the Free Software Foundation, either version 3 of the License, or
131 | (at your option) any later version.
132 | GuiPittix is distributed in the hope that it will be useful,
133 | but WITHOUT ANY WARRANTY; without even the implied warranty of
134 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
135 | GNU Lesser General Public License for more details.
136 | You should have received a copy of the GNU Lesser General Public License
137 | along with ArduinoOnPc. If not, see .
138 |
139 | web-site: https://github.com/ChrisMicro/ArduinoOnPc
140 | */
141 |
--------------------------------------------------------------------------------
/src/system/Touch_LinuxWrapper.cpp:
--------------------------------------------------------------------------------
1 | // Adafruit compatible touchscreen wrapper
2 | // June 2017 by ChrisMicro
3 |
4 | #include "Touch_LinuxWrapper.h"
5 | #include "XWindow.h"
6 |
7 | XWindow *TouchScreen::window=NULL;
8 |
9 | void TouchScreen::setWindow(XWindow *win)
10 | {
11 | window=win;
12 | }
13 |
14 | TouchScreen::TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, uint16_t rxplate = 0)
15 | {
16 | window = NULL;
17 | isInitialized = false;
18 | }
19 |
20 | TouchScreen::TouchScreen()
21 | {
22 | window = NULL;
23 | isInitialized = false;
24 | }
25 |
26 | bool TouchScreen::Touch_Read()
27 | {
28 | bool flag=false;
29 | if ( !isInitialized )
30 | {
31 | isInitialized = true;
32 | }
33 |
34 | if(window!=NULL)
35 | {
36 | window->mouseUpdate();
37 | flag=true;
38 | }
39 | return flag;
40 | }
41 |
42 | TSPoint::TSPoint(void)
43 | {
44 | x = y = z = 0;
45 | }
46 |
47 | TSPoint::TSPoint(int16_t x0, int16_t y0, int16_t z0)
48 | {
49 | x = x0;
50 | y = y0;
51 | z = z0;
52 | }
53 |
54 | bool TSPoint::operator==(TSPoint p1)
55 | {
56 | return ((p1.x == x) && (p1.y == y) && (p1.z == z));
57 | }
58 |
59 | bool TSPoint::operator!=(TSPoint p1)
60 | {
61 | return ((p1.x != x) || (p1.y != y) || (p1.z != z));
62 | }
63 |
64 | TSPoint TouchScreen::getPoint(void)
65 | {
66 | TSPoint p;
67 |
68 | p.x=p.y=p.z=0;
69 |
70 | if(Touch_Read())
71 | {
72 | p.x = window->MouseX;
73 | p.y = window->MouseY;
74 | p.z = window->MouseButtonLeft_flag * 500;
75 | }
76 |
77 | return p;
78 |
79 | }
80 |
81 |
82 |
83 | int TouchScreen::readTouchX(void)
84 | {
85 | if(Touch_Read())
86 | {
87 | return window->MouseX;
88 |
89 | }else return 0;
90 | }
91 |
92 |
93 | int TouchScreen::readTouchY(void)
94 | {
95 | if(Touch_Read())
96 | {
97 | return window->MouseY;
98 |
99 | }else return 0;
100 | }
101 |
102 |
103 | uint16_t TouchScreen::pressure(void)
104 | {
105 | if(Touch_Read())
106 | {
107 | return window->MouseButtonLeft_flag * 500;
108 |
109 | }else return 0;
110 | }
111 |
112 | /*
113 | ArduinoOnPc
114 |
115 | © ChrisMicro 2017.
116 | This file is part of ArduinoOnPc.
117 | ArduinoOnPc is free software: you can redistribute it and/or modify
118 | it under the terms of the GNU Lesser General Public License as published by
119 | the Free Software Foundation, either version 3 of the License, or
120 | (at your option) any later version.
121 | GuiPittix is distributed in the hope that it will be useful,
122 | but WITHOUT ANY WARRANTY; without even the implied warranty of
123 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
124 | GNU Lesser General Public License for more details.
125 | You should have received a copy of the GNU Lesser General Public License
126 | along with ArduinoOnPc. If not, see .
127 |
128 | web-site: https://github.com/ChrisMicro/ArduinoOnPc
129 | */
130 |
--------------------------------------------------------------------------------
/src/system/Touch_LinuxWrapper.h:
--------------------------------------------------------------------------------
1 | // Touch screen library with X Y and Z (pressure) readings as well
2 | // as oversampling to avoid 'bouncing'
3 | // (c) ladyada / adafruit
4 | // Code under MIT License
5 | // adapted for STM32F746 Discovery
6 | // by ChrisMicro
7 |
8 | #ifndef _ADAFRUIT_TOUCHSCREEN_H_
9 | #define _ADAFRUIT_TOUCHSCREEN_H_
10 | #include
11 | //#include "posixWrapper.h"
12 | #include "XWindow.h"
13 |
14 | class TSPoint
15 | {
16 | public:
17 | TSPoint(void);
18 | TSPoint(int16_t x, int16_t y, int16_t z);
19 |
20 | bool operator==(TSPoint);
21 | bool operator!=(TSPoint);
22 |
23 | int16_t x, y, z;
24 | };
25 |
26 | class TouchScreen
27 | {
28 | public:
29 | static XWindow *window;
30 |
31 | static void setWindow(XWindow *window);
32 |
33 | TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, uint16_t rx);
34 | TouchScreen(void);
35 | bool isTouching(void);
36 | uint16_t pressure(void);
37 | int readTouchY();
38 | int readTouchX();
39 | TSPoint getPoint();
40 | //int16_t pressureThreshhold;
41 |
42 | private:
43 | bool Touch_Read(void);
44 | uint8_t isInitialized;
45 | };
46 |
47 | #endif
48 |
49 | /*
50 | ArduinoOnPc
51 |
52 | © ChrisMicro 2017.
53 | This file is part of ArduinoOnPc.
54 | ArduinoOnPc is free software: you can redistribute it and/or modify
55 | it under the terms of the GNU Lesser General Public License as published by
56 | the Free Software Foundation, either version 3 of the License, or
57 | (at your option) any later version.
58 | GuiPittix is distributed in the hope that it will be useful,
59 | but WITHOUT ANY WARRANTY; without even the implied warranty of
60 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
61 | GNU Lesser General Public License for more details.
62 | You should have received a copy of the GNU Lesser General Public License
63 | along with ArduinoOnPc. If not, see .
64 |
65 | web-site: https://github.com/ChrisMicro/ArduinoOnPc
66 | */
67 |
--------------------------------------------------------------------------------
/src/system/XWindow.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * XWindow.cpp
3 | *
4 | * Created on: 23.07.2017
5 | * Author: christoph
6 | */
7 |
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | /*
15 | * function: create_simple_window. Creates a window with a white background
16 | * in the given size.
17 | * input: display, size of the window (in pixels), and location of the window
18 | * (in pixels).
19 | * output: the window's ID.
20 | * notes: window is created with a black border, 2 pixels wide.
21 | * the window is automatically mapped after its creation.
22 | */
23 | Window XWindow::create_simple_window(Display* display, int width, int height, int x, int y)
24 | {
25 | int screen_num = DefaultScreen(display);
26 | int win_border_width = 2;
27 | Window win;
28 |
29 | /*
30 | create a simple window, as a direct child of the screen's
31 | root window. Use the screen's black and white colors as
32 | the foreground and background colors of the window,
33 | respectively. Place the new window's top-left corner at
34 | the given 'x,y' coordinates.
35 | */
36 | win = XCreateSimpleWindow(display, RootWindow(display, screen_num), x, y,
37 | width, height, win_border_width, BlackPixel(display, screen_num),
38 | WhitePixel(display, screen_num));
39 |
40 | XSelectInput(display, win, ExposureMask);
41 |
42 | // Name the window
43 | //XStoreName(display, win, "ArduinoOnPc");
44 | XStoreName(display, win, windowTitle);
45 | XMapWindow(display, win);
46 | while (1) {
47 | XEvent event;
48 | XNextEvent(display, &event);
49 | if (event.type == Expose)
50 | break;
51 | }
52 |
53 | // flush all pending requests to the X server.
54 | XFlush(display);
55 |
56 | return win;
57 | }
58 |
59 | GC XWindow::create_gc( Display* display, Window win, int reverse_video )
60 | {
61 | GC gc; // handle of newly created GC.
62 | unsigned long valuemask = 0; // which values in 'values' to
63 | // check when creating the GC.
64 | XGCValues values; // initial values for the GC.
65 | unsigned int line_width = 2; // line width for the GC.
66 | int line_style = LineSolid; // style for lines drawing and
67 | int cap_style = CapButt; // style of the line's edje and
68 |
69 | int join_style = JoinBevel; // joined lines.
70 | int screen_num = DefaultScreen(display);
71 |
72 | gc = XCreateGC(display, win, valuemask, &values);
73 |
74 | if ((intptr_t)gc < 0)
75 | {
76 | fprintf(stderr, "XCreateGC: \n");
77 | }
78 |
79 | // allocate foreground and background colors for this GC.
80 | if (reverse_video)
81 | {
82 | XSetForeground(display, gc, WhitePixel(display, screen_num));
83 | XSetBackground(display, gc, BlackPixel(display, screen_num));
84 | } else
85 | {
86 | XSetForeground(display, gc, BlackPixel(display, screen_num));
87 | XSetBackground(display, gc, WhitePixel(display, screen_num));
88 | }
89 |
90 | // define the style of lines that will be drawn using this GC.
91 | XSetLineAttributes(display, gc, line_width, line_style, cap_style, join_style);
92 |
93 | // define the fill style for the GC. to be 'solid filling'.
94 | XSetFillStyle(display, gc, FillSolid);
95 |
96 | return gc;
97 | }
98 |
99 | uint16_t XWindow::MouseX = 0;
100 | uint16_t XWindow::MouseY = 0;
101 |
102 | uint8_t XWindow::MouseButtonLeft_flag = 0;
103 | uint8_t XWindow::MouseButtonRight_flag = 0;
104 |
105 |
106 | XWindow::XWindow(int windowWidth, int windowHeight, char const* windowTitle)
107 | {
108 | width = windowWidth;
109 | height = windowHeight;
110 | this->windowTitle=windowTitle;
111 | }
112 | /*
113 | XWindow::XWindow()
114 | {
115 | XWindow::XWindow(320,240,"default");
116 | }*/
117 |
118 | void XWindow::initScreen()
119 | {
120 | char *display_name = getenv("DISPLAY"); // address of the X display.
121 |
122 | // open connection with the X server.
123 | display = XOpenDisplay(display_name);
124 | if (display == NULL)
125 | {
126 | //fprintf(stderr, "%s: cannot connect to X server '%s'\n",
127 | //argv[0], display_name);
128 | exit(1);
129 | }
130 |
131 | // get the geometry of the default screen for our display.
132 | screen_num = DefaultScreen(display);
133 | display_width = DisplayWidth(display, screen_num);
134 | display_height = DisplayHeight(display, screen_num);
135 |
136 | // create a simple window, as a direct child of the screen's
137 | // root window. Use the screen's white color as the background
138 | // color of the window. Place the new window's top-left corner
139 | // at the given 'x,y' coordinates.
140 |
141 | win = create_simple_window(display, width, height, 0, 0);
142 |
143 | // allocate a new GC (graphics context) for drawing in the window.
144 | gc = create_gc(display, win, 0); // window with black background
145 | //gc = create_gc(display, win, 1); // window white background
146 | XSync(display, False);
147 |
148 | // get access to the screen's color map.
149 | screen_colormap = DefaultColormap(display, DefaultScreen(display));
150 | }
151 |
152 | void XWindow::closeScreen()
153 | {
154 | //close the connection to the X server.
155 | XCloseDisplay(display);
156 | }
157 |
158 | void XWindow::setForeground_RGB(int r, int g, int b)
159 | {
160 | XColor xcolour;
161 |
162 | static int old_r = -1, old_g = -1, old_b = -1;
163 |
164 | // check of color hasn't changed and return ( more speed )
165 | if (r == old_r && g == old_g && b == old_b)
166 | return;
167 |
168 | old_r = r;
169 | old_g = g;
170 | old_b = b;
171 |
172 | xcolour.red = r * 255;
173 | xcolour.green = g * 255;
174 | xcolour.blue = b * 255;
175 |
176 | xcolour.flags = DoRed | DoGreen | DoBlue;
177 | XAllocColor(display, screen_colormap, &xcolour);
178 |
179 | XSetForeground(display, gc, xcolour.pixel); // BlackPixel(display, screen_num))
180 | }
181 |
182 | void XWindow::drawPoint_RGB(int x, int y, int r, int g, int b)
183 | {
184 | setForeground_RGB(r, g, b);
185 | XDrawPoint(display, win, gc, x, y);
186 | }
187 |
188 | uint16_t color565(uint8_t r, uint8_t g, uint8_t b)
189 | {
190 | return ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3);
191 | }
192 |
193 | void XWindow::drawPoint_Color565(int x, int y, uint16_t color)
194 | {
195 | int r = color >> 8;
196 | int g = (color & 0x7E0) >> 3;
197 | int b = (color & 0x1F) * 8;
198 | drawPoint_RGB(x, y, r, g, b);
199 | }
200 |
201 | void XWindow::drawLine_RGB(int x1, int y1, int x2, int y2, int r, int g, int b)
202 | {
203 | setForeground_RGB(r, g, b);
204 | XDrawLine(display, win, gc, x1, y1, x2, y2);
205 | XFlush(display);
206 |
207 | }
208 |
209 | void XWindow::drawLine_Color565(int x1, int y1, int x2, int y2, uint16_t color)
210 | {
211 | int r = color >> 8;
212 | int g = (color & 0x7E0) >> 3;
213 | int b = (color & 0x1F) * 8;
214 | drawLine_RGB(x1, y1, x2, y2, r, g, b);
215 | }
216 |
217 | void XWindow::showNow()
218 | {
219 | //flush all pending requests to the X server.
220 | XFlush(display);
221 | }
222 |
223 |
224 |
225 | void XWindow::mouseUpdate()
226 | {
227 | Window ret_root;
228 | Window ret_child;
229 | int root_x;
230 | int root_y;
231 | int win_x;
232 | int win_y;
233 | unsigned int mask;
234 |
235 | if (XQueryPointer(display, win, &ret_root, &ret_child, &root_x, &root_y,
236 | &win_x, &win_y, &mask))
237 | {
238 | //printf("%d %d , %x\n", win_x, win_y, mask);
239 | //if(mask&0x100)printf("left button pressed\n");
240 | //if(mask&0x400)printf("right button pressed\n");
241 | //if(mask&0x200)printf("center button pressed\n");
242 | MouseX = win_x;
243 | MouseY = win_y;
244 | MouseButtonLeft_flag = ((mask & 0x100) != 0);
245 | MouseButtonRight_flag = ((mask & 0x400) != 0);
246 | }
247 |
248 | }
249 |
250 | uint8_t XWindow::exitRequested()
251 | {
252 | mouseUpdate();
253 | return (uint8_t) MouseButtonRight_flag;
254 | }
255 |
256 | /*
257 | ArduinoOnPc
258 |
259 | © ChrisMicro 2017.
260 | This file is part of ArduinoOnPc.
261 | ArduinoOnPc is free software: you can redistribute it and/or modify
262 | it under the terms of the GNU Lesser General Public License as published by
263 | the Free Software Foundation, either version 3 of the License, or
264 | (at your option) any later version.
265 | GuiPittix is distributed in the hope that it will be useful,
266 | but WITHOUT ANY WARRANTY; without even the implied warranty of
267 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
268 | GNU Lesser General Public License for more details.
269 | You should have received a copy of the GNU Lesser General Public License
270 | along with ArduinoOnPc. If not, see .
271 |
272 | web-site: https://github.com/ChrisMicro/ArduinoOnPc
273 | */
274 |
275 |
276 |
277 |
278 |
--------------------------------------------------------------------------------
/src/system/XWindow.h:
--------------------------------------------------------------------------------
1 | /*
2 | * XWindow.h
3 | *
4 | * Created on: 23.07.2017
5 | * Author: christoph
6 | */
7 |
8 | #ifndef SYSTEM_XWINDOW_H_
9 | #define SYSTEM_XWINDOW_H_
10 |
11 | #include
12 | #include
13 |
14 | // RGB565 colors
15 | #define COLOR_BLACK 0x0000 /* 0, 0, 0 */
16 | #define COLOR_NAVY 0x000F /* 0, 0, 128 */
17 | #define COLOR_DARKGREEN 0x03E0 /* 0, 128, 0 */
18 | #define COLOR_DARKCYAN 0x03EF /* 0, 128, 128 */
19 | #define COLOR_MAROON 0x7800 /* 128, 0, 0 */
20 | #define COLOR_PURPLE 0x780F /* 128, 0, 128 */
21 | #define COLOR_OLIVE 0x7BE0 /* 128, 128, 0 */
22 | #define COLOR_LIGHTGREY 0xC618 /* 192, 192, 192 */
23 | #define COLOR_DARKGREY 0x7BEF /* 128, 128, 128 */
24 | #define COLOR_GREY COLOR_LIGHTGREY
25 | #define COLOR_BLUE 0x001F /* 0, 0, 255 */
26 | #define COLOR_GREEN 0x07E0 /* 0, 255, 0 */
27 | #define COLOR_CYAN 0x07FF /* 0, 255, 255 */
28 | #define COLOR_RED 0xF800 /* 255, 0, 0 */
29 | #define COLOR_MAGENTA 0xF81F /* 255, 0, 255 */
30 | #define COLOR_YELLOW 0xFFE0 /* 255, 255, 0 */
31 | #define COLOR_WHITE 0xFFFF /* 255, 255, 255 */
32 | #define COLOR_ORANGE 0xFD20 /* 255, 165, 0 */
33 | #define COLOR_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
34 | #define COLOR_PINK 0xF81F
35 |
36 | class XWindow
37 | {
38 | private:
39 | char const* windowTitle;
40 | Display* display; // pointer to X Display structure.
41 | int screen_num; // number of screen to place the window on.
42 | Window win; // pointer to the newly created window.
43 | unsigned int display_width, display_height; // height and width of the X display.
44 | unsigned int width, height; // height and width for the new window.
45 |
46 | GC gc; // GC (graphics context) used for drawing in our window.
47 | Colormap screen_colormap; // color map to use for allocating colors.
48 |
49 | XColor red, brown, blue, yellow, green; // used for allocation of the given color
50 | // map entries.
51 | Status rc; // return status of various Xlib functions.
52 |
53 | Window create_simple_window(Display* display, int width, int height, int x, int y);
54 | GC create_gc( Display* display, Window win, int reverse_video );
55 | void setForeground_RGB(int r, int g, int b);
56 |
57 | public:
58 | static uint16_t MouseX;
59 | static uint16_t MouseY;
60 |
61 | static uint8_t MouseButtonLeft_flag;
62 | static uint8_t MouseButtonRight_flag;
63 | //XWindow();
64 | XWindow(int windowWidth=320, int windowHeight=240, char const * windowTitle="default");
65 | void initScreen();
66 | void punktTest();
67 | void drawPoint_RGB(int x, int y, int r, int g, int b);
68 | void drawLine_RGB(int x1, int y1, int x2, int y2, int r, int g, int b);
69 | void drawPoint_Color565(int x, int y, uint16_t color);
70 | void drawLine_Color565(int x1, int y1, int x2, int y2, uint16_t color);
71 | void showNow();
72 | void closeScreen();
73 | void mouseUpdate();
74 | uint8_t exitRequested();
75 | };
76 |
77 | #endif /* SYSTEM_XWINDOW_H_ */
78 |
79 | /*
80 | ArduinoOnPc
81 |
82 | © ChrisMicro 2017.
83 | This file is part of ArduinoOnPc.
84 | ArduinoOnPc is free software: you can redistribute it and/or modify
85 | it under the terms of the GNU Lesser General Public License as published by
86 | the Free Software Foundation, either version 3 of the License, or
87 | (at your option) any later version.
88 | GuiPittix is distributed in the hope that it will be useful,
89 | but WITHOUT ANY WARRANTY; without even the implied warranty of
90 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
91 | GNU Lesser General Public License for more details.
92 | You should have received a copy of the GNU Lesser General Public License
93 | along with ArduinoOnPc. If not, see .
94 |
95 | web-site: https://github.com/ChrisMicro/ArduinoOnPc
96 | */
97 |
--------------------------------------------------------------------------------
/src/system/depreciated/posixWrapper.h:
--------------------------------------------------------------------------------
1 | /*
2 | * posixWrapper.h
3 | *
4 | * Created on: 06.07.2017
5 | * Author: ChrisMicro
6 | */
7 | #ifdef __cplusplus
8 | extern "C"
9 | {
10 | #endif
11 |
12 | #ifndef PUNKT_H_
13 | #define PUNKT_H_
14 |
15 | #include
16 | #include "posixTime.h"
17 |
18 | // RGB565 colors
19 | #define COLOR_BLACK 0x0000 /* 0, 0, 0 */
20 | #define COLOR_NAVY 0x000F /* 0, 0, 128 */
21 | #define COLOR_DARKGREEN 0x03E0 /* 0, 128, 0 */
22 | #define COLOR_DARKCYAN 0x03EF /* 0, 128, 128 */
23 | #define COLOR_MAROON 0x7800 /* 128, 0, 0 */
24 | #define COLOR_PURPLE 0x780F /* 128, 0, 128 */
25 | #define COLOR_OLIVE 0x7BE0 /* 128, 128, 0 */
26 | #define COLOR_LIGHTGREY 0xC618 /* 192, 192, 192 */
27 | #define COLOR_DARKGREY 0x7BEF /* 128, 128, 128 */
28 | #define COLOR_GREY COLOR_LIGHTGREY
29 | #define COLOR_BLUE 0x001F /* 0, 0, 255 */
30 | #define COLOR_GREEN 0x07E0 /* 0, 255, 0 */
31 | #define COLOR_CYAN 0x07FF /* 0, 255, 255 */
32 | #define COLOR_RED 0xF800 /* 255, 0, 0 */
33 | #define COLOR_MAGENTA 0xF81F /* 255, 0, 255 */
34 | #define COLOR_YELLOW 0xFFE0 /* 255, 255, 0 */
35 | #define COLOR_WHITE 0xFFFF /* 255, 255, 255 */
36 | #define COLOR_ORANGE 0xFD20 /* 255, 165, 0 */
37 | #define COLOR_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
38 | #define COLOR_PINK 0xF81F
39 |
40 | void initScreen();
41 | void punktTest();
42 | void drawPoint_Black(int x , int y);
43 | void drawPoint_RGB(int x , int y, int r, int g, int b);
44 | void drawPoint_Color565(int x, int y, uint16_t color);
45 | void drawLine_Color565(int x1, int y1, int x2, int y2, uint16_t color);
46 | void showNow();
47 | void closeScreen();
48 |
49 | void mouseTest();
50 |
51 | void mouseUpdate();
52 | extern uint16_t MouseX;
53 | extern uint16_t MouseY;
54 | extern uint8_t MouseButtonLeft_flag;
55 |
56 | uint8_t exitRequested();
57 |
58 |
59 | #endif /* PUNKT_H_ */
60 |
61 | #ifdef __cplusplus
62 | }
63 | #endif
64 |
65 | /*
66 | ArduinoOnPc
67 |
68 | © ChrisMicro 2017.
69 | This file is part of ArduinoOnPc.
70 | ArduinoOnPc is free software: you can redistribute it and/or modify
71 | it under the terms of the GNU Lesser General Public License as published by
72 | the Free Software Foundation, either version 3 of the License, or
73 | (at your option) any later version.
74 | GuiPittix is distributed in the hope that it will be useful,
75 | but WITHOUT ANY WARRANTY; without even the implied warranty of
76 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
77 | GNU Lesser General Public License for more details.
78 | You should have received a copy of the GNU Lesser General Public License
79 | along with ArduinoOnPc. If not, see .
80 |
81 | web-site: https://github.com/ChrisMicro/ArduinoOnPc
82 | */
83 |
--------------------------------------------------------------------------------
/src/system/posixTime.c:
--------------------------------------------------------------------------------
1 | /*
2 | * posixTime.c
3 | *
4 | * Created on: 23.07.2017
5 | * Author: ChrisMicro
6 | */
7 |
8 |
9 | #include
10 | #include "posixTime.h"
11 |
12 | #include
13 | #include /* getenv(), etc. */
14 | #include /* sleep(), etc. */
15 | #include
16 | #include
17 |
18 | /*
19 | // call this function to start a nanosecond-resolution timer
20 | struct timespec timer_start(){
21 | struct timespec start_time;
22 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time);
23 | return start_time;
24 | }
25 |
26 | // call this function to end a timer, returning nanoseconds elapsed as a long
27 | long timer_end(struct timespec start_time){
28 | struct timespec end_time;
29 | clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time);
30 | long diffInNanos = end_time.tv_nsec - start_time.tv_nsec;
31 | return diffInNanos;
32 | }*/
33 |
34 | // Arduino Funktions
35 |
36 |
37 |
38 | long long current_timestamp()
39 | {
40 | struct timeval te;
41 | gettimeofday(&te, NULL); // get current time
42 | long long milliseconds = te.tv_sec*1000LL + te.tv_usec/1000; // calculate milliseconds
43 | return milliseconds;
44 | }
45 |
46 | uint32_t millis()
47 | {
48 | static int runningTheFirstTime_flag = 1;
49 | static uint64_t startTime_msec;
50 | uint32_t t;
51 |
52 | if( runningTheFirstTime_flag )
53 | {
54 | runningTheFirstTime_flag = 0;
55 | t = 0;
56 | startTime_msec = current_timestamp();
57 | }else
58 | {
59 | t = current_timestamp() - startTime_msec;
60 | }
61 | return t;
62 | }
63 |
64 | uint32_t micros()
65 | {
66 | return millis()*1000;
67 | }
68 |
69 | void delayMicroseconds(uint32_t t)
70 | {
71 | usleep(t);
72 | }
73 |
74 | void delay(uint32_t t)
75 | {
76 | usleep( (uint64_t)t *1000);
77 | }
78 |
79 | void yield()
80 | {
81 |
82 | }
83 |
84 | /*
85 | ArduinoOnPc
86 |
87 | © ChrisMicro 2017.
88 | This file is part of ArduinoOnPc.
89 | ArduinoOnPc is free software: you can redistribute it and/or modify
90 | it under the terms of the GNU Lesser General Public License as published by
91 | the Free Software Foundation, either version 3 of the License, or
92 | (at your option) any later version.
93 | GuiPittix is distributed in the hope that it will be useful,
94 | but WITHOUT ANY WARRANTY; without even the implied warranty of
95 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96 | GNU Lesser General Public License for more details.
97 | You should have received a copy of the GNU Lesser General Public License
98 | along with ArduinoOnPc. If not, see .
99 |
100 | web-site: https://github.com/ChrisMicro/ArduinoOnPc
101 | */
102 |
103 |
104 |
--------------------------------------------------------------------------------
/src/system/posixTime.h:
--------------------------------------------------------------------------------
1 | /*
2 | * posixTime.h
3 | *
4 | * Created on: 23.07.2017
5 | * Author: ChirsMicro
6 | */
7 |
8 | #ifdef __cplusplus
9 | extern "C"
10 | {
11 | #endif
12 |
13 | #ifndef SYSTEM_POSIXTIME_H_
14 | #define SYSTEM_POSIXTIME_H_
15 |
16 | #include
17 |
18 | uint32_t millis();
19 | uint32_t micros();
20 | void delayMicroseconds(uint32_t t);
21 | void delay(uint32_t t);
22 | void yield();
23 |
24 | #endif /* SYSTEM_POSIXTIME_H_ */
25 |
26 | #ifdef __cplusplus
27 | }
28 | #endif
29 |
30 | /*
31 | ArduinoOnPc
32 |
33 | © ChrisMicro 2017.
34 | This file is part of ArduinoOnPc.
35 | ArduinoOnPc is free software: you can redistribute it and/or modify
36 | it under the terms of the GNU Lesser General Public License as published by
37 | the Free Software Foundation, either version 3 of the License, or
38 | (at your option) any later version.
39 | GuiPittix is distributed in the hope that it will be useful,
40 | but WITHOUT ANY WARRANTY; without even the implied warranty of
41 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 | GNU Lesser General Public License for more details.
43 | You should have received a copy of the GNU Lesser General Public License
44 | along with ArduinoOnPc. If not, see .
45 |
46 | web-site: https://github.com/ChrisMicro/ArduinoOnPc
47 | */
48 |
--------------------------------------------------------------------------------