From: Lawrence S. <ljs...@us...> - 2013-05-17 22:26:34
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 7442dc8a291c94d0ee20d615567d9d32c89af6cb (commit) from 6cdb72360ed29a9043c38f06747623ce4037c669 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 7442dc8a291c94d0ee20d615567d9d32c89af6cb Author: Lawrence Sebald <ljs...@us...> Date: Fri May 17 18:26:08 2013 -0400 Add example program using fs_ext2 to copy Dreameye images to. ----------------------------------------------------------------------- Summary of changes: examples/dreamcast/dreameye/Makefile | 3 + .../{basic/stacktrace => dreameye/sd}/Makefile | 15 +- examples/dreamcast/dreameye/sd/dreameye-sd.c | 143 ++++++++++++++++++++ 3 files changed, 154 insertions(+), 7 deletions(-) copy examples/dreamcast/{basic/stacktrace => dreameye/sd}/Makefile (50%) create mode 100644 examples/dreamcast/dreameye/sd/dreameye-sd.c diff --git a/examples/dreamcast/dreameye/Makefile b/examples/dreamcast/dreameye/Makefile index c072d23..826dd38 100644 --- a/examples/dreamcast/dreameye/Makefile +++ b/examples/dreamcast/dreameye/Makefile @@ -6,10 +6,13 @@ all: $(KOS_MAKE) -C basic + $(KOS_MAKE) -C sd clean: $(KOS_MAKE) -C basic clean + $(KOS_MAKE) -C sd clean dist: $(KOS_MAKE) -C basic dist + $(KOS_MAKE) -C sd dist diff --git a/examples/dreamcast/basic/stacktrace/Makefile b/examples/dreamcast/dreameye/sd/Makefile similarity index 50% copy from examples/dreamcast/basic/stacktrace/Makefile copy to examples/dreamcast/dreameye/sd/Makefile index 00c04ae..5f2ca60 100644 --- a/examples/dreamcast/basic/stacktrace/Makefile +++ b/examples/dreamcast/dreameye/sd/Makefile @@ -1,10 +1,13 @@ +# KallistiOS ##version## # -# Stack trace test -# (c)2002 Dan Potter +# examples/dreamcast/dreameye/sd/Makefile # -TARGET = stacktrace.elf -OBJS = stacktrace.o +TARGET = dreameye-sd.elf +OBJS = dreameye-sd.o + +# Compile cleanly, or die trying! +KOS_CFLAGS += -Werror -W -std=gnu99 all: rm-elf $(TARGET) @@ -17,8 +20,7 @@ rm-elf: -rm -f $(TARGET) $(TARGET): $(OBJS) - $(KOS_CC) $(KOS_CFLAGS) $(KOS_LDFLAGS) -o $(TARGET) $(KOS_START) \ - $(OBJS) $(OBJEXTRA) $(KOS_LIBS) + kos-cc -o $(TARGET) $(OBJS) -lkosext2fs run: $(TARGET) $(KOS_LOADER) $(TARGET) @@ -26,4 +28,3 @@ run: $(TARGET) dist: rm -f $(OBJS) $(KOS_STRIP) $(TARGET) - diff --git a/examples/dreamcast/dreameye/sd/dreameye-sd.c b/examples/dreamcast/dreameye/sd/dreameye-sd.c new file mode 100644 index 0000000..bfe4bc8 --- /dev/null +++ b/examples/dreamcast/dreameye/sd/dreameye-sd.c @@ -0,0 +1,143 @@ +/* KallistiOS ##version## + + dreameye-sd.c + Copyright (C) 2013 Lawrence Sebald + + This example simply dumps all the images on the first connected Dreameye to + the SD card. It creates a new directory and saves the images in it. +*/ + +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include <dirent.h> + +#include <dc/sd.h> +#include <kos/blockdev.h> +#include <ext2/fs_ext2.h> +#include <dc/maple.h> +#include <dc/maple/dreameye.h> +#include <kos/dbgio.h> + +int main(int argc, char *argv[]) { + maple_device_t *dreameye; + dreameye_state_t *state; + uint8 *buf; + int size, err; + FILE *fp; + int img_count, i; + char fn[64]; + kos_blockdev_t sd_dev; + uint8 partition_type; + + /* We're not using these, obviously... */ + (void)argc; + (void)argv; + + /* Comment this out if you'd rather that debug output went to dcload. Of + course, you'll need to be using dcload-ip, but you should have already + known that. ;-) */ + //dbgio_dev_select("fb"); + + printf("KallistiOS Dreameye Image Dump program\n"); + printf("Attempting to find a connected Dreameye device...\n"); + + dreameye = maple_enum_type(0, MAPLE_FUNC_CAMERA); + + if(!dreameye) { + printf("Couldn't find any attached devices, bailing out.\n"); + exit(EXIT_FAILURE); + } + + state = (dreameye_state_t *)maple_dev_status(dreameye); + + printf("Attempting to grab the number of saved images...\n"); + dreameye_get_image_count(dreameye, 1); + + printf("Image Count is %s -- (%d)\n", + state->image_count_valid ? "valid" : "invalid", state->image_count); + img_count = state->image_count; + + /* Initialize the low-level SD card stuff. */ + if(sd_init()) { + printf("Could not initialize the SD card. Please make sure that you " + "have an SD card adapter plugged in and an SD card inserted.\n"); + exit(EXIT_FAILURE); + } + + /* Grab the block device for the first partition on the SD card. Note that + you must have the SD card formatted with an MBR partitioning scheme. */ + if(sd_blockdev_for_partition(0, &sd_dev, &partition_type)) { + printf("Could not find the first partition on the SD card!\n"); + exit(EXIT_FAILURE); + } + + /* Check to see if the MBR says that we have a Linux partition. */ + if(partition_type != 0x83) { + printf("MBR indicates a non-ext2 filesystem. Will try to mount " + "anyway\n"); + } + + /* Initialize fs_ext2 and attempt to mount the device. */ + if(fs_ext2_init()) { + printf("Could not initialize fs_ext2!\n"); + exit(EXIT_FAILURE); + } + + if(fs_ext2_mount("/sd", &sd_dev, FS_EXT2_MOUNT_READWRITE)) { + printf("Could not mount SD card as ext2fs. Please make sure the card " + "has been properly formatted.\n"); + exit(EXIT_FAILURE); + } + + /* Try to make a "dreameye" directory on the root of the card and move to + the new directory. */ + if(mkdir("/sd/dreameye", 0777)) { + printf("Cannot create a dreameye directory: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + + if(chdir("/sd/dreameye")) { + printf("Cannot set current working directory: %s\n", strerror(errno)); + exit(EXIT_FAILURE); + } + + for(i = 0; i < img_count; ++i) { + printf("Reading image %d...\n", i + 1); + err = dreameye_get_image(dreameye, i + 2, &buf, &size); + + if(err != MAPLE_EOK) { + printf("Error was: %d\n", err); + free(buf); + continue; + } + + printf("Image received successfully, size %d bytes\n", size); + sprintf(fn, "image%02d.jpg", i + 1); + + if(!(fp = fopen(fn, "wb"))) { + printf("Cannot open /sd/dreameye/%s: %s\n", fn, strerror(errno)); + free(buf); + continue; + } + + if(fwrite(buf, 1, size, fp) != (size_t)size) { + printf("Cannot write image to file: %s\n", strerror(errno)); + free(buf); + fclose(fp); + continue; + } + + fclose(fp); + free(buf); + } + + /* Clean up the filesystem and everything else */ + fs_ext2_unmount("/sd"); + fs_ext2_shutdown(); + sd_shutdown(); + + printf("Complete!\n"); + return 0; +} hooks/post-receive -- A pseudo Operating System for the Dreamcast. |