Quote of an Undetermined Amount of Time

"In science there is only physics; all the rest is stamp collecting."

- Ernest Rutherford

Recent site activity

Home


AnimatedEuler144



Hey, what's up?
If you're seeing this site, you most likely heard about its existence via word of mouth from its creator, ats3117, aka Drew (That's me, in case you didn't know), or some other means.

Basically, I write programs and tutorials and post them here for the fun of it all. It's also a useful tool when I don't have a jump drive with my latest programs on it to show to other people.

So, with all of that being said, you're probably wondering what kind of stuff I program. I write whatever comes to my mind, something usually inspires me to make it, and so I try to make it with my limited programming ability. For all of you people out there who know about computers/programming, I'm familiar with a few languages like C/C++ and Lua (on the PSP). I've done some simple things in other languages like FORTRAN and Perl, but I'm not familiar with them quite yet to start making anything decent with them.

As far as platforms/targets, I've coded mostly for Command-line interfaces on Windows Machines. I've done a few things with a multimedia/video game library for C++ called Allegro (kudos goes to Matt for telling/showing me it).

I began programming on the PSP after I learned how to hack it, leading me to my first programming language, Lua for PSP. From there, I moved to C and C++, and now here I am with a large collection of a bunch of pretty much useless programs in various languages.

So, wilkommen (welcome), and check out my updates below and my downloads page here or at the top of the page.

Laptop LCD Brightness Reading

posted Jul 24, 2010 7:58 PM by Drew Steinacher   [ updated Jul 24, 2010 8:27 PM ]

Hello! I haven't been on here in a while because I graduated high school, and did all sorts of stuff. It's been busy. I've completed several projects which I have yet to release on this site, including the Snell's Law simulator, and maybe a few more applications.

To sum things up, I've recently begun to program using Microsoft Visual C++. It is AMAZING. It was difficult to use at first, but I feel more like a professional software developer now that I have a full-blown debugger, automatic code completion, and several other things (like Static Linking!!! Say bye-bye to those blasted DLL's...). 

Also, I was working on FORTRAN 77 again, and I wrote several physics functions such as every possible combination of the Kinematics Equations. I might talk about it on here later, I don't know if I'll have time before I go to college.

So anyways, I had a crazy idea. I wanted to write a battery monitoring program that would be (mostly) invisible to the user, and that idea was really hard. I finally got it working, and its current version is 0.999. I'm scared to make it 1.00 yet.
I kept adding features to it, and the biggest feature I wanted to have was to be able to monitor the brightness of the LCD Backlight. After LOADS of searching on the internet, I found a few ways this could be done, but the documentation wasn't clear or it was just way over my head. I don't like Windows API stuff because of all of the funny data types like DWORD, UCHAR, and WCHAR arrays. By the way, wide characters suck. Dealing with them is such a pain. I wish everything could just be ANSI compliant and you didn't have to use char arrays. I'd prefer to just do everything in strings, because they're so easy to use. But that's off-topic.

So I did a lot of searching, and I finally found an example that wasn't working completely yet to get the available brightness levels. I had to play with this for a long while, but I finally got it. I made it into my own GetBrightness() function that returns an integer that is a percent.

Here's some simplified code that will do the job and make it easy if you need it:

-----------------------

#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <strsafe.h>

using namespace std;

typedef struct _DISPLAY_BRIGHTNESS {
    UCHAR ucDisplayPolicy; 
    UCHAR ucACBrightness; 
    UCHAR ucDCBrightness;
} DISPLAY_BRIGHTNESS, *PDISPLAY_BRIGHTNESS;

#define IOCTL_VIDEO_QUERY_SUPPORTED_BRIGHTNESS \
    CTL_CODE(FILE_DEVICE_VIDEO, 0x125, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS \
    CTL_CODE(FILE_DEVICE_VIDEO, 0x126, METHOD_BUFFERED, FILE_ANY_ACCESS)

int Brightness;

void ErrorExit(LPTSTR lpszFunction);
int GetBrightness();



int main(void)
{
cout << "Press a button to check what brightness setting you're on." << endl;

while (1) {
    Brightness = GetBrightness(); // This does magic here

cout << "Brightness = " << Brightness << "%" << endl;
_getch();
} // ends while

    return 0;
}

void ErrorExit(LPTSTR lpszFunction) 
    // Retrieve the system error message for the last-error code

    LPVOID lpMsgBuf;
    LPVOID lpDisplayBuf;
    DWORD dw = GetLastError(); 

    FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM |
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        dw,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMsgBuf,
        0, NULL );

    // Display the error message and exit the process

    lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, 
        (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR)); 
    StringCchPrintf((LPTSTR)lpDisplayBuf, 
        LocalSize(lpDisplayBuf) / sizeof(TCHAR),
        TEXT("%s failed with error %d: %s"), 
        lpszFunction, dw, lpMsgBuf); 
    MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK); 

    LocalFree(lpMsgBuf);
    LocalFree(lpDisplayBuf);
    ExitProcess(dw); 
}

int GetBrightness() {
//This function should be labled "magic"

DWORD dwError;
    HANDLE hDevice;
    hDevice = CreateFile(TEXT("\\\\.\\LCD"),       // open LCD device
                        GENERIC_READ,            // no access to the drive
                        FILE_SHARE_READ|
                        FILE_SHARE_WRITE,     // share mode
                        NULL,                                  // default security attributes
                        OPEN_EXISTING,             // disposition
                        0,                                          // file attributes
                        NULL);                                 

   
    if (hDevice == INVALID_HANDLE_VALUE) 
    {
        dwError = GetLastError();
        printf("error(%d): CreateFile\n", dwError);
        exit(-1);
    }

    DISPLAY_BRIGHTNESS DisplayBrightness;
    DWORD  nOutBufferSize=sizeof(DisplayBrightness);
    DWORD  nBytesReturned;

    int nRes = DeviceIoControl(
        (HANDLE) hDevice,                                                                // handle to device
        IOCTL_VIDEO_QUERY_DISPLAY_BRIGHTNESS,  // dwIoControlCode
        NULL,                                                                                        // lpInBuffer
        0,                                                                                                // nInBufferSize
        (LPVOID) &DisplayBrightness,                                           // output buffer
        sizeof(&DisplayBrightness),                                                // size of output buffer
        (LPDWORD) &nBytesReturned,                                            // bytes returned
        NULL                                                                                         // OVERLAPPED
        );

if (nRes == 0) {
ErrorExit(TEXT("DeviceIoControl"));
}
else {
//cout << "Result = " << nRes << endl;
//printf("AC: %d\n", DisplayBrightness.ucACBrightness);
//printf("DC: %d\n", DisplayBrightness.ucDCBrightness);
}

dwError = GetLastError();
    CloseHandle(hDevice);

return DisplayBrightness.ucACBrightness;
}

-----------------------


So yeah, it's kinda complex, but it should work. You don't always need to know *how* it works, you just need to know that it *does* work.

I kinda get the idea behind it, but making it work in the syntax is the hardest part. I probably should have started in easier languages like Visual Basic or C#, because I found several useful things in just about every language besides C++.

I mainly wanted to post this code so other people might be able to use it to do whatever they want with it. I know it would have been helpful to have when I was looking to make it work. Hopefully it helps someone. 

Edit: I realize that it works on my HP Pavilion (dv6), and may not work on ALL laptops. But at least it's a start if you can't get it to work.

In the next few days, I hope to release v1.00 of my Battery and System Monitor. Keep an eye out if I do...

Mouse support and a few useful apps...

posted Apr 17, 2010 7:57 PM by Drew Steinacher   [ updated Apr 18, 2010 12:11 PM ]

So I finally got a whole bunch of ideas about a week ago, and now that I've given up on doing my homework for a little while, I started on a few of those ideas. I wound up completing a few them, and so I'm gonna release them.

First up is a simple resistance and capacitance calculator. It supports both parallel and series combinations. And yes, I know it only does a single parallel circuit, not nested circuits and most definitely not series-parallel combinations. That'd be tough to pull off. Maybe I'll do that in the future.



But for now, it works pretty decently. Play around with the input to find some interesting results. (Try letters, just don't stare too close to the screen.)



Seeing how useful my Vector Calculator that added up vectors was, I decided I'd make some functions that would take vectors and break them down into components, and vice versa. It didn't take long at all, and now it's ready to port to Allegro if I ever have the need for it.



It's pretty simple, but very useful. I can support both degrees and radians for the angle.




Finally, and probably the most impressive thing I did over this weekend is figuring out Mouse support in Allegro. It wasn't too hard, but it was pretty rewarding.



Upon learning this new feat, I came up with a system of using the mouse for on-screen buttons to modify variables in my code. It was a tad confusing, but I think it'll be pretty useful in the future.

In the picture below, left-clicking on the red box increases X by one, and right-clicking decreases it by one.
Left-clicking the large green box turns the "Clicked!" message on, whereas right clicking on it turns it off.



So yeah, that pretty much does it. My next hope is to begin writing a demonstration of Snell's Law with allegro and my newly learned Mouse Abilities.

Hopefully I'll get to work on that soon.

Downloads for all are here.

Happy Coding!

4-17-10

--Drew

Allegro II: My Return to Visual Programing...

posted Jan 23, 2010 1:22 PM by Drew Steinacher

Okay, so it's been a while since I've uploaded anything. Lately, I've restarted on writing programs in Allegro, and I finally figured out how to get button input done correctly. Also, it doesn't randomly crash anymore.
So, since I finally got a stable dev-environment, I decided to start over with visual programming. So now, I'm releasing two programs that I've been working on for several weeks now.

First up is the inspiration to start over: A simple polygon screen saver.



Basically, I had the idea to draw a rectangle and have the corners bounce around the screen (al a Lua Balls, Wii Balls, or Pong without paddles).
So I started with that idea, and that idea turned into fixing my Allegro environment, and I finally got somewhere on it. I was very pleased. 
Then the rectangle idea turned into using a really neat (and useful) function in the Allegro library: polygon(). 
It draws a polygon based on the verticies you give it, which you put in an array (Verticies are like corners, for those of you who don't know geometry).
So, that led me to find a way to recognize odd and even numbered things in the array to figure out which was the X coordinate or Y coordinate. It was kind of a fun--yet pretty simple--challenge.

It allows up to 28 verticies (And that looks pretty trippy). The color changes too, I randomized a whole bunch of stuff involving that and the speed of corners when they collide with the "walls" of the screen.

Sometimes, if you're lucky and patient (and you have 5 verticies), you'll wind up with a star like this (for a split second):




It can support almost any resolution, widescreen (16:9) or 4:3. It defaults to an 800x600 window, but you can change all of that by using the command line (or a batch file):

Polygon <screenwidth> <screenheight> <Fullscreen?>     // Fullscreen is optional, 1 for on, 0 for windowed
Polygon.exe 1024 768 1 // This would be 1024x768, Fullscreen
Polygon.exe 640 480      // This would be 640x480, windowed

The best setting to watch it is in fullscreen, and I included a batch file that will set it up for 1024x768 fullscreen. Just double click on "fullscreen.cmd".

Next is another idea that spawned from having a working visual development envirnonment: Tic Tac Toe.



Although it's a simple game, this program is nearly 800 lines of code. It also has support for both widescreen (16:9) and 4:3 resolutions.
It has a command-line main menu to adjust video settings and launch the game. 

You just follow the on-screen instructions, and you should be able to figure it out. The arrow keys allow you to move your piece around the board, and the Enter key will place your piece on the board.
If there's a piece already there, then you'll have to pick another spot, though. It's pretty straight-forward.

It keeps track of score and the colors of the text and board change depending on who's turn it is, or who won.

AI (Artificial Intelligence) is another cool thing I added. There are two modes: Easy and Hard.
Easy means exactly that: It has the intelligence of a chicken. It knows no strategy, and only picks a random place on the board.
Hard, however, isn't really all that hard. It does recognize when you have 2 pieces in a row, and attempts to stop you, but it's still pretty beatable.
Some good strategies to beat it are to play an "up-and-down" , a "left-right-middle", or "top-right-to-lower-left-diagonal" strategy. It only picks up on "left-to-right" and "right-to-left" strategies.

So, hopefully you won't lose too many times to it. I've lost countless times trying to debug it (even to the easy chicken).

Note: On occasion, the Hard AI player doesn't always make a move when it should. I have noticed this, but I can't reproduce the bug consistently. If you come across this, let me know and I'll get to it ASAP.

The game is not only for 1 player, it is 2-player compatible. Just hit A to toggle AI, and then X and O use the same controls during their respective turns.

Well, that's about it. To run any of these, you will need the "alleg42.dll" file in the same directory as the .exe file is. Otherwise, it will complain. All of my Allegro apps will be bundled with the DLL, but if you lose it, it's not working or anything else, you can always re-dowload the program or DLL here on this site.

Again, if you have any questions, comments, concerns, hate-mail, etc., don't hesitate to E-mail me.

Thanks again! Happy coding!

Download them here: Apps

1-23-10
--Drew

Foil - A Simple Binomial Foiler

posted Jan 2, 2010 12:49 PM by Drew Steinacher

Hello all, I just released a very picky piece of code today. It's a simple program that foils two binomials.
For example, if you put in the first binomial as...

(2x+3y)

...and the 2nd one as...

(3x+4y)

...your foiled output would be...

6xx + 8xy + 9yx + 12yy

..which is pretty crude, but it's the best I could do for now.

The answer really should be 6x^2 + 17xy + 12 y^2, but I'm not willing to try to add support for adding like terms and simplification.

I'm not sure I want to add anything else, because how difficult it is to play with strings and prepare for every possible method of input. I'm just not that good at messing with strings.

Anyways, it works only when you follow the syntax:

1. You must have an opening parenthesis "(" at the beginning of each binomial
2. You must use only single letter variables, like x and y. Other letters work too.
3. All constants/coefficients must be positive integers. No decimals, no negatives or zeros.
4. Variables cannot be raised to a power.

And I think that's all. If you don't follow the syntax, you will get interesting results. And your answer will more than likely be completely wrong.
Don't blame me if it's wrong, it's not supposed to be 110% perfect anyways. There are a lot of bugs in it.

So, I think that does it. If you have questions, comments, concerns, ideas, hate mail, just let me know by hitting up my e-mail on the left side of the page.

Download is here on the Apps Page, under the C++ folder as Foil.

Delta_t - Time differences made easy...

posted Dec 6, 2009 1:51 PM by Drew Steinacher

Well, I just wrote and released a pretty simple but somewhat useful program today. I was trying to calculate the time I had worked at our craft fair for Band service hours, and I wanted to see how long I had worked. I'm pretty slow at these calculations, and so I really have to think it through. I immediately thought that I could write a program to do that, and so I did.

Well, that just about does it. If you want to try it out, just head to the apps page by clicking on the "Apps" link at the left of the page. It's under the "C++" folder. It's Delta_t.zip.

And yes, I'm a physics geek for calling it "Delta_t". Physics FTW!

--Drew, 12-6-09

Lawn Mower is Up

posted Nov 15, 2009 9:58 AM by Drew Steinacher

I uploaded my lawn mowing app today. It's not that great, and I haven't worked on it in a long time, but I uploaded it anyways.

Hope you like it!

Download is on this page, under Lua (PSP): Apps

Unit Converter Beta 1

posted Sep 13, 2009 4:43 PM by Drew Steinacher   [ updated Sep 13, 2009 5:00 PM ]

Hi everybody! I just finished adding some final touches to my beta of my Unit Converter. You can download it here.

It pretty much does what its name implies: it converts units. When you start the program, it'll ask you what kind of stuff you want to convert, like mass, speed, time, length, etc. After that, you can choose which units you are converting to and from. It's pretty simple, just follow the on-screen instructions and you should be fine. If you want to add any more units, please let me know via any means. My e-mail address is on the left of the page, under the "Navigation" pane. Also let me know if you find any bugs, errors, have any suggestions for future versions, inconsistencies in what a unit should be, etc.

I plan on updating this again at some point, so don't expect this to be finished forever. I hope to add argument support, so you can just type... 

convert 450 paperclips to grams

...on the command-line and have it return the correct answer. (Which is about 207 grams, BTW)

Other than that, I'm working on a simple 2-player pong game for the Wii, with support for both Wiimotes and GC controllers. If you have ideas for that too, let me know.

I'm also still looking for people who would like to help me with writing code that will determine the prime numbers of a given number. I've had a little bit of luck, but I've run into several problems. Any help would be appreciated. 

Sorry for such a long post, but hey, I haven't been on here for a while.

later
9-13-09

Edit: Damn tyops...

Fibonacci Sequence Generator

posted Aug 16, 2009 2:39 PM by Drew Steinacher   [ updated Aug 16, 2009 2:37 PM ]

Hi! I just made a simple program that generates the Fibonacci Sequence. For those of you who don't know what that is, check this
out.

I have my own little explanation of it in the documentation, so I'll just let you download it and see for yourself how that works.

I'll see how soon I get done with my next project, which might be a unit converter for almost everything I can think of. It shouldn't be too hard, just time consuming.
Also, if anyone who sees this would like to help me come up with a program that will break apart numbers into prime factors, please let me know if you can help (ats3117 [at] hughes <dot> net). I tried that earlier today, and I didn't have a good place to start. (Part of the problem is I'm not a mathematician kind of person.)

Anyways, happy coding!

Text to Morse Converter completed!

posted Aug 1, 2009 6:19 PM by Drew Steinacher

I just finished making my Text to Morse converter better than it was before. 

You can download it in the Apps file cabinet here.

I'll leave all of the details in the Readme, but I'll outline a few things here:

I added a configuration file so you don't have to use arguments and it makes it much easier to change settings and preferences.

Among the things you can change in the file are frequency (the pitch of the beeps), if beeping is on, the speed at which the program beeps, file input and output settings, and skipping of required button presses.

Oh yeah, it does have full compatibility for my newest program, the Morse to Text Converter. Unfortunately, it's not quite as good as I want it to be yet, so I won't be releasing a beta for it. Sorry. But, if you would like to beta test it or see it in its unfinished state, just let me know.

And I will notify people who might care when it does get released.

So yeah, that does it. Again, if you have any questions, comments, concerns, hate mail, etc, please don't hesitate to contact me at ats3117 <at> hughes [dot] net. Or any other mode of communication.

Later!
8-1-09

Restructuring Complete!!! (At least for now...)

posted Jul 24, 2009 4:22 PM by Drew

Okay, I think all of the changes are finished after I put a link to the Apps page on the home page... 

1-10 of 11