Jump to content

force Function - generel app.c NewBee Questions (LPC17) Triggering Events in other Functions


Phatline
 Share

Recommended Posts

hello can give me someone a littel C instruction...

i dont write my code here, because its 2000 lines long.... it is more a generell newbe question then something specific --- i think its a standart knowhow

that i just have to know, to do more complex progamms... anyway:

 

my APP has following Midibox -standart-functions:

void APP_Init(void){}
void APP_Tick(void){}//counts DECAY Timings, and do with that NOTE-OFF Handling
void APP_Background(Void){}
void APP_MIDI_NotifyPackage(mios32void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package){}//do Note-ON-Handling, MidiInCC
void APP_SRIO_ServicePrepare(void){}//filling the 8x8 LED-Matrix
void APP_SRIO_ServiceFinish(void)}//nothing
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value)}//All Buttons, and Virtual Matrix Buttons
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer)}//Menue Encoders
void APP_AIN_NotifyChange(u32 pin, u32 pin_value)}//4 Potis
void BUTTON_NotifyToggle(u8 row, u8 column, u8 pin_value, u32 timestamp){}//nothing....

with the MidiBox Buttons that are connectet to the DIN-Modules --- I am in the "DIN_Notifiy" Lo and HIs:

I do there most things that happens only one time: when i hit a button - something happens - up to an end, where nothing happens... everthing runs perfect in this closed box, I am happy like a childe with a blinking led speaking robot, and aslong i dont need a time counter like and DECAY-Time it is serial and very logical (for me)...

 

I run into problems when I want to Remote this APP extra via "Midi_Notify" -like an footboard (MB Buttons and Midi Note On/OFFs controll the some Code):

- problems? >  many code strings are locatet in the DIN_Notify, from Midi-Notify I dont have access to the DIN --- in Din there must be Triggerd something... else nothing is happening there....

 

So my idea was: Is there a way to force, fake, call from MidiNotify to DinNotify? >>> MidiNoteOn comes in >>> fake Din Pin HI, >>> MidiNoteOff Comes in >>> fake Din Pin LO Event??? like "force pin = 32, pin_value =1"

 

away of that serial processing of triggers (without program loop) i found also loops here "App_Tick" and "App_Background" --- so i run into a world that is not mine... not mine in the past...

so tried a workaround, by puting my CODE-Strings (Calculations) under the "APP_Tick" Function,

and manage-ing the DIN and Midi HI and LOs --- by working with "Done 0" "Done 1" Flags...to avoid endless triggers on code blocks (each ms)

but with that i get so much flags, unbelieveable... @the end off the program there is something and in top this and 2000 lines between others.... mindfuck...

and @ the end of day the machine does anything but not that what i want off... (maybe because there is so much code...)

Bevore this workaround, i used this TICK only for LCD-Menue & for the Decay-Time for the NoteOFF Events (Note On I do in the Midi-Notify Tread)

 

I come from max msp, and all there is TRIGGER, that triggers this and that, and after a serial way of happenings the code ends... --- so  I like that "Midi or DIN trigger a event" very much... for me its logical...

that Din and Midi Events in differnt Treads/Functions cracks my head --- help please.

 

michi

 

 

 

Link to comment
Share on other sites

Hi!

 

I'm not sure if I understand your problem correctly, but it seems like a general code design problem?

 

If I understand well, you have things that should happen when there's a Midi notify or a button press? A simple way to handle this is simply putting the code that does something outside the MIOS call back :

void doSomething(u32 value) {
 // put your code here
}

void APP_MIDI_NotifyPackage(mios32void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package){
  if(/*condition*/) {
    doSomething(1); // or doSomething(0)
  }
}

#define doSomethingButton 4 /* for example */
void APP_DIN_NotifyToggle(u32 pin, u32 pin_value) {
  if(pin == doSomethingButton) {
    doSomething(pin_value);
  }
}

 

Now for the problem with flag (it's a "common" problem, I still see a lots of code with flags every where, and when you want to modify to do something, it does everything but not what you want it to do!). There are several way to handle this. A good one (but it can be tricky to implement sometimes) is the state pattern. Instead of having flags and then testing flags, you replace those by on or more states.

States can be function in C, and then you keep a pointer to the current state function, which will do what it should when the app is in this state.

I don't have a good example to show this, but if you want to post your code, I can take time to look at it if you want.

Edited by pilo
Link to comment
Share on other sites

yes you understand enough... because the answer is 1A

a self written function which is called from both DIN and Midi!!!

 

@ flag and state.... the word state is enough i youtube this...thx

 

@ take a look on this... i make it more readable the next days - and then 2000lines here

Link to comment
Share on other sites

I built with your help something like an router...so i merge DIN and Midi to my Function where now almost everthing is... stripped down this it is:

#include <mios32.h>
#include "app.h"
#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>

u8 CCinPort = 33;
u8 CCInChn  = Chn9;

//Function "Router" Variables
u32 Cc = 0;
u32 Cc_value = 0;
u32 port = 0;

void APP_Init(void){} 

void Router(u32 port, u32 Cc, u32 Cc_value) {
MIOS32_LCD_Clear();         // clear screen
MIOS32_LCD_CursorSet(0, 0); // X,Y FIRST LINE
MIOS32_LCD_PrintFormattedString("%d %d %d", port, Cc, Cc_value); //Ports are Midi=0 and Din=1
}
void APP_Tick(void) {}
void APP_Background(void){}

void APP_MIDI_NotifyPackage(mios32_midi_port_t port, mios32_midi_package_t midi_package){
	if((port == CCinPort) && (midi_package.chn == CCInChn) && (midi_package.type == NoteOn))
	{Router(0, midi_package.note, midi_package.velocity);}}
	
void APP_SRIO_ServicePrepare(void){}
void APP_SRIO_ServiceFinish(void){} //called after the shift register chain has been scanned

void APP_DIN_NotifyToggle(u32 pin, u32 pin_value){
	if(pin < 256) {Router(1, pin, pin_value);}} //
	
void APP_ENC_NotifyChange(u32 encoder, s32 incrementer){}
void APP_AIN_NotifyChange(u32 pin, u32 pin_value){}
void BUTTON_NotifyToggle(u8 row, u8 column, u8 pin_value, u32 timestamp){}
Edited by Phatline
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...