Skip to content

Commit

Permalink
Using midi as libs now
Browse files Browse the repository at this point in the history
  • Loading branch information
jw-smaal committed Oct 22, 2020
1 parent e5693da commit 621df71
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 650 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ BUILD
mbed-os
TextLCD
SerialMidi
serialmidi
FXOS8700CQ
1 change: 1 addition & 0 deletions FXOS8700CQ.lib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
http://os.mbed.com/users/janjongboom/code/FXOS8700CQ/#2bd683278d237b4ea680823133145d4a08b070da
61 changes: 58 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
#include "mbed.h"
#include "SerialBase.h"
#include <cstdint>
#include <cstdio>

#include "serial-usart-midi.h"
#include "serial-midi.h"
#include "FXOS8700CQ.h"
#include "unity_internals.h"


/////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -154,13 +157,34 @@ SerialMidi serialMidiGlob(
void midi_tx_thread()
{
uint16_t b2in_value;
uint16_t b3in_value;
uint16_t b3in_value;
uint16_t prev_tmp;
uint16_t tmp;
int16_t tmpsig;
uint8_t tmp8_t;


// Analog inputs
AnalogIn b2in(PTB2, MBED_CONF_TARGET_DEFAULT_ADC_VREF);
AnalogIn b3in(PTB3, MBED_CONF_TARGET_DEFAULT_ADC_VREF);


// I prefer the USB console port of the mbed to be 115200
// This way printf's don't slow down the execution of the thread.
// too much.
BufferedSerial pc(USBTX, USBRX);
pc.set_baud(115200);

// Built in magneto and gyro chip of the NXP FRDM board
FXOS8700CQ magneto(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
magneto.enable();
printf("Sensor: %2X", magneto.get_whoami());
magneto.get_accel_scale();
// printf("Magneto %d %d %d\n",
// magneto.getMagnetX(),
// magneto.getMagnetY(),
// magneto.getMagnetZ() );

while(true ) {
/*
* MIDI TX processing
Expand All @@ -181,6 +205,8 @@ void midi_tx_thread()
SerialMidi::CTL_MSB_MODWHEEL,
tmp);
}


tmp = b3in.read_u16();
//printf("Read b3in %u\n",tmp);
if (tmp == b3in_value) {
Expand All @@ -193,7 +219,35 @@ void midi_tx_thread()
SerialMidi::CTL_MSB_EXPRESSION,
tmp);
}
ThisThread::sleep_for(3ms);


magneto.get_data();
// 16 bit signed
//printf("32768 -32768 ");
#if 1
printf("%04d %04d %04d ",
magneto.getMagnetX(),
magneto.getMagnetY(),
magneto.getMagnetZ());
// 14 bit signed
#endif
#if 1
printf("%04d %04d %04d \r\n",
magneto.getAccelX(),
magneto.getAccelY(),
magneto.getAccelZ());
#endif
tmpsig = magneto.getMagnetZ();
tmp = MIDI_DATA & ((tmpsig + 8192) >>4);

// Only send out if there is a change in value
if (prev_tmp != tmp ) {
serialMidiGlob.ControlChange(SerialMidi::CH2,
SerialMidi::CTL_MSB_MODWHEEL,
tmp);
prev_tmp = tmp;
}
ThisThread::sleep_for(30ms);
}
}

Expand All @@ -210,6 +264,7 @@ int main()
uint16_t b2in_value;
uint16_t b3in_value;
uint16_t tmp;


// I prefer the USB console port of the mbed to be 115200
// This way printf's don't slow down the execution of the thread.
Expand Down
2 changes: 1 addition & 1 deletion mbed-os.lib
Original file line number Diff line number Diff line change
@@ -1 +1 @@
https://github.com/ARMmbed/mbed-os/#a2ada74770f043aff3e61e29d164a8e78274fcd4
https://github.com/ARMmbed/mbed-os/#8ef0a435b2356f8159dea8e427b2935d177309f8
Loading

0 comments on commit 621df71

Please sign in to comment.