Skip to content

Commit

Permalink
Add license, more C demo files, .gitignore and update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
maehw committed Jun 23, 2024
1 parent 02c26d5 commit 002cda5
Show file tree
Hide file tree
Showing 8 changed files with 703 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.lx
*.o
.depend

360 changes: 360 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
LIBDIR = /usr/lib/brickos
KERNEL = $(LIBDIR)/brickOS

PROGRAMS=helloworld.lx
PROGRAMS=helloworld.lx linetrack.lx robots.lx rover.lx sound.lx

# extra dynamic sources
DOBJECTS=
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# BrickOsTest
Testing brickOS

This repository contains some of the C programming language demo files of brickOS.

See also: https://sourceforge.net/projects/brickos/

113 changes: 113 additions & 0 deletions linetrack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*! \file linetrack.c
\brief A simple line tracker demo
\author Markus L. Noga <markus@noga.de>
A simple line tracker demo.
Lines are assumed to curve to the right, and initially encountered
from the right (for example, from the inside of the test pad).
Straight line tracking needs to define STRAIGHT_LINE.
Assumes motors on A,C, light sensors on port 2
*/

/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (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 legOS code, released October 17, 1999.
*
* The Initial Developer of the Original Code is Markus L. Noga.
* Portions created by Markus L. Noga are Copyright (C) 1999
* Markus L. Noga. All Rights Reserved.
*
* Contributor(s): Markus L. Noga <markus@noga.de>
*/

#include <config.h>
#if defined(CONF_DSENSOR) && defined(CONF_DMOTOR)

#include <conio.h>
#include <unistd.h>
#include <tm.h>

#include <dsensor.h>
#include <dmotor.h>

#define LIGHTSENS SENSOR_2
#define DARK_THRESH 0x40
#define BRIGHT_THRESH 0x48

#define NORMAL_SPEED (2*MAX_SPEED/3)
#define TURN_SPEED (MAX_SPEED)

// #define STRAIGHT_LINE


static wakeup_t dark_found(wakeup_t data) {
return LIGHT(LIGHTSENS)<(unsigned short)data;
}

static wakeup_t bright_found(wakeup_t data) {
return LIGHT(LIGHTSENS)>(unsigned short)data;
}

static void locate_line() {
motor_a_speed(NORMAL_SPEED);
motor_c_speed(NORMAL_SPEED);
motor_a_dir(fwd);
motor_c_dir(fwd);

wait_event(dark_found,DARK_THRESH);
}

static void follow_line() {
int dir=0;


while (!shutdown_requested()) {
motor_a_speed(NORMAL_SPEED);
motor_c_speed(NORMAL_SPEED);
motor_a_dir(fwd);
motor_c_dir(fwd);

if (wait_event(bright_found,BRIGHT_THRESH) != 0)
{
if(dir==0)
motor_a_dir(rev);
else
motor_c_dir(rev);
#ifdef STRAIGHT_LINE
dir=!dir;
#endif

motor_a_speed(TURN_SPEED);
motor_c_speed(TURN_SPEED);

wait_event(dark_found,DARK_THRESH);
}
}
}

int main(int argc, char *argv[]) {
ds_active(&LIGHTSENS);

locate_line();
follow_line();

return 0;
}
#else
#warning linetrack.c requires CONF_DSENSOR and CONF_DMOTOR
#warning linetrack demo will do nothing
int main(int argc, char *argv[]) {
return 0;
}
#endif // defined(CONF_DSENSOR) && defined(CONF_DMOTOR)
30 changes: 30 additions & 0 deletions robots.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Plays "wir sind die roboter" theme by Kraftwerk.

#include <config.h>
#if defined(CONF_DSOUND)

#include <dsound.h>
#include <tm.h>

//! "wir sind die roboter" theme by Kraftwerk
static const note_t robots[] = {
{ PITCH_D4, 2 } , { PITCH_C4, 1 } , { PITCH_D4, 1 },
{ PITCH_F4, 1 } , { PITCH_D4, 1 } , { PITCH_D4, 2 },
{ PITCH_F4, 2 } , { PITCH_G4, 1 } , { PITCH_C5, 1 },
{ PITCH_A4, 2 } , { PITCH_D4, 2 } , { PITCH_END, 0 }
};

int main(int argc,char *argv[]) {
while (!shutdown_requested()) {
if (wait_event(dsound_finished,0) != 0)
dsound_play(robots);
}
return 0;
}
#else // CONF_DSOUND
#warning robots.c requires CONF_DSOUND
#warning robots demo will do nothing
int main(int argc, char *argv[]) {
return 0;
}
#endif // CONF_DSOUND
107 changes: 107 additions & 0 deletions rover.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*! \file rover.c
\brief A simple rover demo
\author Markus L. Noga <markus@noga.de>
a simple rover that evades obstacles.
assumes motors on A,C, touch sensors on port 1,3
*/

/*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (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 legOS code, released October 17, 1999.
*
* The Initial Developer of the Original Code is Markus L. Noga.
* Portions created by Markus L. Noga are Copyright (C) 1999
* Markus L. Noga. All Rights Reserved.
*
* Contributor(s): Markus L. Noga <markus@noga.de>
*/

#include <config.h>
#if defined(CONF_DSENSOR) && defined(CONF_DMOTOR)

#include <conio.h>
#include <unistd.h>

#include <dsensor.h>
#include <dmotor.h>

#include <sys/lcd.h>
#include <tm.h>

///////////////////////////////////////////////////////////////////////////////
//
// Functions
//
///////////////////////////////////////////////////////////////////////////////

wakeup_t sensor_press_wakeup(wakeup_t data);

// the rover driver
//
int main(int argc, char *argv[]) {
int dir=0;

while (!shutdown_requested()) {
motor_a_speed(2*MAX_SPEED/3); // go!
motor_c_speed(2*MAX_SPEED/3);

motor_a_dir(fwd);
motor_c_dir(fwd);

cputs("fwwd ");

if (wait_event(&sensor_press_wakeup, 0) != 0) {
if(SENSOR_1<0xf000) // keep in mind.
dir=0;
else
dir=1;

// back up
//
motor_a_dir(rev);
motor_c_dir(rev);

cputs("rev ");

msleep(500);

motor_a_speed(MAX_SPEED); // go!
motor_c_speed(MAX_SPEED);

if(dir==1) {
motor_c_dir(fwd);
cputs("left ");
} else {
motor_a_dir(fwd);
cputs("right");
}

msleep(500);
}
}

return 0;
}

wakeup_t sensor_press_wakeup(wakeup_t data) {
lcd_refresh();
return (SENSOR_1<0xf000) || (SENSOR_3<0xf000);
}

#else
#warning rover.c requires CONF_DMOTOR and CONF_DSENSOR
#warning rover demo will do nothing
int main(int argc, char *argv[]) {
return 0;
}
#endif // CONF_DSENSOR, CONF_DMOTOR
83 changes: 83 additions & 0 deletions sound.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*sound.c*/

#include <config.h>
#if defined(CONF_DSOUND)
#include <dsound.h>
#include <tm.h>

/*array of notes that make up the refrain*/
/*of Devil with a Blue Dress*/

static const note_t devil[] = {
{ PITCH_G4, QUARTER },
{ PITCH_G4, QUARTER },
{ PITCH_G4, QUARTER },
{ PITCH_G4, QUARTER },
{ PITCH_G4, HALF },
{ PITCH_G4, HALF },

{ PITCH_G4, HALF },
{ PITCH_G4, HALF },
{ PITCH_G4, HALF },
{ PITCH_G4, HALF },

{ PITCH_F4, QUARTER },
{ PITCH_F4, QUARTER },
{ PITCH_F4, QUARTER },
{ PITCH_F4, QUARTER },
{ PITCH_F4, HALF },
{ PITCH_F4, HALF },

{ PITCH_F4, HALF },
{ PITCH_PAUSE, HALF },
{ PITCH_PAUSE, HALF },
{ PITCH_PAUSE, HALF },

{ PITCH_E4, QUARTER },
{ PITCH_E4, QUARTER },
{ PITCH_E4, QUARTER },
{ PITCH_E4, QUARTER },
{ PITCH_F4, HALF },
{ PITCH_F4, HALF },

{ PITCH_E4, HALF },
{ PITCH_E4, HALF },
{ PITCH_F4, HALF },
{ PITCH_F4, HALF },

{ PITCH_E4, QUARTER },
{ PITCH_E4, QUARTER },
{ PITCH_E4, QUARTER },
{ PITCH_E4, QUARTER },
{ PITCH_F4, HALF },
{ PITCH_F4, HALF },

{ PITCH_E4, HALF },
{ PITCH_PAUSE, HALF },
{ PITCH_PAUSE, HALF },
{ PITCH_PAUSE, HALF },
{ PITCH_END, 0 }
};

int main(int argc,char *argv[]) {

/*The default makes this a really, really slow song*/
/*So, we speed it up a little bit.*/
dsound_set_duration(40);

/*now, we play it*/
while (!shutdown_requested()) {
if (wait_event(dsound_finished,0) != 0)
dsound_play(devil);
sleep(1);
}

return 0;
}
#else
#warning sound.c requires CONF_DSOUND which is not set
#warning sound demo will do nothing
int main(int argc, char *argv[]) {
return 0;
}
#endif // CONF_DSOUND

0 comments on commit 002cda5

Please sign in to comment.