This program operates a pH meter and requires an Excel spreadsheet template available at www.kissinstrments.com

Dependencies:   mbed

Committer:
KISScientific
Date:
Fri Jul 22 00:03:25 2016 +0000
Revision:
0:f6b418db17d2
pH-V12 version 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
KISScientific 0:f6b418db17d2 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
KISScientific 0:f6b418db17d2 2 *
KISScientific 0:f6b418db17d2 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
KISScientific 0:f6b418db17d2 4 * and associated documentation files (the "Software"), to deal in the Software without
KISScientific 0:f6b418db17d2 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
KISScientific 0:f6b418db17d2 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
KISScientific 0:f6b418db17d2 7 * Software is furnished to do so, subject to the following conditions:
KISScientific 0:f6b418db17d2 8 *
KISScientific 0:f6b418db17d2 9 * The above copyright notice and this permission notice shall be included in all copies or
KISScientific 0:f6b418db17d2 10 * substantial portions of the Software.
KISScientific 0:f6b418db17d2 11 *
KISScientific 0:f6b418db17d2 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
KISScientific 0:f6b418db17d2 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
KISScientific 0:f6b418db17d2 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
KISScientific 0:f6b418db17d2 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
KISScientific 0:f6b418db17d2 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
KISScientific 0:f6b418db17d2 17 */
KISScientific 0:f6b418db17d2 18
KISScientific 0:f6b418db17d2 19 #include "stdint.h"
KISScientific 0:f6b418db17d2 20 #include "USBMIDI.h"
KISScientific 0:f6b418db17d2 21
KISScientific 0:f6b418db17d2 22
KISScientific 0:f6b418db17d2 23 USBMIDI::USBMIDI(uint16_t vendor_id, uint16_t product_id, uint16_t product_release): USBDevice(vendor_id, product_id, product_release) {
KISScientific 0:f6b418db17d2 24 midi_evt = NULL;
KISScientific 0:f6b418db17d2 25 USBDevice::connect();
KISScientific 0:f6b418db17d2 26 }
KISScientific 0:f6b418db17d2 27
KISScientific 0:f6b418db17d2 28 void USBMIDI::write(MIDIMessage m) {
KISScientific 0:f6b418db17d2 29 USBDevice::write(EPBULK_IN, m.data, 4, MAX_PACKET_SIZE_EPBULK);
KISScientific 0:f6b418db17d2 30 }
KISScientific 0:f6b418db17d2 31
KISScientific 0:f6b418db17d2 32
KISScientific 0:f6b418db17d2 33 void USBMIDI::attach(void (*fptr)(MIDIMessage)) {
KISScientific 0:f6b418db17d2 34 midi_evt = fptr;
KISScientific 0:f6b418db17d2 35 }
KISScientific 0:f6b418db17d2 36
KISScientific 0:f6b418db17d2 37
KISScientific 0:f6b418db17d2 38 bool USBMIDI::EP2_OUT_callback() {
KISScientific 0:f6b418db17d2 39 uint8_t buf[64];
KISScientific 0:f6b418db17d2 40 uint32_t len;
KISScientific 0:f6b418db17d2 41 readEP(EPBULK_OUT, buf, &len, 64);
KISScientific 0:f6b418db17d2 42
KISScientific 0:f6b418db17d2 43 if (midi_evt != NULL) {
KISScientific 0:f6b418db17d2 44 for (int i=0; i<len; i+=4) {
KISScientific 0:f6b418db17d2 45 midi_evt(MIDIMessage(buf+i));
KISScientific 0:f6b418db17d2 46 }
KISScientific 0:f6b418db17d2 47 }
KISScientific 0:f6b418db17d2 48
KISScientific 0:f6b418db17d2 49 // We reactivate the endpoint to receive next characters
KISScientific 0:f6b418db17d2 50 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
KISScientific 0:f6b418db17d2 51 return true;
KISScientific 0:f6b418db17d2 52 }
KISScientific 0:f6b418db17d2 53
KISScientific 0:f6b418db17d2 54
KISScientific 0:f6b418db17d2 55
KISScientific 0:f6b418db17d2 56 // Called in ISR context
KISScientific 0:f6b418db17d2 57 // Set configuration. Return false if the
KISScientific 0:f6b418db17d2 58 // configuration is not supported.
KISScientific 0:f6b418db17d2 59 bool USBMIDI::USBCallback_setConfiguration(uint8_t configuration) {
KISScientific 0:f6b418db17d2 60 if (configuration != DEFAULT_CONFIGURATION) {
KISScientific 0:f6b418db17d2 61 return false;
KISScientific 0:f6b418db17d2 62 }
KISScientific 0:f6b418db17d2 63
KISScientific 0:f6b418db17d2 64 // Configure endpoints > 0
KISScientific 0:f6b418db17d2 65 addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPBULK);
KISScientific 0:f6b418db17d2 66 addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
KISScientific 0:f6b418db17d2 67
KISScientific 0:f6b418db17d2 68 // We activate the endpoint to be able to receive data
KISScientific 0:f6b418db17d2 69 readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
KISScientific 0:f6b418db17d2 70 return true;
KISScientific 0:f6b418db17d2 71 }
KISScientific 0:f6b418db17d2 72
KISScientific 0:f6b418db17d2 73
KISScientific 0:f6b418db17d2 74 uint8_t * USBMIDI::stringIinterfaceDesc() {
KISScientific 0:f6b418db17d2 75 static uint8_t stringIinterfaceDescriptor[] = {
KISScientific 0:f6b418db17d2 76 0x0c, //bLength
KISScientific 0:f6b418db17d2 77 STRING_DESCRIPTOR, //bDescriptorType 0x03
KISScientific 0:f6b418db17d2 78 'A',0,'u',0,'d',0,'i',0,'o',0 //bString iInterface - Audio
KISScientific 0:f6b418db17d2 79 };
KISScientific 0:f6b418db17d2 80 return stringIinterfaceDescriptor;
KISScientific 0:f6b418db17d2 81 }
KISScientific 0:f6b418db17d2 82
KISScientific 0:f6b418db17d2 83 uint8_t * USBMIDI::stringIproductDesc() {
KISScientific 0:f6b418db17d2 84 static uint8_t stringIproductDescriptor[] = {
KISScientific 0:f6b418db17d2 85 0x16, //bLength
KISScientific 0:f6b418db17d2 86 STRING_DESCRIPTOR, //bDescriptorType 0x03
KISScientific 0:f6b418db17d2 87 'M',0,'b',0,'e',0,'d',0,' ',0,'A',0,'u',0,'d',0,'i',0,'o',0 //bString iProduct - Mbed Audio
KISScientific 0:f6b418db17d2 88 };
KISScientific 0:f6b418db17d2 89 return stringIproductDescriptor;
KISScientific 0:f6b418db17d2 90 }
KISScientific 0:f6b418db17d2 91
KISScientific 0:f6b418db17d2 92
KISScientific 0:f6b418db17d2 93 uint8_t * USBMIDI::configurationDesc() {
KISScientific 0:f6b418db17d2 94 static uint8_t configDescriptor[] = {
KISScientific 0:f6b418db17d2 95 // configuration descriptor
KISScientific 0:f6b418db17d2 96 0x09, 0x02, 0x65, 0x00, 0x02, 0x01, 0x00, 0xc0, 0x50,
KISScientific 0:f6b418db17d2 97
KISScientific 0:f6b418db17d2 98 // The Audio Interface Collection
KISScientific 0:f6b418db17d2 99 0x09, 0x04, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, // Standard AC Interface Descriptor
KISScientific 0:f6b418db17d2 100 0x09, 0x24, 0x01, 0x00, 0x01, 0x09, 0x00, 0x01, 0x01, // Class-specific AC Interface Descriptor
KISScientific 0:f6b418db17d2 101 0x09, 0x04, 0x01, 0x00, 0x02, 0x01, 0x03, 0x00, 0x00, // MIDIStreaming Interface Descriptors
KISScientific 0:f6b418db17d2 102 0x07, 0x24, 0x01, 0x00, 0x01, 0x41, 0x00, // Class-Specific MS Interface Header Descriptor
KISScientific 0:f6b418db17d2 103
KISScientific 0:f6b418db17d2 104 // MIDI IN JACKS
KISScientific 0:f6b418db17d2 105 0x06, 0x24, 0x02, 0x01, 0x01, 0x00,
KISScientific 0:f6b418db17d2 106 0x06, 0x24, 0x02, 0x02, 0x02, 0x00,
KISScientific 0:f6b418db17d2 107
KISScientific 0:f6b418db17d2 108 // MIDI OUT JACKS
KISScientific 0:f6b418db17d2 109 0x09, 0x24, 0x03, 0x01, 0x03, 0x01, 0x02, 0x01, 0x00,
KISScientific 0:f6b418db17d2 110 0x09, 0x24, 0x03, 0x02, 0x06, 0x01, 0x01, 0x01, 0x00,
KISScientific 0:f6b418db17d2 111
KISScientific 0:f6b418db17d2 112 // OUT endpoint descriptor
KISScientific 0:f6b418db17d2 113 0x09, 0x05, 0x02, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00,
KISScientific 0:f6b418db17d2 114 0x05, 0x25, 0x01, 0x01, 0x01,
KISScientific 0:f6b418db17d2 115
KISScientific 0:f6b418db17d2 116 // IN endpoint descriptor
KISScientific 0:f6b418db17d2 117 0x09, 0x05, 0x82, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00,
KISScientific 0:f6b418db17d2 118 0x05, 0x25, 0x01, 0x01, 0x03,
KISScientific 0:f6b418db17d2 119 };
KISScientific 0:f6b418db17d2 120 return configDescriptor;
KISScientific 0:f6b418db17d2 121 }