summaryrefslogtreecommitdiffstats
path: root/tools/simulator.c
diff options
context:
space:
mode:
authorDaveHodder67 <dave.hodder@focusrite.com>2015-07-02 18:32:18 +0100
committerDaveHodder67 <dave.hodder@focusrite.com>2015-07-02 18:32:18 +0100
commite1f9c0ada85d1538e08d5d51986bd4593f05ff9c (patch)
tree0dcd5b7ff29fdcfb468a7e607b0c4a968705066d /tools/simulator.c
parent114d76fbcd987bf382bc255af0128a839321ed84 (diff)
downloadlaunchpad-polymaker-e1f9c0ada85d1538e08d5d51986bd4593f05ff9c.tar.gz
launchpad-polymaker-e1f9c0ada85d1538e08d5d51986bd4593f05ff9c.zip
added trivial simulator.c
Though it’s nice, as it’s part of the build process to run the simulator - so if your app crashes, it won’t even get as far as the device.
Diffstat (limited to 'tools/simulator.c')
-rw-r--r--tools/simulator.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/tools/simulator.c b/tools/simulator.c
new file mode 100644
index 0000000..56298d7
--- /dev/null
+++ b/tools/simulator.c
@@ -0,0 +1,114 @@
1/******************************************************************************
2
3 Copyright (c) 2015, Focusrite Audio Engineering Ltd.
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8
9 * Redistributions of source code must retain the above copyright notice, this
10 list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
16 * Neither the name of Focusrite Audio Engineering Ltd., nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 *****************************************************************************/
32
33#include <stdio.h>
34#include "app.h"
35
36// ____________________________________________________________________________
37//
38// Simulator "hal". This lets you exercise your device code without having to upload
39// it to the hardware, which also means you can debug it interactively.
40// ____________________________________________________________________________
41
42void hal_plot_led(u8 type, u8 index, u8 red, u8 green, u8 blue)
43{
44 // wire this up to MIDI out...
45 printf("...hal_plot_led(%d, %d, %d, %d, %d);\n", type, index, red, green, blue);
46}
47
48void hal_send_midi(u8 port, u8 status, u8 d1, u8 d2)
49{
50 // send this up a virtual MIDI port?
51 printf("...hal_send_midi(%d, 0x%2.2x, 0x%2.2x, 0x%2.2x);\n", port, status, d1, d2);
52}
53
54void hal_send_sysex(u8 port, const u8* data, u16 length)
55{
56 // as above, or just dump to console?
57 printf("...hal_send_midi(%d, (data), %d);\n", port, length);
58}
59
60// ____________________________________________________________________________
61//
62// App event wrappers - these just log to the console. Would be nice to wire
63// these up to a MIDI input from the real Launchpad Pro!
64// ____________________________________________________________________________
65
66static void sim_app_init()
67{
68 printf("calling app_init()...\n");
69 app_init();
70}
71
72static void sim_app_surface_event(u8 type, u8 index, u8 value)
73{
74 printf("calling sim_app_surface_event(%d, %d, %d)...\n", type, index, value);
75 app_surface_event(type, index, value);
76}
77
78static void sim_app_midi_event(u8 port, u8 status, u8 d1, u8 d2)
79{
80 printf("calling app_midi_event(%d, 0x%2.2x, 0x%2.2x, 0x%2.2x)...\n", port, status, d1, d2);
81 app_midi_event(port, status, d1, d2);
82}
83
84static void sim_app_timer_event()
85{
86 printf("calling app_timer_event()...\n");
87 app_timer_event();
88}
89
90// ____________________________________________________________________________
91
92int main(int argc, char * argv[])
93{
94 // let's just call a few things to give the app a very brief workout.
95 sim_app_init();
96
97 // surface
98 sim_app_surface_event(TYPEPAD, 35, 127);
99 sim_app_surface_event(TYPESETUP, 0, 127);
100 sim_app_surface_event(TYPEPAD, 35, 0);
101
102 // MIDI
103 sim_app_midi_event(USBSTANDALONE, NOTEON, 60, 127);
104 sim_app_midi_event(USBSTANDALONE, NOTEON, 60, 0);
105
106 // timer
107 const int timerTicks = 21;
108 printf("sending %d timer events via app_timer_event()...\n", timerTicks);
109 for (int i=0; i < timerTicks; ++i)
110 {
111 sim_app_timer_event();
112 }
113 return 0;
114} \ No newline at end of file