-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
869 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
# LDCC | ||
DCC for the Lego MindStorms RCX | ||
|
||
Links | ||
----- | ||
* [DCC for the RCX](http://home.surewest.net/markril/lego/dcc/) | ||
* [Beta Zone: DCC for the RCX](http://home.surewest.net/markril/lego/dcc/beta.html) | ||
* [LDCC and RCX](http://news.lugnet.com/org/us/indylug/?n=618) | ||
* [DCC and Lego Robotics Creations](http://folk.uio.no/thomasw/robotics/creations.html) | ||
* [DCC on LeJOS](http://news.lugnet.com/robotics/rcx/legos/?n=3959) | ||
* [LeJOS Support for LDCC IR Protocol](http://news.lugnet.com/robotics/rcx/java/?n=259&t=i&v=a) | ||
* [LGauge DCC](http://www.lgauge.com/trains/dcc/dcc.htm) | ||
* [Dr. Vegetable’s Full Throttle App](http://www.drvegetable.com/download_throttle.html) | ||
* [pbForth with DCC Support](http://news.lugnet.com/robotics/rcx/?n=2297) | ||
* [LDCC Patch for BrickOS](http://news.lugnet.com/org/ca/rtltoronto/?n=14996) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/****************************************************************************** | ||
Author : Mark Riley | ||
File : ldcc_lnp.c | ||
Created : 6/29/2003 | ||
Purpose : Demonstration of BrickOS to LDCC comms using LNP | ||
******************************************************************************/ | ||
|
||
#include <unistd.h> | ||
#include <dsensor.h> | ||
#include <lnp.h> | ||
|
||
/****************************************************************************** | ||
LDCC Declarations & Functions | ||
******************************************************************************/ | ||
|
||
enum | ||
{ | ||
LDCC_CMD_SPEED = 1, | ||
LDCC_CMD_FN_OFF, | ||
LDCC_CMD_FN_ON, | ||
LDCC_CMD_STOP_ALL, | ||
LDCC_CMD_POWER_OFF, | ||
LDCC_CMD_POWER_ON, | ||
LDCC_CMD_SWITCH_CLOSED, | ||
LDCC_CMD_SWITCH_THROWN | ||
}; | ||
|
||
unsigned char g_packet[8]; | ||
|
||
#define LDCC_REPEAT 3 | ||
|
||
void ldcc_send_packet(unsigned char length, char times) | ||
{ | ||
for ( ; times; times--) | ||
lnp_addressing_write(g_packet, length, 0x11, 0x01); | ||
} | ||
|
||
void ldcc_power(int state) | ||
{ | ||
g_packet[0] = state ? LDCC_CMD_POWER_ON : LDCC_CMD_POWER_OFF; | ||
ldcc_send_packet(1, LDCC_REPEAT); | ||
} | ||
|
||
void ldcc_stop_all() | ||
{ | ||
g_packet[0] = LDCC_CMD_STOP_ALL; | ||
ldcc_send_packet(1, LDCC_REPEAT); | ||
} | ||
|
||
void ldcc_speed(char loco, int speed) | ||
{ | ||
g_packet[0] = LDCC_CMD_SPEED; | ||
g_packet[1] = loco; | ||
g_packet[2] = speed >> 8; | ||
g_packet[3] = speed & 0xFF; | ||
ldcc_send_packet(4, 1); | ||
} | ||
|
||
void ldcc_function(char loco, char fn, int state) | ||
{ | ||
g_packet[0] = state ? LDCC_CMD_FN_ON : LDCC_CMD_FN_OFF; | ||
g_packet[1] = loco; | ||
g_packet[2] = fn; | ||
ldcc_send_packet(3, 1); | ||
} | ||
|
||
/****************************************************************************** | ||
Demo | ||
******************************************************************************/ | ||
|
||
#define MAX_ANGLE 48 | ||
#define LOCO 3 | ||
|
||
int main() | ||
{ | ||
int angle = 0; | ||
int last_angle = -1; | ||
char state = 0; | ||
char headlight = 0; | ||
char headlight_repeat = LDCC_REPEAT; | ||
char speed_repeat = LDCC_REPEAT; | ||
int time; | ||
|
||
ds_active(&SENSOR_3); | ||
ds_rotation_on(&SENSOR_3); | ||
ds_rotation_set(&SENSOR_3, 0); | ||
|
||
ldcc_power(1); | ||
|
||
while (!shutdown_requested()) | ||
{ | ||
switch (state) | ||
{ | ||
case 1: | ||
if (SENSOR_3 >= 0x4000) | ||
{ // button released, toggle headlight; | ||
headlight = !headlight; | ||
headlight_repeat = LDCC_REPEAT; | ||
state = 0; | ||
} | ||
else | ||
{ // button still held down | ||
if (time - (int)get_system_up_time() <= 0) | ||
{ // 1/4 second elapsed, stop loco | ||
ds_rotation_set(&SENSOR_3, 0); | ||
angle = 0; | ||
speed_repeat = LDCC_REPEAT; | ||
state = 2; | ||
} | ||
} | ||
break; | ||
|
||
case 2: | ||
if (SENSOR_3 >= 0x4000) | ||
// button released, resume | ||
state = 0; | ||
break; | ||
|
||
default: | ||
if (SENSOR_3 >= 0x4000) | ||
{ // no button pressed, normal throttle operation | ||
angle = ROTATION_3; | ||
|
||
if (angle < -MAX_ANGLE) | ||
angle = -MAX_ANGLE; | ||
else if (angle > MAX_ANGLE) | ||
angle = MAX_ANGLE; | ||
|
||
if (angle != last_angle) | ||
{ | ||
last_angle = angle; | ||
speed_repeat = LDCC_REPEAT; | ||
} | ||
} | ||
else | ||
{ // button pressed | ||
time = (int)get_system_up_time() + 250; // 1/4 second | ||
state = 1; | ||
} | ||
break; | ||
} | ||
|
||
if (speed_repeat) | ||
{ | ||
speed_repeat--; | ||
ldcc_speed(LOCO, ((long)angle << 14) / MAX_ANGLE); | ||
} | ||
|
||
if (headlight_repeat) | ||
{ | ||
headlight_repeat--; | ||
ldcc_function(LOCO, 0, headlight); | ||
} | ||
|
||
// so the man will run... | ||
msleep(1); | ||
} | ||
|
||
ldcc_power(0); | ||
|
||
ds_rotation_off(&SENSOR_3); | ||
ds_passive(&SENSOR_3); | ||
|
||
return 0; | ||
} | ||
|
||
// EOF // |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/****************************************************************************** | ||
The contents of this file are subject to the Mozilla Public License | ||
Version 1.1 (the "License"); you may not use this file except in | ||
compliance with the License. You may obtain a copy of the License at | ||
http://www.mozilla.org/MPL/ | ||
Software distributed under the License is distributed on an "AS IS" | ||
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See | ||
the License for the specific language governing rights and limitations | ||
under the License. | ||
The Original Code is DCC Library for the RCX. | ||
The Initial Developer of the Original Code is Mark Riley. Portions | ||
created by Mark Riley are Copyright (C) 2003 Mark Riley. All Rights | ||
Reserved. | ||
File : dccdemo.c | ||
Created : 6/12/2003 | ||
Purpose : DCC demonstration program for DCC library | ||
******************************************************************************/ | ||
|
||
#include <unistd.h> | ||
#include <dmotor.h> | ||
#include <dsensor.h> | ||
#include <dcc.h> | ||
|
||
#define MASK (MOTOR_A_MASK | MOTOR_B_MASK | MOTOR_C_MASK) | ||
|
||
#define MAX_ANGLE 48 | ||
|
||
#define ADDR 3 | ||
|
||
// state of decoder functions FL through F4 | ||
unsigned char funcs = 0; | ||
|
||
int main() | ||
{ | ||
unsigned char old_dm_mask = dm_mask; | ||
int angle = 0; | ||
char state = 0; | ||
int time; | ||
|
||
dm_mask &= ~MASK; | ||
dcc_mask = MASK; | ||
|
||
ds_active(&SENSOR_3); | ||
ds_rotation_on(&SENSOR_3); | ||
ds_rotation_set(&SENSOR_3, 0); | ||
|
||
dcc_power_on(); | ||
|
||
while (!shutdown_requested()) | ||
{ | ||
switch (state) | ||
{ | ||
case 1: | ||
if (SENSOR_3 >= 0x4000) | ||
{ // button released, toggle headlight; | ||
funcs ^= DCC_FL; | ||
state = 0; | ||
} | ||
else | ||
{ // button still held down | ||
if (time - (int)get_system_up_time() <= 0) | ||
{ // 1/4 second elapsed, stop loco | ||
angle = 0; | ||
ds_rotation_set(&SENSOR_3, 0); | ||
state = 2; | ||
} | ||
} | ||
break; | ||
|
||
case 2: | ||
if (SENSOR_3 >= 0x4000) | ||
// button released, resume | ||
state = 0; | ||
break; | ||
|
||
default: | ||
if (SENSOR_3 >= 0x4000) | ||
{ // no button pressed, normal throttle operation | ||
angle = ROTATION_3; | ||
|
||
if (angle < -MAX_ANGLE) | ||
angle = -MAX_ANGLE; | ||
else if (angle > MAX_ANGLE) | ||
angle = MAX_ANGLE; | ||
} | ||
else | ||
{ // button pressed | ||
time = (int)get_system_up_time() + 250; // 1/4 second | ||
state = 1; | ||
} | ||
break; | ||
} | ||
|
||
//dcc_speed14(ADDR, angle * 14 / MAX_ANGLE, funcs & DCC_FL); | ||
//dcc_speed28(ADDR, angle * 28 / MAX_ANGLE); | ||
dcc_speed126(ADDR, angle * 126 / MAX_ANGLE); | ||
|
||
dcc_idle(); | ||
dcc_idle(); | ||
|
||
dcc_FL_F4(ADDR, funcs); | ||
|
||
dcc_idle(); | ||
dcc_idle(); | ||
} | ||
|
||
dcc_power_off(); | ||
|
||
ds_rotation_off(&SENSOR_3); | ||
ds_passive(&SENSOR_3); | ||
|
||
dm_mask = old_dm_mask; | ||
|
||
return 0; | ||
} | ||
|
||
// EOF // |
Oops, something went wrong.