Last active
March 13, 2021 18:24
-
-
Save madskjeldgaard/117e9ee328641aae10b5493a94f7efe2 to your computer and use it in GitHub Desktop.
Project generator script (UNIX) for the Daisy Seed platform
This file contains hidden or 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
#! /usr/bin/bash | |
TARGET_DIR=/home/mads/code/mcu | |
PROJECT_NAME="$1" | |
PROJECT_NAME_LOWER=$(echo ${PROJECT_NAME} | awk '{ print tolower($0) }') | |
PROJECT_DIR=$TARGET_DIR/$PROJECT_NAME | |
function init(){ | |
if [[ -z "$PROJECT_NAME" ]]; then | |
echo "No project name supplied" | |
echo "Usage: daisyproject <projectname>" | |
exit 1 | |
fi | |
mkdir $PROJECT_DIR; cd $PROJECT_DIR && \ | |
git init && \ | |
create_cpp_file && \ | |
create_makefile && \ | |
download_and_add_libs | |
} | |
function download_and_add_libs(){ | |
git submodule add https://github.com/electro-smith/DaisySP | |
git submodule add https://github.com/electro-smith/libDaisy | |
echo "building DaisySP . . ." | |
cd "DaisySP" ; make clean ; make | grep "warning:r\|error" ; | |
echo "done." | |
cd ../libDaisy | |
echo "building libDaisy . . ." | |
make clean ; make | grep "warning:r\|error" ; | |
echo "done." | |
} | |
function create_cpp_file(){ | |
echo "#include \"daisysp.h\" | |
#include \"daisy_patch.h\" | |
#include <string> | |
using namespace daisy; | |
using namespace daisysp; | |
DaisyPatch patch; | |
Parameter pot1, pot2, pot3, pot4; | |
static void AudioCallback(float **in, float **out, size_t size) | |
{ | |
patch.ProcessAnalogControls(); | |
for(size_t i = 0; i < size; i++) | |
{ | |
for (size_t chn = 0; chn < 4; chn++) { | |
/* out[chn][i] = sig; */ | |
} | |
} | |
} | |
void greeting() { | |
// briefly display module name | |
std::string str = "Hello..."; | |
char *cstr = &str[0]; | |
patch.display.WriteString(cstr, Font_7x10, true); | |
patch.display.Update(); | |
patch.DelayMs(500); | |
} | |
int main(void) | |
{ | |
float samplerate; | |
patch.Init(); // Initialize hardware (daisy seed, and patch) | |
samplerate = patch.AudioSampleRate(); | |
// Initialize potentiometers | |
pot1.Init(patch.controls[patch.CTRL_1], 0.0, 1.0f, Parameter::LINEAR); | |
pot2.Init(patch.controls[patch.CTRL_2], 0.0f, 1.0f, Parameter::LINEAR); | |
pot3.Init(patch.controls[patch.CTRL_3], 0.0f, 1.0f, Parameter::LINEAR); | |
pot4.Init(patch.controls[patch.CTRL_4], 0.0f, 1.0f, Parameter::LINEAR); | |
// Start adc and audio | |
patch.StartAdc(); | |
patch.StartAudio(AudioCallback); | |
// Display greeting | |
greeting(); | |
while(1) | |
{ | |
patch.DisplayControls(false); | |
} | |
} | |
" > main.cpp | |
} | |
function create_makefile(){ | |
echo "# Project Name | |
TARGET = ${PROJECT_NAME} | |
# Sources | |
CPP_SOURCES = main.cpp | |
# Library Locations | |
LIBDAISY_DIR = libDaisy | |
DAISYSP_DIR = DaisySP | |
# Core location, and generic Makefile. | |
SYSTEM_FILES_DIR = \$(LIBDAISY_DIR)/core | |
include \$(SYSTEM_FILES_DIR)/Makefile | |
" > Makefile | |
} | |
init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment