Suga koubou
/
dmx_test
DMX512 library test http://mbed.org/users/okini3939/notebook/dmx512
Revision 4:4a566dc74bfb, committed 2013-09-02
- Comitter:
- okini3939
- Date:
- Mon Sep 02 08:16:11 2013 +0000
- Parent:
- 3:f8a105b2daf3
- Child:
- 5:d3b2ebcd5c25
- Commit message:
- fix library
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DMX.lib Mon Sep 02 08:16:11 2013 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/okini3939/code/DMX/#e687f321c428
--- a/DMX/DMX.cpp Fri Jun 03 13:20:01 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,136 +0,0 @@ -/* - * DMX512 send/recv library - * Copyright (c) 2011 Hiroshi Suga - * Released under the MIT License: http://mbed.org/license/mit - */ - -/** @file DMX.cpp - * @brief DMX512 send/recv - */ - -#include "mbed.h" -#include "DMX.h" - -DMX::DMX (PinName p_tx, PinName p_rx) : dmx(p_tx, p_rx) { - int i; - - for (i = 0; i < DMX_SIZE; i ++) { - data_tx[i] = 0; - data_rx[i] = 0; - } - mode_tx = DMX_MODE_BEGIN; - mode_rx = DMX_MODE_BEGIN; - - if (p_tx == p9) { - uart_lcr = &LPC_UART3->LCR; - } else - if (p_tx == p13) { - uart_lcr = &LPC_UART1->LCR; - } else - if (p_tx == p28) { - uart_lcr = &LPC_UART2->LCR; - } - if (p_rx == p10) { - uart_lsr = &LPC_UART3->LSR; - } else - if (p_rx == p14) { - uart_lsr = &LPC_UART1->LSR; - } else - if (p_rx == p27) { - uart_lsr = &LPC_UART2->LSR; - } - - dmx.baud(250000); - dmx.format(8, Serial::None, 2); - dmx.attach(this, &DMX::int_rx, Serial::RxIrq); - - timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_BETWEEN); -} - -void DMX::put (int ch, int data) { - data_tx[ch] = data; -} - -int DMX::get (int ch) { - return data_rx[ch]; -} - -void DMX::int_timer () { - - switch (mode_tx) { - case DMX_MODE_BEGIN: - // Break Time - timeout01.detach(); - *uart_lcr |= (1 << 6); - mode_tx = DMX_MODE_BREAK; - timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_BREAK); - break; - - case DMX_MODE_BREAK: - // Mark After Break - timeout01.detach(); - *uart_lcr &= ~(1 << 6); - mode_tx = DMX_MODE_MAB; - timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_MAB); - break; - - case DMX_MODE_MAB: - // Start code - timeout01.detach(); - addr_tx = 0; - mode_tx = DMX_MODE_DATA; - dmx.attach(this, &DMX::int_tx, Serial::TxIrq); - dmx.putc(0); - break; - } -} - -void DMX::int_tx () { - // Data - if (mode_tx == DMX_MODE_DATA) { - dmx.putc(data_tx[addr_tx]); - addr_tx ++; - - if (addr_tx >= DMX_SIZE) { - dmx.attach(0, Serial::TxIrq); - mode_tx = DMX_MODE_BEGIN; - timeout01.attach_us(this, &DMX::int_timer, DMX_TIME_BETWEEN); - } - } -} - -void DMX::int_rx () { - int flg, dat; - - flg = *uart_lsr; - dat = dmx.getc(); - - if (flg & (1 << 3) || flg & (1 << 4)) { - // Break Time - mode_rx = DMX_MODE_BREAK; - return; - } - - if (mode_rx == DMX_MODE_BREAK) { - - // Start Code - if (dat == 0) { - addr_rx = 0; - mode_rx = DMX_MODE_DATA; - } else { - mode_rx = DMX_MODE_ERROR; - } - - } else - if (mode_rx == DMX_MODE_DATA) { - - // Data - data_rx[addr_rx] = dat; - addr_rx ++; - - if (addr_rx >= DMX_SIZE) { - mode_rx = DMX_MODE_BEGIN; - } - } -} -
--- a/DMX/DMX.h Fri Jun 03 13:20:01 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,71 +0,0 @@ -/* - * DMX512 send/recv library - * Copyright (c) 2011 Hiroshi Suga - * Released under the MIT License: http://mbed.org/license/mit - */ - -/** @file DMX.h - * @brief DMX512 send/recv - */ - -#ifndef DMX_H -#define DMX_H - -#include "mbed.h" - -#define DMX_SIZE 512 -#define DMX_TIME_BREAK 100 // 100us -#define DMX_TIME_MAB 10 // 10us -#define DMX_TIME_BETWEEN 10 // 10us - -enum DMX_MODE { - DMX_MODE_BEGIN, - DMX_MODE_START, - DMX_MODE_BREAK, - DMX_MODE_MAB, - DMX_MODE_DATA, - DMX_MODE_ERROR, -}; - -/** DMX512 class (sender/client) - */ -class DMX { -public: - /** init DMX class - * @param p_tx TX serial port (p9, p13, p28) - * @param p_rx RX serial port (p10, p14, p27) - */ - DMX (PinName p_tx, PinName p_rx); - - /** Send the message - * @param ch DMX data address (0-511) - * @param data DMX data (0-255) - */ - void put (int ch, int data); - - /** Send the message - * @param ch DMX data address (0-511) - * @return DMX data (0-255) - */ - int get (int ch); - -protected: - - void int_timer (); - void int_tx (); - void int_rx (); - - Serial dmx; - Timeout timeout01; - __IO uint8_t *uart_lcr; - __I uint8_t *uart_lsr; - volatile DMX_MODE mode_tx, mode_rx; - volatile int addr_tx, addr_rx; - unsigned char data_tx[512]; - unsigned char data_rx[512]; - -private: - -}; - -#endif \ No newline at end of file
--- a/main.cpp Fri Jun 03 13:20:01 2011 +0000 +++ b/main.cpp Mon Sep 02 08:16:11 2013 +0000 @@ -12,29 +12,29 @@ int main() { int i, n; - // OUTPUT1: fade in / OUTPUT2: fade out - while(1) { - for (n = 0; n < 256; n ++) { - dmx1.put(0, n); - dmx2.put(0, 255 - n); - led_r = (float)n / 255; - led_y = (float)(255 - n) / 255; - wait(0.02); - } + dmx1.start(); + dmx2.start(); + + for (i = 0; i < 512; i ++) { + dmx1.put(i, i & 0xff); + dmx2.put(i, 255 - (i & 0xff)); } - -/* - // INPUT1 -> OUTPUT2 / INPUT2 -> OUTPUT1 - while (1) { + + while(1) { + n = 1; for (i = 0; i < 512; i ++) { - n = dmx1.get(i); - dmx2.put(i, n); - n = dmx2.get(i); - dmx1.put(i, n); + if (dmx1.get(i) != (i & 0xff)) { + n = 0; + } } - led_r = (float)dmx1.get(0) / 255; - led_y = (float)dmx2.get(0) / 255; - wait(0.1); + led_y = n; + + n = 1; + for (i = 0; i < 512; i ++) { + if (dmx2.get(i) != 255 - (i & 0xff)) { + n = 0; + } + } + led_r = n; } -*/ -} +} \ No newline at end of file
--- a/mbed.bld Fri Jun 03 13:20:01 2011 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912