Another version of a simple char driver (Using x86_64 VMware)

Once the module is Live, Use
HEAD -c {no.of.bytes} /dev/mycharDevice for read operation
echo “” > /dev/mycharDevice for write operation

#include <linux/init.h>
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <asm/uaccess.h>
#define DEVICE_NAME "mycharDevice"
#define CLASS_NAME "mycharClass"

MODULE_LICENSE("GPL");
MODULE_AUTHOR("PraveenMax");

//Function prototypes for file_op
static int device_open(struct inode *, struct file *);
static int device_close(struct inode *, struct file *);
static ssize_t device_read(struct file *, char *, size_t , loff_t *);
static ssize_t device_write(struct file *, const char *, size_t , loff_t *);

static struct file_operations my_fops={
	.owner = THIS_MODULE,
	.read  = device_read,
	.write = device_write,
	.open  = device_open,
	.release = device_close,
};	

//module variables
static struct class* mycharClass = NULL;
static struct device* mycharDevice = NULL;
static int majorNumber;

static char myBuffer[100]={0};
static short readPos=0;
static int times = 0;

static int device_open(struct inode *inode, struct file *filep)
{
	times++;
	printk(KERN_ALERT "MYCHARDEVICE Device opened %d times \n",times);
	return 0;
}

static int device_close(struct inode *inode, struct file *fileop)
{
	printk(KERN_ALERT "MYCHARDEVICE Device closed\n");
	return 0;
}

//Read len length of data from kernel buffer and stores in userbuffer "buff"
static ssize_t device_read(struct file *fileop, char *buff, size_t len, loff_t *f_pos)
{
	printk(KERN_ALERT "Reading from the device of Data length : %d \n", len);
	
	int bytesRead = 0;
	
	while(len>0)
	{
		//copies the kernel buffer "myBuffer" into userbuffer buff
		put_user(myBuffer[readPos++], buff++);
		len--;
		bytesRead++;
	}
	
	return bytesRead;
}

//Writes the data from userbuffer "buff" of length "len" into kernel buffer "msg"s
static ssize_t device_write(struct file *fileop, const char *buff, size_t len, loff_t *off)
{
	printk(KERN_ALERT "Writing to the device. Data length : %d \n", len);
	
	int bytesWritten = 0; //also acts as buffer index
	memset(myBuffer,0,100); //reset the buffer values
	readPos=0;//reset kernelbuffer pointer
	
	while(len >0)
	{
		myBuffer[bytesWritten] = buff[bytesWritten];
		bytesWritten++;
		len--;
	}

	return bytesWritten;
}
 
static int __init load_module(void)
{
	printk(KERN_ALERT "Mychardriver :: Loading the module \n");

	//Dynamically get the Major Number
	majorNumber = register_chrdev(0, DEVICE_NAME, &my_fops);

	if(majorNumber < 0)
	{
		printk(KERN_ALERT "*** Unable to register MYCHARDRIVER driver : %d\n", majorNumber);
		return majorNumber;
	}
	
	printk(KERN_ALERT "Obtained a Major number !\n");

	//Create a device class for my char driver (appears in /sys/class )
	mycharClass = class_create(THIS_MODULE, CLASS_NAME);
	if(IS_ERR(mycharClass))
	{
		unregister_chrdev(majorNumber, DEVICE_NAME);
		printk(KERN_ALERT "Failed to register the char device \n");
		return PTR_ERR(mycharClass);
	}
	printk(KERN_ALERT "Device class created successfully!\n");

	
	//Create the device node and register it (appears in /dev/DEVICE_NAME )
	mycharDevice = device_create(mycharClass, NULL, MKDEV(majorNumber,0), NULL, DEVICE_NAME);
	if(IS_ERR(mycharDevice))
	{
		class_destroy(mycharClass);
		unregister_chrdev(majorNumber, DEVICE_NAME);
		printk(KERN_ALERT "Failed the create Device node ! \n");
		return PTR_ERR(mycharDevice);
	}
	printk(KERN_ALERT "Device node created successfully ! \n");

	//some initializations
	memset(myBuffer,0,100); //reset the buffer values


 	return 0;
}

static void __exit unload_module(void)
{
	device_destroy(mycharClass, MKDEV(majorNumber, 0) );//destroy the device
	class_unregister(mycharClass);						 //Unregister the device class
	class_destroy(mycharClass); 						 //destroy the class
	unregister_chrdev(majorNumber, DEVICE_NAME);    	 //Unregister the major number
	printk(KERN_ALERT "MYCHARDRIVER Module exited!!\n");
} 

module_init(load_module);
module_exit(unload_module);

Dual Assault

It is an endless top-down shooter game.The main objective of the game is to prevent the enemies from capturing the territory. Made using Unity3d.

 

Learn Sheet music

 

screenshotscreenshot (1)

screenshot (2)

Game screenshot

 

Made this android application for understanding game programming for mobile devices mainly Android. Used the core android sdk with eclipse. This educational game is for people who want to learn basics of staff sheet music. The user has to tell the name of the note as it appears on different lines in the staff. Score is calculated based on the percentage of correct answers.

Download link   :   Sheet Music for Android

Learn Music Notes – Cheat sheet

Staff notes.

Staff notes.

Alien shooter : A HTML 5 game

This game is developed in HTML 5 using canvas and Javascript. The objective of the game is to shoot all the enemies. The enemies also shoot at the player. The background is scrolled in order to give a fast moving action feel. Sprites are self made.

 

introScreen

This is the main menu

 

 

Game screen

Game screen

Download : https://app.box.com/s/7ualzgwo88nuqf5720ha

Tic Tac Toe game in C++

This is a tic tac toe game made in C++. The game starts with player choosing the symbol O (letter) or X.

The A.I is pretty much basic.

screenshot

Download Link:

https://app.box.com/s/dwdcz3uwnd5qfafypjrp

Rooting Lava Xtron android tablet

WARNING : It worked for me but still, do at your our risk. 

Lava Xtron is the only cheapest android tablet which has performance equalling nexus 7.  See the flipkart link below for more details

http://www.flipkart.com/lava-e-tab-xtron-tablet/p/itmdgjwxm7zfpxwc?pid=TABDHVNGHZGHYNME&ref=e7fa0475-6e55-491a-a704-9565f7810e15&srno=t_1&otracker=from-search&query=lava%20xtron

But the problem is that you dont get usb drivers for connecting it to your windows pc. More worse for developers, since it is impossible to perform adb tasks, app debugging ,etc.

Just follow these steps to root your xtron tablet.

A . Getting USB drivers

1.First, we need usb drivers so that our device gets detected.Install Moborobo which is an software for managing your device sms,videos,pics,etc

http://www.moborobo.com/products/moborobo.html

2.After installing it, connect your tablet and wait for it check your device for downloading necessary drivers.

3.Once connected vid USB, you should be able to see your device files, sd-card size in the moborobo desktop application.

NOTE : In moborobo software, Device model of the tablet will not be shown when detected. Its just a bug.Ignore it.

B . Rooting the device

1. Download the software  ZhuoDaShi-2.2.0-setup.exe . Sometimes your antivirus might block this. Deal with them.

https://hotfile.com/dl/165309989/766c52f/ZhuoDaShi-2.2.0-setup.exe.html

2.Since it is a japanese/chinese software, you may see some crazy instrution text while installing. Follow the screenshots below…

Installcaption

Screen 1

Screen 2

Screen 2

Screen 3

Screen 3

Screen 4

Screen 4

Screen 5

Screen 5

Screen 6

Screen 6

Screen 7: Installation is done

Screen 7: Installation is done

Screen 8 : This is the main screen. Click the mentioned icon

Screen 8 : This is the main screen. Click the mentioned icon. My AV is sneeking around..:-/..dont mind it

Screen 9 : When clicked, an app is intalled and opened on your device. You dont need to select anything on your device screen. Just follow the desktop instructions

Screen 9 : When clicked, an app is intalled and opened on your device. You dont need to select anything on your device screen. Just follow the desktop instructions

Screen 10: Click  root. On the next screen, you will see the script in action.

Screen 10: Click root. On the next screen, you will see the script in action.

Screen 11: At last ,rooting is done.

Screen 11: At last ,rooting is done.

Go to Play and download any root checking software to confirm your root status. Thats it….

Update: This tablet is out of production(Incase, you are planning to buy :/ )

JFighter- A custom 2d Java Game Engine

This is a 2d fighting game that i made entirely using Java 6.Still incomplete.

Download it from the link below,

https://github.com/downloads/indiedev/JFighter/JFighter_2.7z

Controls:

X – Kick, Shift– change direction, Arrow Keys(as usual,movements)…..

Note: If the jar file is not opening on double-click, choose “Open with” and select “Java Platform(something similar)”.

Critics welcomed..

Bouncing ball with collision detection in Java

This program shows the same ball simulation with collision detection using “Rectangle” class of java.
Eg:-It works like this,
“r1.intersects(Rectangle r2)” method checks whether the r1 touches the r2.I have made special conditions for ball deflection based on the side it collides.

Class 1:Base Frame with some UI components

package ball_bounds;
import javax.swing.*;

import ball_bounds.canvas.ball;
import java.awt.*;
import java.awt.event.*;
public class base_frame extends JFrame implements ActionListener
{

	canvas draw_panel;
	JButton b_changebg,b_add,b_remove;
	JPanel ui_panel;
	base_frame()
	{
		super("Ball Bounds");

		//our UI panel which contains gui comps
		ui_panel=new JPanel();
		b_changebg=new JButton("Change Background");
		b_add=new JButton("Add");
		b_remove=new JButton("Remove");

		//add listeners
		b_changebg.addActionListener(this);
		b_add.addActionListener(this);
		b_remove.addActionListener(this);

		setLayout(new FlowLayout());
		draw_panel=new canvas();

		//adding to UI panel
		ui_panel.add(b_changebg);
		ui_panel.add(b_add);
		ui_panel.add(b_remove);

		//adding to our JFrame
		add(draw_panel);
		add(ui_panel);

		setSize(540,470);
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public static void main(String[] args)
	{
		new base_frame();
	}
	public void actionPerformed(ActionEvent ae)
	{
		if(ae.getSource()==b_changebg)
		{
				draw_panel.changeBGcolor();
		}
		else
		if(ae.getSource()==b_add)
		{
			//adds a ball of size 20;
			draw_panel.addBall(20);
			System.out.println("Added a ball");
		}
		else
		if(ae.getSource()==b_remove)
		{
				draw_panel.removeBall();
				System.out.println("Removed a ball");
		}
	}
}

Class 2:Our Drawing canvas

package ball_bounds;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class canvas extends JComponent implements KeyListener,MouseMotionListener
{
	//display details
	private final int width=512;
	private final int height=384;
	boolean bg_change=false;
	int color=254,incr=1;

	//a  ball array
	ArrayList ballarray;

	//my custom box
	My_box b1;

	canvas()
	{
		ballarray=new ArrayList(1);
		b1=new My_box(0,0,120,20);

		addKeyListener(this);
		addMouseMotionListener(this);

		setPreferredSize(new Dimension(width,height));
		setFocusable(true);
	}

	//change to background color dynamically(default:white)
	public void changeBGcolor()
	{
		if(bg_change)
		{
			bg_change=false;
		}
		else
		{
			bg_change=true;
		}
	}

	//add a new ball by passing a "ball" class instance
	public void addBall(int size)
	{
		//added to the arraylist
		ballarray.add(new ball(size));
	}

	public void removeBall()
	{
		if(!ballarray.isEmpty())
		{
			ballarray.remove(ballarray.size()-1);
		}
	}
	public int getBallCount()
	{
			return ballarray.size();
	}
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);

		//fill rect
		if(bg_change)
		{
			color=color-incr;

			 if(color<1)                         
                        {
                                    incr=-1;                         
                        }             
                         if(color>250)
			{
				incr=1;
			}
			g.setColor(new Color(color,color,color));
		}
		else
		{
			color=254;
			g.setColor(Color.WHITE);
		}
		g.fillRect(0,0,getWidth(),getHeight());

		//my box
		g.setColor(Color.BLACK);
		b1.drawBox(g);

		try{
			Thread.sleep(5);
			for(ball temp_ball:ballarray)
			{
				//drawing the ball using "drawBall(Graphics g,boolean)".
				//boolean is for displaying ball's bounding rectangle which deals with collision
				temp_ball.drawBall(g,false);

				//checking for collision with our movable pad
				temp_ball.collision(b1);
			}
			repaint();//calls the paint method

		}catch(Exception e)
		{
			System.out.println(e);
		}
	}

	//keyboard call-back methods
	public void keyPressed(KeyEvent ke)
	{
		if(ke.getKeyCode()==KeyEvent.VK_RIGHT)//increase x
		{

			b1.translate(10,0);
		}
		else
		if(ke.getKeyCode()==KeyEvent.VK_LEFT)
		{
			b1.translate(-10,0);
		}
       	}
	public void keyReleased(KeyEvent ke)
	{
	}
	public void keyTyped(KeyEvent ke)
	{

	}

	//mouse call-back methods

	public void mouseMoved(MouseEvent me)
	{
		//move the rectangle box too
		b1.setLocation(me.getX(),me.getY());
	}
	public void mouseDragged(MouseEvent me)
	{

	}

	//Ball inner-class
	class ball
	{
		private int x_pos=0;
		private int y_pos=0;
		private int dir_x=1;
		private int dir_y=1;
		private int size=0;

		ball(int size)
		{
			this.size=size;
		}

		private void calculate_direction()
		{
			//move the ball
			x_pos=x_pos-dir_x;
			y_pos=y_pos-dir_y;

			//for X-direction
			if(x_pos<0)
                        { 		       
                            x_pos=0; 	
          		    dir_x=-1;//incr   
                        }
                        else   
                       if(x_pos+size>getWidth())
			{
				 dir_x=1;//decr
			}

			//for Y-direction
			if(y_pos<0)  
                        {  
                                 y_pos=0;     
                             dir_y=-1;//incr                         

                        }                         
                         else                                            
                         if(y_pos+size>getHeight())
			{
				dir_y=1;//decr
			}
		}

		public void changeDirection_Y()
		{
             		if(dir_y==-1)
			{
				dir_y=1;
			}
			else
			{
				dir_y=-1;
			}
		}

		public void changeDirection_X()
		{
			if(dir_x==-1)
			{
				dir_x=1;
			}
			else
			{
				dir_x=-1;
			}
		}

		public void drawBall(Graphics g,boolean bound)
		{
			calculate_direction();
			g.setColor(Color.BLUE);
			g.fillOval(x_pos,y_pos,size,size);

			if(bound)
			{
				g.drawRect(x_pos,y_pos,size,size);
			}
		}

		public Rectangle getRectBounds()
		{
			return new Rectangle(x_pos,y_pos,size,size);
		}

                //this method is called for all balls and checked whether it touches the rect.if so,the ball's direction gets changed accordingly.
		public void collision(My_box rect)
		{
                           //if ball collides with top/bottom part of the rect
			if(this.getRectBounds().intersectsLine(rect.x,rect.y,rect.x+rect.width,rect.y) ||
                           this.getRectBounds().intersectsLine(rect.x,rect.y+rect.height, rect.x+rect.width,rect.y+rect.height))
			{

				changeDirection_Y();//reverses the direction along Y

			}

			  //if ball collides with left/right part of the rect
			if(this.getRectBounds().intersectsLine(rect.x,rect.y    ,    rect.x,rect.y+rect.height) ||
                           this.getRectBounds().intersectsLine(rect.x+rect.width,rect.y  ,   rect.x+rect.width,rect.y+rect.height))
			{
				changeDirection_X();//reverses the direction along X

			}

		}
	}
}

Class 3:Our “My_box ” class.
This class extends Rectangle class.It is written in separate class just for future scalability.nothing specific

package ball_bounds;
import java.awt.*;
import java.awt.event.*;
class My_box extends Rectangle
{
	//default vars
	/*
	 * x,y,width,height
	 */
	My_box(int x1,int y,int width,int height)
	{
		super(x1,y,width,height);
	}

	public void drawBox(Graphics g)
	{
		g.setColor(Color.BLACK);
		g.fillRect(x,y,width,height);
	}
}

This is the Screenshot

Screenshot:

Bouncing balls in Java Swing

This program displays several ball(more precisely “circles”) bouncing off the sides of the enclosing component.

Code 1:The JFrame class (Main window)

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class base_frame extends JFrame
{
	
	Container c;
	
	//our components
	JPanel b_panel;
	JButton b_add,b_sub;
	JLabel l_counter,l_ballsize;
	JTextField t_ballsize;
	
	//Actionlistener class instance
	handler handle;
	
	//class which contains drawing surface "JComponent"
	canvas ballcanvas;
	
	base_frame()
	{
		super("Ball Simulator");
		c=getContentPane();
		
		//setting to "flowlayout"
		c.setLayout(new FlowLayout());
		
		//all components
		t_ballsize=new JTextField(2);
		l_counter=new JLabel("Ball Count:  ");
		l_ballsize=new JLabel("Ball Size:  ");
		l_counter.setBorder(BorderFactory.createBevelBorder(1));
		b_add=new JButton("Add");
		b_sub=new JButton("Remove");
		handle=new handler();
		//adding actionlistener to buttons
		b_add.addActionListener(handle);
		b_sub.addActionListener(handle);
		
		//button panel 
		b_panel=new JPanel();//panel to hold buttons,textfields..
		b_panel.add(l_ballsize);//label
		b_panel.add(t_ballsize);//textfield to input ball size
		b_panel.add(b_add);//button to add a ball
		b_panel.add(b_sub);//button to del a ball (the most recent one)
		b_panel.add(l_counter);//label displaying total balls being rendered
		
		//ball canvas
		ballcanvas=new canvas(); 
		
		//container details
		c.add(ballcanvas);//adding drawing surface(ballcanvas) to main jframe
		c.add(b_panel);//adding the panel along with its smaller components
		
		//set visuals
		setSize(640,480);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setVisible(true);
	
	}
	public static void main(String[] args)
	{
		new base_frame();//creating main jframe instance
	}
	
	//an inner class to take care of button events
	class handler implements ActionListener
	{
		public void actionPerformed(ActionEvent ae)
		{
			//if "Add" button clicked
			if(ae.getSource()==b_add)
			{
				if(!t_ballsize.getText().equals(""))
				{
					
					try{
						ballcanvas.addBall(Integer.parseInt(t_ballsize.getText()));
						
						//updates the counter label
						l_counter.setText("Ball Count:"+ballcanvas.countBall());
					}catch(NumberFormatException e)
					{
						System.out.println(e);
						JOptionPane.showMessageDialog(null,"Enter only numbers!","Invalid Input",JOptionPane.INFORMATION_MESSAGE);
						
					}
					
				}
				else
				{
					JOptionPane.showMessageDialog(null,"Enter the ball size!","Input needed",JOptionPane.INFORMATION_MESSAGE);
				}
			}//b_add
			
			//if "Sub" button clicked
			if(ae.getSource()==b_sub)
			{
				ballcanvas.removeBall();
				//updates the counter label
				l_counter.setText("Ball Count:"+ballcanvas.countBall());
			}
		}
	}
}

Code 2:The drawing surface class .JComponent used

import java.awt.*;
import javax.swing.*;
import java.util.*;
public class canvas extends JComponent
{
	//display details	
	private final int width=512;
	private final int height=384;
	
	//ball array
	final private ArrayList<ball> ball_array;
	
	canvas()
	{
		ball_array=new ArrayList<ball>();
		
		setPreferredSize(new Dimension(width,height));
		setBorder(BorderFactory.createEtchedBorder(1));
	}
	
	public void paintComponent(Graphics g)
	{
		super.paintComponent(g);
		g.setColor(Color.BLACK);
		
		//fill rect
		g.fillRect(0,0,getWidth(),getHeight());
		try
		{
			//draw balls from ball_array
			for(int i=0;i<ball_array.size();i++)
			{
				ball_array.get(i).drawBall(g);
				//System.out.println("Drawing ball");
			}
			Thread.sleep(5);//to control animation speed

		}catch(InterruptedException e)
		{
			System.out.println("cannot control the paint thread!!");
		}
		repaint();//calls the paint method 
	}
	
	//to add a ball
	public void addBall(int size)
	{
		ball_array.add(new ball(size));
	}
	
	//to remove a ball
	public void removeBall()
	{
		if(!ball_array.isEmpty())
		{
			ball_array.remove(ball_array.size()-1);
		}
		
	}
	
	//return total balls from the array
	public int countBall()
	{
		return ball_array.size();
	}
	
	//Ball inner-class
	class ball
	{
		private int x_pos=0;
		private int y_pos=0;
		private int dir_x=1;
		private int dir_y=1;
		private int size;
		
		ball(int size)
		{
			this.size=size;
		}
		
		private void calculate_direction()
		{
			//move the ball
			x_pos=x_pos-dir_x;
			y_pos=y_pos-dir_y;
			
			//for X-direction
			if(x_pos<0)
			{
				x_pos=0;
				dir_x=-1;//incr
			}
			else
			if(x_pos+size>getWidth())
			{
				dir_x=1;//decr
			}
			
			//for Y-direction
			if(y_pos<0)
			{
				y_pos=0;
				dir_y=-1;//incr
			}else
			if(y_pos+size>getHeight())
			{
				dir_y=1;//decr
			}
		}
		
		public void drawBall(Graphics g)
		{
			calculate_direction();
			g.setColor(Color.WHITE);
			g.drawOval(x_pos,y_pos,size,size);
		}
	}
}

Download the jar file : Ball Simulate