Saturday, May 22, 2010

Nano-X window system

Recently I have worked in Linux environment with a great NanoX project
It is about 300k size. NanoX provide solution for timer support, windows management, user input.

To use Nano-X you need only gcc c/c++ compiler that it is included in many(most) Linux systems

Architecture:




Features:
- message based system
- small size
- simple API
- add/replace any keyboard/mouse/screen driver
- font support. It is possible to add Unicode TrueType fonts

Lets discuss how to use it:

To create nano-X window you need :


#include  "nano-x.h"
  
int main(int argv, char[][] argv)
{
   GR_WINDOW_ID wnd = 
     GrNewWindow( GR_ROOT_WINDOW_ID
                  , 0,0,100,100
                  , WINDOW_NO_BORDER
                  , FOREGROUND_COLOR
                  , BLACKGROUND_COLOR); // create a window

   gc = GrNewGC(); // create a graphic context


   //select events. you are able to select 
   //only that events that you need. this will boost your application  
   GrSelectEvents( wnd, GR_EVENT_MASK_ALL); 


   GrMapWindow( wnd ); // show window


   // you may create as many windows as you wish
   // there is only one message queue for all Nano-X windows


   GR_EVENT anEvent;
   while (true)
   {
     GrCheckNextEvent(&anEvent);
     if (anEvent.type == GR_EVENT_TYPE_NONE )
     {
       sleep(1); 
       continue;
     }
     if (HandleEvent(anEvent) == NEED_TO_EXIT) break; 
   }
   // close all handles and exit
   GrUnmapWindow(wnd); // hide window
   GrDestroyGC( gc ); //
   GrDestroyWindow( wnd ); 

}

Now you might understand nano-x weak side: 

  • Messages might not be synchronized. ( for example when you kill window but some messages that was in queue might come)
  • Timer messages might not work proper under some circumstances  (for example when you create a timer event, then change time in your system) 
  • Pure focus management (for example you can use GrSetFocus() then destroy window and then GrGetFocus() doesn't return you focus to a parent window like it is in MS Window OS,
  • Font support is available but you have to dig into sources to add it. 

Saturday, April 10, 2010

iPhone SDK

Yesterday, I start investigating IPhone SDK
there are few links that may help to start developing

MAC OS reference library SDK and framework

Objective C /C/C++  compiler for windows platform

Sunday, March 28, 2010

Yii framework

Not so long time ago I have learned php5 Yii framework
It is quite simple and well documented MVC  framework
I like it!

So why I think it will be popular?
because it is easy to use.. and it is free
Here is  few the most important features for me

Localization 
first of all I pay attention to frameworks localization
only one static function  

Yii::t("section", "string")

Security
It is very important to have only one entry point for all user requests
in this case you can wrap this entry with security patterns and framework itself already did it for you

All requests have the same entry for example


http://mysite.com/index.php?r=action&...

of cause you are able to create more attractive requests like


http://mysite.com/home/livingroom
http://mysite.com/2010/09/01/school

there is a trick.. all this urls redirect your request to one php file. remove php file entry name like "index.php" is done using .htaccess or if you are able to configure apache yourself it is could be done in *.conf file

Database
You are able to request data  from database even if you don't know sql and even if you are not sure what database is installed on you web server. I mean code that Yii framework produces is working with any sql database platform (MySQL, PostageSQL, SQLite or other PDO php extention. 
As results of the request it returns associative array and all other low-level stuff framework hides inside.

Widgets and Components
Widgets is a way to reuse you code - very powerful thing

I am not going to describe all Yii features, there is a manual for that

Friday, March 19, 2010

Android Streaming Audio

Android audio framework

I will try to explain as detailed as possible about streaming audio in android. For this purposes in SDK 1.5 has been added AudioRecord and AudioTrack classes. AudioRecord is responsible to get samples from microphone and AudioTrack is responsible for playback samples.

This classes works only with PCM encoded data (it means that they are not encoded at all :)

Examples:
Play one buffer loop

Initialzation

AudioRecord record = null;
AudioTrack track = null;
 
record = new AudioRecord(MediaRecorder.AudioSource.MIC, 8000,
  AudioFormat.CHANNEL_CONFIGURATION_MONO,
  AudioFormat.ENCODING_PCM_16BIT, 
    AudioRecord.getMinBufferSize(8000, AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT) * 4
  );

log.d("AudioTrack min buffer size: "
+ AudioTrack.getMinBufferSize(8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT));

track = new AudioTrack(AudioManager.STREAM_VOICE_CALL, 8000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, AUDIO_SYSTEM_BUFFER_SIZE, AudioTrack.MODE_STREAM);
 
Initialization is quite simple. All you have to do is to create AudioRecord and AudioTrack

Start audio player
track.play();


Start audio recorder

record.startRecording(); 

Main Loop 
while (needMoreAudioData)
{
     recorder.read(buffer, bufferSize);
     player.write(buffer, bufferSize);


Stop audio player/recorder
track.stop();
record.stop(); 

Remove player
Because this objects works with system resources developer has to release them when they are not in use. Java garbage collector will not release them automatically because instances hold system handlers.
 
track.release();
record.release();


Hope you have got the idea ...

Now few practical tips

When you call  record.startRecording();  recording is already started! and to reduce latency you have to read that data immediately.

You should realize that android is not a real-time operating system and often call backs come not exactly at certain. You will end-up with increased latency over time unless you apply a sort of throttling algorithm to adjust playback side.

Wednesday, March 25, 2009

Sintral IDE

Hello All,
I decided to delay all my own projects and ideas to finish Sintral IDE project

this is a program for STOLL knitting machine. From the first glance it looks like very simple VB language but also it is quite specific.
I've start this project for all old STOLL machines. they are still working bug they didn't have support by vendors. Software for them was created in 80-90s. Once I was able to see STOLL program for windows 95.

My friend ask me started this project... and I agreed :)

Features that are already done:

  • - BMP to TXT image converter
  • - TXT to BMP converter
  • - Sintral highlighter
  • - export to MS Word
  • - Pack/Unpack big Jackards
  • - Line, Rectangle, Normal selection
  • - Renumeration lines
  • - Syntax check
  • - STOLL communication via com port (read, write, erase)
  • - Language pack (russian, english)
  • - Add/remove external tools in programs menu
  • - Users help
I've translated all sources to Delphi 2009 Unicode version
Also I remove 3rd party component UniHighlighter and wrote a plugin component for UniSyn to highlight a sin language. I could not compile UniHighlighter in 30 minutes so I decided to drop this component down and remove from future using.
If you are the one who needs this application, please contact me over email or send me request here

Saturday, January 31, 2009

Canon A540 camera problem

Hi there

I'd like to talk about files...

I have a camera Canon A540 and when I get files to PC, they have name like img_XXXX.jpg

this is bad name for image because there is no information in the name. It doesn't contain when and where the photo was taken.

Other problem occurs when I try to remove some small defects (red ayes for example) I am losing last modification date and then I don't know when the photo was taken

If my camera is more smart I won't have this problem

So I decided to create a console application for changing file name. And the main task was to add date, time and prefix to filename. Sure I understand that if I change filename the last file  modification date would be changed. So I add a file description to do reverse operation if there is a need.


Finally I have finished the program. It was not difficult to implement but I have no free time for that game.

So about program:

NameChanger - if you need one just mail me

You should use program with arguments:

-r - recursive search in sub-folders

-d -t - rename fonded file and insert date and time in file name

-pimg - insert prefix img in file name so all you files will start from this prefix. it is convinient when you just download photos from camera and wanted a prefix (for example: my_summer_holidays )

-ejpg - rename files only with jpg extension

-iimg - ignore files started with "img"

So in general you could use this command tool like bellow:

NameChanger.exe -d -t -r -pparty -ejpg


I have used it and noticed that some files have the same file modify date and time. In this case NameChanger add a letter to the resulted name. For example if you have three files with the same date and time then you will have 

summer_2009_06_01_13_27_10.jpg

summer_2009_06_01_13_27_10A.jpg

summer_2009_06_01_13_27_10B.jpg


Friday, October 31, 2008

Windows Mobile API ToolBar

Today I'd like to make some suggestion about CCommandBar class for Windows Mobile 5.0.
You can use MFC menu wrapper class or you can use Windows WINAPI function to get access to the ToolBar


MFC class CCommandBar class has no API to access to menu items and doesn't know how to control the menu. After a brief investigation and experiments with the menu I have got a working code:
 TBBUTTON tbb;
 ::SendMessage(m_oCommandBar.GetSafeHwnd(),     TB_GETBUTTON, 1, (LPARAM)&tbb);
 HMENU hMenu=HMENU(tbb.dwData);
 if(hMenu)
 {
     ::DeleteMenu(hMenu,0,MF_BYPOSITION);

     ::InsertMenu(hMenu,0,MF_BYPOSITION, ID_MENU_FR_SHOWDETAILS, L"Show Details");
 }


Here m_oCommandBar is an instance of CCommandBar. By using windows messages you can access to WINAPI menu and create a dynamic menus :-)